Ծանուցում. Հիշելուց հետո կատարված փոփոխությունները տեսնելու համար մաքրեք ձեր զննարկիչի հիշապահեստը. Mozilla / Firefox / Safari՝ Ctrl+Shift+R (Cmd+Shift+R Mac OS X-ում) Konqueror՝ F5 Opera՝ Tools→Preferences ընտրացանկից։ Internet Explorer՝ Ctrl+F5

/**
 * Created by Admin on 18.02.14.
 */

// DRAGS function copied from http://css-tricks.com/snippets/jquery/draggable-without-jquery-ui/
(function($) {
	$.fn.drags = function(opt) {

		opt = $.extend({handle:"",cursor:"move"}, opt);

		if(opt.handle === "") {
			var $el = this;
		} else {
			var $el = this.find(opt.handle);
		}

		return $el.css('cursor', opt.cursor).on("mousedown", function(e) {
			if(opt.handle === "") {
				var $drag = $(this).addClass('draggable');
			} else {
				var $drag = $(this).addClass('active-handle').parent().addClass('draggable');
			}
			var z_idx = $drag.css('z-index'),
					drg_h = $drag.outerHeight(),
					drg_w = $drag.outerWidth(),
					pos_y = $drag.offset().top + drg_h - e.pageY,
					pos_x = $drag.offset().left + drg_w - e.pageX;
			$drag.css('z-index', 1000).parents().on("mousemove", function(e) {
				$('.draggable').offset({
					top:e.pageY + pos_y - drg_h,
					left:e.pageX + pos_x - drg_w
				}).on("mouseup", function() {
					$(this).removeClass('draggable').css('z-index', z_idx);
				});
			});
			e.preventDefault(); // disable selection
		}).on("mouseup", function() {
			if(opt.handle === "") {
				$(this).removeClass('draggable');
			} else {
				$(this).removeClass('active-handle').parent().removeClass('draggable');
			}
		});

	}
})(jQuery);

