MediaWiki:Common.js/Quotes.js

// AdvancedQuoting 3.0 // License: WTFPL // HTML5 || GTFO //source: http://ru.borderlands.wikia.com/wiki/MediaWiki:Common.js/Quotes.js //3.0 msg edit api used //2.8 new design supported now //2.5: article comments are supported now. and user comments. and ie. //will NOT work on ie. ever. //ever is gone. works on ie. (function ($) {	$(function { //$(document).ready if (nbReady) return; //multiple doc.ready protection var nbReady = true; //multiple doc.ready protection var nVersion = 3.0; //debug 4 var nTranslations = { en : 'Quote', ru : 'Цитировать' };		//edit api var neditApi = null; //settings var noSettings = window.nQuoteSettings || {}; noSettings = { debug : typeof(noSettings.debug) !== 'undefined' ? noSettings.debug : false, //false; //obviously ex : typeof(noSettings.ex) !== 'undefined' ? noSettings.ex : true, //true; //experimental functions lang : typeof(noSettings.lang) !== 'undefined' ? noSettings.lang : null, //language override articleCommentFeature : typeof(noSettings.articleCommentFeature) !== 'undefined' ? noSettings.articleCommentFeature : true, //article comments quoteStyle : typeof(noSettings.quoteStyle) !== 'undefined' ? noSettings.quoteStyle : '', qsButtonClass : typeof(noSettings.qsButtonClass) !== 'undefined' ? noSettings.qsButtonClass : 'nquoteClass', //'nquoteClass'; //static button class qfButtonStyle : typeof(noSettings.qfButtonStyle) !== 'undefined' ? noSettings.qfButtonStyle : 'display:none; position:absolute; z-index:999;', //floating buttons style qfButtonName : typeof(noSettings.qfButtonName) !== 'undefined' ? noSettings.qfButtonName : 'nquoteFloatingButton', //floating button name qfButtonHideInterval : typeof(noSettings.qfButtonHideInterval) !== 'undefined' ? noSettings.qfButtonHideInterval : 3000, //3000; //ms. 0=forever rNamespace : typeof(noSettings.rNamespace) !== 'undefined' ? noSettings.rNamespace : '.nRemovable', //'.nRemovable'; //removable events namespace minSelectionLength : typeof(noSettings.minSelectionLength) !== 'undefined' ? noSettings.minSelectionLength : 3, //3; //if lesser then full msg will be marked for quoting minSelection4Float : typeof(noSettings.minSelection4Float) !== 'undefined' ? noSettings.minSelection4Float : 1, //1; //do not show floating button if lesser usernameAsLink : typeof(noSettings.usernameAsLink) !== 'undefined' ? noSettings.usernameAsLink : true, //true; //link(w\ ending extra space) or plain text staticButtonOverpass : typeof(noSettings.staticButtonOverpass) !== 'undefined' ? noSettings.staticButtonOverpass : true, //true; //do not use static reply button. false for mobile clients useQuoteTemplate : typeof(noSettings.useQuoteTemplate) !== 'undefined' ? noSettings.useQuoteTemplate : true, //true; //wanna use template 4 quotes? quoteTemplateName : typeof(noSettings.quoteTemplateName) !== 'undefined' ? noSettings.quoteTemplateName : 'nquote', //'nquote'; //quote template doNotName : typeof(noSettings.doNotName) !== 'undefined' ? noSettings.doNotName : 'njustno', //'njustno'; //disabling cookie name. if true then script will do nothing qchkName : typeof(noSettings.qchkName) !== 'undefined' ? noSettings.qchkName : 'nQChkBox', //'nQChkbox'; //chkbox id/name qchkClass : typeof(noSettings.qchkClass) !== 'undefined' ? noSettings.qchkClass : 'nQChkC', //'nQChkC'; //chkbox class qchkStyle : typeof(noSettings.qchkStyle) !== 'undefined' ? noSettings.qchkStyle :  //; //chkbox style };		var nButtonText = nTranslations[noSettings.lang || mw.config.get('wgContentLanguage')] || nTranslations.en || 'Quote'; var nTimerInterval = 100; var nMaxAttempts2Frame = 1000; //w8 for article comments var nbArticleCommentFeature = noSettings.articleCommentFeature; //article comments var nQuoteStyle = noSettings.quoteStyle; //'border:1px solid #191919; font-style:italic; margin:8px 0; padding:10px;'; var nQSButtonClass = noSettings.qsButtonClass; //'nquoteClass'; //static button class var nQFButtonStyle = noSettings.qfButtonStyle; //'display:none; position:absolute; z-index:999;' var nQFButtonName = noSettings.qfButtonName; //'nquoteFloatingButton'; var nQFButtonHideInterval = noSettings.qfButtonHideInterval; //3000; //ms. 0=forever var nQFBHI = null; //qfbutton hiding timer var neRNamespace = noSettings.rNamespace; //'.nRemovable'; //removable events namespace var nLastClickEvent = 0; //mouseup->click collision prevention var nLastClickEventLimit = 1000; //ignores click events for n ms		var nActiveMessage = null; var nSelectedText = ''; var nMinSelectionLength = noSettings.minSelectionLength; //3; //if lesser then full msg will be marked for quoting var nMinSelectionLen4Float = noSettings.minSelection4Float; //1; //do not show floating button if lesser var nbUsernameAsLink = noSettings.usernameAsLink; //true; //link(w\ ending extra space) or plain text var nbStaticButtonOverpass = noSettings.staticButtonOverpass; //true; //do not use static reply button. false for mobile clients var nbMobile = false; //is mobile client. var nNamespace = 0; //active namespace. 1-forum, 2-wikia article var nbUseQuoteTemplate = noSettings.useQuoteTemplate; //true; //wanna use template 4 quotes? var nQuoteTemplateName = noSettings.quoteTemplateName; //'nquote'; //quote template

