User:Vadim/common.js
From CruisersWiki
Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh); Konqueror: click Reload or press F5; Opera: clear the cache in Tools → Preferences; Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.
addOnloadHook(function () { if (wgAction == 'edit' || wgAction == 'submit') { if ((/\.js$/.test(wgPageName) || /\.css$/.test(wgPageName))) { // load code editor var initCodeEditor = function () { // https://ace.c9.io/#nav=embedding // https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts< $wpTextbox1 = $( '#wpTextbox1' ); $aceEditor = $( "<div></div>" ).insertAfter( "#wpTextbox1" ); $aceEditor.height($wpTextbox1.height()); $aceEditor.text($wpTextbox1.text()); $wpTextbox1.hide(); $('#toolbar').hide(); editor = ace.edit($aceEditor[0]); editor.getSession().on( 'change', function(e) { // e.type, etc $wpTextbox1.text(editor.getValue()); }); // editor.setTheme("ace/theme/monokai"); editor.getSession().setUseSoftTabs(true); if (/\.js$/.test(wgPageName)) { editor.getSession().setMode("ace/mode/javascript"); } else if (/\.css$/.test(wgPageName)) { editor.getSession().setMode("ace/mode/css"); } }; loadScript('https://cdn.jsdelivr.net/ace/1.2.3/min/ace.js', initCodeEditor); //function () {}); } else { // install [[Wikipedia:WikEd]] in-browser text editor importScriptURI('//en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js&action=raw&ctype=text/javascript'); } } }); // after [[w:User:Rezonansowy/SimpleLightbox]] addOnloadHook(function () { $('body').append( '<div id="lightbox" style="display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.6);text-align:center;z-index:9999">' + '<span style="display: inline-block; height: 100%; vertical-align: middle;" ></span>' + // http://stackoverflow.com/a/7310398 '<img style="display:none;background:#fff;box-shadow: 0 0 25px #111;max-height:100%;max-width:100%;vertical-align:middle;cursor:pointer;" />' + '</div>'); $('#lightbox').on('click', function() { $(this).fadeOut('fast', function () { $('#lightbox img').hide(); }); }); $('a.image').click(function(e) { e.preventDefault(); var src = $(this).find('img').attr('src'); var thumb = src.match(/^(.*)(\/thumb)(.*)(\/[^\/]*)$/,''); if (thumb) { src = thumb[1] + thumb[3]; } else if (src.match("/Special:Redirect/") ) { src = src.replace(/(\?width=.*)$/,''); } $('#lightbox img') .attr('src', src) .load(function () { $(this).fadeIn('fast'); }); $('#lightbox').fadeIn('fast'); }); });