« Popup.js » : différence entre les versions
Aucun résumé des modifications |
Aucun résumé des modifications |
||
Ligne 25 : | Ligne 25 : | ||
if ($("#input_level").length == 1) { | if ($("#input_level").length == 1) { | ||
var input_level = $('<input type="number" style="width: | var input_level = $('<input type="number" style="width:95px;" class="west" placeholder="Votre niveau" min="0" max="150">').bind("propertychange keyup input paste", function() { | ||
if (this.value > 150) { | if (this.value > 150) { | ||
this.value = 150; | this.value = 150; | ||
Ligne 46 : | Ligne 46 : | ||
//Search | //Search | ||
if ($("#input_search").length == 1) { | if ($("#input_search").length == 1) { | ||
var input_search = $('<input type="search" class="west" placeholder="Recherche">').bind("propertychange keyup input paste", function() { | var input_search = $('<input type="search" style="width:200px;" class="west" placeholder="Recherche">').bind("propertychange keyup input paste", function() { | ||
var val = this.value.toLowerCase(); | var val = this.value.toLowerCase(); | ||
if (val == '') { | if (val == '') { |
Version du 3 juillet 2018 à 10:06
$('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:95px;" class="west" placeholder="Votre niveau" 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" style="width:200px;" class="west" placeholder="Recherche">').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 = '
' + data.name + '
' + data.type + '
';
var upgraded = false; if ((lvl>=1)&&(lvl<=5)){ upgraded = true; data.auc = false; } if (data.dgmin&&data.dgmax){ if (upgraded) { data.dgmin += Math.round(Math.max(1, data.dgmin * 0.1 * lvl)); data.dgmax += Math.round(Math.max(1, data.dgmax * 0.1 * lvl)); }
html += '
'+data.dgmin+'-'+data.dgmax+' Dégâts
';
} 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 = " (par Niveau)"; 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 += '
'+data.text[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="https://westfr.innogamescdn.com/images/jobs/'+data.jobs[i][1]+'.png"/> | '+data.jobs[i][0]+' |
';
} if (data.craft){
html += '
<img src="https://westfr.innogamescdn.com/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 += 'Vitesse: +' + data.spd + '%
';
}
if (data.set) html += '' + data.set + '
'; if (data.quete) html += '
Quête(s) : ' + data.quete + '
';
if (data.sp) { html += '<img src="/images/2/22/Achat.png"/>' + data.bp + ' <img src="/images/3/3b/Vente.png"/> ' + data.sp + 'html += '
'; } else { html += 'Non vendable
'; } if (data.lvl) html += 'Niveau ' + data.lvl + '
'; if (data.sex) { if (data.sex == 0) { html += '<img src="/images/8/83/Homme.png"/> '; } else { html += '<img src="/images/8/8c/Femme.png"/> '; } } if (data.auc == 1){ html += 'Peut être acheté/vendu aux enchères
'; } else { html += 'Ne peut pas être acheté/vendu aux enchères
'; } if (data.upg == 0) { html += 'Non améliorable
'; } else { html += 'Améliorable
'; }
[item=' + data.id + ']
';
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: {
dglvl: '
+ #1 Dégâts#2
'
}, skills: {
fo: '
+ #1 Force#2
', mo: '
+ #1 Mobilité#2
', ha: '
+ #1 Habileté#2
', ch: '
+ #1 Charisme#2
', co: '
+ #1 Construction#2
', pu: '
+ #1 Puissance#2
', te: '
+ #1 Ténacité#2
', pe: '
+ #1 Persévérance#2
', pv: '
+ #1 Points de vie#2
', mc: '
+ #1 Monter à cheval#2
', rx: '
+ #1 Réflexe#2
', ev: '
+ #1 Eviter#2
', ca: '
+ #1 Se cacher#2
', na: '
+ #1 Nager#2
', vi: '
+ #1 Viser#2
', ti: '
+ #1 Tirer#2
', pi: '
+ #1 Piéger#2
', de: '
+ #1 Dextérité#2
', re: '
+ #1 Réparer#2
', di: '
+ #1 Diriger#2
', ta: '
+ #1 Tactique#2
', ma: '
+ #1 Marchander#2
', an: '
+ #1 Manier les animaux#2
', pr: '
+ #1 Prestance#2
'
}, fb: {
fbdef: '
+ #1 Défense (Bonus de BdF)
', fboff: '
+ #1 Attaque (Bonus de BdF)
', fbres: '
+ #1 Résistance (Bonus de BdF)
', fbdefs: '
+ #1 Défense (Bonus de secteur de BdF)
', fboffs: '
+ #1 Attaque (Bonus de secteur de BdF)
', fbdmgs: '
+ #1 Dégâts (Bonus de secteur de BdF)
'
} }
};