battles/js/kicke.js

57 lines
11 KiB
JavaScript
Raw Normal View History

2018-01-28 16:40:49 +00:00
function Dialog(t){
function e(t, e) {
var i = l.outerWidth(!0), n = l.outerHeight(!0), o = $(window).width(), c = $(window).height();
switch(t) {
case"center":
if("t"==e) return c/2-n/2;
if("l"==e)return o/2-i/2;
break;
case"top":
case"left":return 0;
case"bottom":return c-n;
case"right":return o-i
}
}
function i() {
var t = s.position.split(","), i = $.trim(t[0]), n = $.trim(t[1]);
l.css({position:"absolute", top:parseInt(i)?i:e(i, "t"), left:parseInt(n)?n:e(n, "l")})
}
function n() {
l.draggable({containment:"window", handle:".dialog-header"})
}
function o() {
$.each(s.buttons, function(t, e) {
e = $.isFunction(e)?{click:e, value:t}:e, e = $.extend({type:"button"}, e);
var i = e.click;
e.click = function() {
i.apply(this, r, l, arguments)
}, $("<input />", e).appendTo(p)
})
}
function c(t) {
var e, i = ["", 0, null, void 0];
for(e in i)
if(t == i[e])return!0; return!1
}
if(!jQuery)return alert("Для работы диалогов требуется jQuery библиотека."), !1;
var r = this, a = {position:"center,center", style:{}, title:"", content:"", template:['<div class="dialog">','<div class="dialog-header">','<span class="dialog-title"></span>','<a href="#" class="dialog-close-button">[x]</a>',"</div>",'<div class="dialog-content"></div>','<div class="dialog-buttons"></div>',"</div>"], onopen:$.noop, onclose:$.noop, buttons:!1, autoopen:!0, draggable:!0}, s = $.extend(a, t), l = $(s.template.join("")), d = l.find(".dialog-header"), u = d.find(".dialog-title"), k = l.find(".dialog-content"), p = l.find(".dialog-buttons"), f = d.find(".dialog-close-button"); return 0 == u.length || 0 == d.length || 0 == k.length || 0 == p.length || 0 == f.length ? void alert("Error css classes: dialog-title, dialog-header, dialog-content, dialog-buttons, dialog-close-button not found!"):(this.open =!1,
this.set = function(t, e) {
switch(t) {
case"content":
s.content = e, k.html(e);
break;
case"title":
s.title=e, u.text(e);
break;
case"position":
s.position = e, this.rePosition();
break;
case"onopen":
$.isFunction(e) && (s.onopen = e);
break;
case"onclose":$.isFunction(e)&&(s.onclose=e);break;case"draggable":"enable"==e?n():"disable"==e&&l.draggable("destroy");break;case"buttons":$.isPlainObject(e)&&!$.isEmptyObject(e)&&(p.show(),s.buttons=e,o())}},this.get=function(t){return s[t]||null},this.rePosition=function(){i()},this.close=function(){r.open=!1,s.onclose.call(r,l),l.hide()},this.show=function(){r.open=!0,s.onopen.call(r,l),l.show()},$("body").append(l),l.hide(),l.css(s.style),c(s.title)||u.html(s.title),f.click(function(){return r.close(),!1}),c(s.content)||k.html(s.content),($.isPlainObject(s.buttons)&&!$.isEmptyObject(s.buttons)||$.isArray(s.buttons)&&s.buttons.length>0)&&o(),$.isEmptyObject(s.buttons)&&p.hide(),i(),s.draggable&&void 0!==$.fn.draggable&&n(),void(s.autoopen&&this.show()))}jQuery&&($.extend({isEmpty:function(t){var e,i=["",0,null,void 0,!1,"null","undefined","false"];for(e in i)if(t==i[e])return!0;return!1},random:function(t,e){return void 0==t||void 0==e?Math.random():Math.ceil(Math.random()*(e-t))+t},isTrue:function(t){return t>$.random(0,1e4)/100},parseTime:function(t){var e=t.split("-");if(e.length>1){var i=e[0]<1?1:e[0],n=e[1]<1?1:e[1];return n=i>n?i+1:n,1e3*$.random(parseInt(i),parseInt(n))}return 1e3*parseInt(e[0]<1?1:e[0])},getButton:function(t,e,i){return e=e||document,i?i&&$(t,e).length>1?$(t,e).eq(i):!1:$(t,e)},getLink:function(t,e,i){return e=e||document,i?i&&$('a:contains("'+t+'")').length>1?$('a:contains("'+t+'")').eq(i):!1:$('a:contains("'+t+'")')}}),$.fn.findInput=function(t){var e=null;return this.each(function(){var i=$(this),n=i.val();-1!==n.search(t)&&(e=i)}),e});var Kicker=function(){function t(){return-1!=top.frames.main.document.location.href.search("battle")}function e(){var t=$("#"+x+"kick-r").is(":checked"),e=$("#"+x+"block-r").is(":checked"),n=0,o={},c=0,r={},a="",s=i($("#"+x+"waittime").val());t?o[0]="r":($("."+x+"kick:checked").each(function(){var t=$(this),e=t.attr("id").split("-").pop(),i=parseInt($("#"+x+"kick-perc-"+e).val());o[e]=i,n+=i}),n>=0&&100>n?a+='<div class="red">'+m.err_low_perc_kick+"</div>":n>100&&(a+='<div class="red">'+m.err_big_perc_kick+"</div>")),e?r[0]="r":($("."+x+"block:checked").each(function(){var t=$(this),e=t.attr("id").split("-").pop(),i=parseInt($("#"+x+"block-perc-"+e).val());r[e]=i,c+=i}),c>=0&&100>c?a+='<div class="red">'+m.err_low_perc_block+"</div>":c>100&&(a+='<div class="red">'+m.err_big_perc_block+"</div>")),$.isEmpty(s)&&(a+='<div class="red">'+m.err_no_waittime+"</div>"),$.isEmpty(a)?(O.waittime=s,O.kick=o,O.block=r,O.ontimeout=$("#"+x+"ontimeout").val(),f[x+"setting"]=JSON.stringify(O),$("#"+x+"errors").show().html('<div class="green">Настройки сохранены</div>').fadeOut(5e3)):$("#"+x+"errors").show().html(a).fadeOut(3e3)}function i(t){var e=t.split("-");if(e.length>1){var i=Math.ceil(e[0])||1,n=Math.ceil(e[1])||i+1;return n=i>=n?i+1:n,i+"-"+n}var i=Math.ceil(e[0])||1;return""+i}function n(){if($.isPlainObject(O.kick)&&!$.isEmpty(O.kick[0])&&($("#"+x+"kick-r").attr("checked",!0),$("."+x+"kick").attr("disabled",!0)),$.isPlainObject(O.block)&&!$.isEmpty(O.block[0])&&($("#"+x+"block-r").attr("checked",!0),$("."+x+"block").attr("disabled",!0)),$.isPlainObject(O.kick)&&!$.isEmptyObject(O.kick)&&$.isEmpty(O.kick[0])){$("#"+x+"kick-r").attr("checked",!1),$("."+x+"kick").attr("disabled",!1);for(var t in O.kick){var e=O.kick[t];$("#"+x+"kick-"+t).attr("checked",!0),$("#"+x+"kick-perc-"+t).val(e)}}if($.isPlainObject(O.block)&&!$.isEmptyObject(O.block)&&$.isEmpty(O.block[0])){$("#"+x+"block-r").attr("checked",!1),$("."+x+"block").attr("disabled",!1);for(var t in O.block){var e=O.block[t];$("#"+x+"block-"+t).attr("checked",!0),$("#"+x+"block-perc-"+t).val(e)}}$("#"+x+"ontimeout").val(O.ontimeout)}function o(){for(var t,e="off"==h.power?"red":"green",i='<div><input type="checkbox" class="'+x+'kick-r" id="'+x+'kick-r"> <label for="'+x+'kick-r">Случайно</label></div>',n='<div><input type="checkbox" class="'+x+'block-r" id="'+x+'block-r"> <label for="'+x+'block-r">СлуСР°Р<EFBFBD><EFBFBD>