Popup.js

Από Wiki The-West GR
Jump to navigation

westui={lang:{input_level:"Το επίπεδό σου",input_search:"Αναζήτηση: ID, Σετ ή Όνομα",damages:"Ζημιά",per_level:"ανά επίπεδο",speed:"Ταχύτητα",level:"Επίπεδο",unsalable:"Μη εμπορεύσιμο",auction:"Με δυνατότητα δημοπρασίας",not_auction:"Χωρίς δυνατότητα δημοπρασίας",not_upgrade:"Χωρίς δυνατότητα αναβάθμισης",upgrade:"Με δυνατότητα αναβάθμισης",total:"Σύνολο",popup:{dmg:{dmglvl:'

'},skills:{str:'

',mob:'

',dex:'

',cha:'

',con:'

',vig:'

',tou:'

',sta:'

',hea:'

',rid:'

',ref:'

',dod:'

',hid:'

',swi:'

',aim:'

',sho:'

',pit:'

',fin:'

',rep:'

',lea:'

',tac:'

',tra:'

',ani:'

',app:'

'},fb:{fbdef:'

',fboff:'

',fbres:'

',fbdmgs:'

',fbdefs:'

',fboffs:'

'},special:{xp:'

',money:'

',luck:'

',drop:'

',regen:'

',labor_pts:'

',spd:'

',pray:'

'}}},config:{enable_set_calc:!0,plain_popup:!0,redirect_on_dblclick:!1,link_on_dblclick:!1,enable_sorting:!0,cdn:"//westgr.innogamescdn.com",media_cdn:"//media.innogamescdn.com/com_WEST_GR/wiki/event_offers",img_buyprice:"/images/5/57/Buy_price.png",img_sellprice:"/images/f/fc/Sell_price.png",img_male:"/images/e/ed/Ανδρικό.png",img_female:"/images/b/b5/Γυναικείο.png",img_prof:["c/c0","c/c3","2/2d","9/9a","f/fc"],img_job:{all:["d/d1","Οποιαδήποτε εργασία"]},cat_img:'

'),$("#popup_plain").hide(),$("#popup_plain_contents").append(westui.popup.createPopup($(".item_container").attr("data-popup"),$(".item_container").attr("data-cdn-cat"),$(".item_container").attr("data-cdn-img"),0)),$("#popup_plain").slideDown()),westui.config.redirect_on_dblclick&&$(".item_container img").on("dblclick",function(){window.location="/wiki/"+mw.config.get("wgFormattedNamespaces")[10]+":Item="+JSON.parse($(this).parent().attr("data-popup")).id/1e3})},popup:{content:"",delay:200,active:!1,show:function(t){westui.popup.content=westui.popup.createPopup($(t).attr("data-popup"),$(t).attr("data-cdn-cat"),$(t).attr("data-cdn-img"),parseInt($(t).attr("data-lvl"))),westui.popup.active=!0,westui.popup.setTimeout(),westui.popup.getContainer().html(westui.popup.content)},hide:function(){westui.popup.getEl().css({display:"none",top:0,left:0}),westui.popup.active=!1,westui.popup.clearTimeout()},setTimeout:function(){westui.popup.clearTimeout(),westui.popup.timer=window.setTimeout(function(){westui.popup.getEl().css("display","block")},westui.popup.delay)},clearTimeout:function(){westui.popup.timer&&window.clearTimeout(westui.popup.timer)},getEl:function(){return $("#popup_window")},getContainer:function(){return $("#popup_contents")},createPopup:function(t,e,i,s){t=JSON.parse(t);var a=westui.lang,p=westui.config,n=n=t.id?'

Shift+κλικ για αντιγραφή [item=ID]

':"",l=!1;d=t.dmg&&t.dmg.split("-");var o=0;if(t.jobGroup,n+="",t.cdn_img&&(n+='

'),t.id&&(n+='

'),t.name&&(n+='

"),t.ico&&(n+='

",n+=""}if(t.typeW){for(c=0;c<t.typeW.length;c++);n+='

",n+=""}if(t.type){for(c=0;c<t.type.length;c++);n+='

",n+=""}if(t.unique&&(n+='

"),s>=1&&s<=5&&(l=!0,t.auc=!1),t.text){t.unique&&(n+="
");for(var c=0;c<t.text.length;c++)n+='

";n+=""}for(var r in t.type||t.typeW?n+="
":n+="",s>=1&&s<=5&&(l=!0,t.auc=!1),d&&(o=1)&&(l&&(d[0]=1*d[0]+Math.round(Math.max(1,.1*d[0]*s)),d[1]=1*d[1]+Math.round(Math.max(1,.1*d[1]*s))),n+='

")&&!t.dmglvl&&d[0]&&(n+="
"),s>=1&&s<=5&&(l=!0,t.auc=!1),t.dmg_min&&t.dmg_max&&(l&&(t.dmg_min=1*t.dmg_min+Math.round(Math.max(1,.1*t.dmg_min*s)),t.dmg_max=1*t.dmg_max+Math.round(Math.max(1,.1*t.dmg_max*s))),n+='

")&&!t.dmglvl&&t.dmg_min&&(n+="
"),a.popup){o=0;for(var u in a.popup[r])if(t.hasOwnProperty(u)){o++;var _="";t[u]<0?$("#input_level input").val()>0?(t[u]=Math.ceil($("#input_level input").val()*-t[u]),l&&(t[u]+=Math.round(Math.max(1,.1*t[u]*s)))):(t[u]=-t[u],_=" ("+a.per_level+")",l&&(t[u]=Math.round(1e6*(1*t[u]+Math.round(Math.max(1,1e3*t[u]*s))/1e4))/1e6)):l&&(t[u]<1?t[u]=Math.round(1e6*(1*t[u]+Math.round(Math.max(1,1e3*t[u]*s))/1e4))/1e6:t[u]+=Math.round(Math.max(1,.1*t[u]*s))),n+=a.popup[r][u].replace("#1",t[u]).replace("#2",_)}o>0&&(n+="
")}if(t.textjob){for(c=0;c<t.textjob.length;c++)n+='

";n+="
"}if(t.bonus){for(n+='

',c=0;c<t.bonus.length;c++)n+='

";n+="
"}if(t.jobs){for(l in n+='

Από την εργασία:

',t.jobs)if("req"==l){for(var m of(n+='"}else{var g=p.jobIcon(l,t.jobs[l]);n+='"}n+="


"}if(t.craft){for(n+='

Χρειάζονται για την Δημιουργία:


"}var b=s,v=Math.pow(3,b),f=(Math.pow(3,Number(b)+Number(1))-3-2*b)/4,h=(t.bp*(v+f)).toString().replace(/\B(?=(\d{3})+(?!\d))/g,".");return t.hspd||t.set||t.sp||t.bp||t.blding||t.lvl||t.cat||t.auc||t.upg?n+='":n+="",n+""},setPosition:function(t){var e,i,s=$(window).width(),a=$(window).height(),p=westui.popup.getEl().outerWidth(),n=westui.popup.getEl().outerHeight(),l=t.clientX,o=t.clientY;i=l+p+10>s?l-p-10+(t.pageX-t.clientX):l+10+(t.pageX-t.clientX),e=o+n+10>a?a-n+(t.pageY-t.clientY):o+10+(t.pageY-t.clientY),westui.popup.getEl().css({top:e,left:i})},copyToClipboard:function(t){var e=$("<input>");$("body").append(e),e.val($(t).text()).select(),document.execCommand("copy"),e.remove()},init:function(){var t=westui.popup;$("body").append(''),$(document).on("mouseenter",".item_container",function(e){t.show(this),t.setPosition(e)}),$(document).on("click",".item_container",function(e){var i="",s=t.copyToClipboard(".popup_id");e.shiftKey&&t.copyToClipboard(".popup_id"),e.ctrlKey&&(i=s.replace(/[\[\]]/gi,""),console.log(i,s),window.open("https://wiki.the-west.gr/wiki/Πρότυπο:"+i,"_blank"))}),$(document).on("mouseleave",".item_container",function(){t.hide()}),$(document).on("mousemove",".item_container",function(e){t.setPosition(e)}),$(".item_level").mousedown(function(t){t.preventDefault()}),$(document).on("click",".upgrade",function(){var e=$(this).closest(".item_container"),i=parseInt(e.attr("data-lvl"));5!==i&&(e.attr("data-lvl",i+1),e.find(".level").html(i+1)),t.show(e[0])}),$(document).on("click",".downgrade",function(){var e=$(this).closest(".item_container"),i=parseInt(e.attr("data-lvl"));0!==i&&(e.attr("data-lvl",i-1),e.find(".level").html(i-1)),t.show(e[0])})}},set_calc:{bonus:{extra_set_bonus:{}},data:{},itemStatus:{},getData:function(){var t=westui.set_calc,e=westui.config;$(".set_container").each(function(){var e=$(this).attr("data-set-id");t.itemStatus[e]={},t.data[e]={items:{},set:{}}}),$(".infoSet").each(function(){var i=$(this).attr("data-set-id");$(this).find(".infosetatt").each(function(){var s=$(this).attr("data-nb");t.data[i].set[s]={},$(this).find(".set_bonus").each(function(){key=$(this).attr("data-type"),0!==$(this).find(".calc").length?t.data[i].set[s][key]=-parseFloat($(this).find(".calc").attr("id")):t.data[i].set[s][key]=parseFloat($(this).find(".val").text()),e.set_bonus.hasOwnProperty(key)||(t.bonus.extra_set_bonus[key]={img:$(this).find("img").attr("src"),name:$(this).find("#tooltip_content").text()})})})}),$(".set_container").each(function(){var i=$(this).attr("data-set-id");$(this).find(".item_container").each(function(){var s=JSON.parse($(this).attr("data-popup"));for(var a in $(this).is(":hidden")?t.itemStatus[i][s.id]=!1:t.itemStatus[i][s.id]=0,s)if("dmg"!=a){var p=a.startsWith("Job_");s.hasOwnProperty(a)&&(e.set_bonus.hasOwnProperty(a)||t.bonus.extra_set_bonus.hasOwnProperty(a)||p&&(t.bonus.extra_set_bonus[a]={img:e.jobIcon(a.replace("Job_",""))[0],name:s[a][1]}))&&(t.data[i].items[a]||(t.data[i].items[a]={}),t.data[i].items[a][s.id]=p?s[a][0]:s[a])}})})},calc:function(){var t=westui.set_calc,e=westui.config;if(0===$("#input_level").length|""!==$("#input_level input").val()){var i=parseInt($("#input_level input").val());for(var s in total={},t.data){for(var a in t.data[s].items)for(var p in t.data[s].items[a])if(!1!==t.itemStatus[s][p]){lvl=t.itemStatus[s][p],total[a]||(total[a]=0);var n=t.data[s].items[a][p];t.data[s].items[a][p]<0?(n=-n,t.itemStatus[s][p]>0?total[a]+=Math.ceil(n*i)+Math.round(Math.max(1,.1*Math.ceil(n*i)*lvl)):total[a]+=Math.ceil(n*i)):t.itemStatus[s][p]>0?total[a]+=n<1?Math.round(1e6*(1*n+Math.round(Math.max(1,1e3*n*lvl))/1e4))/1e6:n+Math.round(Math.max(1,.1*n*lvl)):total[a]+=n}var l=0;for(var p in t.itemStatus[s])!1!==t.itemStatus[s][p]&&l++;for(var a in t.data[s].set[l])total[a]||(total[a]=0),t.data[s].set[l][a]<0?total[a]+=Math.ceil(-t.data[s].set[l][a]*i):total[a]+=t.data[s].set[l][a]}var o='
<tbody>

'+westui.lang.total+"
";for(var a in e.set_bonus)total.hasOwnProperty(a)&&(o+='
<img src="/images/'+e.set_bonus[a].img+'.png" width="40px">
+'+total[a]+(-1!==["xp","money","luck","spd","regen","drop"].indexOf(a)?"%":"")+'
'+(e.set_bonus[a].icon?'<img src="/images/'+e.set_bonus[a].icon+'.png"> ':"")+e.set_bonus[a].name+"
");for(var c in t.bonus.extra_set_bonus)total.hasOwnProperty(c)&&(o+='
<img src="'+t.bonus.extra_set_bonus[c].img+'" width="40px">
+'+total[c]+(-1!==["xp","money","luck","spd","regen","drop"].indexOf(c)?"%":"")+'
'+(t.bonus.extra_set_bonus[c].icon?'<img src="/images/'+t.bonus.extra_set_bonus[c].icon+'.png"> ':"")+t.bonus.extra_set_bonus[c].name+"
");$("#set_calc").html(o)}else $("#set_calc").html("")},initEvents:function(){var t=westui.set_calc;$(".item_container > img").on("click",function(){var e=$(this).closest(".item_container");e.toggleClass("item_off");var i=e.closest(".set_container").attr("data-set-id"),s=JSON.parse(e.attr("data-popup")).id;e.hasClass("item_off")||e.is(":hidden")?t.itemStatus[i][s]=!1:westui.set_calc.itemStatus[i][s]=parseInt(e.attr("data-lvl")),t.calc()}),$(document).on("click",".upgrade, .downgrade",function(){var e=$(this).closest(".item_container"),i=e.closest(".set_container").attr("data-set-id");e.hasClass("item_off")||e.is(":hidden")||(t.itemStatus[i][JSON.parse(e.attr("data-popup")).id]=parseInt(e.attr("data-lvl")),t.calc())}),$("#input_level").bind("propertychange keyup input paste",function(){t.calc()}),$("#switch").on("click",function(){$("#melee, #fire").each(function(){var e=$(this).find(".item_container"),i=$(this).closest(".set_container").attr("data-set-id");$(this).is(":hidden")?t.itemStatus[i][JSON.parse(e.attr("data-popup")).id]=!1:t.itemStatus[i][JSON.parse(e.attr("data-popup")).id]=parseInt(e.attr("data-lvl"))}),t.calc()})},init:function(){var t=westui.set_calc;t.initEvents(),t.getData(),$("#mw-content-text").append('
'),0===$("#input_level").length&&t.calc()}},sorting:{sortItems:function(t){function e(e){var i=JSON.parse($(e).attr("data-popup")),s=$("#input_level input").val();s=s||150;var a=-1!==Object.keys(t).indexOf("id")||t.bool&&!0===t.bool,p=0;if(t.bool&&!0===t.bool)for(var n in p=1,t)"bool"!==n&&i[n]!==t[n]&&(p=0);else for(var n in t)"id"===n?p-=i[n]:(!i.lvl||i.lvl<=s)&&i[n]&&(i[n]<0?p+=Math.round(-i[n]*s)*t[n]:p+=i[n]*t[n]);$(e).attr("data-sort",p),0==p&&$(e).hide(),0!==$(e).find(".sortval").length?a?$(e).find(".sortval").html(""):$(e).find(".sortval").html(p):a||$(e).append('
'+p+"
")}$(".item_container").removeAttr("data-sort").show(),$("#mw-content-text").find(".sorting_hidden").hide(),$(".sorting_container").each(function(){$(this).find(".item_container").sort(function(t,i){return $(t).attr("data-sort")||e(t),$(i).attr("data-sort")||e(i),$(i).attr("data-sort")-$(t).attr("data-sort")}).appendTo($(this))})},init:function(){if(1===$("div#sort_items").length){var t="",$("div#sort_items").html(t),$("select#sort_items").on("change",function(){westui.sorting.sortItems(JSON.parse($(this).find("option:selected").attr("value")))})}}},init:function(){westui.initPage(),westui.popup.init(),westui.config.enable_sorting&&westui.sorting.init(),westui.config.enable_set_calc&&0!==$(".infoSet").length&&westui.set_calc.init()}},westui.init();