$.when(
				$.getScript("/w/index.php?title=User:HrantKhachatrian/morebits.js&action=raw&ctype=text/javascript"),
				$.getScript("/w/index.php?title=User:HGayane/GetNameDescrFromInfoBox.js&action=raw&ctype=text/javascript"),
				$.getScript("/w/index.php?title=User:Mariamarutunian/getDatesFromInfoBox.js&action=raw&ctype=text/javascript"),
				$.getScript("/w/index.php?title=User:ATaguhi/getDatesFromArticleText.js&action=raw&ctype=text/javascript"),
				$.getScript("/w/index.php?title=User:MariamMarti/GetNameDescriptionFromArticleText.js&action=raw&ctype=text/javascript"),
				$.getScript("/w/index.php?title=User:HGayane/GetDatePageText.js&action=raw&ctype=text/javascript"),
				$.getScript("/w/index.php?title=User:HGayane/GetYearPage.js&action=raw&ctype=text/javascript"),
				$.getScript("/w/index.php?title=User:SaroMarkosyan/checkPersonExists.js&action=raw&ctype=text/javascript"),
				$.getScript("/w/index.php?title=User:Tik-ionut/add person.js&action=raw&ctype=text/javascript"),
				$.Deferred(function (deferred) {
					$(deferred.resolve);
				})
		).done(
		function () {
			var htmlAdd=' <div style="position: absolute; top: 40px; left: 100px; display: block;background: white;border: 5px black solid;border-radius:15px;padding: 5px 10px 10px 10px;z-index:100;"><p class="head"><input type="button" name="close" id="Close_button" value="Փակել" position="right"></p><div id="birth_day"><p>Կատարե՞լ փոփոխություն ծննդյան օրվա էջում:</p><p> <textarea  rows="20" cols="66" id="wiki_text_B_D"></textarea></p><p> <input type="button" name="save_b_d" id="Save_button_B_D" value="Այո" ></p></div> <div id="birth_year"><p>Կատարե՞լ փոփոխություն ծննդյան տարվա էջում:</p> <p> <textarea rows="20" cols="66" id="wiki_text_B_Y"></textarea></p><p><input type="button" name="save_b_y" id="Save_button_B_Y" value="Այո"></p></div><div id="death_day"><p>Կատարե՞լ փոփոխություն մահվան օրվա էջում:</p> <p> <textarea rows="20" cols="66" id="wiki_text_D_D"></textarea></p> <p> <input type="button" name="save_b_d" id="Save_button_D_D" value="Այո"></p></div> <div id="death_year"> <p>Կատարե՞լ փոփոխություն մահվան տարվա էջում:</p><p> <textarea rows="20" cols="66" id="wiki_text_D_Y"></textarea></p><p>  <input type="button" name="save_b_y" id="Save_button_D_Y" value="Այո"></p></div></div>'
			var buttonHtml = '<a href="#" style="font-size: 9pt;font-weight: bold; float: right;">WikiAutoDates</a>';
			var formHtml=  '<div id="display1" style="position: absolute; top: 40px; left: 100px; display: block;background: white;border: 5px grey solid;padding: 5px 10px 10px 10px;z-index:100;">	<h1>Ծննդյան և  Մահվան ամսաթվեր </h1>	<div>		<table>	<tr><td><h2> Անուն </h2></td> <td colspan="3"> <input type="text" id="name"></td></tr>	<tr><td><h2>Նկարագրություն</h2> </td > <td colspan="3" > <input type="text" id="name_describtion"> </td></tr>	<tr><td><h2>Ծննդյան ամսաթիվ</h2></td>				<td></td>				<td ><input  type="text"  id="ID_Birth_Day" style="width:25px"></td>				<td ><input  type="text"  id="ID_Birth_Month" style="width:25px"></td>				<td ><input  type="text" id="ID_Birth_Year" style="width:50px"></td>			</tr>			<tr><td><h2>Մահվան ամսաթիվ</h2></td>				<td></td>				<td ><input  type="text" id="ID_Death_Day" style="width:25px"></td>				<td ><input  type="text"  id="ID_Death_Month" style="width:25px"></td>				<td ><input  type="text" id="ID_Death_Year"  style="width:50px"></td></tr>		</table>	</div>	<div id="button"> <input id="submitDates" type="button" value="Հաստատել"><input id="closeForm" type="button" value="Փակել"></div></div>'

			function DayObject(dday, mmonth, yyear)
			{
				this.day=dday;
				this.month=mmonth;
				this.year=yyear;
			}

			function NameObject(namm, descr)
			{
				this.name=namm;
				this.description=descr;
			}
			function ManObject( birth1, death1)
			{
				this.death=new DayObject;
				this.death= death1;
				this.birth=new DayObject;
				this.birth=birth1;

			}

			function Man(mano, descr)
			{
				this.data=new ManObject;
				this.data= mano;
				this.describe= new NameObject;
				this.describe=descr;
			}

			var currentPage = new Morebits.wiki.page(mw.config.get('wgPageName'));

			currentPage.load(function () {
				var text = currentPage.getPageText();
				var datArt= new ManObject();
				var describeArt= new NameObject();
				var datInf= new ManObject();
				var describeInf= new NameObject();
				datArt=WikiAutoDates.getDatesFromArticleText(text);
				describeArt=WikiAutoDates.getNameDescriptionFromArticleText(text);
				datInf=WikiAutoDates.getDatesFromInfoBox(text);
				describeInf=WikiAutoDates.getNameDescriptionFromInfoBox(text);
				var objArticle =new  Man(datArt,describeArt);
				var objInfoBox =new Man(datInf,describeInf);
				var Obj= new Man();
				Obj=objArticle;
				if(objArticle.data.birth.day=="" )
				{
					Obj.data.birth.day=objInfoBox.data.birth.day;
				}
				if(objArticle.data.birth.month=="")
				{
					Obj.data.birth.month=objInfoBox.data.birth.month;
				}
				if(objArticle.data.birth.year=="")
				{
					Obj.data.birth.year=objInfoBox.data.birth.year;
				}
				if(objArticle.data.death.day=="" )
				{
					Obj.data.death.day=objInfoBox.data.death.day;
				}
				if(objArticle.data.death.month=="")
				{
					Obj.data.death.month=objInfoBox.data.death.month;
				}
				if(objArticle.data.death.year=="")
				{
					Obj.data.death.year=objInfoBox.data.death.year;
				}
				
				if (objInfoBox.describe.description)
				{
					Obj.describe.description=objInfoBox.describe.description;
				}
				
				Obj.describe.name = mw.config.get('wgPageName').replace(/_/g, ' ');
				
				debugger;
				if (!(objArticle.data.birth.year || objArticle.data.death.year  || objInfoBox.data.birth.year|| objInfoBox.data.death.year)) {
					// no dates are detected
					return;
				}

				var textOfDateBirthF = function(textOfDateBirth){

					if (!WikiAutoDates.checkPersonExists(textOfDateBirth, sectionBirth, Obj.describe, Obj.data.birth, 0)) {
						var showtextBDate = WikiAutoDates.addPerson(textOfDateBirth, sectionBirth, Obj.describe, Obj.data.birth, 0);
						$("#wiki_text_B_D").val(showtextBDate);
					}

					else  $("#birth_day").hide();
				};
				var textOfYearBirthF=function(textOfYearBirth){

					if (!WikiAutoDates.checkPersonExists(textOfYearBirth, sectionBirth, Obj.describe, Obj.data.birth, 1)) {
						var showtextBYear = WikiAutoDates.addPerson(textOfYearBirth, sectionBirth, Obj.describe, Obj.data.birth, 1);
						$("#wiki_text_B_Y").val(showtextBYear);
					}

					else $("#birth_year").hide();
				};
				var textOfDateDeathF=function(textOfDateDeath){

					if (!WikiAutoDates.checkPersonExists(textOfDateDeath, sectionDeath, Obj.describe, Obj.data.death, 0)) {
						var showtextDDate=WikiAutoDates.addPerson(textOfDateDeath, sectionDeath, Obj.describe, Obj.data.death, 0);
						$("#wiki_text_D_D").val(showtextDDate);

					}
					else $("#death_day").hide();
				};
				var textOfYearDeathF=function(textOfYearDeath){

					if (!WikiAutoDates.checkPersonExists(textOfYearDeath, sectionDeath, Obj.describe, Obj.data.death, 1)) {
						var showtextDYear= WikiAutoDates.addPerson(textOfYearDeath, sectionDeath, Obj.describe, Obj.data.death, 1);
						$("#wiki_text_D_Y").val(showtextDYear);
					}

					else  $("#death_year").hide();
				};
				var $button = $(buttonHtml);
				$('#firstHeading').append($button);
				var $form = $(formHtml);
				$form.appendTo($('body'));
				$form.hide().drags({
					handle: "h1"
				});
				var $form2 = $(htmlAdd);
				$form2.appendTo($('body'));
				$form2.hide().drags({
					handle: ".head"
				});

				$button.click(function (event) {
					$form.show();
					$("#ID_Birth_Day").val(Obj.data.birth.day);
					$("#ID_Birth_Month").val(Obj.data.birth.month);
					$("#ID_Birth_Year").val(Obj.data.birth.year);
					$("#ID_Death_Day").val(Obj.data.death.day);
					$("#ID_Death_Month").val(Obj.data.death.month);
					$("#ID_Death_Year").val(Obj.data.death.year);
					$("#name_describtion").val(Obj.describe.description);
					$("#name").val(Obj.describe.name);
					event.preventDefault();
					return false;
				});

				$("#closeForm").click(function()
				{
					$form.hide();
				});
				$("#submitDates").click(function () {
					Obj.data.birth.day = $("#ID_Birth_Day").val();
					Obj.data.birth.month = $("#ID_Birth_Month").val();
					Obj.data.birth.year = $("#ID_Birth_Year").val();
					Obj.data.death.day = $("#ID_Death_Day").val();
					Obj.data.death.month = $("#ID_Death_Month").val();
					Obj.data.death.year = $("#ID_Death_Year").val();
					Obj.describe.description=$("#name_describtion").val();
					Obj.describe.name = $("#name").val();

					if(!Obj.describe.name)
					{
						alert("Անունը բացակայում է");
						return;
					}
					if(!!Obj.data.birth.day ^ !!Obj.data.birth.month == 1){
						alert("Ծննդյան ամսաթիվը կամ ամիսը բացակայում է");
						return;
					}
					if(!!Obj.data.death.day ^ !!Obj.data.death.month == 1){
						alert("Մահվան ամսաթիվը կամ ամիսը բացակայում է");
						return;
					}
					$form.hide();

					$.when(
									$.Deferred(function (deferred) {
										if(!Obj.data.birth.year)
										{
											deferred.resolve();
											$("#birth_year").hide();
											return;
										}
										WikiAutoDates.getYearPageText(Obj.data.birth.year, function (textOfYearBirth) {
											$("#birth_year").show();
											textOfYearBirthF(textOfYearBirth);
											deferred.resolve();
										});
									}),
									$.Deferred(function (deferred) {
										if(!Obj.data.birth.day)
										{
											deferred.resolve();
											$("#birth_day").hide();
											return;
										}
										WikiAutoDates.getDatePageText(Obj.data.birth, function (textOfDateBirth) {
											$("#birth_day").show();
											textOfDateBirthF(textOfDateBirth);
											deferred.resolve();
										});
									}),
									$.Deferred(function (deferred) {
										if(!Obj.data.death.day)
										{
											deferred.resolve();
											$("#death_day").hide();
											return;
										}
										WikiAutoDates.getDatePageText(Obj.data.death, function (textOfDateDeath) {
											$("#death_day").show();
											textOfDateDeathF(textOfDateDeath);
											deferred.resolve();
										});
									}),
									$.Deferred(function (deferred) {
										if(!Obj.data.death.year)
										{
											deferred.resolve();
											$("#death_year").hide();
											return;
										}
										WikiAutoDates.getYearPageText(Obj.data.death.year, function (textOfYearDeath) {
											$("#death_year").show();
											textOfYearDeathF(textOfYearDeath);
											deferred.resolve();
										});
									})
							).done(function () {

								$form2.show();
								checkAllFieldHidden();
							});


				});


				var sectionBirth = "Ծնունդներ";
				var sectionDeath = "Մահեր";

				$("#Close_button").click(function(){

					$form2.hide();

				});

				$("#Save_button_B_D").click(function(){
					$(this).prop('disabled', true);
					var text = $("#wiki_text_B_D").val();
					WikiAutoDates.setDatePageText(Obj.data.birth, text, function () {
						alert("Ծննդյան ամսաթիվը ավելացված է");
						$("#birth_day").hide();
						checkAllFieldHidden();
						$(this).prop('disabled', false);
					});
				});
				$("#Save_button_B_Y").click(function(){
					$(this).prop('disabled', true);
					var text = $("#wiki_text_B_Y").val();
					WikiAutoDates.setYearPageText(Obj.data.birth.year, text, function () {
						alert("Ծննդյան տարին ավելացված է");
						$("#birth_year").hide();
						checkAllFieldHidden();
						$(this).prop('disabled', false);
					});
				});
				$("#Save_button_D_D").click(function(){
					$(this).prop('disabled', true);
					var text = $("#wiki_text_D_D").val();
					WikiAutoDates.setDatePageText(Obj.data.death, text, function () {
						alert("Մահվան ամսաթիվը ավելացված է");
						$("#death_day").hide();
						checkAllFieldHidden();
						$(this).prop('disabled', false);
					});
				});
				$("#Save_button_D_Y").click(function(){
					$(this).prop('disabled', true);
					var text = $("#wiki_text_D_Y").val();
					WikiAutoDates.setYearPageText(Obj.data.death.year, text, function () {
						alert("Մահվան տարին ավելացված է");
						$("#death_year").hide();
						checkAllFieldHidden();
						$(this).prop('disabled', false);
					});
				});

				var checkAllFieldHidden = function () {
					if($("#birth_day, #birth_year, #death_day, #death_year").filter(':visible').length==0)
					{
						$form2.hide();
						alert("Բոլոր անհրաժեշտ էջերում ավելացումները կատարված են");
					}

				};
			});

		}
).fail(function () {
	debugger;
});