var nbVE = mw.config.get('wgVisualEditorPreferred'); //check 4 visual editor var nbDebug = noSettings.debug; //false; //obviously var nbEx = noSettings.ex; //true; //experimental functions

var nckDoNotName = noSettings.doNotName; //'njustno'; //disabling cookie name. if true then script will do nothing var nTChk = { en : 'Quotation', ru : 'Цитирование' };		var nQChkText = nTChk[noSettings.lang || mw.config.get('wgContentLanguage')] || nTChk.en || 'Quotation'; var nQChkName = noSettings.qchkName; //'nQChkbox'; //chkbox id/name var nQChkClass = noSettings.qchkClass; //'nQChkC'; //chkbox class var nQChkStyle = noSettings.qchkStyle; //''; //chkbox style var nbShouldIKillMyself = nShouldIStopNow; if (nbDebug) console.log('naq. doc.ready');

function naddQB2FHandler(npiTargetClass) { //add handler 2 static quote button. forum if ((!npiTargetClass) || (npiTargetClass.length < 1)) npiTargetClass = '.nquoteClass'; if (nbDebug) console.log('addQB2FH. class:' + npiTargetClass); $(document).find(npiTargetClass).on('click' + neRNamespace, function {				var nText = neditApi.getMessage;				var selectedText = ngetSelectedText(this);				if (selectedText === null) {					return;				}				var username = $(this).parents('.MiniEditorWrapper').find('.edited-by').text.trim;				var quoteText = nCreateQuote(nText, nQuoteStyle, username, selectedText.trim);				if (!nbMobile) {					$('.replyBody').focus; //will not work on ie				}				neditApi.setMessage(quoteText);				//if (nsetMessage(quoteText)===null) window.alert('smth wrng in da wrld');			});

} //naddQB2FHandler

