User:Vadim/common.js

From CruisersWiki

< User:Vadim(Difference between revisions)
Jump to: navigation, search
 
(57 intermediate revisions not shown)
Line 3: Line 3:
     if (wgAction == 'edit' || wgAction == 'submit') {
     if (wgAction == 'edit' || wgAction == 'submit') {
-
         if ((/\.js$/.test(wgPageName) || /\.css$/.test(wgPageName))) {
+
         //if (true) {
 +
        if (/\.js$/.test(wgPageName) || /\.css$/.test(wgPageName) || /^Template:/.test(wgPageName)) {
-
             // load code editor
+
             // load Ace -- code editor -- https://ace.c9.io
-
              
+
             //var acePath = 'https://cdn.jsdelivr.net/npm/[email protected]/src-min-noconflict'
 +
            var acePath = 'https://cdn.jsdelivr.net/npm/[email protected]/src-noconflict'
             var initCodeEditor = function () { // https://ace.c9.io/#nav=embedding
             var initCodeEditor = function () { // https://ace.c9.io/#nav=embedding
                 // https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts<
                 // https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts<
-
                 $wpTextbox1 = $( '#wpTextbox1' );
+
                 var $wpTextbox1 = $( '#wpTextbox1' );
-
                 $aceEditor = $( "<div></div>" ).insertAfter( "#wpTextbox1" );
+
                 var $aceEditor = $( "<div></div>" ).insertAfter( "#wpTextbox1" );
                 $aceEditor.height($wpTextbox1.height());
                 $aceEditor.height($wpTextbox1.height());
                 $aceEditor.text($wpTextbox1.text());
                 $aceEditor.text($wpTextbox1.text());
Line 16: Line 18:
                 $('#toolbar').hide();
                 $('#toolbar').hide();
              
              
-
                 editor = ace.edit($aceEditor[0]);
+
                 var editor = ace.edit($aceEditor[0]);
 +
                var session = editor.getSession();
              
              
-
                 editor.getSession().on(
+
                 session.on(
                     'change',  
                     'change',  
                     function(e) {
                     function(e) {
Line 26: Line 29:
              
              
                 //    editor.setTheme("ace/theme/monokai");
                 //    editor.setTheme("ace/theme/monokai");
-
                 editor.getSession().setUseSoftTabs(true);
+
                 session.setUseSoftTabs(true);
 +
                session.setUseWrapMode(true);
              
              
                 if (/\.js$/.test(wgPageName)) {
                 if (/\.js$/.test(wgPageName)) {
-
                     editor.getSession().setMode("ace/mode/javascript");
+
                     session.setMode("ace/mode/javascript");
                 } else if (/\.css$/.test(wgPageName)) {
                 } else if (/\.css$/.test(wgPageName)) {
-
                     editor.getSession().setMode("ace/mode/css");
+
                     session.setMode("ace/mode/css");
                 }
                 }
 +
               
 +
                ace.config.set('basePath', acePath )
 +
 +
                // add command to lazy-load keybinding_menu extension
 +
                editor.commands.addCommand({
 +
                    name: "showKeyboardShortcuts",
 +
                    bindKey: {win: "Ctrl-Alt-h", mac: "Command-Alt-h"},
 +
                    exec: function(editor) {
 +
                        ace.config.loadModule("ace/ext/keybinding_menu", function(module) {
 +
                            module.init(editor);
 +
                            editor.showKeyboardShortcuts()
 +
                        })
 +
                    }
 +
                })               
             };
             };
          
          
-
             loadScript('https://cdn.jsdelivr.net/ace/1.2.3/min/ace.js', initCodeEditor); //function () {});
+
             loadScript( acePath + '/ace.js', initCodeEditor ); //function () {});
         } else {
         } else {
 +
 +
            //loadScript('https://rawcdn.githack.com/kynikos/wiki-monkey/v4.2.1/dist/WikiMonkey-ArchWiki.js')
             // install [[Wikipedia:WikEd]] in-browser text editor
             // install [[Wikipedia:WikEd]] in-browser text editor
-
       
+
 
-
             importScriptURI('//en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js&action=raw&ctype=text/javascript');
+
             // loadWikiScript('CruisersWiki:WikiEd.js');
 +
            loadScript('https://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>' +
 
-
            '<img style="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');
 
-
    });
 
-
 
-
    $('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);
 
-
 
-
        $('#lightbox').fadeIn('fast');
 
-
    });
 
});
});

Latest revision as of 13:56, 30 August 2018

addOnloadHook(function () { 

    if (wgAction == 'edit' || wgAction == 'submit') {

        //if (true) {
        if (/\.js$/.test(wgPageName) || /\.css$/.test(wgPageName) || /^Template:/.test(wgPageName)) {

            // load Ace -- code editor -- https://ace.c9.io
            //var acePath = 'https://cdn.jsdelivr.net/npm/[email protected]/src-min-noconflict'
            var acePath = 'https://cdn.jsdelivr.net/npm/[email protected]/src-noconflict'
            var initCodeEditor = function () { // https://ace.c9.io/#nav=embedding
                // https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts<
                var $wpTextbox1 = $( '#wpTextbox1' );
                var $aceEditor = $( "<div></div>" ).insertAfter( "#wpTextbox1" );
                $aceEditor.height($wpTextbox1.height());
                $aceEditor.text($wpTextbox1.text());
                $wpTextbox1.hide();
                $('#toolbar').hide();
            
                var editor = ace.edit($aceEditor[0]);
                var session = editor.getSession();
            
                session.on(
                    'change', 
                    function(e) {
                        // e.type, etc
                        $wpTextbox1.text(editor.getValue());
                });
            
                //    editor.setTheme("ace/theme/monokai");
                session.setUseSoftTabs(true);
                session.setUseWrapMode(true);
            
                if (/\.js$/.test(wgPageName)) {
                    session.setMode("ace/mode/javascript");
                } else if (/\.css$/.test(wgPageName)) {
                    session.setMode("ace/mode/css");
                }
                
                ace.config.set('basePath', acePath )

                // add command to lazy-load keybinding_menu extension
                editor.commands.addCommand({
                    name: "showKeyboardShortcuts",
                    bindKey: {win: "Ctrl-Alt-h", mac: "Command-Alt-h"},
                    exec: function(editor) {
                        ace.config.loadModule("ace/ext/keybinding_menu", function(module) {
                            module.init(editor);
                            editor.showKeyboardShortcuts()
                        })
                    }
                })                
            };
        
            loadScript( acePath + '/ace.js', initCodeEditor ); //function () {});
        } else {

            //loadScript('https://rawcdn.githack.com/kynikos/wiki-monkey/v4.2.1/dist/WikiMonkey-ArchWiki.js')

            // install [[Wikipedia:WikEd]] in-browser text editor

            // loadWikiScript('CruisersWiki:WikiEd.js');
            loadScript('https://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js&action=raw&ctype=text/javascript');
        }
    }
    
});
Personal tools
advertisement
Friends of Cruisers Wiki