User:Matxx25/global.js

//// Sidebar function Sidebar { var $rail = $('#WikiaRail'); if ($rail.length === 0) return; $(''+       ' Rejoignez-nous sur le chat ! '+        ' '+            ' '+            ' Kiwi '+            ' Mibbit '+        '  '+        ' '+            ' '+                ''+            ' '+            ' Ouvrir la page d\'une unité '+        ' '+        ' '+            ''+                ' '+                    ''+                ' '+                ''+                    ''+                    'dans une nouvelle page '+ ''+ ' '+           ' '+        ' '+    ' ')    .appendTo($rail);    var $container = $('#frwikiabf-activities');    $container.on('submit','#redirect-to-unit-page-form',function ( event ) { var unitName = $(this).find('.autocomplete-units-name').val; var url = '/wiki/'+encodeURIComponent(unitName); var target = ( $(this).find('.autocomplete-units-name-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é."); }       event.preventDefault; }); } //*/

//// Autocompletion UnitsIDs  = []; UnitsNames = []; function AutocompleteInit{ console.log('jQueryUI-Autocomplete: initialisation ...'); $('.autocomplete-ui img').prop('src','//i.imgur.com/G4P7PER.gif') if (sessionStorage) { UnitsIDs  = JSON.parse(sessionStorage.getItem("UnitsIDs")); UnitsNames = JSON.parse(sessionStorage.getItem("UnitsNames")); }   if (UnitsIDs && UnitsNames) { console.log('jQueryUI-Autocomplete: Units retrieved from sessionStorage'); AutocompleteReady(UnitsIDs); } else { console.log('jQueryUI-Autocomplete: fetching ...'); UnitsIDs  = []; UnitsNames = []; $.getJSON('/api.php?format=json&action=parse&text=', function(data) {           var code = data.parse.text['*'];            lines = code.split(' ');           $.each(lines,function(k,v){ // line = stars | ID | name var line = v.split('|'); // first line contains a ' ' if (k===0) line[0] = line[0].split(' ')[1]; UnitsNames.push({value:line[2],label:'('+parseInt(line[0])+'★) '+line[2]}); UnitsIDs .push({value:parseInt(line[1]),label:'('+parseInt(line[0])+'★) '+line[2]}) });           // last line parsed is garbage            UnitsIDs  .pop;             UnitsNames.pop;            // store values            if (sessionStorage) {                 sessionStorage.setItem("UnitsIDs"  ,JSON.stringify(UnitsIDs));                 sessionStorage.setItem("UnitsNames",JSON.stringify(UnitsNames));                console.log('jQueryUI-Autocomplete: Units saved to sessionStorage');            }            AutocompleteReady;        }); } } function AutocompleteReady { console.log('jQueryUI-Autocomplete: autocomplete ready'); $('.autocomplete-ui img').prop('src','//i.imgur.com/QK78lTQ.png'); Autocomplete($('#WikiaRail')); } function Autocomplete(container) { var $container = $(container); $container.find("input.autocomplete-units-id").autocomplete({ source: UnitsIDs }); $container.find("input.autocomplete-units-name").autocomplete({ source: UnitsNames }); } //*/

//// Form for comparing units function CompareTwoUnits { var $compareForm = $('#compare-form'); var $compareContainer = $('#compare-container'); if ( ($compareForm.length === 0) && ($compareContainer.length === 0) ) return; // prepare form $(' '+       ' '+    ' '    ).appendTo($compareForm); // 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={' + '{CompareTwoUnits|'+encodeURIComponent(unit1)+'|'+encodeURIComponent(unit2)+'}}&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') .done(function( data, textStatus, jqxhr ) {   // plugins depending on jQueryUI    AutocompleteInit; });

// function to launch on startup $(function{   Sidebar;    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',        'u:dev:OggPlayer.js',    ] });

