Szerkesztő:Cirkalo1/monobook.js

A Wikipédiából, a szabad enciklopédiából

Megjegyzés: közzététel után frissítened kell a böngésződ gyorsítótárát, hogy lásd a változásokat.

  • Firefox / Safari: tartsd lenyomva a Shift gombot és kattints a Frissítés gombra a címsorban, vagy használd a Ctrl–F5 vagy Ctrl–R (Macen ⌘–R) billentyűkombinációt
  • Google Chrome: használd a Ctrl–Shift–R (Macen ⌘–Shift–R) billentyűkombinációt
  • Internet Explorer / Edge: tartsd nyomva a Ctrl-t, és kattints a Frissítés gombra, vagy nyomj Ctrl–F5-öt
  • Opera: Nyomj Ctrl–F5-öt
// ezeket a sorokat wikEd telepítése során 
// kell beilleszteni a saját_userlap/monobook.js oldalra
//
// magyar fordítás az eredetileg angol en:User:Cacycle/wikEd-hez
document.write('<script type="text/javascript" src="'
+ 'http://en.wikipedia.org/w/index.php?title=User:Cs%C3%B6rf%C3%B6ly_D/wikEd-hu.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
//
// a en:User:Cacycle/wikEd "szövegszerkesztő-a-böngészőben" telepítése
document.write('<script type="text/javascript" src="'
+ 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');


document.write('<script type="text/javascript" src="'
 + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js' 
 + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

document.write('<script type="text/javascript" src="'
 + 'http://hu.wikipedia.org/w/index.php?title=User:Bdamokos/strings-hu.js' 
 + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');



// define  custom buttons (id, class, popup title, image src, width, height, alt text, onClick and parameters)
var wikEdButton = [];
wikEdButton[100] = ['wikEdDiv', 'wikEdButton', 'Make the selection a html DIV element', 'http://upload.wikimedia.org/wikipedia/commons/6/67/WikEd_logo.png', '16', '16', 'DIV', 'javascript:WikEdEditButton(this, this.id, null, TestHandler);'];
wikEdButton[101] = ['wikEdTest', 'wikEdButton', 'This is a test button', 'http://upload.wikimedia.org/wikipedia/commons/0/07/WikEd_disabled.png', '16', '16', 'Test', 'javascript:WikEdEditButton(this, this.id, null, TestHandler);'];

// define custom button bars (id outer, class outer, id inner, class inner, height, grip title, button numbers)
var wikEdButtonBar = [];
wikEdButtonBar['custom1'] = ['wikEdButtonBarCustom1',  'wikEdButtonBarCustom1',  'wikEdButtonsCustom1',  'wikEdButtonsCustom1',  44, 'My custom buttons', [100, 'br', 101] ];
wikEdButtonBar['custom2'] = ['wikEdButtonBarCustom2',  'wikEdButtonBarCustom2',  'wikEdButtonsCustom2',  'wikEdButtonsCustom2',  44, 'My custom buttons', [100, 'br', 101] ];

// define the function which is called upon clicking the custom button

function TestHandler(obj) {

// select the appropriate text change target (whole, selection, cursor, focusWord, focusLine, selectionWord, or selectionLine)
//   focus... is the text under the cursor; ...Word and ...Line extend the target to the start/end of the word or line
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
obj.changed = obj.cursor;
}

// make the changes to the plain target text

// remove the previously added formatting
if ( /&lt;div&gt;(.*?)&lt;\/div&gt;/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/&lt;div&gt;(.*?)&lt;\/div&gt;/gi, '$1');
}

// add the text formatting
else {
obj.changed.plain = '&lt;div&gt;' + obj.changed.plain + '&lt;/div&gt;';
obj.changed.plain = obj.changed.plain.replace(/(&lt;div&gt;)( *)(.*?)( *)(&lt;\/div&gt;)/, '$2$1$3$5$4');
}

// keep the changed text selected, needed to remove the formatting with a second click
obj.changed.keepSel = true;

return;
}

// ezeket a sorokat wikEd telepítése során 
// kell beilleszteni a saját_userlap/monobook.js oldalra
//
// [[:hu:Wikipédia:wikEd|magyar]] fordítás az eredetileg angol [[:en:User:Cacycle/wikEd]]-hez
document.write('<script type="text/javascript" src="'
+ 'http://en.wikipedia.org/w/index.php?title=User:Cs%C3%B6rf%C3%B6ly_D/wikEd-hu.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
//
// a [[:en:User:Cacycle/wikEd]] "szövegszerkesztő-a-böngészőben" telepítése
document.write('<script type="text/javascript" src="'
+ 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');


document.write('<script type="text/javascript" src="http://hu.wikipedia.org/w/index.php?title=User:Bdanee/sablonmester.js&action=raw&ctype=text/javascript&dontcountme=s"> </script>');


// category insert script
 
// TODO lehessen megadni egyéni kezdőkategóriát shift-klikkre
//      szebb hibakezelés
//      rendes kurzor ( .CategoryTreeLabel { cursor: pointer; } )
//      ESC gombra bezárás
//      pozicionálás (mi van, ha felül van a preview?)
//      kategória címe + fel gomb
//      WikEd cuccok külön fájlba
 
if(wgAction == 'edit' || wgAction == 'submit') {
   if(typeof categoryTreeCollapseMsg == "undefined") var categoryTreeCollapseMsg = "összecsuk";
   if(typeof categoryTreeExpandMsg == "undefined") var categoryTreeExpandMsg = "kinyit";
   if(typeof categoryTreeLoadMsg == "undefined") var categoryTreeLoadMsg = "load";
   if(typeof categoryTreeLoadingMsg == "undefined") var categoryTreeLoadingMsg = "töltés";
   if(typeof categoryTreeNothingFoundMsg == "undefined") var categoryTreeNothingFoundMsg = "nincs találat";
   if(typeof categoryTreeNoSubcategoriesMsg == "undefined") var categoryTreeNoSubcategoriesMsg = "nincs alkategória.";
   if(typeof categoryTreeNoPagesMsg == "undefined") var categoryTreeNoPagesMsg = "nincs cikk vagy alkategória."; 
 
   var ciDefaultCategory = "Kategóriák";
   var ciStyleSheet = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/extensions/CategoryTree/CategoryTree.css";
 
   // read starting category from cookie
   var results = document.cookie.match("ciStart=(.*?)(;|$)");
   if (results) var ciStartingCategory = unescape(results[1]);
   else var ciStartingCategory = ciDefaultCategory;
   var ciMode = 0;
   // FIXME
   var ciFrame;
   var ciKey;
   var ciTrail;
   var ciTextRange;
   var ciError = false;
   var ciWikEdObj;
 
   if(document.createStyleSheet) {
      document.createStyleSheet(ciStyleSheet);
   } else {
      document.write('<link rel="stylesheet" type="text/css" href="' + ciStyleSheet + '">');
   }
 
   function ciGetDialog() {
      ciFrame = document.getElementById('catInsertFrame');
      if(!ciFrame) {
         ciFrame = document.createElement('div');
         ciFrame.id = 'catInsertFrame';
         ciFrame.style.position = "absolute";
         ciFrame.style.zIndex = "3";
         ciFrame.style.border = "solid #FFBE20 1px";
         ciFrame.style.background = "#FFFAEF";
         ciFrame.style.padding = "0.5em 1.5em 0.5em 0.5em";
         ciFrame.style.fontSize = "12px";
         ciFrame.onkeypress = function(e) { 
            if((event) ? 
                  (event.keyCode == 27) : // IE
                  (e.keyCode == e.DOM_VK_ESCAPE) // FF
               ) ciCloseDialog();
         }
 
         if (typeof(wikEdUseWikEd) != 'undefined' && wikEdUseWikEd == true) {
         var box = document.getElementById('wikEdFrameOuter');
         } else {
            var box = document.getElementById('wpTextbox1');
         }
         box.parentNode.insertBefore(ciFrame, box);
 
         var x = document.createElement('div');
         x.id = 'catInsertClose';
         x.style.position = 'absolute';
         x.style.top = '2px';
         x.style.right = '2px';
         // x.style.width = x.style.height = '1em';
         x.style.textAlign = 'center';
         x.style.verticalAlign = 'middle';
         x.style.padding = '1px 3px';
         x.style.border = '1px solid black'; 
         x.style.background = 'white';
         // x.style.fontFamily = 'monospace';
         // x.style.fontWeight = 'bold';
         x.style.fontFamily = 'Verdana, sans-serif';
         x.style.cursor = 'pointer';
         x.appendChild(document.createTextNode('x'));
         x.onclick = ciCloseDialog;
         ciFrame.appendChild(x);
      }
 
      var ciDiv = document.getElementById('catInsertBody');
      if(!ciDiv) {
         ciDiv = document.createElement('div');
         ciDiv.id = 'catInsertBody';
         ciFrame.appendChild(ciDiv);
      }
      ciFrame.style.display = 'block';
      return ciDiv;
   }
 
   function ciCloseDialog() {
      ciFrame.style.display = 'none';
      if (typeof(wikEdUseWikEd) != 'undefined' && wikEdUseWikEd == true) {
         wikEdFrameWindow.focus();         
      } else {
         document.editform.wpTextbox1.focus();
      }
   }
 
   function ciNextDiv(e) {
      var n= e.nextSibling;
      while ( n && ( n.nodeType != 1 || n.nodeName != 'DIV') ) {
         //alert('nodeType: ' + n.nodeType + '; nodeName: ' + n.nodeName);
         n= n.nextSibling;
      }
 
      return n;
   }
 
   function ciExpandNode(cat, mode, lnk) {
      var div= ciNextDiv( lnk.parentNode.parentNode );
 
      div.style.display= 'block';
      lnk.innerHTML= '&ndash;';
      lnk.title= categoryTreeCollapseMsg;
      lnk.onclick= function() { ciCollapseNode(cat, mode, lnk) }
 
      if (lnk.className != "CategoryTreeLoaded") {
         ciLoadNode(cat, mode, lnk, div);
      }
   }
 
   function ciCollapseNode(cat, mode, lnk) {
      var div= ciNextDiv( lnk.parentNode.parentNode );
 
      div.style.display= 'none';
      lnk.innerHTML= '+';
      lnk.title= categoryTreeExpandMsg;
      lnk.onclick= function() { ciExpandNode(cat, mode, lnk) }
   }
 
   function ciLoadNode(cat, mode, lnk, div) {
      div.style.display= 'block';
      lnk.className= 'CategoryTreeLoaded';
      lnk.innerHTML= '&ndash;';
      lnk.title= categoryTreeCollapseMsg;
      lnk.onclick= function() { ciCollapseNode(cat, mode, lnk); }
 
      ciLoadChildren(cat, mode, div);
   }
 
   function ciLoadChildren(cat, mode, div) {
      div.innerHTML= '<i class="CategoryTreeNotice">' + categoryTreeLoadingMsg + '</i>';
      function f( request ) {
         result= request.responseText;
         result= result.replace(/^\s+|\s+$/, '');
 
         if (request.status != 200) {
            if(ciError == false) { // show default list on error
               sajax_debug('Error loading ' + cat + ': ' + request.status + " " + request.statusText + ": " + result);
               ciLoadChildren(ciStartingCategory,ciMode,ciGetDialog());
            } else { // avoid infinite cycle
               result= "<div class='error'> " + request.status + " " + request.statusText + ": " + result + "</div>";
               ciError = false;
            }
         }
 
         if ( result == '' ) {
            result= '<i class="CategoryTreeNotice">';
 
            if ( mode == 0 ) result= categoryTreeNoSubcategoriesMsg;
            else if ( mode == 10 ) result= categoryTreeNoPagesMsg;
            else result= categoryTreeNothingFoundMsg;
 
            result+= '</i>';
         }
 
         result = result.replace(/categoryTreeExpandNode/g, 'ciExpandNode');
         // result = result.replace(/categoryTreeExpandNode/g, 'ciLoadChildren'); // replace, don't expand
         result = result.replace(/href="\/wiki\/[^"]*">([^<]*)/g, 'onclick="ciInsertCategory(\'$1\')">$1');
         result = result.replace(/##LOAD##/g, categoryTreeExpandMsg);
         div.innerHTML = result;
      }
 
      sajax_do_call( "efCategoryTreeAjaxWrapper", [cat, mode] , f );
   }
 
   function ciInsertCategory(cat) {
      var categoryLink = '[' + '[Kategória:' + cat + ciKey + ']' + ']' + ciTrail;
      if (typeof(wikEdUseWikEd) != 'undefined' && wikEdUseWikEd == true) {
         ciWikEdObj.changed.plain = categoryLink;
         ciWikEdObj.changed.keepSel = true;
         wikEdLastVersion = null;
         ciWikEdObj.html = ciWikEdObj.changed.plain;
         if (wikEdHighlightSyntax == true) {
            WikEdHighlightSyntax(ciWikEdObj);
         } else {
            ciWikEdObj.html = ciWikEdObj.html.replace(/(\t)/g, '<span class="wikEdTabPlain">$1</span><!--wikEdTabPlain-->');
         }
         ciWikEdObj.sel.removeAllRanges();
         ciWikEdObj.sel.addRange(ciWikEdObj.changed.range);
         WikEdFrameExecCommand('inserthtml', ciWikEdObj.html);
         wikEdFrameDOMCache = null;
         wikEdFrameWindow.focus();
         if (wikEdHighlightSyntax == true) {
            WikEdFollowLinks();
         }
      } else {
         var textarea = document.editform.wpTextbox1;
         textarea.focus();
         if (document.selection && document.selection.createRange) { // IE, Opera
            if (document.documentElement && document.documentElement.scrollTop) {
               var winScroll = document.documentElement.scrollTop
            } else if (document.body) {
               var winScroll = document.body.scrollTop;
            }
            ciTextRange.text = categoryLink;
            if (document.documentElement && document.documentElement.scrollTop) {
               document.documentElement.scrollTop = winScroll;
            } else if (document.body){ 
               document.body.scrollTop = winScroll;
            }
         } else if(textarea.selectionStart || textarea.selectionStart == '0') { // Gecko-based
            var textScroll = textarea.scrollTop;
            var selStart = textarea.selectionStart;
            textarea.value = textarea.value.substring(0, selStart)
                           + categoryLink
                           + textarea.value.substring(textarea.selectionEnd, textarea.value.length);
            textarea.selectionStart = textarea.selectionEnd = selStart + categoryLink.length;
            textarea.scrollTop = textScroll;
         }
      }
      ciFrame.style.display = 'none';
   }
 
   function ciButtonClicked() {
      if(arguments.length) var e = arguments[0]; // FIXME
      else var e = event;
      if (typeof(e.shiftKey) != "undefined") var shift = e.shiftKey;
      else var shift = e.modifiers & Event.SHIFT_MASK;
      if (shift) { // set default starting category
         var start = prompt("Induló kategória: ", ciStartingCategory);
         if(start) {
            ciStartingCategory = start;
            document.cookie = 'ciStart='+escape(start);
         } else if (start === "") {
            ciStartingCategory = ciDefaultCategory;
            document.cookie = 'ciStart=; expires=Thu, 01-Jan-1970 00:00:01 GMT;'; // delete cookie
         }
         return;
      }
      if (typeof(wikEdUseWikEd) != 'undefined' && wikEdUseWikEd == true) {
         ciWikEdObj = {};
	      ciWikEdObj.changed = {};
         WikEdGetText(ciWikEdObj, 'selection');
         ciWikEdObj.changed = ciWikEdObj.selection;
         var selection = ciWikEdObj.selection.plain;
      } else {
         var textarea = document.editform.wpTextbox1;
         if (document.selection && document.selection.createRange) { // IE, Opera
            textarea.focus();
            ciTextRange = document.selection.createRange();
            if(!is_opera) { // workaround for the inconsistent handling of trailing newlines in IE 
               var l = ciTextRange.text.length;
               while(ciTextRange.text.length == l) {
                  ciTextRange.moveEnd('character', -1);
               }
               ciTextRange.moveEnd('character', 1);
            }
            var selection = ciTextRange.text;
         } else if(textarea.selectionStart || textarea.selectionStart == '0') { // Gecko-based
            var selection = textarea.value.substring(textarea.selectionStart, textarea.selectionEnd);
         }
      }
      ciKey = ciTrail = '';
      if(!selection) { // use ciStartingCategory as default
         selection = ciStartingCategory;
      } else {
         var match = selection.match(/(\s+)$/);
         if (match && match.length >= 2) { // allow trailing whitespace
            selection = selection.substring(0, selection.length - (match[1].length));
            ciTrail = match[1];
         }
         match = selection.match(/\[\[.*(\|.*)]]$/);
         if(match && match.length >= 2) {
            ciKey = match[1];
         }
         selection = selection.replace(/^\[\[[Kk]ategória:/, '');
         selection = selection.replace(/(\|.*)?]]$/, '');
      }
      var div = ciGetDialog();
      ciFrame.focus();
      ciLoadChildren(selection,ciMode,div);
   }
 
   function ciInstallButton() {
      var toolbar = document.getElementById('toolbar');
      if (!toolbar) { return false; }
      mwInsertEditButton(toolbar, {
         "imageId": "insertCategory",
         "imageFile": 'http://upload.wikimedia.org/wikipedia/commons/b/b4/Button_category03.png',
         "speedTip": "Kategória kiválasztása",
         "tagOpen": "",
         "tagClose": "",
         "sampleText": ""
      });
      var button = document.getElementById("insertCategory");
      button.onclick = ciButtonClicked;
   }
   hookEvent('load', ciInstallButton);
}