User:Matxx25/global.js

Units = []; UnitsLabels = []; function AutocompleteInit{ console.log('jQueryUI-Autocomplete: initialisation ...'); $('.autocomplete-ui img').prop('src','//cmfscrecruits.com/wp-content/themes/coquitlam/lib/images/ajaxloader.gif') if (sessionStorage) { Units = JSON.parse(sessionStorage.getItem("Units")); UnitsLabels = JSON.parse(sessionStorage.getItem("UnitsLabels")); }   if (Units && UnitsLabels) { console.log('jQueryUI-Autocomplete: Units retrieved from sessionStorage'); AutocompleteReady(Units); } else { console.log('jQueryUI-Autocomplete: fetching ...'); Units = []; UnitsLabels = []; $.getJSON('/api.php?format=json&action=parse&text=', function(data) {           var code = data.parse.text['*'];            lines = code.split(' ');           $.each(lines,function(k,v){ var line = v.split(' &#160; = &#160; '); // only labels UnitsLabels.push(line[1]); // ID + labels : { value: ID, label: label } if (k===0) line[0] = line[0].split(' ')[1]; // first line contains a ' ' Units.push({value:parseInt(line[0]),label:line[1]}) });           // last line parsed is garbage            Units.pop;             UnitsLabels.pop;            // store values            if (sessionStorage) {                 sessionStorage.setItem("Units",JSON.stringify(Units));                 sessionStorage.setItem("UnitsLabels",JSON.stringify(UnitsLabels));                console.log('jQueryUI-Autocomplete: Units saved to sessionStorage');            }            AutocompleteReady;        }); } } function AutocompleteReady { $("input.autocomplete-units-id").autocomplete({ source: Units }); $("input.autocomplete-units-name").autocomplete({ source: UnitsLabels }); $("input.autocomplete-units-redirect").autocomplete({       source: UnitsLabels,        select: function( event, ui ) {             window.location = '/wiki/'+encodeURIComponent(ui.item.label);         }    }); $("input.autocomplete-units-link").autocomplete({       source: UnitsLabels,        select: function( event, ui ) {             var url = '/wiki/'+encodeURIComponent(ui.item.label);            var target = ( $('.autocomplete-units-link-target').prop('checked') ? '_blank' : '_self' );           var win = window.open(url,target);            if (win) {                // Browser has allowed it to be opened                win.focus;            } else {                // Broswer has blocked it                alert("Merci d'autoriser ce site à ouvrir des pop-up afin d'obtenir cet fonctionalité.");            }        }    }); console.log('jQueryUI-Autocomplete: autocomplete ready'); $('.autocomplete-ui img').prop('src','//cliparts.co/cliparts/8iE/7qe/8iE7qe8ia.png'); }

function CompareTwoUnits { var $compareForm = $('#compare-form'); var $compareContainer = $('#compare-container'); if ( ($compareForm.length === 0) && ($compareContainer.length === 0) ) return; // prepare form $compareForm.append(       $(' ')            .append( $(' ').prop('id','unit1').prop('class','autocomplete-units-id') )            .append( $(' ').prop('id','unit2').prop('class','autocomplete-units-name') )            .append( $('') )            .append( ' ' )            .append( $(' ') .prop('id','unit3') .prop('class','autocomplete-units-redirect') )           .append( ' ' )            .append( $(' ') .prop('id','unit4') .prop('class','autocomplete-units-link') )           .append( $(' ') .prop('class','autocomplete-units-link-target') .prop('title','Ouvrir dans une nouvelle page') )   );    // submit form => retrieve comparison $compareForm.find('form').on('submit',function(e){       var unit1 = $(this).find('#unit1').val;        var unit2 = $(this).find('#unit2').val;        $.getJSON('/api.php?action=parse&text=&format=json', function(data) { var code = data.parse.text['*']; $compareContainer.html(code); });       e.preventDefault;    }); }

// highest version compatible with wikia jquery 1.8.2 $.getScript('https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js',function{   // plugins depending on jQueryUI    AutocompleteInit; });

// function to launch on startup $(function{   CompareTwoUnits; });

//// AjaxRC window.ajaxPages = ["Special:RecentChanges","Spécial:Modifications_récentes","Spécial:WikiActivity","Special:Watchlist","Special:Log","Special:Contributions"]; //window.ajaxIndicator = 'http://images2.wikia.nocookie.net/__cb20100609110347/software/images/a/a9/Indicator.gif'; //window.ajaxRefresh = 30000; window.AjaxRCRefreshText = 'Auto-refresh'; window.AjaxRCRefreshHoverText = 'Automatically refresh the page'; //window.ajaxCallAgain = window.ajaxCallAgain || []; //window.ajaxCallAgain.push(function1, function2, function3); //*/

importArticles({   type: 'script',    articles: [        'u:dev:LastEdited/code.js',        'u:dev:QuickDiff/code.js',        'u:dev:QuickToolsv2/code.js',        'u:dev:FindAndReplace/code.js',        'u:dev:AjaxRC/code.js',        'u:dev:AjaxUndo/code.js',        //'u:dev:Loadables/JQueryUI.js',    ] });

/*// raw content (with wiki markup) $.getJSON('/api.php?format=json&action=query&titles=RéférencesUnités&prop=revisions&rvprop=content', function(data) {   console.log('query');    console.log(data);    window.Data = data; }); //*/

/*// parsed content $.getJSON('/api.php?format=json&action=parse&text=', function(data) {   console.log(data);    var code = data.parse.text['*'];    console.log(code);    window.Data = code; }); //*/

/*// action unknown... $.getJSON('/api.php?format=json&action=raw&titles=RéférencesUnités&prop=revisions&rvprop=content', function(data) {   console.log('raw');    console.log(data);    window.Data = data; }); //*/