Popup.js: diferenças entre revisões

Fonte: Wiki The-West PT
Saltar para a navegação
mSem resumo de edição
Sem resumo de edição
Linha 241: Linha 241:
     data: {
     data: {
         dmg: {
         dmg: {
             dmglvl: '<p class="popup_dmg">+ #1 Damages#2</p>'
             danolvl: '<p class="popup_dmg">+ #1 Dano#2</p>'
         },
         },
         skills: {
         skills: {
             str: '<p class="popup_attribute">+ #1 Strength#2</p>',
             for: '<p class="popup_attribute">+ #1 Força#2</p>',
             mob: '<p class="popup_attribute">+ #1 Mobility#2</p>',
             mob: '<p class="popup_attribute">+ #1 Mobilidade#2</p>',
             dex: '<p class="popup_attribute">+ #1 Dexterity#2</p>',
             des: '<p class="popup_attribute">+ #1 Destreza#2</p>',
             cha: '<p class="popup_attribute">+ #1 Charisma#2</p>',
             car: '<p class="popup_attribute">+ #1 Carisma#2</p>',
             con: '<p class="popup_skill">+ #1 Construction#2</p>',
             con: '<p class="popup_skill">+ #1 Construção#2</p>',
             vig: '<p class="popup_skill">+ #1 Vigor#2</p>',
             vig: '<p class="popup_skill">+ #1 Vigor#2</p>',
             tou: '<p class="popup_skill">+ #1 Toughness#2</p>',
             res: '<p class="popup_skill">+ #1 Resistência#2</p>',
             sta: '<p class="popup_skill">+ #1 Stamina#2</p>',
             tol: '<p class="popup_skill">+ #1 Tolerância#2</p>',
             hea: '<p class="popup_skill">+ #1 Health Points#2</p>',
             vid: '<p class="popup_skill">+ #1 Pontos de vida#2</p>',
             rid: '<p class="popup_skill">+ #1 Horseback Riding#2</p>',
             cav: '<p class="popup_skill">+ #1 Andar a cavalo#2</p>',
             ref: '<p class="popup_skill">+ #1 Reflex#2</p>',
             ref: '<p class="popup_skill">+ #1 Reflexos#2</p>',
             dod: '<p class="popup_skill">+ #1 Dodging#2</p>',
             eva: '<p class="popup_skill">+ #1 Evasão#2</p>',
             hid: '<p class="popup_skill">+ #1 Hiding#2</p>',
             esc: '<p class="popup_skill">+ #1 Esconder#2</p>',
             swi: '<p class="popup_skill">+ #1 Swimming#2</p>',
             nad: '<p class="popup_skill">+ #1 Nadar#2</p>',
             aim: '<p class="popup_skill">+ #1 Aiming#2</p>',
             mir: '<p class="popup_skill">+ #1 Mira#2</p>',
             sho: '<p class="popup_skill">+ #1 Shooting#2</p>',
             tir: '<p class="popup_skill">+ #1 Tiroteio#2</p>',
             pit: '<p class="popup_skill">+ #1 Setting traps#2</p>',
             arm: '<p class="popup_skill">+ #1 Colocar armadilhas#2</p>',
             fin: '<p class="popup_skill">+ #1 Fine Motor Skills#2</p>',
             per: '<p class="popup_skill">+ #1 Perícia#2</p>',
             rep: '<p class="popup_skill">+ #1 Repairing#2</p>',
             rep: '<p class="popup_skill">+ #1 Reparar#2</p>',
             lea: '<p class="popup_skill">+ #1 Leadership#2</p>',
             lid: '<p class="popup_skill">+ #1 Liderança#2</p>',
             tac: '<p class="popup_skill">+ #1 Tactics#2</p>',
             tac: '<p class="popup_skill">+ #1 Tática#2</p>',
             tra: '<p class="popup_skill">+ #1 Trading#2</p>',
             com: '<p class="popup_skill">+ #1 Comércio#2</p>',
             ani: '<p class="popup_skill">+ #1 Animal Instinct#2</p>',
             ani: '<p class="popup_skill">+ #1 Instinto animal#2</p>',
             app: '<p class="popup_skill">+ #1 Appearance#2</p>'
             apa: '<p class="popup_skill">+ #1 Aparência#2</p>'
         },
         },
         fb: {
         fb: {

Revisão das 17h07min de 13 de fevereiro de 2018

$('body').append('

');

$(document).on('mouseenter','.item_container',function(e){Popup.show(this);Popup.setPosition(e);}); $(document).on('mouseleave','.item_container',function(){Popup.hide();}); $(document).on('mousemove','.item_container', function(e){Popup.setPosition(e);});

$('.item_level').mousedown(function(e){ e.preventDefault(); }); $(document).on('click','.upgrade',function(){

   var container = $(this).closest('.item_container');
   var lvl = parseInt(container.attr('data-lvl'));
   if (lvl!==5){
       container.attr('data-lvl',lvl+1);
       container.find('.level').html(lvl+1);
   }
   Popup.show(container[0]);

}); $(document).on('click','.downgrade',function(){

   var container = $(this).closest('.item_container');
   var lvl = parseInt(container.attr('data-lvl'));
   if (lvl!==0){
       container.attr('data-lvl',lvl-1);
       container.find('.level').html(lvl-1);
   }
   Popup.show(container[0]);

});

if ($("#input_level").length == 1) {

   var input_level = $('<input type="number" style="width:80px;" class="west" placeholder="Your level" min="0" max="150">').bind("propertychange keyup input paste", function() {
       if (this.value > 150) {
           this.value = 150;
       } else if (this.value < 0) {
           this.value = 0;
       }
       $(".calc").each(function() {
           if (input_level.val() == 0) {
               $(this).html(this.id);
               $('.per_level_off').addClass('per_level').removeClass('per_level_off');
           } else {
               $(this).html(Math.ceil(Number(this.id) * input_level.val()));
               $('.per_level').addClass('per_level_off').removeClass('per_level');
           }
       });
   }).appendTo($("#input_level"));

}


//Search if ($("#input_search").length == 1) {

   var input_search = $('<input type="search" class="west" placeholder="Search">').bind("propertychange keyup input paste", function() {
       var val = this.value.toLowerCase();
       if (val == ) {
           $('.item_container').show();
       } else {
           $('.item_container').hide();
           $('.item_container').filter(function() {
               return $(this).attr('data-popup').toLowerCase().indexOf(val) > -1;
           }).show();
       }
   }).appendTo($("#input_search"));

}

//Switch weapons if ($("#switch").length == 1) {

   $("#fire").hide();
   $("#switch").on("click", function() {
       $('#melee, #fire').toggle()
   });

}

var Popup = {

   content : "",
   delay : 200,
   active : false,
   show: function(obj) {
       Popup.content = Popup.createPopup($(obj).attr('data-popup'), $(obj).attr('data-cdn-cat'), $(obj).attr('data-cdn-img'), parseInt($(obj).attr('data-lvl')));
       Popup.active = true;
       Popup.setTimeout();
       Popup.getContainer().html(Popup.content);
   },
   hide: function() {
       Popup.getEl().css({
           display: 'none',
           top: 0,
           left: 0
       });
       Popup.active = false;
       Popup.clearTimeout();
   },
   setTimeout: function() {
       Popup.clearTimeout();
       Popup.timer = window.setTimeout(function() {
           Popup.getEl().css('display', 'block');
       }, Popup.delay);
   },
   clearTimeout : function() {
       if (Popup.timer) window.clearTimeout(Popup.timer);
   },
   getEl : function() {
       return $('#popup_window');
   },
   getContainer : function() {
       return $('#popup_contents');
   },
   createPopup: function(data, cdn_cat, cdn_name, lvl) {
       data = JSON.parse(data);

var html = '


';

       var upgraded = false;
       if ((lvl>=1)&&(lvl<=5)){
           upgraded = true;
           data.auc = false;
       }
       if (data.dmg_min&&data.dmg_max){
           if (upgraded) {
               data.dmg_min += Math.round(Math.max(1, data.dmg_min * 0.1  * lvl));
               data.dmg_max += Math.round(Math.max(1, data.dmg_max * 0.1  * lvl));
           }

html += '

';

       }
       for (var cat in Popup.data) {
           var cnt = 0;
           for (var key in Popup.data[cat]) {
               if (data.hasOwnProperty(key)) {
                   cnt++;
                   var per_level = "";
                   if (data[key] < 0) {
                       if ($('#input_level input').val() > 0) {
                           data[key] = Math.ceil($('#input_level input').val() * -data[key]);
                           if (upgraded){
                               data[key] += Math.round(Math.max(1, data[key] * 0.1  * lvl));
                           }
                       } else {
                           data[key] = -data[key];
                           per_level = " (per Level)";
                           if (upgraded){
                               data[key] = Math.round(1e6 * (data[key] * 1 + Math.round(Math.max(1, data[key] * 1000 * lvl)) / 10000)) / 1e6;
                           }
                       }
                   } else if (upgraded) {

if (data[key]<1){ data[key] = Math.round(1e6 * (data[key] * 1 + Math.round(Math.max(1, data[key] * 1000 * lvl)) / 10000)) / 1e6; } else { data[key] += Math.round(Math.max(1, data[key] * 0.1 * lvl)); }

                   }
                   html += Popup.data[cat][key].replace('#1', data[key]).replace('#2', per_level);
               }
           }
           if (cnt > 0) {
               html += '
'; } } if (data.text){ for (var i = 0; i < data.text.length;i++){

html += '

';

           }
           html+='
'; } if (data.bonus){ for (var i = 0; i < data.bonus.length;i++){

html += '

';

           }
           html+='
'; } if (data.jobs){

html += '

';
           for (var i =0; i<data.jobs.length;i++){
html += '';
           }
html += '

';

       }
       if (data.craft){

html += '

';

       }

html += '

';

       return html;
   },
   setPosition : function (e) {
       var window_width = $(window).width();
       var window_height = $(window).height();
       var popup_width = Popup.getEl().outerWidth();
       var popup_height = Popup.getEl().outerHeight();
       var pos_x = e.clientX;
       var pos_y = e.clientY;
       var top;
       var left;
       var margin_top = 20;
       var margin_left = 20;
       if (pos_x + popup_width + margin_left > window_width) {
           left = pos_x - popup_width - margin_left + (e.pageX - e.clientX);
       } else {
           left = pos_x + margin_left + (e.pageX - e.clientX);
       }
       if (pos_y + popup_height + margin_top > window_height) {
           top = window_height - popup_height + (e.pageY - e.clientY);
       } else {
           top = pos_y + margin_top + (e.pageY - e.clientY);
       }
       Popup.getEl().css({
           top: top,
           left: left
       });
   },
   data: {
       dmg: {

danolvl: '

'

       },
       skills: {

for: '

', mob: '

', des: '

', car: '

', con: '

', vig: '

', res: '

', tol: '

', vid: '

', cav: '

', ref: '

', eva: '

', esc: '

', nad: '

', mir: '

', tir: '

', arm: '

', per: '

', rep: '

', lid: '

', tac: '

', com: '

', ani: '

', apa: '

'

       },
       fb: {

fbdef: '

', fboff: '

', fbres: '

', fbdefs: '

', fboffs: '

', fbdmgs: '

'

       }
   }

};

if ((new RegExp(mw.config.get('wgFormattedNamespaces')[10]+'\:Item\_*').test(mw.config.get('wgPageName')))&&($('.item_container').length==1)){

$('#mw-content-text').append('

');

   $('#popup_plain').hide();
   $('#popup_plain_contents').append(Popup.createPopup($('.item_container').attr('data-popup'), $('.item_container').attr('data-cdn-cat'), $('.item_container').attr('data-cdn-img'),0))
   $('#popup_plain').slideDown();

}

$('.item_container img').on('dblclick',function(){window.location='/wiki/'+mw.config.get('wgFormattedNamespaces')[10]+':Item_'+JSON.parse($(this).parent().attr('data-popup'))['id']/1000});