function naddQB2WAHandler(npiTargetClass) { //let event-oriented programming begins if ((!npiTargetClass) || (npiTargetClass.length < 1)) npiTargetClass = '.nquoteClass'; //is classname //npiTargetClass=((npiTargetClass[0]=='.') ? npiTargetClass : '.'+npiTargetClass); //shoulda w8 4 button actually appears. x10 interval var i = 0; var nQB2WAI4B = setInterval(function {					if (nbShouldIKillMyself) {						//chkbox unticked is						clearInterval(nQB2WAI4B);						return;					}					if (($(document).find(npiTargetClass).length > 0) || (i > nMaxAttempts2Frame)) {						clearInterval(nQB2WAI4B);						//add handler						$(document).find(npiTargetClass).on('click' + neRNamespace, function  { var nText = neditApi.getMessage; var selectedText = ngetSelectedText(this); if (selectedText === null) { return; }							var username = $(this).parents('.comment').data('user').trim; var quoteText = nCreateQuote(nText, nQuoteStyle, username, selectedText.trim); neditApi.setMessage(quoteText); });					}				}, nTimerInterval * 10); } //naddQB2WAHandler

function naddSHandler2F { //add selection handler. forum if (nbDebug) { console.log('addSHandler2F'); }			$('li.message').on('mouseup' + neRNamespace, function (e) {				if (e.which != 1)					return; //1-lmb, 2-mmb, 3-rmb				var t1 = ngetSelectionQuick || ;				var text = ngetSelectedText(e.target);				if ((text !== ) && (t1.toString.trim.length > nMinSelectionLen4Float)) {					nActiveMessage = $(e.target).parents('.MiniEditorWrapper');					nSelectedText = text;					nLastClickEvent = e.timeStamp;					if (nbDebug) {						console.log('SHandler2F. ShowButton w p:' + nActiveMessage + ' ' + nSelectedText + ' ' + nLastClickEvent);					}					nShowButton(e);					return;				} else {					nHideButton;				}			}); //mouseup //add mouseclick handler. button hiding purposes $('body').on('click' + neRNamespace, function (e) {				if (((e.timeStamp - nLastClickEvent) > nLastClickEventLimit) || (e.which != 1))					nHideButton;			}); //keydown handler. button hiding 4 $('body').on('keydown' + neRNamespace, nHideButton); return; } //naddSHandler2F

function naddSHandler2WA { //add selection handler. wikia article if (nbDebug) { console.log('addSHandler2WA'); }			$('#article-comments-ul.comments').on('mouseup' + neRNamespace, function (e) {				if (e.which != 1)					return; //1-lmb, 2-mmb, 3-rmb				var t1 = ngetSelectionQuick || ;				var text = ngetSelectedText(e.target, 2);				if ((text !== ) && (t1.toString.trim.length > nMinSelectionLen4Float)) {					//e.stopImmediatePropagation; //fail					//e.stopPropagation; //fail					nActiveMessage = $(e.target).parents('.comment');					nSelectedText = text;					nLastClickEvent = e.timeStamp;					if (nbDebug) {						console.log('SHandler2WA. ShowButton w p:' + nActiveMessage + ' ' + nSelectedText + ' ' + nLastClickEvent);					}					nShowButton(e);					return;				} else {					nHideButton;				}			}); //mouseup //add mouseclick handler. button hiding purposes $('body').on('click' + neRNamespace, function (e) {				if (((e.timeStamp - nLastClickEvent) > nLastClickEventLimit) || (e.which != 1))					nHideButton;			}); //keydown handler. button hiding 4 $('body').on('keydown' + neRNamespace, nHideButton); return; } //naddSHandler2WA

function nCreateButton { //create button. 1-forum, 2-wikia article if (nbDebug) { console.log('CreateButton. Target:' + nNamespace); }			var ncb = $(' ', {					type : 'button',					class : 'nquoteFloatingClass',					id : nQFButtonName,					name : nQFButtonName,					style : nQFButtonStyle,					text : nButtonText				}); $(ncb).appendTo($('body')); //.on('ready'+neRNamespace, function {			switch (nNamespace) {			case 1:				if (nbDebug) {					console.log('CreateButton. add QFB2F_click');				}				$('#' + nQFButtonName).on('click' + neRNamespace, nQFB2F_click);				break;			case 2:				if (nbDebug) {					console.log('CreateButton. add QFB2WA_click');				}				$('#' + nQFButtonName).on('click' + neRNamespace, nQFB2WA_click);				break;			default:				if (nbDebug) {					console.log('CreateButton. switch:default. Target:' + nNamespace);				}				$('#' + nQFButtonName).on('click' + neRNamespace, nQFB2F_click);				break;			}			//}); } //nCreateButton

function nShowButton(npie) { if (nbDebug) { console.log('ShowButton. ' + npie.pageX + ' ' + npie.pageY); }			$('#' + nQFButtonName).css({				left : npie.pageX,				top : npie.pageY			}); $('#' + nQFButtonName).show; if (nQFButtonHideInterval > 0) { if (nQFBHI !== null) clearInterval(nQFBHI); nQFBHI = window.setInterval(function {						if (nbDebug) {							console.log('qfbutton hiding timer fired is. ' + nQFBHI);						}						window.clearInterval(nQFBHI);						nQFBHI = null;						nHideButton;					}, nQFButtonHideInterval); }		} //nShowButton

function nHideButton { if (nbDebug) { console.log('HideButton'); }			if (nQFBHI !== null) { if (nbDebug) { console.log('HideButton.qfbhi:' + nQFBHI); }				window.clearInterval(nQFBHI); nQFBHI = null; }			$('#' + nQFButtonName).hide; nSelectedText = ''; nActiveMessage = null; } //nHideButton

function nQFB2F_click(npie) { // quote button. forum. click if (nbDebug) { console.log('QFB2F_click'); }			if ((nSelectedText === ) || (nSelectedText.trim === )) { nHideButton; if (nbDebug) { console.log('QFB2F_click. SelectedText=null. return'); }				return; }			if (nbDebug) { console.log('QFB2F_click. getMessage'); }			var nText = neditApi.getMessage; if (nbDebug) { console.log('QFB2F_click. Message:' + nText); console.log('QFB2F_click. GetUsername'); }			var username = nGetUsername($(nActiveMessage),					($('.new-reply').find('.MiniEditorWrapper.mode-source').length > 0) ? false : true); //$(nActiveMessage).find('.edited-by').html.trim; if (nbDebug) { console.log('QFB2F_click. Username:' + username); console.log('QFB2F_click. CreateQuote'); }			var quoteText = nCreateQuote(nText, nQuoteStyle, username, nSelectedText.trim); if (nbDebug) { console.log('QFB2F_click. Quote:' + quoteText); }			$('.replyBody').focus; //will not work on ie			if (nbDebug) { console.log('QFB2F_click. setMessage'); }			neditApi.setMessage(quoteText); if (nbDebug) { console.log('QFB2F_click. HideButton'); }			nHideButton; } //nQFB2F_click

function nQFB2WA_click(npie) { // quote button. wikia article. click if (nbDebug) { console.log('QFB2WA_click'); }			if ((nSelectedText === ) || (nSelectedText.trim === )) { nHideButton; if (nbDebug) { console.log('QFB2WA_click. SelectedText=null. return'); }				return; }			if (nbDebug) { console.log('QFB2WA_click. getMessage'); }			var nText = neditApi.getMessage; if (nbDebug) { console.log('QFB2WA_click. Message:' + nText); console.log('QFB2WA_click. GetUsername'); }			var username = nGetUsername($(nActiveMessage),					($('.MiniEditorWrapper.active').hasClass('mode-source') ? false : true)); if (nbDebug) { console.log('QFB2WA_click. USername:' + username); console.log('QFB2WA_click. CreateQuote'); }			var quoteText = nCreateQuote(nText, nQuoteStyle, username, nSelectedText.trim); if (nbDebug) { console.log('QFB2WA_click. Quote:' + quoteText); }			$('.replyBody').focus; //will not work on ie			if (nbDebug) { console.log('QFB2WA_click. setMessage'); }			neditApi.setMessage(quoteText); if (nbDebug) { console.log('QFB2WA_click. HideButton'); }			nHideButton; } //nQFB2WA_click

function naddQB2F { //add quote button. forum if (nbDebug) { console.log('addQB2F ' + window.nQButtonExist); }			if (nbDebug) { console.log('addQB2F. addSHandler'); }			naddSHandler2F; if (nbDebug) { console.log('addQB2F. SBO:' + nbStaticButtonOverpass); }			if (nbDebug || nbMobile || (!nbStaticButtonOverpass)) { //sorry, mario, but your button is in another castle $(' ', {					type : 'button',					class : nQSButtonClass,					text : nButtonText				}) .appendTo('.msg-toolbar .buttonswrapper .buttons').on('ready' + neRNamespace, naddQB2FHandler('.' + nQSButtonClass)); }		} //naddQB2F

function naddQB2WA { //add quote button. wikia article if (nbDebug) { console.log('addQB2WA ' + window.nQButtonExist); }			//shoulda w8 4 comments. x10 timer interval. var nQB2WAInterval = null; //4 paranoid java compilers //if mobile. fixed probably if (nbDebug || nbMobile || (!nbStaticButtonOverpass)) { if (nbDebug) { console.log('addQB2WA. set interval'); }				nQB2WAInterval = setInterval(function {						//$(nqsb).appendTo('.WikiaArticleComments .comment .buttons');						//if ($('.'+nQSButtonClass).text) {						//w8 4 comments						if ($('.WikiaArticleComments').find('.comment').length > 0) {							clearInterval(nQB2WAInterval);							var nqsb = $(' ', { type : 'button', class : nQSButtonClass, text : nButtonText }).addClass('actionButton wikia-button');							if (nbDebug) {								console.log('addQB2WA. Interval. Comment is ready. addQB2WAButton');							}							$(nqsb).prependTo('.WikiaArticleComments .comment .buttons').on('ready' + neRNamespace, naddQB2WAHandler('.' + nQSButtonClass));						}					}, nTimerInterval * 10); }			//else { //w8 4 comments if (nbDebug) { console.log('addQB2WA. set interval'); }			var nQFB2WAInterval = setInterval(function {					if ($('.WikiaArticleComments').find('.comment').length > 0) {						clearInterval(nQFB2WAInterval);						if (nbDebug) {							console.log('addQB2WA. Interval. Button is ready. addSHandler2WA');						}						naddSHandler2WA;					}				}, nTimerInterval * 10);

} //naddQB2WA

function naddQButton { //add quote button. 1-forum, 2-wikia article if (nbDebug) { console.log('addQButton. Target:' + nNamespace); }			switch (nNamespace) { case 1: if (nbDebug) { console.log('addQButton. addQB2F'); }				naddQB2F; break; case 2: if (nbDebug) { console.log('addQButton. addQB2WA'); }				naddQB2WA; break; default: if (nbDebug) { console.log('addQButton. switch:default. Target:' + nNamespace); }				naddQB2F; break; }		} //naddQButton

function ngetSelectedText(target) { //get selected text. additional targets //selected text || full message if (nbDebug) { console.log('getSelectedText'); }			if (nbDebug) { console.log('getSelectedText. Target:' + target + ' ' + nNamespace); }			var nret = null; switch (nNamespace) { case 1: nret = ngetSelectedTextF(target); break; case 2: if (nbDebug) { console.log('getSelectedText. switching 2 wa'); }				nret = ngetSelectedTextWA(target); break; default: nret = ngetSelectedTextF(target); }

return nret; } //ngetSelectedText

function ngetSelectedTextF(target) { //get selected text. forum if (nbDebug) { console.log('getSelectedTextF. Target:' + target); }			var selection; var selectedElement; var selectedText = ''; if (nbMobile) { if (nbDebug) { console.log('getSelectedTextF. mobile'); }				if (nbDebug) { console.log('getSelectedTextF. quote full msg'); }				if ($(target).parents('.MiniEditorWrapper').find('.msg-body').parentNode) { //it works and renders nested quotes. sometimes selectedText = $(target).parents('.MiniEditorWrapper').find('.msg-body').parentNode.innerHTML; if (nbDebug) { console.log('getSelectedTextF. qfm.mew.msg-body.innerhtml:' + selectedText); }				} else { //if sometimes not happen selectedText = $(target).parents('.MiniEditorWrapper').find('.msg-body').text; if (nbDebug) { console.log('getSelectedTextF. qfm.mew.msg-body.text:' + selectedText); }				}				return selectedText; }			if (window.getSelection) { selection = window.getSelection; } else if (document.getSelection) { selection = document.getSelection; } else { if (nbDebug) { console.log('getSelectedText. no selection found. return'); }				return null; }

if (selection.rangeCount > 0) { selectedElement = selection.getRangeAt(0).startContainer.parentNode; } // else return null; if ((selectedElement && $(target).parents('.MiniEditorWrapper').find($(selectedElement)).length) && (selection.toString.length > nMinSelectionLength)) { selectedText = selection.toString; if (nbDebug) { console.log('getSelectedTextF. s:' + selectedText.length + ' ' + selectedText); }				return selectedText; } else { //quote full msg if (nbDebug) { console.log('getSelectedTextF. full msg'); }				if ($(target).parents('.MiniEditorWrapper').find('.msg-body').parentNode) { //it works and renders nested quotes. sometimes selectedText = $(target).parents('.MiniEditorWrapper').find('.msg-body').parentNode.innerHTML; } else { //if sometimes not happen selectedText = $(target).parents('.MiniEditorWrapper').find('.msg-body').text; }				return selectedText; }		} //ngetSelectedTextF

function ngetSelectedTextWA(target) { //get selected text. wikia article if (nbDebug) { console.log('getSelectedTextWA. Target:' + target); }			var selection; var selectedElement; var selectedText = ''; if (nbMobile) { if (nbDebug) { console.log('getSelectedTextWA. mobile'); }				if ($(target).parents('.comment').find('.WikiaArticle').parentNode) { //it works and renders nested quotes. sometimes selectedText = $(target).parents('.comment').find('.WikiaArticle').parentNode.innerHTML; if (nbDebug) { console.log('getSelectedTextWA. wa.innerhtml' + selectedText); }				} else { //if sometimes not happen selectedText = $(target).parents('.comment').find('.WikiaArticle').text; if (nbDebug) { console.log('getSelectedTextWA. wa.text' + selectedText); }				}				return selectedText; }			if (window.getSelection) { selection = window.getSelection; } else if (document.getSelection) { selection = document.getSelection; } else { if (nbDebug) { console.log('getSelectedTextWA. no selection found. return'); }				return null; }

if (selection.rangeCount > 0) { selectedElement = selection.getRangeAt(0).startContainer.parentNode; } // else return null; if ((selectedElement && $(target).parents('.comment').find($(selectedElement)).length) && (selection.toString.length > nMinSelectionLength)) { selectedText = selection.toString; return selectedText; } else { //quote full msg if (nbDebug) { console.log('getSelectedTextWA. full msg'); }				if ($(target).parents('.comment').find('.WikiaArticle').parentNode) { //it works and renders nested quotes. sometimes selectedText = $(target).parents('.comment').find('.WikiaArticle').parentNode.innerHTML; } else { //if sometimes not happen selectedText = $(target).parents('.comment').find('.WikiaArticle').text; }				return selectedText; }		} //ngetSelectedTextWA

function ngetSelectionQuick { var selection=null; if (window.getSelection) { selection = window.getSelection; } else if (document.getSelection) { selection = document.getSelection; } else { return null; }			if (selection.rangeCount > 0) return selection; // else return null; return null; } //nGetSelectionQuick

function nGetUsername(npiContext, npiLink) { //get username. 1-active message context, 2-username as link override (source-mode link issue) if (npiLink === null) npiLink = true; if (!npiContext) npiContext = $(nActiveMessage); if (nbDebug) { console.log('GetUsername.', npiContext, npiLink); }			var nuname = ''; switch (nNamespace) { case 1: nuname = (nbUsernameAsLink & npiLink) ? npiContext.find('.edited-by').html.trim : npiContext.find('.edited-by').text.trim; break; case 2: nuname = npiContext.data('user'); break; default: nuname = npiContext.data('user'); }			return nuname; } //nGetUsername

function nCreateQuote(npiM, npiQS, npiU, npiT) { //create quote. 1-prev message, 2-quote style, 3-username, 4-text if (nbUseQuoteTemplate) { //strip pipe (|) chars npiT = npiT.replace('|', '|'); var text = (npiM.length > 0 ? npiM : ) + ; return text; }			return npiM + '' +  + npiU + ((!nbUsernameAsLink) ? ':' : ) + '' + npiT + '  '; } //nCreateQuote

function nCreateQChkbox { //create quotation toggler //if (window.nQChkbox) return; //window.nQChkbox=true; var ntag = ''; ntag = ''; ntag = ntag + ''; ntag = ntag + nQChkText + ' '; var $li = $(''); $(ntag).appendTo($li); $li.appendTo('.page-header__contribution-buttons .wds-list'); //.on('ready', function {			$('#' + nQChkName).on('click', nQChkboxClick);			//}); } //nCreateQChkBox

function nQChkboxClick { //qchkbox event handler if (nbDebug) { console.log('QChkboxClick'); }			//disable chkbox-job in progress. sync is presumed $('#' + nQChkName).prop('disabled', true); if ($('#' + nQChkName).prop('checked')) { nbShouldIKillMyself = false; nSetQCookie(false); //enable script the nResurrectMyself; //bring me to life } else { nbShouldIKillMyself = true; nSetQCookie(true); //disable script the nKillMyself; //remove me			} //enable chkbox-job done, ready to operate $('#' + nQChkName).removeProp('disabled'); } //nQChkboxClick

function nSetQCookie(npi) { if (nbDebug) console.log('SetQCookie:' + npi); if ($.cookies.test) { document.cookie = nckDoNotName + '=' + npi + ';' + 'path=/;' + 'expires=' + (new Date(new Date.setMonth(new Date.getMonth + 12))).toUTCString; } else { if (nbDebug) { console.log('SetCookie. cookies not supported are'); }			}		} //nSetQCookie

function nShouldIStopNow { //use string below to prevent the script running //document.cookie=nckDoNotName+'='+'true;'+'path=/;'+'expires='+(new Date(new Date.setMonth(new Date.getMonth+12))).toUTCString; if ($.cookies.test) { var nck = $.cookies.get(nckDoNotName); //if (nbDebug) {console.log('ShouldIStopNow:'+nck)} if (nck && (nck == 'true')) { //if (nbDebug) console.log('ShouldIStopNow:'+nck); return true; }			} else { if (nbDebug) { console.log('ShouldIStopNow. cookies are not supported. return sikm'); }				return (nbShouldIKillMyself || false); }			return false; } //nShouldIStopNow

function nKillMyself { //cleaning tool if (nbDebug) console.log('KillMyself:'); //remove handlers by namespace $('*').off(neRNamespace); //remove buttons $('.' + nQSButtonClass).remove; //$('.'+nQChkClass).remove; $('#' + nQFButtonName).remove; } //nKillMyself

function nResurrectMyself { //turn up the buttons if (nbDebug) console.log('ResurrectMyself'); nmain(false); } //nResurrectMyself

function nmain(npi1stRun) { //main //preparing enable\disable feat w\o reloading //todo: save setting(s) 4 un- or decooked browsers(through mw.user.options. probably) //return; //debug console.log('naq.main. version:' + nVersion); //make sure the script running is			if (typeof(npi1stRun) === 'undefined') npi1stRun = true; //default parameters are not supported yet. es2015 :\ //add enabling\disabling checkbox. only once if (npi1stRun) nCreateQChkbox; //nCreateQChkbox; //should it fall if (nShouldIStopNow) { if (nbDebug) { console.log('naq.main. i should stop now. debug:' + nbDebug); }				if (!nbDebug) return; }			//$.each($.browser, function( i, val ) {console.log(i,val);}); if (navigator.userAgent.indexOf('Mobile') != -1) { nbMobile = true; //it means falling to ie+additional restrictions if (nbDebug) { console.log('naq.main. mobile'); }			}			//ie-specific. ie10-mozilla+trident. if (nbMobile || (!nbVE) || ((navigator.userAgent.indexOf('Mozilla') != -1) && (navigator.userAgent.indexOf('Trident') != -1))) { if (nbDebug) { console.log('naq.main. Browser: IE'); }				nbUsernameAsLink = false; }			switch (mw.config.get('wgNamespaceNumber')) { case 0: //wikia article //if !mobile. will(not) be fixed later if (nbDebug) { console.log('naq.main. wikia article'); }				nNamespace = 2; break; case 500: //blog = wikia article if (nbDebug) { console.log('naq.main. blog'); }               nNamespace = 2; break; case 1201: //forum if (nbDebug) { console.log('naq.main. forum'); }				nNamespace = 1; break; default: //undefined nNamespace = 0; break; }			//if wrong namespace or disabled article comment feat if ((nNamespace === 0) || ((nNamespace === 2) && (!nbArticleCommentFeature))) return; //get edit api neditApi = new window.ngMsgEditAPI; //create floating button nCreateButton; //add floating and static buttons naddQButton; } //nmain

//and here we go		if (!window.ngMsgEditAPI || !window.ngMsgEditAPI.version) { if (nbDebug) console.log('naq. load edit api'); $.ajaxSetup({cache: true}); $.getScript('http://ru.borderlands.wikia.com/index.php?title=MediaWiki:MessageEditAPI.js&action=raw&ctype=text/javascript', nmain); //getscript } else { if (nbDebug) console.log('naq. api already loaded is. main'); nmain; }//if not editapi }); //$(document).ready }(jQuery));