/* exemple autocomplete $(' ').prop('class','autocomplete-units') .append( $(' ')               .prop('id','unit3')                .prop('class','autocomplete-units-redirect')     ) .append('br') .append( $(' ').prop('class','autocomplete-units-link') ) .append( $(' ')       .prop('class','autocomplete-units-link-target')        .prop('title','Ouvrir dans une nouvelle page')     )

/*// 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={' + '{:RéférencesUnités}}', 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; }); //*/ /*/// Ajax WikiaRail Sidebar var rail = $('#WikiaRail'); if (rail.length !== 0) { var $newSection = $(' '); rail.append($newSection); $.getJSON('/api.php?action=parse&text={' + '{Sidebar}}&format=json') .done(function(data) {       var code = data.parse.text['*'];        $('section#frwikiabf-activities').append(code);    }); } //*/

/*/// exemples $(function {   // version lente ?    var t0 = new Date;    $(' ').prop('id','frwikiabf-activities').prop('class','module').append( $(' ').append( $(' ').prop('class','mw-headline').text('Rejoignez-nous sur le Chat !') ) ).append( $(' ')           .append( $(' ').prop('id','chat-irc-popup')  .css('float','left') ) .append( $(' ').prop('id','mibbit-irc-popup').css('float','right').text('Mibbit') ) .append( $(' ').prop('id','kiwi-irc-popup') .css('float','right').text('Kiwi') ) ).append( $(' ').css('clear','both') ).append( $(' ').append(            $(' ').prop('class','autocomplete-ui').css('float','right').append( $(' ').prop('src','').css('width','15px') )       ).append(            $(' ').prop('class','mw-headline').text("Ouvrir la page d'une unité")        ) ).append( $(' ').prop('id','sidebar-units-autocomplete').append(           $(' ')                .append( $(' ').prop('class','autocomplete-units-link').css('width','97%') )                .append(' ')                .append( $(' ').prop({'title':"Ouvrir dans une nouvelle page",'class':'autocomplete-units-link-target','id':'autocomplete-units-link-target','type':'checkbox'}) )                .append( $(' ').prop('for','autocomplete-units-link-target').text("dans une ouvelle page") )        ) )   .appendTo( $('#WikiaRail') );    var t1 = new Date;    console.log(t1-t0);    // version à peine plus rapide    var t0 = new Date;    $(''+ ' Rejoignez-nous sur le Chat ! '+       ' '+            ' '+            ' Mibbit '+ ' Kiwi '+ '  '+ ' '+           ' '+                ''+ ' '+           ' Ouvrir la page d\'une unité '+ ' '+       ' '+            ' '+                ' '+ ''+ '<label for="autocomplete-units-link-target">dans une ouvelle page '+ ' '+       ' '+    ' ')    .appendTo( $('#WikiaRail') );    var t1 = new Date;    console.log(t1-t0);    var $caontainer = $('#frwikiabf-activities');    $caontainer.on('submit','form',function ( event ) { var url = '/wiki/'+encodeURIComponent(ui.item.label); var target = ( $container.find('.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é."); }       event.preventDefault; }); }); //*/

/*/// Auctomplete actions on click function RedirectEvent ($container) { return function ( event, ui ) { var url = '/wiki/'+encodeURIComponent(ui.item.value); var target = ( $container.find('.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é."); }   } } function Autocomplete { $("input.autocomplete-units-id").autocomplete({ source: UnitsIDs }); $("input.autocomplete-units-name").autocomplete({ source: UnitsNames }); $("input.autocomplete-units-redirect").autocomplete({       source: UnitsNames,        select: function( event, ui ) {             window.location = '/wiki/'+encodeURIComponent(ui.item.value);         }    }); var $container = $('.autocomplete-units'); $container.find("input.autocomplete-units-link").autocomplete({       source: UnitsNames,        select: RedirectEvent($container)    }); var $container = $('#sidebar-units-autocomplete') $container.find("input.autocomplete-units-link").autocomplete({       source: UnitsNames,        select: RedirectEvent($container)    }); } //*/