Popup.js: Διαφορά μεταξύ των αναθεωρήσεων
Χωρίς σύνοψη επεξεργασίας |
Χωρίς σύνοψη επεξεργασίας |
||
Γραμμή 1: | Γραμμή 1: | ||
westui = { | |||
lang: { | |||
input_level: "Your level", | |||
input_search: "Search", | |||
damages: "Damages", | |||
per_level: "per Level", | |||
speed: "Speed", | |||
level: "Level", | |||
unsalable: "Unsalable", | |||
auction: "Auctionable", | |||
not_auction: "Not auctionable", | |||
not_upgrade: "Not upgradeable", | |||
upgrade: "Upgradeable", | |||
total: "Total", | |||
popup: { | |||
dmg: { | |||
dmglvl: '<p class="popup_dmg">+ #1 Damages#2</p>' | |||
}, | |||
skills: { | |||
str: '<p class="popup_attribute">+ #1 Strength#2</p>', | |||
mob: '<p class="popup_attribute">+ #1 Mobility#2</p>', | |||
dex: '<p class="popup_attribute">+ #1 Dexterity#2</p>', | |||
cha: '<p class="popup_attribute">+ #1 Charisma#2</p>', | |||
con: '<p class="popup_skill">+ #1 Construction#2</p>', | |||
vig: '<p class="popup_skill">+ #1 Vigor#2</p>', | |||
tou: '<p class="popup_skill">+ #1 Toughness#2</p>', | |||
sta: '<p class="popup_skill">+ #1 Stamina#2</p>', | |||
hea: '<p class="popup_skill">+ #1 Health Points#2</p>', | |||
rid: '<p class="popup_skill">+ #1 Horseback Riding#2</p>', | |||
ref: '<p class="popup_skill">+ #1 Reflex#2</p>', | |||
dod: '<p class="popup_skill">+ #1 Dodging#2</p>', | |||
hid: '<p class="popup_skill">+ #1 Hiding#2</p>', | |||
swi: '<p class="popup_skill">+ #1 Swimming#2</p>', | |||
aim: '<p class="popup_skill">+ #1 Aiming#2</p>', | |||
sho: '<p class="popup_skill">+ #1 Shooting#2</p>', | |||
pit: '<p class="popup_skill">+ #1 Setting traps#2</p>', | |||
fin: '<p class="popup_skill">+ #1 Fine Motor Skills#2</p>', | |||
rep: '<p class="popup_skill">+ #1 Repairing#2</p>', | |||
lea: '<p class="popup_skill">+ #1 Leadership#2</p>', | |||
tac: '<p class="popup_skill">+ #1 Tactics#2</p>', | |||
tra: '<p class="popup_skill">+ |
Αναθεώρηση της 16:50, 18 Ιουνίου 2018
westui = {
lang: { input_level: "Your level", input_search: "Search", damages: "Damages", per_level: "per Level", speed: "Speed", level: "Level", unsalable: "Unsalable", auction: "Auctionable", not_auction: "Not auctionable", not_upgrade: "Not upgradeable", upgrade: "Upgradeable", total: "Total", popup: { dmg: {
dmglvl: '
+ #1 Damages#2
'
}, skills: {
str: '
+ #1 Strength#2
', mob: '
+ #1 Mobility#2
', dex: '
+ #1 Dexterity#2
', cha: '
+ #1 Charisma#2
', con: '
+ #1 Construction#2
', vig: '
+ #1 Vigor#2
', tou: '
+ #1 Toughness#2
', sta: '
+ #1 Stamina#2
', hea: '
+ #1 Health Points#2
', rid: '
+ #1 Horseback Riding#2
', ref: '
+ #1 Reflex#2
', dod: '
+ #1 Dodging#2
', hid: '
+ #1 Hiding#2
', swi: '
+ #1 Swimming#2
', aim: '
+ #1 Aiming#2
', sho: '
+ #1 Shooting#2
', pit: '
+ #1 Setting traps#2
', fin: '
+ #1 Fine Motor Skills#2
', rep: '
+ #1 Repairing#2
', lea: '
+ #1 Leadership#2
', tac: '
+ #1 Tactics#2
', tra: '
+ #1 Trading#2
', ani: '
+ #1 Animal Instinct#2
', app: '
+ #1 Appearance#2
'
}, fb: {
fbdef: '
+ #1 Defense (Fort battle bonus)#2
', fboff: '
+ #1 Attack (Fort battle bonus)#2
', fbres: '
+ #1 Resistance (Fort battle bonus)#2
', fbdefs: '
+ #1 Defense (Fort battle sector bonus)#2
', fboffs: '
+ #1 Attack (Fort battle sector bonus)#2
', fbdmgs: '
+ #1 Damages (Fort battle sector bonus)#2
'
}, special: {
xp: '
+ #1% Experience from jobs, duels and fort battles#2
', money: '
+ #1% Money from jobs and duels#2
', luck: '
+ #1% Improved Luck#2
', regen: '
+ #1% Regeneration#2
', drop: '
+ #1% Improved drop chance#2
', labor_pts: '
+ #1 labor point#2
',
} } }, config: { enable_set_calc: true, plain_popup: true, redirect_on_dblclick: false, cdn: "https://westzz.innogamescdn.com", img_buyprice: "/images/5/57/Buy_price.png", img_sellprice: "/images/f/fc/Sell_price.png", img_male: "/images/c/c5/Gender_m.png", img_female: "/images/4/41/Gender_f.png", set_bonus: { str: { name: "Strength", img: "/images/thumb/8/8b/Strength.png/40px-Strength.png" }, mob: { name: "Mobility", img: "/images/thumb/5/5a/Mobility.png/40px-Mobility.png" }, dex: { name: "Dexterity", img: "/images/thumb/0/0d/Dexterity.png/40px-Dexterity.png" }, cha: { name: "Charisma", img: "/images/thumb/c/c9/Charisma.png/40px-Charisma.png" }, con: { name: "Construction", img: "/images/thumb/3/37/Construction.png/40px-Construction.png" }, vig: { name: "Vigor", img: "/images/thumb/9/90/Skill_Punch.png/40px-Skill_Punch.png" }, tou: { name: "Toughness", img: "/images/thumb/f/f8/Skill_Tough.png/40px-Skill_Tough.png" }, sta: { name: "Stamina", img: "/images/thumb/8/8d/Stamina.png/40px-Stamina.png" }, hea: { name: "Health Points", img: "/images/thumb/9/94/Health.png/40px-Health.png" }, rid: { name: "Horseback Riding", img: "/images/thumb/7/78/Hbr.png/40px-Hbr.png" }, ref: { name: "Reflex", img: "/images/thumb/e/e9/Skill_Reflex.png/40px-Skill_Reflex.png" }, dod: { name: "Dodging", img: "/images/thumb/0/07/Skill_Dodge.png/40px-Skill_Dodge.png" }, hid: { name: "Hiding", img: "/images/thumb/9/97/Hiding.png/40px-Hiding.png" }, swi: { name: "Swimming", img: "/images/thumb/f/f4/Swimming.png/40px-Swimming.png" }, aim: { name: "Aiming", img: "/images/thumb/5/53/Skill_Aim.png/40px-Skill_Aim.png" }, sho: { name: "Shooting", img: "/images/thumb/7/73/Skill_Shot.png/40px-Skill_Shot.png" }, pit: { name: "Setting traps", img: "/images/thumb/e/e1/Trapping.png/40px-Trapping.png" }, fin: { name: "Fine Motor Skills", img: "/images/thumb/1/18/Fms.png/40px-Fms.png" }, rep: { name: "Repairing", img: "/images/thumb/d/d5/Repairing.png/40px-Repairing.png" }, lea: { name: "Leadership", img: "/images/thumb/4/44/Leadership.png/40px-Leadership.png" }, tac: { name: "Tactics", img: "/images/thumb/9/91/Skill_Tactic.png/40px-Skill_Tactic.png" }, tra: { name: "Trading", img: "/images/thumb/f/f3/Skill_Trading.png/40px-Skill_Trading.png" }, ani: { name: "Animal Instinct", img: "/images/thumb/9/9d/AnimalInstinct.png/40px-AnimalInstinct.png" }, app: { name: "Appearance", img: "/images/thumb/4/4c/Skill_Appearance.png/40px-Skill_Appearance.png" }, fbdef: { name: "Defense (Fort battle bonus)", img: "/images/8/82/Set_Fb_defense.png" }, fboff: { name: "Attack (Fort battle bonus)", img: "/images/3/30/Set_Fb_offense.png" }, fbres: { name: "Resistance (Fort battle bonus)", img: "/images/4/4b/Resistance.png" }, fbdefs: { name: "Defense (Fort battle sector bonus)", img: "/images/1/1a/Set_Fb_defense_sec.png" }, fboffs: { name: "Attack (Fort battle sector bonus)", img: "/images/f/fe/Set_Fb_offense_sec.png" }, fbdmgs: { name: "Damages (Fort battle sector bonus)", img: "/images/b/b3/Damages_sector.png" }, xp: { name: "Experience from jobs, duels, and fort battles (%)", img: "/images/7/71/Set_xp.png" }, money: { name: "Money from jobs and duels (%)", img: "/images/d/df/Set_money.png" }, luck: { name: "Increased Luck", img: "/images/c/c1/Set_luck.png" }, regen: { name: "Regeneration", img: "/images/5/53/Regeneration.png", }, drop: { name: "Improved drop chance", img: "/images/thumb/b/b8/Drop.png/40px-Drop.png" }, labor_pts: { name: "Labor points (all jobs)", img: "/images/5/5e/Labor_pts.png" } } }, initPage: function () { //Append input level if ($("#input_level").length === 1) { var input_level = $('<input type="number" style="width:80px;" class="west" placeholder="' + westui.lang.input_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="' + westui.lang.input_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(); }); } //Switch products if ($("#switch_prod").length === 1) { $("#prod2").hide(); $("#switch_prod").on("click", function () { $('#prod, #prod2').toggle(); }); }
//Show a "plain text" popup in the template if (westui.config.plain_popup && (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(westui.popup.createPopup($('.item_container').attr('data-popup'), $('.item_container').attr('data-cdn-cat'), $('.item_container').attr('data-cdn-img'), 0)); $('#popup_plain').slideDown(); }
//On dbl click on item, redirect the user to the template if (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 / 1000; }); }
}, popup: { content: "", delay: 200, active: false, show: function (obj) { westui.popup.content = westui.popup.createPopup($(obj).attr('data-popup'), $(obj).attr('data-cdn-cat'), $(obj).attr('data-cdn-img'), parseInt($(obj).attr('data-lvl'))); westui.popup.active = true; 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 = false; 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 () { if (westui.popup.timer) window.clearTimeout(westui.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 = '
' + data.name + '
' + data.type + '
';
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 += '
' + data.dmg_min + '-' + data.dmg_max + ' ' + westui.lang.damages + '
';
} if (data.text) { for (var i = 0; i < data.text.length; i++) {
html += '
' + data.text[i] + '
';
} html += '
'; } for (var cat in westui.lang.popup) { var cnt = 0; for (var key in westui.lang.popup[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 = " (" + westui.lang.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 += westui.lang.popup[cat][key].replace('#1', data[key]).replace('#2', per_level); } } if (cnt > 0) { html += '
'; } } if (data.textjob) { for (var i = 0; i < data.textjob.length; i++) {
html += '
' + data.textjob[i] + '
';
} html += '
'; } if (data.bonus) { for (var i = 0; i < data.bonus.length; i++) {
html += '
' + data.bonus[i] + '
';
} html += '
'; } if (data.jobs) {
html += '
for (var i = 0; i < data.jobs.length; i++) {html += '';
}html += '
<img src="' + westui.config.cdn + '/images/jobs/' + data.jobs[i][1] + '.png"/> | ' + data.jobs[i][0] + ' |
';
} if (data.craft) {
html += '
<img src="' + westui.config.cdn + '/images/crafting/profsymbol_' + data.craft.id + '_small.png"/> | ';
for (var i = 0; i < data.craft.req.length; i++) {html += ''; }html += ''; for (var i = 0; i < data.craft.req.length; i++) { html += ''; }html += '
|
';
}
html += '
if (data.spd) { if (upgraded) { data.spd += Math.round(Math.max(1, data.spd * 0.1 * lvl)); }html += '
' + westui.lang.speed + ': +' + data.spd + '%
';
}if (data.set) html += '
<a class="popup_set" href="/wiki/' + data.set + '">' + data.set + '</a>
';
if (data.sp) { html += '<img src="' + westui.config.img_buyprice + '"/>' + data.bp + ' <img src="' + westui.config.img_sellprice + '"/> ' + data.sp + 'html += '
'; } else { html += '' + westui.lang.unsalable + '
'; } if (data.lvl) html += westui.lang.level + ' ' + data.lvl + '
'; if (data.sex) { if (data.sex == 0) { html += '<img src="' + westui.config.img_male + '"/> '; } else { html += '<img src="' + westui.config.img_female + '"/> '; } } if (data.auc == 1) { html += '' + westui.lang.auction + '
'; } else { html += '' + westui.lang.not_auction + '
'; } if (data.upg == 0) { html += '' + westui.lang.not_upgrade + '
'; } else { html += '' + westui.lang.upgrade + '
'; }
[item=' + data.id + ']
';
return html; }, setPosition: function (e) { var window_width = $(window).width(); var window_height = $(window).height(); var popup_width = westui.popup.getEl().outerWidth(); var popup_height = westui.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); } westui.popup.getEl().css({ top: top, left: left }); }, init: function () {
//Append popup container
$('body').append('
');
//Set events $(document).on('mouseenter', '.item_container', function (e) { westui.popup.show(this); westui.popup.setPosition(e); }); $(document).on('mouseleave', '.item_container', function () { westui.popup.hide(); }); $(document).on('mousemove', '.item_container', function (e) { westui.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); } westui.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); } westui.popup.show(container[0]); }); } }, set_calc: { bonus: { //If there are any other "special" bonuses, they will be dynamically retrieved and stored there extra_set_bonus: {} }, //Bonuses from all sets / items : data: {}, //Status of all items (item lvl, activated or not) itemStatus: {}, getData: function () { //Get bonuses from all item sets $('.set_container').each(function () { var set_id = $(this).attr('data-set-id'); westui.set_calc.itemStatus[set_id] = {}; westui.set_calc.data[set_id] = { items: {}, set: {} }; $(this).find('.item_container').each(function () { var json = JSON.parse($(this).attr('data-popup')); if ($(this).is(":hidden")) { westui.set_calc.itemStatus[set_id][json.id] = false; } else { westui.set_calc.itemStatus[set_id][json.id] = 0; } for (var prop in json) { if (json.hasOwnProperty(prop) && westui.config.set_bonus.hasOwnProperty(prop)) { if (!westui.set_calc.data[set_id].items[prop]) { westui.set_calc.data[set_id].items[prop] = {}; } westui.set_calc.data[set_id].items[prop][json.id] = json[prop]; } } }); }); //Get bonuses from all sets $('.infoSet').each(function () { var set_id = $(this).attr('data-set-id'); $(this).find('.infosetatt').each(function () { var nb = $(this).attr('data-nb'); westui.set_calc.data[set_id].set[nb] = {}; $(this).find('.set_bonus').each(function () { key = $(this).attr('data-type'); if ($(this).find('.calc').length !== 0) { westui.set_calc.data[set_id].set[nb][key] = -parseFloat($(this).find('.calc').attr('id')); } else { westui.set_calc.data[set_id].set[nb][key] = parseFloat($(this).find('.val').text()); } if (!westui.config.set_bonus.hasOwnProperty(key)) { westui.set_calc.bonus.extra_set_bonus[key] = { img: $(this).find('img').attr('src'), name: $(this).find('#tooltip_content').text() }; } }); }); });
}, calc: function () { //Only calc if a player level is provided if ($('#input_level').length === 0 | $('#input_level input').val() !== "") { var level = parseInt($('#input_level input').val()); total = {}; for (var set_id in westui.set_calc.data) { for (var key in westui.set_calc.data[set_id].items) { for (var item_id in westui.set_calc.data[set_id].items[key]) { if (westui.set_calc.itemStatus[set_id][item_id] !== false) { lvl = westui.set_calc.itemStatus[set_id][item_id]; if (!total[key]) { total[key] = 0; } var value = westui.set_calc.data[set_id].items[key][item_id];
if (westui.set_calc.data[set_id].items[key][item_id] < 0) { //If bonus (per Level) value = -value;
if (westui.set_calc.itemStatus[set_id][item_id] > 0) { //If item upgraded total[key] += Math.ceil(value * level) + Math.round(Math.max(1, Math.ceil(value * level) * 0.1 * lvl)); } else { total[key] += Math.ceil(value * level); } } else { if (westui.set_calc.itemStatus[set_id][item_id] > 0) { if (value < 1) { total[key] += Math.round(1e6 * (value * 1 + Math.round(Math.max(1, value * 1000 * lvl)) / 10000)) / 1e6; } else { total[key] += Math.round(Math.max(1, value * 0.1 * lvl)); } } else { total[key] += value; } } } } } var item_nb = 0; for (var item_id in westui.set_calc.itemStatus[set_id]) { if (westui.set_calc.itemStatus[set_id][item_id] !== false) { item_nb++; } } for (var key in westui.set_calc.data[set_id].set[item_nb]) { if (!total[key]) { total[key] = 0; } if (westui.set_calc.data[set_id].set[item_nb][key] < 0) { total[key] += Math.ceil(-westui.set_calc.data[set_id].set[item_nb][key] * level); } else { total[key] += westui.set_calc.data[set_id].set[item_nb][key]; } } } //Create the html table
var html = '
';
for (var key in westui.config.set_bonus) { if (total.hasOwnProperty(key)) {html += ' <img src="' + westui.config.set_bonus[key].img + '">+' + total[key] + ' ';
' + westui.config.set_bonus[key].name + ' } } for (var key in westui.set_calc.bonus.extra_set_bonus) { if (total.hasOwnProperty(key)) {html += ' <img src="' + westui.set_calc.bonus.extra_set_bonus[key].img + '">+' + total[key] + (['xp', 'money', 'luck', 'spd', 'regen', 'drop'].indexOf(key) !== -1 ? "%" : "") + ' ';
' + westui.set_calc.bonus.extra_set_bonus[key].name + ' } } //Display the result at the bottom of the page $('#set_calc').html(html); } else { $('#set_calc').html(""); } }, initEvents: function () { //Deactivate / activate item on click $('.item_container > img').on('click', function () { var item_container = $(this).closest('.item_container'); item_container.toggleClass('item_off'); var set_id = item_container.closest('.set_container').attr('data-set-id'); var item_id = JSON.parse(item_container.attr('data-popup')).id; if (item_container.hasClass('item_off') || item_container.is(":hidden")) { westui.set_calc.itemStatus[set_id][item_id] = false; } else { westui.set_calc.itemStatus[set_id][item_id] = parseInt(item_container.attr('data-lvl')); } westui.set_calc.calc(); }); //Update item level on upgrade / downgrade $(document).on('click', '.upgrade, .downgrade', function () { var item = $(this).closest('.item_container'); var set_id = item.closest('.set_container').attr('data-set-id'); if (!item.hasClass('item_off') && !item.is(":hidden")) { westui.set_calc.itemStatus[set_id][JSON.parse(item.attr('data-popup')).id] = parseInt(item.attr('data-lvl')); westui.set_calc.calc(); } }); //Calc again when player level changes $("#input_level").bind("propertychange keyup input paste", function () { westui.set_calc.calc(); }); //Activate/deactivate melee/fire weapon when the switch btn is clicked $("#switch").on('click', function () { $('#melee, #fire').each(function () { var item = $(this).find('.item_container'); var set_id = $(this).closest('.set_container').attr('data-set-id'); if ($(this).is(":hidden")) { westui.set_calc.itemStatus[set_id][JSON.parse(item.attr('data-popup')).id] = false; } else { westui.set_calc.itemStatus[set_id][JSON.parse(item.attr('data-popup')).id] = parseInt(item.attr('data-lvl')); } }); westui.set_calc.calc(); }); }, init: function () { westui.set_calc.initEvents(); westui.set_calc.getData();$('#mw-content-text').append(''); if ($('#input_level').length === 0) westui.set_calc.calc(); } }, init: function () { westui.initPage(); westui.popup.init(); if (westui.config.enable_set_calc && $('.infoSet').length !== 0) { westui.set_calc.init(); } } }; westui.init(); |