From 15542d9c26b813b832846dc6465c6b60f7c053da Mon Sep 17 00:00:00 2001 From: ermouth Date: Thu, 11 Sep 2014 03:22:25 +0400 Subject: [PATCH] 1.0.2 Modal dialog and popup improvements. --- Release/1.0/jquerymy-1.0.2.js | 3649 +++++++++++++++++++++++++++++ Release/1.0/jquerymy-1.0.2.min.js | 5 + Release/jquery.my.last.js | 4 +- bower.json | 2 +- jquerymy.js | 784 +++++-- jquerymy.min.js | 4 +- my.jquery.json | 2 +- package.json | 2 +- 8 files changed, 4216 insertions(+), 236 deletions(-) create mode 100644 Release/1.0/jquerymy-1.0.2.js create mode 100644 Release/1.0/jquerymy-1.0.2.min.js diff --git a/Release/1.0/jquerymy-1.0.2.js b/Release/1.0/jquerymy-1.0.2.js new file mode 100644 index 0000000..f349d58 --- /dev/null +++ b/Release/1.0/jquerymy-1.0.2.js @@ -0,0 +1,3649 @@ +/* + * jQuery.my 1.0.2 + * Requires jQuery 1.11.0+, SugarJS 1.3.9-1.4.x + * + * + * More details at jquerymy.com + * + * @ermouth, thanks @carpogoryanin, @ftescht + * 2014-09-11 ✈ + */ + +;(function ($) {var _version = "jQuery.my 1.0.2"; + + // Some shortcuts and constants + var lang = "en", + wURL = window.URL || window.webkitURL, + ie8 = !document.addEventListener, + forms = _getref($,"my.f.repo")? $.my.f.repo():{_src:{}, _name:"Global manifest cache"}, + $E = $.extend, T = $.type, N = null, TMP, + n = function (o) {return o!==null && o!==undefined;}, + d8 = "{yyyy}-{MM}-{dd}", h24="{HH}:{mm}", + Ob = "object", Da = "data", Ar = "array", + St = "string", Fu = "function", Ch = "change", + rthis = /^this\./, + isA = Object.isArray, + isB = Object.isBoolean, + isS = Object.isString, + isO = Object.isObject, + isN = Object.isNumber, + isR = Object.isRegExp, + isF = Object.isFunction, + isP = function (a) {/*is promise*/return !!(null!=a&&(isO(a)||a.jquery)&&isF(a.then)&&isF(a.fail)&&isF(a.state));}; + + + //======================================= + // Manifest repo getter/setter and helpers + + var _cache = function _localCache (A1, A2) { + // ( no args ) – returns all forms obj container + // ({manifest}, {container}) – caches form in container, id must be defined, return form or null + // ({manifest}) – caches form in local container, id must be defined + // ("form.Id", "exist") – true/false + // ("form.Id", {container}) – get from container + // ("form.Id") – get from local cache + var ref, obj; + if (isS(A1)) { + ref=A1; + obj = _getref(isO(A2)?A2:forms, ref); + if ("exist"===A2) return isO(obj); + return !obj?null:Object.clone(obj,true); + } else if (isO(A1)){ + obj = _putmanifest (A1, A2); + if (!isO(obj)) { + console.log(obj); + return null; + } + return obj; + } else if (undefined===A1) { + return forms._src; + } else if (null===A1) { + return Object.reject(forms,/^_/); + }else return null; + }; + + // - - - - - - - - - - - - - - - - - - - - + + function _getref(obj,ref) { + //gets branch of obj by string ref like "data.list.items.1" + return (ref||"").split(".").reduce(function (a,b){ + if (null!=a && null!=a[b]) return a[b]; + else return undefined; + }, obj); + } + + // - - - - - - - - - - - - - - - - - - - - + + function _manifest (manifest, ref) { + // Dereferences pointer to form component, + // manifest is caller manifest obj, + // internal function + var t, ext; + if (isO(ref)) return ref; + else if (isS(ref)) { + + //try to find it on manifest + t = _getref(manifest, ref); + + //then in local repo as original + if (null==t) t = Object.clone(forms._src[ref],true); + + //then in local repo as part of component + if (null==t) { + t = _getref(forms, ref); + if (isO(t) && isO(t._self)) t=Object.clone(t._self,true); + else if (isO(t)) t = Object.clone(t,true); + } + + //then in ext repo as part of component + if (null==t && _getref(manifest,"params.cache")) { + ext = _getref(manifest,"params.cache"); + if (isF(ext)) t = ext(ref); + else if (isO(ext)) t = _cache(ref, ext); + + if (isO(t)){ + if (isO(t._self)) t=Object.clone(t._self,true); + Object.merge(t, {params:{cache:ext}}, true); + } + } + + if (null!=t && isO(t)) { + ext = ext||_getref(manifest,"params.cache"); + if (ext) Object.merge(t, {params:{cache:ext}}, true); + return t; + } + else throw "Component "+ref+" not found"; + + } else if (isF(ref)) { + return ref.apply(manifest, Array.prototype.slice.call(arguments, 2)); + } else return null; + } + + // - - - - - - - - - - - - - - - - - - - - + + function _putmanifest (obj0, root0) { + // Mounts obj to root in a branch, defined in + // obj.id property. If id =="x.y.z", root will be + // deep extended with {x:{y:{z:obj}}}. + // obj also is unjsonned and extended with _self ref, + // which point to original version of obj. + + //Returns direct link to entire branch obj or string error. + + var i, file, root=root0||forms, obj=obj0, path, id, prev, res; + + if (!(isO(root) && isO(obj) && isO(obj.ui) && isS(obj.id))) + return "Invalid arguments."; + + if (!root.hasOwnProperty("_src")) root._src={}; + + id = obj.id; + + + //path = id.split("."); + + try {obj=Object.clone(obj0, true);} + catch (e) {return "Can't mount circular-referencing obj.";} + + //unwind string defs of functions + try {if (!obj.params || (obj.params && !obj.params.strict)) _unjson(obj, true);} + catch (e) { + return "Invalid manifest, parse error."; + } + + //blobify files + i = _files2urls (obj); + if (isS(i)) { + f.con(i); + return i; + } + + //mark manifest as unjsonned + Object.merge(obj,{params:{strict:true}}, true); + // save it + root._src[id] = obj; + + + if (prev=f.mask(root, id)) { + if (prev.params && prev.params.protect) return "Can't mount on protected"; + if (prev._self) delete prev._self; + } //else { + //no prev node, mount + Object.merge(root,f.unmask(obj, id),true); + //} + res = _getref(root,id); + + if (ie8) res["_self"] = root._src[id]; + else Object.defineProperty(res, "_self", { + get: function () { return root._src[id]; }, + set: function () { throw "Can not change repo";}, + enumerable : false, + configurable : true + }); + + return res; + } + + + function _files2urls (obj) { + var i, flist = [], file; + if (isO(obj.files) && Object.size(obj.files)) { + //blobify files + for (i in obj.files) { + file = obj.files[i]; + if (isO(file) && file.data && !file.url) { + if (wURL) { + try { + f.base642blob(file.data,function(res){ + file.blob = res; + file.url = wURL.createObjectURL(file.blob); + },(file.content_type||file.mime)); + flist.push(i); + } catch(e) { + return "Invalid base64 data in files/"+i+"."; + } + } else { + //ie8-9 fallback + file.url = 'data:'+(file.content_type||file.mime)+';base64,'+file.data; + flist.push(i); + } + } + } + } + return flist; + } + + + //######################################################## + // Storage of rules defined by cascading selectors + // very similar to css. Leafs are processor + // or processing rules for this type of node + + var MY = { + + + //getter and setter functions for different types of nodes + + vals : { + + /**/ ".my-form": function ($o, v) { + //object is jQuery.my instance + if ($o && $o.my ) {var d = $o.my(Da); return Object.equal(d,v)?d:$o.my(Da, v, true);} + else return v||N; + }, + + /**/ ".hasDatepicker":function ($o,v) { + //object has jQ UI datepicker + if(n(v)) $o.datepicker("setDate", ((v=="")?v:Date.create(v))); + var date = $o.datepicker("getDate"); + return (date?date.format(d8):""); + }, + + /**/ ".my-tags": function ($o,v) { + //object is jQ tags control + if (n(v)) { + if (isS(v) || isN(v)) $o.tags(Da,[v+""]); + else if (isA(v)) $o.tags(Da,v); + } + return $o.tags(Da); + }, + + /**/ ".ui-draggable": function ($o,v) { + //object is jQ UI draggable + if (n(v) && isO(v)) { + var c = {}; + if (!isNaN(v.left)) c.left = Number(v.left).ceil(2)+"px"; + if (!isNaN(v.top)) c.top = Number(v.top).ceil(2)+"px"; + if (c.left || c.top) $o.css(c); + } + var p = $o.position(); + return { + left:((v&&!isNaN(v.left))?(v.left*1).ceil(2):p.left.ceil(2)), + top:((v&&!isNaN(v.top))?(v.top*1).ceil(2):p.top.ceil(2)) + }; + }, + + /**/ ".my-form-list": function ($o,list) { + //object is list of forms + var i,old,mod,eq,ctr = 0, + sP = "ui-sortable", sPlc= "."+sP+"-placeholder", + od = $o.data("formlist")||{}, + gen = od.generator||{}, + itemSel = gen.selector||">.my-form", + tmpl = gen.template||"
", + tmplIsVar = /\{/.test(tmpl), + hasher = gen.hash|| f.sdbmCode, + ider = gen.id|| f.sdbmCode, + extHasher = gen.ext, + delay = gen.delay||50, + sortable = $o.is("."+sP), + sorting = !!$o.children(sPlc).size(), + result=[], redraw = [], + $n, $drag, now = Date.now(); + var $c = sortable?$o.find($o.sortable("option","items")):$o.find(itemSel); + + if (n(list) && isA(list)) { + //return list passed if dragging taking place + if (sorting) return list; + // first we must estimate + // if putting new data over old + // changes anything + old= []; $c.each(function () { + var $x = $(this), xd = $x.data("my"); + if (xd) old.push(xd.data); + }); + + //fast compare + eq=false; + if (old.length===list.length) for (eq=true, i=0;i idx and hashes + for (i=0;i1.4*delay) + || now-gen.stamp > 100 + || !gen.stashed + || (gen.stashed.length !== $c.size()-(sorting?1:0)) + ) { + + if (sorting) $drag = $o.find('>.'+sP+'-helper'); + $c.each(function (idx) { + var $x = $(this), xd, xf, chash, dirty = false; + if (!sorting || !$x.hasClass(sP+'-helper')) { + if (sorting && $x.hasClass(sP + '-placeholder')) $x = $drag; + xd = $x.data("my"); + xf = $x.data("formlist"); + if (xd && xf) { + result.push(xd.data); + if (ctr != xf.index) { + xf.index = ctr; + dirty = !0; + } + if (extHasher) { + chash = hasher(xd.data, ctr)+""; + if (chash !== xf.hash) { + xf.hash = chash; + dirty = !0; + } + } + ctr += 1; + if (dirty) redraw.push($x); + } + } + }); + for (i=0;i=0; i--) { + var j = f.sdbmCode(v[i]); + if (w[j]) { + w[j].prependTo($o).show();z[j]=true; + if (a.indexOf(v[i])==-1) a.push(v[i]); + } + } + a=a.reverse(); + for (i in w) if (!z[i]) w[i].hide(); + } else { + var $p = $o.find(sPlaceholder), $q = $o.eq(0); + if ($p.size()!=0) { + + //if placeholder state changed saving new data + if ($q.my()[sP] != $p.position().left+""+$p.position().top) { + $c = $c.filter(":visible:not(:disabled, .ui-state-disabled, .ui-sortable-helper)"); + $m = $o.find($o.sortable("option","items")).filter(".ui-sortable-helper"); + $c.each(function () { + var $x = $(this); + if ($x.is(".ui-sortable-placeholder")) {a.push(f.extval($m));} + else a.push(f.extval($x)); + }); + //caching placeholder state and data retrieved + $q.my()[sP] = $p.position().left+""+$p.position().top; + $q.my()[sP+"1"] = a; + } else a = $q.my()[sP+"1"]; + if (a==N) $c.each(function () {a.push(f.extval($(this)));}); + } else { + $c = $o.find($o.sortable("option","items")).filter(":visible:not(:disabled, .ui-state-disabled)"); + $c.each(function () {a.push(f.extval($(this)));}); + } + } + return a; + }, + + /**/ "input[type=date]":function ($o,v) { + //object is date input + if(n(v)) { + if (v!="") d = Date.create(v).format(d8); else d = ""; + if (isS(d) && !/Invalid/.test(d)) $o.val(d); + return d; + } + var d = $o.val(); + return (d!=""?Date.create(d).format(d8):""); + }, + + /**/ "input[type=time]":function ($o,v) { + //object is time input + if(n(v)) { + if (v!="") d = Date.create(v).format(h24); else d = ""; + if (isS(d) && !/Invalid/.test(d)) $o.val(d); + return d; + } + var d = $o.val(); + return (d!=""?Date.create(d).format(h24):""); + }, + + + /**/ "input":{ + "[type='text'],[type='number'],[type='search'],[type='hidden'],[type='password'],[type='button'],[type='range'],:not([type])":{ + //nearly all main input types and button + + ".ui-slider-input": function ($o,v) { + //input with jQ UI slider() applied + if (n(v)) $o.val(v).slider("refresh"); + }, + + ".tagstrip input.value": function ($o,v) { + //input of tagstrip() applied + if (n(v)) $o.val(v).trigger("update"); + }, + + "div.select2-container+input": function ($o, v) { + //select2 + if (n(v) && JSON.stringify(v)!==JSON.stringify($o.select2("val"))) $o.select2("val", (isA(v)?v:[v])); + return $o.select2("val"); + }, + + "": function ($o,v) {if(n(v)) $o.val(v+"");} + }, + + ":radio":function ($o,v) { + //radio buttons + var pos = -1; + if (n(v)) { + $o.each(function (ind) { + var val = $(this).val(); + if ((v+"")===(val+"")) pos=ind; + }); + var jqcheck = $o.eq(0).checkboxradio; + if (jqcheck) $o.each(function (ind){ + var $x = $(this); + if (pos!=ind && $x.is(":checked")) + $x.prop("checked",false).checkboxradio("refresh"); + }); + if (pos>-1) { + var $x = $o.eq(pos); + if (!$x.is(":checked")) { + $x.prop("checked",true); + if (jqcheck) $x.checkboxradio("refresh"); + } + } else if (!jqcheck) $o.each(function () { $(this).prop("checked",false); }); + } + if (pos==-1) for (var ind=0; ind<$o.size(); ind++) { + if ($o.eq(ind).is(":checked")) pos=ind; + } + return pos!=-1?$o.eq(pos).val():""; + }, + + ":checkbox": function ($o, v0) { + //checkbox + var pos = -1, v = v0, a = []; + if (n(v)) { + if (!isA(v)) v = [v0]; + var jqcheck = !!$o.eq(0).checkboxradio; + $o.each(function (ind) { + var $x = $(this), val = $x.val(), on = $x.is(":checked"); + if (v.indexOf(val)!=-1) { + a.push(val); + if (!on) $x.prop("checked", true); + } else if (on) $x.prop("checked", false); + if (jqcheck) $x.checkboxradio("refresh"); + }); + } else { + $o.each(function () { + var $x = $(this); + if ($x.is(":checked")) a.push($x.val()); + }); + } + return a; + } + }, + + /**/ "select": { + ".ui-slider-switch": function ($o,v) { + //on-off in jQ Mobile + if (n(v)) { + $o.val(v+""); + $o.slider("refresh"); + } + }, + "div.select2-container+select":{ + "[multiple]": function ($o, v) { + if (n(v)) $o.select2("val", (isA(v)?v:[v])); + return $o.select2("val"); + }, + "":function ($o, v) { + if (n(v)) $o.select2("val", v+""); + return $o.select2("val"); + } + }, + "[multiple]": function ($o,v) { + if (n(v)) { + $o.val(v,[]); + if ($o.selectmenu) $o.selectmenu("refresh",true); + //the only way to check if we have jQ UI selectmenu() attached + } + }, + "": function ($o,v) { + if (n(v)) { + $o.val(v+""); + if ($o.selectmenu) { + //now ditinguish between jQ selectmenu plugin and jQ Mobile + if ($o.selectmenu("option").theme!==undefined) $o.selectmenu("refresh",true); + else $o.find("option").each(function (i){ + var $x = $(this); + if (f.extval($x) == v) $o.selectmenu("value",i); + }); + }}}}, + + /**/ "textarea": { + ".my-cleditor":function ($o,v) { + if(n(v)) $o.val(v).cleditor()[0].updateFrame(); + return $o.val(); + }, + "div.redactor_box textarea,.redactor": function ($o,v) { + var r9 = $o.hasClass('my-redactor-9'); + if(n(v)) { + if(r9) $o.redactor('set', v); + else $o.setCode(v, false); + return v; + } + return r9 ? $o.redactor('get') : $o.getCode(); + }, + ".my-codemirror":function ($o,v){ + if (n(v)) { + $o[0].nextSibling.CodeMirror.setValue(v); + return v; + } + return $o[0].nextSibling.CodeMirror.getValue(); + }, + "":function ($o,v) {if(n(v)) $o.val(v+"");} + }, + + /**/ "fieldset,form,section,aside,.my-container": function ($o, v) { + //object is class-manageable container, + //value is an array of css rules + var clist = Array.prototype.slice.call($o[0],0).sort(), + list = v; + if (n(v)) { + if (isS(v)) list = v.split(/[,\s]+/).compact(true); + if (isA(list)) { + list.sort(); + if (list.join(" ")!==clist.join(" ")) { + $o.atrr("css", list.join(" ")); + clist = list; + } + } + } + return clist; + }, + + /**/ "div,span,a,p,li,td,th,h1,h2,h3,h4,h5,h6":{ + ".ui-slider":function ($o, v){ + if(n(v)) $o.slider("option",$o.slider("option","values")?"values":"value", f.clone(v)); + return f.clone($o.slider("option","values")||$o.slider("option","value")||0); + }, + ".ui-buttonset": function ($o,v) { + //jQ UI buttonset () + if (!n(v)) { + var jor = $o.find(":radio:checked"); + if (jor.size() && jor.button) return jor.val()||jor.button("option", "label") ; + } else if (v!="") { + var jon = N; + $o.find(":radio").each(function () { + jon=( ($(this).val()||$(this).button("option", "label"))==v?$(this):jon ); + }); + if (jon) { + jon.attr("checked",true); + $o.buttonset("refresh"); + return v; + } + } + $o.find(":radio:checked").attr("checked",false); + $o.buttonset("refresh"); + return ""; + }, + ".ace_editor":function ($o,v) { + if(n(v)) ace.edit($o[0]).setValue(v); + return ace.edit($o[0]).getValue(v); + }, + "": function ($o,v) { + if(n(v)) $o.html(v); + return $o.html(); + } + }, + /**/ "pre,code":function ($o,v) { + if(n(v)) $o.html(v); + return $o.html(); + }, + /**/ "img":function ($o,v) { + if (n(v)) $o.attr("src",v); + return $o.attr("src")||""; + }, + /**/ "":function ($o,v) { + if (n(v)) $o.html(v); + return $o.html()||$o.text()||String($o.val())||""; + } + }, + + + //messages + //######################################################## + + msg:{ + "":{en:"Invalid input", ru:(TMP="Неверное значение")}, + + formError:{en:"Form error",ru:"Ошибка формы"}, + initFailed:{ + en:'

Form init failed

', + ru:'

Ошибка инициализации формы

' + }, + + badInput:{en:"Invalid input", ru:TMP}, + patternMismatch:{en:"Pattern mismatch", ru:"Не соответствует шаблону"}, + rangeOverflow:{en:"Over maximum", ru:"Больше максимума"}, + rangeUnderflow:{en:"Under minimum", ru:"Меньше минимума"}, + stepMismatch:{en:"Step mismatch", ru:"Не кратно шагу"}, + tooLong:{en:"Too long", ru:"Слишком длинно"}, + typeMismatch:{en:"Invalid type", ru:"Неверный тип"}, + valueMissing:{en:"Required", ru:"Обязательное поле"} + }, + + + //different controls' events to watch for + //######################################################## + + events: { + ".hasDatepicker":"change.my check.my", + ".my-form,.my-tags":"change.my check.my", + ".ui-slider":"slide.my check.my", + "div.redactor_box textarea":"redactor.my check.my", + ".my-codemirror":"codemirror.my check.my", + ".ace_editor":"ace.my check.my", + ".my-form-list":"sortupdate.my check.my", + ".ui-sortable":"sortchange.my sortupdate.my check.my", + ".ui-draggable":"drag.my dragstop.my check.my", + "a, .pseudolink, input[type=button], button": "click.my", + "img, :radio, :checkbox": "click.my check.my", + "div.select2-container+input,div.select2-container+select":"change.my check.my input.my", + ".ui-buttonset,input, select, textarea":"blur.my change.my check.my"+(navigator.appName.to(5)==="Micro"?" keyup.my":" input.my"), + "":"check.my" + }, + + //functions retrieving container for different controls + //######################################################## + + containers: { + "*[data-role='fieldcontain'] *":{ //jQuery Mobile + "input,textarea,select,button,:radio": function ($o) { + return $o.parents('[data-role="fieldcontain"]').eq(0); + } + }, + ".tagstrip *.value": function ($o){ //$.tagstrip() + return $o.parents('.tagstrip').eq(0); + }, + "div.redactor_box textarea":function ($o){ + return $o.parents('div.redactor_box').eq(0).parent(); + }, + ".my-tags,.hasDatepicker,.ui-widget,input,textarea,select,button" :{ + ".my-cleditor": function ($o) { + return $o.parents('div.cleditorMain').eq(0).parent(); + }, + "": function ($o) { + var p = $o[0].parentNode, t = p.nodeName; + if (/^(div|span|a|p|form|fieldset|li|ul|td|th|h\d)$/i.test(t)) return $(p); + else return $o.parents('div,span,a,p,form,fieldset,li,ul,td,th,h1,h2,h3,h4,h5,h6').eq(0); + } + }, + "": function ($o) {return $o;} + + }, + + //disablers and enablers + //######################################################## + + offon: { //if x==true disables control else enables + ".ace_editor": function (x,$o) {ace.edit($o[0]).setReadOnly(x);}, + ".ui-selectable": function (x,$o) {f.jquix($o,"selectable",x);}, + ".ui-slider": function (x,$o) {f.jquix($o,"slider",x);}, + ".ui-draggable": function (x,$o) {f.jquix($o,"draggable",x);}, + ".ui-buttonset": function (x,$o) {f.jquix($o,"buttonset",x);}, + ".hasDatepicker": function (x,$o) {f.jquix($o,"datepicker",x);}, + ".my-form":function (x,$o){$o.my("disabled", !!x);}, + "div.select2-container+input,div.select2-container+select": function (x,$o) {f.jquix($o,"select2",x);}, + ".my-cleditor": function (x,$o) { $o.cleditor()[0].disable(!!x);}, + "": function (x, $o) {$o.attr("disabled", !!x);} + }, + + //destructors + //######################################################## + destroy:{ + ".hasDatepicker":function ($o){$o.datepicker("destroy");}, + ".ui-slider":function ($o){$o.slider("destroy");}, + ".ui-sortable":{ + ".my-form-list":function ($o){ + $o.find(">.my-form").each(function () { + $(this).my("remove"); + }); + $o.removeClass("my-form-list"); + $o.sortable("destroy"); + }, + "":function ($o){$o.sortable("destroy");} + }, + ".my-form-list":function ($o){ + $o.find(">.my-form").each(function () { + $(this).my("remove"); + }); + + }, + ".ui-draggable":function ($o){$o.draggable("destroy");}, + ".my-redactor-8":function ($o){ + $o.destroyEditor(); + $o.removeClass("my-redactor-8"); + }, + "div.select2-container+input,div.select2-container+select":function ($o){$o.select2('destroy');}, + ".my-form": function ($o) {$o.my("remove");}, + "textarea": { + ".my-codemirror": function ($o) { + $o[0].nextSibling.CodeMirror.toTextArea(); + $o.removeClass("my-codemirror") + } + } + } + }; + + //default values for .params section of manifest + //######################################################## + + MY.params = { + container:function ($o) { // container getter + return _traverse($o, MY.containers)($o); + }, + change:N, + recalcDepth:2, // depth of dependencies resolver tree + delay:0, // default delay of bind invocation + strict:false, // if true form assumed unjsonned + locale:(TMP=(navigator.language||navigator.userLanguage||"en").substr(0,2)), + messages:Object.map(MY.msg, function (k,v){return v[TMP]||v.en;}), + errorTip:".my-error-tip", // $ selector of err tip container + errorCss:"my-error", // class applied on container on err + animate:0, // err tips animation duration + effect: function ($e, onoff, duration) { // err tips animation effect + if (onoff) return $e.fadeIn(duration); $e.fadeOut(duration); + }, + remember:0, // undo steps to remember + silent:false, + history:{}, // form undo history + historyDelay:100, // delay in ms between subsequent calls of history(), + loader: function (manifestId, parentId) { // default loader + var pi = $.Deferred(), m = _cache(manifestId+""); + if (m) pi.resolve(m); + else pi.reject(null); + return pi.promise(); + }, + ajaxTimeout:10000 + }; + + var f = _getHelpersLib(); + f.require = _require; + + //########## SYSTEM FUNCTIONS ########## + + + function _require(man ,params0){ + // Checks and loads required libs, + // returns promise resolved with manifest + // or rejected with err list. + var i, j, k, pi = $.Deferred(), + chunks = [], checks = {}, err=[], r, line, + params = $E(true, { + ajaxTimeout:10000, + loader: MY.params.loader + }, params0||{}), + row, subrow, chunk, + Row = {ref:null, ajax:{type:"GET", async:true, timeout: params.ajaxTimeout}}; + + if (!isO(man)) pi.reject(["Invalid manifest."]); + else if (!isA(man.require)) pi.resolve(man); + else { + r = man.require; + for (i=0;i< r.length;i++) { + line = r[i]; + if (isS(line)) checks[line] = _exist(line); + else if (isO(line)) { + chunk = []; + for (j in line) { + row=null; + if (line[j]===true) { + // global, we can’t load it, just check presence + checks[j] = _exist(j); + } + else if (isS(line[j]) || isO(line[j])) { + row = _row(line[j], j); + } else if (isA(line[j])) { + row = []; + // array of requests + for (k=0;kflevel) { + fval=oi; flevel = level; return; + } else if (otype==Ob) go ($o, oi, level+1); //recursion down + } + if (N != os[""] && typeof os[""]!=Ob && level>flevel) { + fval=os[""]; + flevel = level; + } + } + } + + + //======================================= + + function _bind (data, val, uiNode, $formNode) { + //sets or retrieves data using bind function + var i, path=[], ptr, preptr, that, + bind = uiNode.bind, + bt = T(bind); + if (bt == Fu) { + return bind.call(_form($formNode).manifest, data, val, $formNode); + } + if (bt === St || bt === Ar) { + if (bt === St && !/\./.test(bind)) { + //index is flat + if (val != N) data[bind] = val; + else if (data[bind]===undefined) data[bind] = N; + return data[bind]; + } + //index is composite, we need to traverse tree + //and create some branches if needed + if (bt === St) path = bind.split(".").each(function (a,i){this[i]=a+"";}); + if (bt === Ar) path = bind.slice(0).each(function (a,i){this[i]=a+"";}); + + if (path[0]==="this") { + ptr = _form($formNode).manifest; + path.shift(); + } else ptr = data; + + for (i=0;i-1)?"":err0); + case "s": return (val==pat?"":err0); + case "o": return pat[val]?"":err0; + case "b": { + if ($formNode.is(".my-form-list,.ui-sortable")) { + var sel = $formNode.data("listSrc")||$formNode.data("my").listSrc||">*", ret={}; + $formNode + .find(sel) + .filter("*:not(.ui-sortable-placeholder)") + .each(function (idx){ + var $e = $(this); + if ($e.data("my") && !$e.my("valid")) ret[idx]=$e.my("errors"); + }); + return ret; + } else if ($formNode.hasClass("my-form")){ + return !pat?"":$formNode.my("valid")?"":$formNode.my("errors"); + } + return ""; + } + } + return msg.formError||"Error"; + } + return ""; + } + + + //======================================= + + function _form ($formNode) { + //get control's root.my() + var $my = $formNode.my(); + if (!$my) return null; + return $my.root?$my.root.my():$my; + } + + + //======================================= + + function _css (onOff, $we, css0) { + //applies-discards conditional formatting or enables-disables field + var css = css0.compact(), r = css.replace(/:disabled/g,''); + + $we.each(function () { + var $d = $(this),d = $d.my(), $o = (d?d.container:$d); + if (onOff) { + if (!$o.is(r)) $o.addClass(r); + } else $o.removeClass(r); + + if (r!=css && d!==undefined && !!onOff != !!d.disabled) { + //we have :disabled + $d.my().disabled = !!onOff; + if (!d._disable) $d.my()._disable = _traverse($we, MY.offon).fill(undefined, $we); + d._disable(!!onOff); + } + }); + return $we; + } + + + //======================================= + + function _update ($o, value, depth) { + //validates and updates field and all dependent fields, + //applies conditional formatting + var $box, d, oui, p, val, css, oc, + selector, $root, $we, ui, + isForm = false, isList = false, + $this = $o, + xdata = $this.my(), + err=""; + + if (xdata) { + selector = xdata.selector; + $root = xdata.root; + if ($root.hasClass("my-form-init")) return {}; + $we = $root.find(selector); + ui = $root.my().ui; + isForm = $o.hasClass("my-form"); + isList = $o.hasClass("my-form-list"); + if (isForm){ + $box = $o; d = xdata.ddata; oui = xdata.dui; p = xdata.dparams; + } + else { + $box = xdata.container; d = xdata.data; oui = xdata.ui; p = xdata.params; + } + //exec bind if any + if (oui.bind != N) { + if (n(value)) val = value; + else val = _field($we,_bind(d,N,oui,$we)); + + //validating and storing if correct + //applying or removing error styles + if (N != oui.check) { + err="Unknown error"; + try { err = _validate(d, val, oui, $we); } + catch (e) { f.con ("Error "+ e.message+" validating "+selector, $root , e.stack); } + } + + var ec = p.errorCss; + var jqec = "ui-state-error"; + + try { + if (N != value) val = _field($we, _bind(d, value, oui, $we)); + } + catch (e) { err=p.messages.formError || "Error"; } + + if (err==="") { + if (!isForm) xdata.errors[selector]= ""; + else xdata.derrors[selector]= ""; + $box.removeClass(ec); + if ($box.attr("title")) $box.attr("title",""); + if (!isForm && !isList) p.effect($box.find(p.errorTip), false ,(p.animate/2)); + $this.removeClass(jqec); $this.find(".ui-widget").removeClass(jqec); + } else { + if (isForm) xdata.derrors[selector]= err; + else if (isList) xdata.errors[selector]= err; + else { + $box.addClass(ec); + xdata.errors[selector]= err; + var $tip=$box.find(p.errorTip).eq(0); + if ($tip.size()){ + p.effect($tip.addClass(ec).html(err), true, p.animate); + } else $box.attr("title",(err || "").stripTags()); + } + + if ($this.is(".hasDatepicker")) { + if ($this.is("input")) $this.addClass(jqec); + else $this.find(".ui-widget").addClass(jqec); + } + if ($this.is(".ui-slider")) $this.addClass(jqec); + } + } + //applying conditional formatting if any + var cssval = (value==N?val:value); + if (oui.css) { + for (css in oui.css) { + oc = oui.css[css]; + if (isR(oc)) _css (oc.test(cssval), $we, css); + else if (isF(oc)) _css (oc.call($root.my().manifest, d,cssval,$we), $we, css); + } + } + + //recalculating dependent fields + var i, list = oui.recalc, dest = [], once = {}, item; + + if (depth && oui.recalc && $root.my()) { + ui = $root.my().ui; + for (i=0; i= l*2) { + newh = {}; + for (i=l; i=k.length) n = k.length-1; + old = Object.clone(p.history[k[k.length-n-1]], true); + if (remove) { + newh = {}; + for (i=0; i$/.test(ui.list)) ltmpl=ui.list; + else lsel = ui.list||lsel; + if (!ltmpl) { + var $t0 = $o.find(lsel); + ltmpl='
'; + if ($t0.size()) { + ltmpl = $(ltmpl).append($t0.eq(0).clone(true)).html(); + $t0.eq(0).remove(); + } + } + + //mount data + if (!$o.data("formlist")) $o.data("formlist",{}); + $o.data("formlist").generator={ + manifest:subform, + delay:(ui.delay||p.delay||10)/1.3, + template:ltmpl, + selector:lsel, + parent:man, + bind:ui.bind, + hash:isF(ui.hash)?ui.hash.bind(man):_snapshooter(ui.hash), + id: isF(ui.id)?ui.id.bind(man):_snapshooter(ui.id), + ext:!!(ui.id || ui.hash), + stamp:0 + }; + + //mount insert + $o.on("insert.my", function (evt, obj){ + evt.stopPropagation(); + var p = {what:undefined, where:0}; + if (null==obj) p.where=1e6; + else if (isO(obj)) Object.merge(p,obj); + else if (isS(obj) || isN(obj)) p.where = obj; + $(evt.target).my("insert",p.where, p.what); + }); + + //mount remove + $o.on("remove.my", function (evt){ + evt.stopPropagation(); + $(evt.target).my("remove"); + }); + + } else { + try { + child = $o.my( + _manifest (man, subform), + isO(linked)?linked:undefined + ); + } + catch (e) {_fail("$.my subform init of " +selector+" failed: "+e.message, e.stack);} + } + } + if (isP(child)) { + //we've got promised subform init + child.then(countdown, function (msg, obj){ + _fail("Init of subform "+selector+" failed with error: "+msg,obj); + }); + } else countdown(); + } + + + // - - - - - - - - - - - - - - - - - - - - - - - + + function _fail (msg, obj){ + f.con(msg, obj); + if (pi) pi.reject(msg, obj); + } + + // - - - - - - - - - - - - - - - - - - - - - - - + + function _snapshooter (src) { + var t = T(src).to(3); + return !src?null: + t==="str"?_getref.fill(undefined, src): + t==="arr"? f.mask.fill(undefined, src): + null; + } + + + // - - - - - - - - - - - - - - - - - - - - - - - + + function countdown () { + //start applying monitors to controls + //right before this moment all controls are irresponsive + $o.each(function () { + var $this = $(this), + events, + cm, isControl = false, + ns = $this[0].nextSibling; + + //codemirror fix + cm = ( ns && ns.CodeMirror)?ns.CodeMirror:null; + if (cm) $this.addClass("my-codemirror"); + + //get events + events = ui.events||_traverse($this, MY.events); + + if (!$this.is(".my-form")) { + $this.data("my",{ + events:events, + selector:selector, + initial:v, + previous:v, + root:$root, + container:p.container($this), + id:rd.id, + ui:ui, + data:rd.data, + params:p, + errors:rd.errors + }); + uiNode._update = ui.delay?_update.debounce(ui.delay):N; + isControl = true; + } else { + $E($this.data("my"),{ + dui:ui, + root:$root, + selector:selector, + dparams:p, + devents:events, + ddata:rd.data, + container:p.container($this), + derrors:rd.errors + }); + + } + + // Fixes for different composite controls + if (isControl) { + + //special cleditor fix + //thanks ima007@stackoverflow.com for concept + if ($this.cleditor && $this.parent().is(".cleditorMain")) { + var cledit = $this.cleditor()[0]; + if (cledit && cledit.$frame && cledit.$frame[0]) { + //mark as cleditor + $this.addClass("my-cleditor"); + $E($this.data("my"), {container: p.container($this)}); + var cChange = function (v) { + $this.val(v).trigger(Ch); + }; + var cleditFrame, r = Number.random(1e5, 1e6 - 1); + //aux event handlers for cleditor instance + $(cledit.$frame[0]).attr("id", "cleditCool" + r); + if (!document.frames) cleditFrame = $("#cleditCool" + r)[0].contentWindow.document; + else cleditFrame = document.frames["cleditCool" + r].document; + var $ibody = $(cleditFrame).find("body"); + $(cleditFrame).bind('keyup.my', function () { + cChange($(this).find("body").html()); + }); + $this.parent() + .find("div.cleditorToolbar") + .bind("click.my mouseup.my", function () { + cChange($ibody.html()); + }); + $("body").on("click", "div.cleditorPopup", function () { + cChange($ibody.html()); + }); + } + } + + //redactor fix + else if ($this.is("div.redactor_box textarea")) { + //$this.getEditor().bind("input keyup blur",(function ($o){$o.trigger("redactor");}).fill($this)); + var editor, version = 'my-redactor-9'; + try { + editor = $this.getEditor(); + version = 'my-redactor-8'; + } catch (e) { + editor = $this.redactor('getEditor'); + } + if (editor) { + $this.addClass(version); + editor.bind("input.my keyup.my blur.my", (function ($o) { + $o.trigger("redactor"); + }).fill($this)); + } + } + + //ace fix + else if ($this.is(".ace_editor")) + ace.edit($o[0]).on(Ch, (function ($o) { + $o.trigger("ace"); + }).fill($this)); + + // codemirror fix + else if (cm) { + cm.on(Ch, (function ($o) { + $o.trigger("codemirror"); + }).fill($this)); + } + } + + //create debounced change handler + $this.my()._changed = (_changed).debounce(delay); + $this.my()._recalc = (_recalc).debounce(delay); + + //bind events to the control + $this.bind(events, function (evt) { + if (evt.type==Ch) evt.stopPropagation(); + if (isControl) rd.locktill = Date.now()+uiNode.delay; + $this.my()._changed($this, $root, uiNode, p); + }); + + // if we have no check, attach its silent version + if (!/check(\.my)?/.test(events+"")) $this.on("check.my", function(evt){ + $this.my()._changed($this, $root, uiNode, p, true); + return false; + }); + + //bind events to the control + $this.on("recalc.my, redraw.my", function (evt) { + evt.stopPropagation(); + $this.my()._recalc($this,$root,uiNode,p); + }); + }); + + // we've done + if (pi) pi.resolve(); + } // end countdown + } + + + //======================================= + + function _changed ($o, $root, uiNode, p, silent) { + // called when control is changed + var d = $o.data("my"), + r = $root.data("my"); + if (d && !d.disabled) { + _history(d.ddata||d.data, d.dparams||d.params); + var $we = $root.find(d.selector); + _update($o, !silent?_field($we, N):N, uiNode.recalcDepth||p.recalcDepth); + + if (undefined === r.orphan) { + if (d.root.parent().hasClass("ui-sortable")) { + r.orphan = !d.root.parent().hasClass("my-form-list"); + } + } + if (r.orphan) d.root.parent().trigger("check"); + if (p.change) p.change.call($o); + } + } + +//======================================= + + function _recalc ($o,$root,uiNode,p) { + // called when control must update + var d = $o.my(); + if (d && !d.disabled) { + var $we = $root.find(d.selector); + if (($we).is(".my-form")) $we.my("redraw"); + else _update($o, + ($we.is(".my-form-list")?_getref($we.my().data,$we.data("formlist").generator.bind):N), + uiNode.recalcDepth||p.recalcDepth); + } + } + + + //======================================= + + function _prepare (that, init0, $o, d) { + // prepares init, applies data if its string template, + // dereferences it if it is pointer, + // and calls function or formgen + var init; + if (isS(init0)) { + init = _getref(that, init0); + if (undefined === init) { + $o.html(init0.assign(d.data)); + return null; + } + } else init = init0; + if (isF(init)) return init.apply(that, Array.prototype.slice.call(arguments,2)); + else if (isA(init)) { + try {$o.formgen(init);} + catch(e){} + } + return null; + } + + + //======================================= + + function _unjson (node, exclude){ + //recursively unwinds string def of funcs and regexps, modifies source obj! + var i="", nd, t="", incl = !exclude, a=[]; + for (i in node) if (node.hasOwnProperty(i) && (incl || !/^(data|files|require)$/.test(i))) { + nd = node[i]; + t = T(nd); + if (/^(ob|ar)/.test(t)) _unjson(nd); + else if (t==="string" && /^(function\s\(|new\sRegExp)/.test(nd)) { + if (a = nd.match(/^function\s\(([^\)]*)\)\s*\{([\s\S]*)\}$/)) { + if (a.length===3) { + try { node[i] = Function(a[1], a[2]); } + catch(e){ console.log(e.message, e.stack, nd);} + } + } + else if (a = nd.match(/^new\sRegExp\(\/([\s\S]+)\/([a-z]*)\)$/)) { + if (a.length===3) { + try { node[i] = RegExp(a[1], a[2]); } + catch (e) { console.log(e.message, e.stack, nd); } + } + } + } + } + a=null; + } + + + + //======================================= + + function _normalize (ui, manifest0, p) { + //unwinds ui recalcs, short defs and watch hooks, modifies source obj! + //move shorthand binds to bind attr + var manifest = isO(manifest0)?manifest0:null; + Object.each(ui, function (i,v){ + var t = typeof v; + if (/^str|^fu/.test(t)) ui[i] = {bind:v}; + }); + Object.each(ui, function (i,v){ + //correct ui definitions + //with simplified syntax -- unfolding + //unfold recalcs and watches + var list=[], watch=[], row , re=/\s?[,;]\s?/, rr, j; + if (v.recalc) { + if (isS(v.recalc)) list = v.recalc.split(re); + else if (isA(v.recalc)) list = v.recalc; + list = list.compact(true).unique(); + } + if (list.length) ui[i].recalc=list; + + if (null==v.bind) v.bind=function () {}; + + if (v.watch) { + if (isS(v.watch)) watch = v.watch.split(re); + else if (isA(v.watch)) watch = v.watch.slice(0); + watch = watch.compact(true).unique(); + for (j=0; j sections for form. + // returns custom style section, global is mounted + // to dom if not presented + var aglob=[], aloc=[], man=manifest; + if (!isO(man) || !isO(man.style)) return ""; + + crawl(manifest.style, "", aglob, aloc); + return [aglob, aloc]; + + + function crawl (branch0, key, aglob, aloc){ + var i, j, b, a, branch = branch0; + if (isS(branch)) { + if (/[\r\n]/.test(branch) || branch.split("}",3).length>2) { + branch = f.css2json(branch); + } + else aglob.push(key+(/\{/.test(branch)?branch:'{'+branch+'}')); + } + if (isA(branch) && branch.length) { + for (i=0;i' + + "." + manClass + style[0].join(' \n.' + manClass) + '\n' + + '').appendTo($("body")); + } + + $style.data("count", $style.data("count") * 1 + 1); + $root.data("my").style = $style; + } + + if (style && style[1].length) { + $locstyle = $('style#' + formClass); + if (!$locstyle.size()) { + $locstyle = $('').appendTo($("body")); + } + + $root.data("my").localStyle = $locstyle; + + } + } + } + + //----------------------------------------------------- + + // prepare files section + function _files () { + var i, pi = $.Deferred(), flist; + + flist = _files2urls (manifest); + if (isS(flist)) { + _f("Error decoding base64 to local Blob/URL", flist); + pi.reject(); + } + else { + if (wURL) for(i=0;i*").clone(); + try { + tracker = _prepare(manifest, data.init, $root, data); + } catch (e) { + _f(isS(e)?e:e.message, e.stack); + return $root; + } + } + // init returned promise? + if (isP(tracker)) { + tracker.then(function () {_controls();}, function (err,obj){_f(err, obj);}); + } else _controls(); + + if (!_fail) { + if (!$root.my()) return _f("Internal error initializing controls",""), $root; + + //save initial data for $.my("reset") + $root.data("my").initial = $E(true,{},d); + + //init $.mobile if any + if ($.mobile) $.mobile.changePage($.mobile.activePage); + } + } + + + //----------------------------------------------------- + + //build and init controls + function _controls (){ + var formState={}, ctr=Object.size(ui); + + $root.addClass(initCss); + + // build controls (init and premount) + Object.each(ui, function (selector) { + if (_fail) return; + var $o = $root.find(selector), + built = _build($o, $root, ui[selector], selector); + + if (isP(built)) { + //we've got promise + built.then( + countdown.fill(selector) + ).fail(function (msg, obj){ + _f("Error building "+selector+", "+msg, obj); + }); + } + else if (!_fail) countdown(selector); + }); + + function countdown(selector){ + if (!_fail) { + formState[selector]=_field($root.find(selector),N); + ctr-=1; if (ctr<.5) _values(formState); + } + } + + } + + //----------------------------------------------------- + + //apply values to controls + function _values (formState) { + var uiNode, v, $o; + for (var selector in ui) { + if (_fail) return; + uiNode = ui[selector]; + $o = $root.find(selector); + if ($o.size()) { + try { + v = _bind(d, N, uiNode, $o); + if (v==N && formState[selector]!=N && v!==undefined) + _bind(d, formState[selector], uiNode, $o); + } + catch (e) { + f.con("Transient fail linking " +selector + +" of form $('.my-form-"+cid+"')", + e.message, e.stack + ); + } + try { + if (v!=N) _field($o,v); + $o.eq(0).trigger("check.my"); + } catch (e) { + _f("Error linking "+selector, e.message, e.stack); + } + } + } + $root.removeClass(initCss); + backup=null; + pi.resolve(d); + } + + //----------------------------------------------------- + + // Fail handler + function _f (msg, obj) { + var html; + _fail=true; + f.con("Form "+myid+" failed to initialize: "+msg, obj); + $root.removeClass(initCss); + html = ehandler(msg, obj); + if (isS(html) || (isO(html) && html.jquery)) $root.html(html); + else if (html===true) $root.html(backup); + if (!p.silent) { + if(!$root.my().ddata) { + $root.removeData("my"); + $root.removeClass("my-form"); + if ($style) { + if ($style.data("count")=="1") { + try{$style.remove();}catch(e){} + } + else $style.data("count", $style.data("count")-1); + } + if ($locstyle) { + try{$locstyle.remove();}catch(e){} + } + } + pi.reject("Form "+myid+" failed to initialize: "+msg, obj); + } else pi.resolve(d); + } + }, //end init + + + + //###### REDRAW ###### + + "redraw": function ( noRecalc, silent) { + var $x = this, d = $x.my(); + if (d && d.ui) { + d.ui.each(function (key) { + var $n = $x.find(key); + _update($n, noRecalc?N:undefined , d.params.recalcDepth); + if (!noRecalc) { + if ($n.is(".my-form")) $n.my("redraw"); + if ($n.is(".my-form-list")) $n.trigger("redraw"); + else $n.trigger("check.my"); + } + }); + if (!silent && noRecalc) $x.trigger(Ch); + } + return $x; + }, + + //###### SET OR RETRIEVE DATA ###### + + "data": function (data, noRecalc) { + var $x = this; + if (isO(data)) { + $x.my().data = f.overlap($x.my().data, data); + this.my("redraw", noRecalc); + } + return $x.my().data; + }, + + //###### RETURNS ERRORS ###### + + "errors": function () { + var e0 = $(this).my().errors, e = {}; + for (var i in e0) { + if (e0[i] && isS(e0[i])) e[i]=e0[i]; + if (isO(e0[i]) && Object.keys(e0[i]).length) e[i]=e0[i]; + } + return e; + }, + + //###### RETURNS true IF FORM VALID ###### + + "valid": function () { + var e = $(this).my().errors, ctr=0; + for (var i in e) { + if (e[i] && isS(e[i])) ctr++; + else if (isO(e[i]) && Object.keys(e[i]).length) ctr++; + } + return !ctr; + }, + + //###### RESET INITIAL VALUES ###### + + "reset": function () { + try { + f.kickoff(this.my().data, this.my().initial); + this.my("redraw"); + } catch (e) {return false;} + return true; + }, + + //###### GET id OR SEARCH BY id ###### + + "id": function (id, obj) { + if (isS(id)) return _cache(id, obj); + else { + var d = this.my(); + return (d && d.id)?d.id:N; + } + }, + + //###### UNMOUNT jQuery.my INSTANCE FROM THE DOM ###### + + "remove": function (fromDOM){ + var $o = this, + $style, + $locstyle, m, + locFiles, + d, ui, cid, mid; + + if (!this.my()) return N; + + //child elt requests form removal + if (this.my().root && !this.my().ddata) $o = this.my().root; + + m = $o.my(); + d = m.data; + cid = m.cid; + mid = m.mid; + + + // close modals if any + if ($o.data("modals")) {} + + + // stop event listeners + $o.unbind(".my"); + + // remove stylesheets + if ($style=m.style) { + if ($style.data("count")=="1") { + try{$style.remove();}catch(e){} + } + else $style.data("count", $style.data("count")-1); + } + if ($locstyle=m.localStyle) { + try{$locstyle.remove();}catch(e){} + } + + // revoke data urls + if (window.URL && (locFiles = m.locFiles) && locFiles.length) { + for (var i=0;i< locFiles.length; i++) { + try { URL.revokeObjectURL(locFiles[i]); } catch(e) {} + } + } + + // remove $.my from ui entries + ui = (m||{}).ui; + if (ui) { + ui.each(function (key){ + var $we = $o.find(key), f, mw, i; + + // close dependent modal + if (mw = $we.data("modal")) { + mw.cancel(); + $we.removeData("modal"); + } + + //close child modals + if (mw = $we.data("modals")) { + for (i in mw) if (mw[i]) mw[i].cancel(); + } + + $we.unbind(".my"); + try{ + f = _traverse($we, MY.destroy); + if (isF(f)) f($we); + }catch(e){} + $we .removeData("formlist") + .removeData("myval") + .removeData("my"); + }); + } + + if (fromDOM && $o.is(".my-form")){ + $o.remove(); + } + else if ($o.data("formlist") && $o.is(".my-form")) { + var $p = $o.parents(".my-form-list").eq(0); + $o.remove(); + $p.trigger("check"); + } + else { + $o.removeData("formlist") + .removeData("myval") + .removeData("my") + .removeClass("my-form"); + } + + $o.removeClass("my-form-"+cid+" my-manifest-"+mid); + + return d;//returns data collected by removed instance + }, + + //###### UNDO ###### + + "undo": function (steps){ + var $this = this, + d = $this.my(), + h = d.params.history, + k = Object.keys(h).sort(), + diff = 1*(parseInt(steps)||0), + state; + if (!k.length || diff<0) return N; + if (!d.params.errors || !d.params.errors.values().compact(true).length) { + if ( Object.equal(h[k.last()], d.data)) diff+=1; + } else if (!Object.equal(d.data, d.lastCorrect)) diff+=1; + + state = _history(diff, d.params, true); + + if (state) { + f.kickoff($this.my().data, state); + $this.my("redraw"); + } + return $this.my().data; + }, + + //###### UI RUNTIME GETTER-SETTER ###### + + "ui": function (u) { + var $x = this, d = $x.my(), a=[], i; + if (!d) return N; + var ui = $E(true, {}, d.ui); + if (!isO(u)) return d.ui; + for (i in u) if (true || !ui[i]) a.push(i); //controls to (re)init + d.ui = _normalize(f.overlap(d.ui,u)); + for (i=0;i>{x:1,y:{w:2,a:[1,2],z:3}}. + //return mutated a + for (var i in b) { + if (b.hasOwnProperty(i)) { + if (isO(b[i])) { + if (!a.hasOwnProperty(i)) a[i]=Object.clone(b[i],true); + else patcher (a[i],b[i]); + } else if (!a.hasOwnProperty(i)) { + if (isA(b[i])) a[i]=b[i].clone(true); + else a[i]=b[i]; + } + } + } + return a; + }, + "kickoff": function (a,b) { + //replaces a content with b content; + var def = b && typeof b == "object" ? Object.clone(b, true) : {}, i; + for (i in a) if (a.hasOwnProperty(i)) { + delete a[i]; + if (def[i] !== undefined) a[i] = def[i]; + } + }, + "sdbmCode":function (s0){ + //very fast hash used in Berkeley DB + for (var s = JSON.stringify(s0), hash=0,i=0;i
', + * + * // Row with several controls and HTML, no label + * ["", "num#age",{style:"width:50px"}, "years ", "num#year", {style:"width:100px"}, " born"], + * + * // Select with opts, understands many formats + * ["Choose one", "sel#mychoice", + * {vals:[ + * "Fish", + * "Meat", + * {id:"Poultry", text:"Chicken"}, + * {"Ice Tea":"Tea1"} + * ]}] + * + * //and so on. Shortcuts for controls are below in the code. + * ]") + * + * */ + +(function ($){ + //Some shortcuts and constants + var $E = $.extend, n = function (o) {return o!==null && o!==undefined;}, N = null, + Ob="object", Da="data", Ar = "array", St = "string", Fu="function", Ch = "change", + isA = Object.isArray, isB = Object.isBoolean, isS = Object.isString, isO = Object.isObject, + isN = Object.isNumber, isR = Object.isRegExp, isF = Object.isFunction; + var iHead = '', + "inp" :iHead+'text" {ext}/>', + "sli" :iHead+'range" {ext}/>', + "dat" :iHead+'date" {ext}/>', + "btn" :iHead+'button" {ext}/>', + "div" :'
{txt}
', + "spn" :'{txt}', + "sel" :'', + "mul" :'', + "txt" :'', + "err" :' {txt}', + "msg" :'
{txt}
', + "val" :function (p) { + if (!isA(p.vals)) return ""; + var p0=$E({style:"",css:""},p); + p0.txt=p.vals.reduce(function (a,b){ + return a+'' + +b+' '; + }," "); + return ('{txt}').assign(p0); + }, + "" :'<{_tag} {ext}>{txt}' + }, + txt:{ + sel:function (p) { + if (!p.vals) return ""; + var obj = decrypt(p.vals); + return Object.keys(obj).reduce(function (a,b){ + return a+''; + },''); + } + }, + params:{ + styles:{num:"width:30%;", dat:"width:30%;", inp:"width:100%", + txt:"width:100%;max-width:100%;min-height:1px;word-break:break-word;", + err:"display:none",msg:"display:none"}, + alias: {number:"num",date:"dat",slider:"sli",textarea:"txt",input:"inp", + span:"spn",select:"select",vals:"val"}, + row:"", + rowTag:"div", + rowCss:"my-row", + label:"", + labelTag:"span", + labelCss:"my-label" + }, + + defaults:{id:"","class":"",style:"",placeholder:"",value:"",rows:1}, + attnames:{css:"class",plc:"placeholder",val:"value",txt:"",vals:"",tip:"title"} + }; + + + function chain(a,b,sys) { + if (isS(b)) return a+b; + if (isO(b)) { + sys = $E(true,sys, b); + return a; + } else if (isA(b) && b.length>1 && isS(b[1])) { + + var lbl = b[0],html="",key,type,a0,b0,i=1,j,p,tmpl,ext; + + //iterate through row's inside items + while (i' + +(lbl?( + '<'+sys.labelTag+' class="'+sys.labelCss+'" ' + +(sys.label?'style="display:inline-block;width:'+sys.label+';margin-left:-'+sys.label+'" ':"") + +'>'+lbl+'' + ):"") + +html+''; + } + return a+html; + } + return a; + } + + function decrypt (elt0) { + //translates different forms like [val, val val] + //{id:"",text:""} {key:"",value:""} and so on + // into object {key1:val1, key2:val2, ...} + var elt = elt0; + if (isS(elt)) { + elt = elt.split(/[\s,]/).compact(true); + } + if (isA(elt)) { + var obj={}; + for (var i=0;i> null or + * promise [resolve(formData or true), reject (errMessage, errStack)] + * + * Obj is one of following types: + * 1. jQuery image – will raise modal with the image and text from title or data-text attributes + * 2. HTML string – will raise modal with html content + * 3. Object of type + * { + * manifest: formManifest Object, + * data: initialData Object or none, + * width: formWidth Number or none, + * done: callback Function (formErrors, data) or none, + * esc: false, enables/disables close on escape keypress, + * enter: false, enables commit on Enter keypress + * nose:"", left|right|top|bottom – where to put nose + * global: false, force global modal + * screen: false, show/hide screen div + * drag: false, allows drag of modal if $ ui draggable plugin installed + * align:"top|bottom:NUM%|px;left|right:NUM%|px" + * } + * will raise modal with $.my form inside. Form must call $obj.modal(false) or emit + * "commit" event on itself to close with sendind data. Calling $obj.modal(true) or + * emitting "cancel" event on form will close modal sending null as data with no error. + * + * Callback in obj overlaps done provided as second arg, same for width. + * + * Callback is called prior promise and unlike promise receives 2 arguments, + * not one, even when form succeded. If callback returns true, dialog remains + * opened and promise – pending. + * + * 4. null, undefined or false – close dialog and calls done(formErrors, data), + * if done return false or null promise is resoved with data, + * else modal stays open + * 5. true (strict boolean) – close dialog and calls done (null, null), + * then promise is rejected with "Cancelled" string + * + * If modal on $obj is already open, invoking $obj.modal return promise that is + * immediatly rejected with error "Locked", done is called with (null, null). + * + * $.my.modal.visible() >> Boolean + * Indicates if global modal is opened. + * + * $.my.modal.parent (selector or null) >> jQuery object + * Sets or gets parent DOM node, where all $.my.modal stuff is prepended. + * To work good must be called prior to 1st $.my.modal call. +*/ + +(function ($){ + + var root={}, parent = "body", parentBack, isOpen = false, + $E = $.extend, M = {}, + isA = Object.isArray, isB = Object.isBoolean, isS = Object.isString, isO = Object.isObject, + isN = Object.isNumber, isR = Object.isRegExp, isF = Object.isFunction; + + //Close modal on escape + + $(document).keydown(function (e) { + var code = e.keyCode, $f, m; + if (false!==isOpen && (code ===13 || code === 27)) { + m = isOpen.data("modal"); + $f = m.form; + if (code == 27 && ( m.esc || Object.equal($f.data("my").initial, $f.my("data")) ) ) { + isOpen.modal(true); + return false; + } + else if (code == 13 && m.enter ) { + isOpen.modal.delay(50); + return false; + } + } + + }); + + // - - - - - - - - - - - - - - - - - - + + function _convert (o, obj, ovl, width0) { + var h, w,h0,w0,text,$i,width; + // $ image + if (typeof obj == "object" && obj.jquery) { + if (obj.is("img")) { + $i = obj; + text = obj.attr("alt") || obj.attr("title") || obj.data("text")||""; + w = $i[0].naturalWidth || $i[0].width; + h = $i[0].naturalHeight || $i[0].height; + if (h<1) h=1; + if (w<1) w=1; + w0=$(window).width()-90; + h0=$(window).height()-90; + if (h0' + +'

', + ui:{ + "img:eq(0)":"img", + "h4":{ + bind:"text", + css:{hide:function(d,v){return !v}} + } + } + }, + data:{img:$i.attr("src"),text:text}, + esc:true, + screen:true, + width:width0||width, + focus:false, + global:true + }, ovl); + } + } + + // $.my form + else if (isO(obj) && obj.manifest) { + $E(o, obj, ovl); + } + + //plain html + else if (isS(obj)) { + $E(o, { + source:"html", + manifest:{ + init: function($o){ $o.html(this.HTML); }, + HTML:obj, + ui:{ "div:eq(0)":function(){} } + }, + data:{}, + esc:true, + focus:false, + global:true, + screen:true, + width:width0 + }, ovl); + } + + else return null; + + return o; + } + + + // - - - - - - - - - - - - - - - - - - + + root.modal = function modal (obj, done0, w0) { + var o = {}, + $r = $(parent), $i, + $o=$r.find(">.my-modal-proxy"), + ovl = { + global:true, + screen:true, + done:isF(done0)?done0:undefined + }; + + if (isOpen) { return $o.modal(obj, done0, w0); } + else { + if (!$o.size()) { + $o = $('
').prependTo($r); + $o.css({position:"absolute",top:"0",left:"0",margin:"0",padding:"0",width:"1px",height:"0"}); + } + + if (_convert(o, obj, ovl, w0)) return $o.modal(o); + else { + var pi = $.Deferred(); + return pi.reject("Invalid data").promise(); + } + + } + } + + // - - - - - - - - - - - - - - - - - - + + + root.modal.loading = function (onoff) { + $(parent).find(">.my-modal").toggleClass("my-modal-loading",!!onoff); + } + + root.modal.parent = function (s) { + // sets parent DOM node selector for $.my.modal + if (!s || !$(s).size()) return $(parent); + parent = s; + } + + root.modal.parentBack = function (s) { + // sets parent DOM node selector for $.my.modal background + if (!s || !$(s).size()) return $(parentBack||parent); + parentBack = s; + } + + root.modal.visible = function () {return !!isOpen;} + + if (!$.my) $.my={}; + $.my.modal = root.modal; + + + // ############################### + // Extend jQuery with modal plugin + + $.fn.modal = function (obj0, done0, width0) { + var pi = $.Deferred(), o={}, + $m, $f, $o = this, $r, $bg, $cl, padx=0, pady=0, + done = isF(done0)?done0:function(){ return false; }, + obj = isO(obj0)?obj0:{}, + m = $o.data("modal"), + md, stop; + + $E($o, pi.promise()); + + // check if this already has modal + + if (m) { + if (obj0==null || isB(obj0)) { + + // ##### CLOSE MODAL ########## + + $f = m.form; + $bg = m.bg; $r = m.root; done = m.done; + md = $f.my("data"); + stop = false; + + if (!obj0) { + // check if we can close + try{ + stop = done ($f.my("valid")?null:$f.my("errors"), md); + }catch(e){} + if (!stop) { + _remove(); + $o.removeData("modal"); + // async resolve + (function () { + if (M[m.cid]) M[m.cid].resolve(md); + delete M[m.cid]; + m=null; + }).delay(0); + } + } else { + // force close + try {done(null, null);} catch(e){} + _remove(); + $o.removeData("modal"); + if (M[m.cid]) M[m.cid].reject("Cancelled"); + delete M[m.cid]; + m=null; + } + + return $o; + + + } else if (obj) { + // reinit is not allowed + _f("Locked"); + return $o; + } + } + + // check if $o is visble + if (!$o.is(":visible")) { + _f("Object must be visible"); + return $o; + } + + // convert + if (!(obj = _convert(o, obj0, {}))) { + _f("Invalid data"); + return $o; + } + + // check if fullscreen opened + if (obj.global && isOpen) { + _f("Locked"); + return $o; + } + + + // ##### NEW MODAL ########## + + m=$E({ + type:"DOM", source:"manifest", + form:null, // $obj of the form + modal:null, // $obj of the modal wrapper + root:null, // $obj, modal is appended to + bgroot:null, // $obj, root for bg + caller:$o, // $obj modal is linked with + + global:false, + drag:false, + focus:true, + manifest:{}, data:{}, + nose: "", close:true, esc: false, enter: false, + screen: false, width:width0||300, height:null, + x:"0", y:"0", z:"1997", css:"", + animate:200 + }, obj, { + promise: pi.promise(), + cid:Number.random(268435456,4294967295).toString(16) + }); + m.done = isF(m.done)? m.done:done; + + //parse align + if (isS(m.align) && m.align) { + m.x = (m.align.match(/(left|right):\-?\d+(\.\d+)?(%|px)?/g)||["0"])[0]; + m.y = (m.align.match(/(top|bottom):\-?\d+(\.\d+)?(%|px)?/g)||["0"])[0]; + } + + //refine width + m.width=1*($.my.f.getref( + isS(m.manifest)?$.my.cache(m.manifest):m.manifest, + "params.width" + ) || m.width ); + + // guess if $o is ctrl, form or just dom node + // find parent container + + m.type = "DOM"; + if ($o.hasClass("my-form")) { + m.type = "form"; + m.root = m.root || $o; + } + else if ($o.data("my")) { + m.type = "control"; + m.root = m.root || $o.my().container; + } + else { + m.root = m.root || $o.parents(".my-form").eq(0); + if (!m.root.size()) m.root = $(parent); // global parent + } + + if (m.global) { + m.root = $(parent); + m.bgroot = $(parentBack||parent); + } else m.bgroot = m.root; + + $r = m.root; + if (!$r.data("modals")) $r.data("modals",{}); + + _measure(); + + // ##### Create modal DOM wrapper ##### + + // create wrappers if none defined + $m= $('
').prependTo(m.root); + $m.addClass("my-modal-"+ m.cid); + + padx=$m.outerWidth(); + pady = $m.outerHeight(); + $m.hide(); + + //rebuild modal form obj + $m.html('
'); + $f = $m.find(".my-modal-form"); + + // close btn + if (m.close) { + $cl = $(isS(m.close)? m.close:'
×
') + .prependTo($m).on("click.my",function () {$o.modal(true);}); + $cl.css({"z-index":""+(m.z*1+1)}); + } + + $bg = m.bgroot.find(">.my-modal-screen"); + if (m.screen) { + if (!$bg.size()) { + $bg = $('') + .prependTo(m.root); + + } + + if (m.esc) $bg.on("click.my"+ m.cid, function () { $o.modal(true); }); + } + + // try to init form + $o.data("modal", m); + $m.css({ + position: m.global?"fixed":"absolute", + left: m.pos.vx+"px", + top: m.pos.vy+"px", + display:"block", + height:"none", + opacity:"0.005", + "z-index": m.z, + width:"auto" + }); + $f.my(m.manifest, m.data).then(function () { + var $img, $i, i, focus, ui; + //success + $E(m,{ + form: $f, + bg:$bg, + cancel: function(){$o.modal(true)}, + commit: function(){$o.modal()} + }); + $m.data("modal",m); + + // adjust form + m.height = $m.outerHeight(); + if (m.source !== "manifest") m.width = $m.width(); + _measure(); + $m.css({top:m.pos.vy+"px"}); + _adjust(true); + + // remember cid in parent form root + $r.data("modals")[m.cid] = m; + + // memoize modal promise + M[m.cid] = pi; + + // bind event listeners + $f.bind("commit.my", function(){ + m.commit.delay(50); + return false; + }).bind("cancel.my", function(){ + m.cancel.delay(50); + return false; + }); + + $m.bind("layout.my", function(){ + _adjust(); + }.debounce(50)); + + // fullscreen tuneups + if (m.global) { + isOpen = $o; + $("body").css({overflow:"hidden"}); + } + + // esc and enter monitors + if (!m.global && (m.esc || m.enter)) { + $f.bind("keydown.my", function(e) { + var code = e.keyCode; + if (code == 27 && m.esc) { + m.cancel(); + return false; + } + else if (code == 13 && m.enter){ + m.commit.delay(50); + return false; + } + }) + } + + // autofocus + if (m.focus===true) { + focus = false; + ui = m.manifest.ui; + for (i in ui) { + if (!focus) { + $i = $f.find(i); + if ($i.size() && $i.is("input, textarea")) { + focus = true; $i.focus(); + } + } + } + } + else if (isS(m.focus)) $f.find(m.focus).focus(); + + //If we have images, count them and reheight on load + $img = $f.find("img").filter(function () {return $(this).attr("src")!="";}); + if ($img.size()) { + var _imgdone = function(){ + if (m.source !== "manifest") $m.css({width:"auto"}); + _adjust(); + }.after($img.size()); + $img.each(function () {$(this).bind("load", _imgdone);}); + } + + // Draggable + if (m.drag && $.fn.draggable) { + if (!isS(m.drag)) $m.draggable(); + else $m.draggable({handle: m.drag}); + } + + pi.notify("Ready"); + }) + .fail(function (err){ + _remove(); + $o.data("modal", null); + pi.reject(err); + }); + + return $o; + + + //### Helpers + + function _measure(){ + // measure $o, its pos + // and modal offsets rel to container + + var W = window, h, w, + isfs = !!m.global, + ro = $r.offset(), oo = $o.offset(); + + m.pos = { + px: ro.left, py: ro.top, + pw: $r.outerWidth(), ph: $r.outerHeight(), + + ox: oo.left, oy: oo.top, + ow: $o.outerWidth(), oh: $o.outerHeight(), + + ww:w, wh:h + }; + //if (m.width> m.pos.pw) m.width= m.pos.pw; + + // calculate offsets + var dx = (m.x.match(/\-?\d+(\.\d+)?/)||[0])[0]* 1, + dy = (m.y.match(/\-?\d+(\.\d+)?/)||[0])[0]* 1, + sx = m.x.has("left")?-1: m.x.has("right")?1: 0, + sy = m.y.has("top")?-1: m.y.has("bottom")?1: 0, + vx = m.pos.ox + m.pos.ow/2 - m.pos.px, + vy = m.pos.oy + m.pos.oh/2 - m.pos.py; + + if (isfs) { + m.pos.wh = h = W.innerHeight || $(W).height(); + m.pos.ww = w = W.innerWidth || $(W).width(); + vx = w/2; + vy = h/2.5; + } + dx = m.x.has("%")? m.pos.ow/100*dx:dx; + dy = m.y.has("%")? m.pos.oh/100*dy:dy; + + m.pos.pix = vx; m.pos.piy = vy; + + vx = vx + sx*(m.pos.ow/2) + + dx*(sx>0?-1:1) + - (m.width+padx)*(sx+1)/2; + + if (isfs) { + vy = (h - m.height-20)/3; + if (vy<10) vy=10; + } else { + vy = vy + sy*(m.pos.oh/2) + + dy*(sy>0?-1:1) + - ((m.height||0)+pady)*(sy+1)/2; + } + + vx = vx.round(1); vy = vy.round(1); + + m.pos.vx = vx; m.pos.vy = vy; + } + + // - - - - - - - - - - - - - - - - - - + + function _adjust (skipMeasure){ + //adjust modal position, + if (!skipMeasure) { + m.height = $m.outerHeight(); + if (m.source !== "manifest") m.width = $m.width(); + _measure(); + } + $m.css({ + left: m.pos.vx+"px", + width: (m.width+padx)+"px", + display:"block" + }); + if (m.screen) { + if (!m.global) $bg.css({ + top:0, left:0, position:"absolute", + width: m.pos.pw+"px", + height: m.pos.ph+"px", + display:"block", + background:isS(m.screen)? m.screen:'rgba(40,80,120,0.5)', + "z-index":m.z-1 + }); + else { + $bg.css({ + top:0, left:0, + width:(m.pos.ww*2)+"px", + height:(m.pos.wh*2)+"px", + display:"block", + position:"fixed", + "z-index":m.z-1 + }); + if (isS(m.screen)) $bg.css({ + background:m.screen? m.screen:'rgba(30,65,100,0.8)' + }); + } + } + else if ($bg.size()) $bg.hide(); + + if (m.height> m.pos.wh) { + $m.height(m.pos.wh-30); + $f.css({"overflow-y":$.browser.webkit?"overlay":"scroll"}); + } else { + $f.css({"overflow-y":"none"}); + } + + $m.animate({top: m.pos.vy+"px", opacity:"1"}, m.animate); + } + + // - - - - - - - - - - - - - - - - - - + + function _remove(){ + try { $f.my("remove"); } catch(e){} + $r.data("modals")[m.cid] = null; + $f.parent().unbind(".my").remove(); + $bg.off(".my"+ m.cid).hide(); + if (m.global) { + isOpen = false; + $("body").css({overflow:"auto"}); + } + } + + // - - - - - - - - - - - - - - - - - - + + function _f(msg) { + try { done(null, null); } catch(e) {} + (function () { pi.reject(msg); }).delay(0); + } + + }; + +})(jQuery); diff --git a/Release/1.0/jquerymy-1.0.2.min.js b/Release/1.0/jquerymy-1.0.2.min.js new file mode 100644 index 0000000..d537f49 --- /dev/null +++ b/Release/1.0/jquerymy-1.0.2.min.js @@ -0,0 +1,5 @@ +/* jQuery.my 1.0.2 + * Requires jQuery 1.11.0+, SugarJS 1.3.9-1.4.x + * More details at jquerymy.com */ + +;(function(e){function A(e,t){return(t||"").split(".").reduce(function(e,t){if(null!=e&&null!=e[t])return e[t];else return undefined},e)}function O(e,t){var n,r;if(x(t))return t;else if(S(t)){n=A(e,t);if(null==n)n=Object.clone(s._src[t],true);if(null==n){n=A(s,t);if(x(n)&&x(n._self))n=Object.clone(n._self,true);else if(x(n))n=Object.clone(n,true)}if(null==n&&A(e,"params.cache")){r=A(e,"params.cache");if(C(r))n=r(t);else if(x(r))n=L(t,r);if(x(n)){if(x(n._self))n=Object.clone(n._self,true);Object.merge(n,{params:{cache:r}},true)}}if(null!=n&&x(n)){r=r||A(e,"params.cache");if(r)Object.merge(n,{params:{cache:r}},true);return n}else throw"Component "+t+" not found"}else if(C(t)){return t.apply(e,Array.prototype.slice.call(arguments,2))}else return null}function M(e,t){var n,r,o=t||s,u=e,a,f,l,c;if(!(x(o)&&x(u)&&x(u.ui)&&S(u.id)))return"Invalid arguments.";if(!o.hasOwnProperty("_src"))o._src={};f=u.id;try{u=Object.clone(e,true)}catch(h){return"Can't mount circular-referencing obj."}try{if(!u.params||u.params&&!u.params.strict)J(u,true)}catch(h){return"Invalid manifest, parse error."}n=_(u);if(S(n)){P.con(n);return n}Object.merge(u,{params:{strict:true}},true);o._src[f]=u;if(l=P.mask(o,f)){if(l.params&&l.params.protect)return"Can't mount on protected";if(l._self)delete l._self}Object.merge(o,P.unmask(u,f),true);c=A(o,f);if(i)c["_self"]=o._src[f];else Object.defineProperty(c,"_self",{get:function(){return o._src[f]},set:function(){throw"Can not change repo"},enumerable:false,configurable:true});return c}function _(e){var t,n=[],i;if(x(e.files)&&Object.size(e.files)){for(t in e.files){i=e.files[t];if(x(i)&&i.data&&!i.url){if(r){try{P.base642blob(i.data,function(e){i.blob=e;i.url=r.createObjectURL(i.blob)},i.content_type||i.mime);n.push(t)}catch(s){return"Invalid base64 data in files/"+t+"."}}else{i.url="data:"+(i.content_type||i.mime)+";base64,"+i.data;n.push(t)}}}}return n}function H(t,n){function E(t,n){var r;if(S(t)){if(/[\/]/.test(t)){r=o(true,{},g,{ref:n,ajax:{url:t}});if(b.test(n))r.ajax.dataType="json"}else if(t.length){r=o(true,{},g,{ref:n,ajax:t})}}else if(x(t)){r=o(true,{},g,{ref:n,ajax:e.extend(true,{},Object.select(t,["accepts","async","cache","data","dataType","password","timeout","type","url","username"]))});if(!r.ajax.url)r=null}return r}function T(){u.reject(l)}function N(){y+=1;var e=a[y];if(!e){var n=L(f),r=Object.keys(Object.findAll(n,function(e,t){return!t}));if(r.length)l.push((r.length===1?"Key "+r[0]+" is":"Keys "+r.join(", ")+" are")+" not present after all.");if(l.length)T();else u.resolve(t)}else C(e).then(N).fail(T)}function C(n){function h(){a-=1;if(s)u.reject();else if(a<.5)u.resolve()}var r,i,s=false,u=e.Deferred(),a=n.length,f,c;for(i=0;ir){n=l;r=o;return}else if(c==p)s(e,l,o+1)}if(a!=t[""]&&typeof t[""]!=p&&o>r){n=t[""];r=o}}var n=a,r=0,i="";s(e,t,1);return n}function F(e,t,n,r){var i,s=[],o,f,l,c=n.bind,h=u(c);if(h==g){return c.call(q(r).manifest,e,t,r)}if(h===m||h===v){if(h===m&&!/\./.test(c)){if(t!=a)e[c]=t;else if(e[c]===undefined)e[c]=a;return e[c]}if(h===m)s=c.split(".").each(function(e,t){this[t]=e+""});if(h===v)s=c.slice(0).each(function(e,t){this[t]=e+""});if(s[0]==="this"){o=q(r).manifest;s.shift()}else o=e;for(i=0;i-1?"":h;case"s":return n==s?"":h;case"o":return s[n]?"":h;case"b":{if(i.is(".my-form-list,.ui-sortable")){var d=i.data("listSrc")||i.data("my").listSrc||">*",v={};i.find(d).filter("*:not(.ui-sortable-placeholder)").each(function(t){var n=e(this);if(n.data("my")&&!n.my("valid"))v[t]=n.my("errors")});return v}else if(i.hasClass("my-form")){return!s?"":i.my("valid")?"":i.my("errors")}return""}}return l.formError||"Error"}return""}function q(e){var t=e.my();if(!t)return null;return t.root?t.root.my():t}function R(t,n,r){var i=r.compact(),s=i.replace(/:disabled/g,"");n.each(function(){var r=e(this),o=r.my(),u=o?o.container:r;if(t){if(!u.is(s))u.addClass(s)}else u.removeClass(s);if(s!=i&&o!==undefined&&!!t!=!!o.disabled){r.my().disabled=!!t;if(!o._disable)r.my()._disable=j(n,D.offon).fill(undefined,n);o._disable(!!t)}});return n}function U(e,t,n){var r,i,s,u,f,c,h,p,d,v,m,g=false,y=false,b=e,w=b.my(),E="";if(w){p=w.selector;d=w.root;if(d.hasClass("my-form-init"))return{};v=d.find(p);m=d.my().ui;g=e.hasClass("my-form");y=e.hasClass("my-form-list");if(g){r=e;i=w.ddata;s=w.dui;u=w.dparams}else{r=w.container;i=w.data;s=w.ui;u=w.params}if(s.bind!=a){if(l(t))f=t;else f=B(v,F(i,a,s,v));if(a!=s.check){E="Unknown error";try{E=I(i,f,s,v)}catch(x){P.con("Error "+x.message+" validating "+p,d,x.stack)}}var T=u.errorCss;var k="ui-state-error";try{if(a!=t)f=B(v,F(i,t,s,v))}catch(x){E=u.messages.formError||"Error"}if(E===""){if(!g)w.errors[p]="";else w.derrors[p]="";r.removeClass(T);if(r.attr("title"))r.attr("title","");if(!g&&!y)u.effect(r.find(u.errorTip),false,u.animate/2);b.removeClass(k);b.find(".ui-widget").removeClass(k)}else{if(g)w.derrors[p]=E;else if(y)w.errors[p]=E;else{r.addClass(T);w.errors[p]=E;var L=r.find(u.errorTip).eq(0);if(L.size()){u.effect(L.addClass(T).html(E),true,u.animate)}else r.attr("title",(E||"").stripTags())}if(b.is(".hasDatepicker")){if(b.is("input"))b.addClass(k);else b.find(".ui-widget").addClass(k)}if(b.is(".ui-slider"))b.addClass(k)}}var A=t==a?f:t;if(s.css){for(c in s.css){h=s.css[c];if(N(h))R(h.test(A),v,c);else if(C(h))R(h.call(d.my().manifest,i,A,v),v,c)}}var O,M=s.recalc,_=[],D={},H;if(n&&s.recalc&&d.my()){m=d.my().ui;for(O=0;O=f*2){d={};for(o=f;o=u.length)l=u.length-1;p=Object.clone(i.history[u[u.length-l-1]],true);if(n){d={};for(o=0;o$/.test(l.list))u=l.list;else a=l.list||a;if(!u){var h=t.find(a);u="
";if(h.size()){u=e(u).append(h.eq(0).clone(true)).html();h.eq(0).remove()}}if(!t.data("formlist"))t.data("formlist",{});t.data("formlist").generator={manifest:v,delay:(l.delay||f.delay||10)/1.3,template:u,selector:a,parent:m,bind:l.bind,hash:C(l.hash)?l.hash.bind(m):L(l.hash),id:C(l.id)?l.id.bind(m):L(l.id),ext:!!(l.id||l.hash),stamp:0};t.on("insert.my",function(t,n){t.stopPropagation();var r={what:undefined,where:0};if(null==n)r.where=1e6;else if(x(n))Object.merge(r,n);else if(S(n)||T(n))r.where=n;e(t.target).my("insert",r.where,r.what)});t.on("remove.my",function(t){t.stopPropagation();e(t.target).my("remove")})}else{try{n=t.my(O(m,v),x(o)?o:undefined)}catch(p){N("$.my subform init of "+i+" failed: "+p.message,p.stack)}}}if(k(n)){n.then(M,function(e,t){N("Init of subform "+i+" failed with error: "+e,t)})}else M()}function N(e,t){P.con(e,t);if(c)c.reject(e,t)}function L(e){var t=u(e).to(3);return!e?null:t==="str"?A.fill(undefined,e):t==="arr"?P.mask.fill(undefined,e):null}function M(){t.each(function(){var u=e(this),c,h,d=false,v=u[0].nextSibling;h=v&&v.CodeMirror?v.CodeMirror:null;if(h)u.addClass("my-codemirror");c=l.events||j(u,D.events);if(!u.is(".my-form")){u.data("my",{events:c,selector:i,initial:p,previous:p,root:n,container:f.container(u),id:s.id,ui:l,data:s.data,params:f,errors:s.errors});r._update=l.delay?U.debounce(l.delay):a;d=true}else{o(u.data("my"),{dui:l,root:n,selector:i,dparams:f,devents:c,ddata:s.data,container:f.container(u),derrors:s.errors})}if(d){if(u.cleditor&&u.parent().is(".cleditorMain")){var m=u.cleditor()[0];if(m&&m.$frame&&m.$frame[0]){u.addClass("my-cleditor");o(u.data("my"),{container:f.container(u)});var b=function(e){u.val(e).trigger(y)};var w,E=Number.random(1e5,1e6-1);e(m.$frame[0]).attr("id","cleditCool"+E);if(!document.frames)w=e("#cleditCool"+E)[0].contentWindow.document;else w=document.frames["cleditCool"+E].document;var S=e(w).find("body");e(w).bind("keyup.my",function(){b(e(this).find("body").html())});u.parent().find("div.cleditorToolbar").bind("click.my mouseup.my",function(){b(S.html())});e("body").on("click","div.cleditorPopup",function(){b(S.html())})}}else if(u.is("div.redactor_box textarea")){var x,T="my-redactor-9";try{x=u.getEditor();T="my-redactor-8"}catch(N){x=u.redactor("getEditor")}if(x){u.addClass(T);x.bind("input.my keyup.my blur.my",function(e){e.trigger("redactor")}.fill(u))}}else if(u.is(".ace_editor"))ace.edit(t[0]).on(y,function(e){e.trigger("ace")}.fill(u));else if(h){h.on(y,function(e){e.trigger("codemirror")}.fill(u))}}u.my()._changed=X.debounce(g);u.my()._recalc=V.debounce(g);u.bind(c,function(e){if(e.type==y)e.stopPropagation();if(d)s.locktill=Date.now()+r.delay;u.my()._changed(u,n,r,f)});if(!/check(\.my)?/.test(c+""))u.on("check.my",function(e){u.my()._changed(u,n,r,f,true);return false});u.on("recalc.my, redraw.my",function(e){e.stopPropagation();u.my()._recalc(u,n,r,f)})});if(c)c.resolve()}var s=n.my(),f=(s||{}).params,l=r,c=null,h,p,d=0,v,m=s.manifest,g;if(!s){P.con("Failed to find $root building "+i+" selector.");return null}g=r.delay;if(t.size()){if(l.init!=a)h=$(m,l.init,t,s);if(k(h)){d+=1;c=e.Deferred();h.then(E,function(e,t){N("Init of "+i+" failed: "+e,t)})}else E()}else P.con("Not found "+i+" selector.",n);return c}function X(e,t,n,r,i){var s=e.data("my"),o=t.data("my");if(s&&!s.disabled){z(s.ddata||s.data,s.dparams||s.params);var u=t.find(s.selector);U(e,!i?B(u,a):a,n.recalcDepth||r.recalcDepth);if(undefined===o.orphan){if(s.root.parent().hasClass("ui-sortable")){o.orphan=!s.root.parent().hasClass("my-form-list")}}if(o.orphan)s.root.parent().trigger("check");if(r.change)r.change.call(e)}}function V(e,t,n,r){var i=e.my();if(i&&!i.disabled){var s=t.find(i.selector);if(s.is(".my-form"))s.my("redraw");else U(e,s.is(".my-form-list")?A(s.my().data,s.data("formlist").generator.bind):a,n.recalcDepth||r.recalcDepth)}}function $(e,t,n,r){var i;if(S(t)){i=A(e,t);if(undefined===i){n.html(t.assign(r.data));return null}}else i=t;if(C(i))return i.apply(e,Array.prototype.slice.call(arguments,2));else if(w(i)){try{n.formgen(i)}catch(s){}}return null}function J(e,t){var n="",r,i="",s=!t,o=[];for(n in e)if(e.hasOwnProperty(n)&&(s||!/^(data|files|require)$/.test(n))){r=e[n];i=u(r);if(/^(ob|ar)/.test(i))J(r);else if(i==="string"&&/^(function\s\(|new\sRegExp)/.test(r)){if(o=r.match(/^function\s\(([^\)]*)\)\s*\{([\s\S]*)\}$/)){if(o.length===3){try{e[n]=Function(o[1],o[2])}catch(a){console.log(a.message,a.stack,r)}}}else if(o=r.match(/^new\sRegExp\(\/([\s\S]+)\/([a-z]*)\)$/)){if(o.length===3){try{e[n]=RegExp(o[1],o[2])}catch(a){console.log(a.message,a.stack,r)}}}}}o=null}function K(e,t,n){var r=x(t)?t:null;Object.each(e,function(t,n){var r=typeof n;if(/^str|^fu/.test(r))e[t]={bind:n}});Object.each(e,function(t,i){var s=[],o=[],u,a=/\s?[,;]\s?/,f,l;if(i.recalc){if(S(i.recalc))s=i.recalc.split(a);else if(w(i.recalc))s=i.recalc;s=s.compact(true).unique()}if(s.length)e[t].recalc=s;if(null==i.bind)i.bind=function(){};if(i.watch){if(S(i.watch))o=i.watch.split(a);else if(w(i.watch))o=i.watch.slice(0);o=o.compact(true).unique();for(l=0;l2){h=P.css2json(h)}else i.push(r+(/\{/.test(h)?h:"{"+h+"}"))}if(w(h)&&h.length){for(a=0;a.my-form",d=h.template||"
",v=/\{/.test(d),m=h.hash||P.sdbmCode,g=h.id||P.sdbmCode,y=h.ext,b=h.delay||50,E=t.is("."+a),S=!!t.children(f).size(),x=[],T=[],N,C,k=Date.now();var L=E?t.find(t.sortable("option","items")):t.find(p);if(l(n)&&w(n)){if(S)return n;i=[];L.each(function(){var t=e(this),n=t.data("my");if(n)i.push(n.data)});o=false;if(i.length===n.length)for(o=true,r=0;r1.4*b||k-h.stamp>100||!h.stashed||h.stashed.length!==L.size()-(S?1:0)){if(S)C=t.find(">."+a+"-helper");L.each(function(t){var n=e(this),r,i,s,o=false;if(!S||!n.hasClass(a+"-helper")){if(S&&n.hasClass(a+"-placeholder"))n=C;r=n.data("my");i=n.data("formlist");if(r&&i){x.push(r.data);if(u!=i.index){i.index=u;o=!0}if(y){s=m(r.data,u)+"";if(s!==i.hash){i.hash=s;o=!0}}u+=1;if(o)T.push(n)}}});for(r=0;r."+i+"-placeholder",o=t.find(t.sortable("option","items")),u;if(l(n)&&w(n)){var f={},c={},h=n.unique();if(t.find("input:focus:eq(0),textarea:focus:eq(0)").size()||t.find(s).size())return h;o.each(function(){f[P.sdbmCode(P.extval(e(this)))]=e(this)});for(var p=h.length-1;p>=0;p--){var d=P.sdbmCode(h[p]);if(f[d]){f[d].prependTo(t).show();c[d]=true;if(r.indexOf(h[p])==-1)r.push(h[p])}}r=r.reverse();for(p in f)if(!c[p])f[p].hide()}else{var v=t.find(s),m=t.eq(0);if(v.size()!=0){if(m.my()[i]!=v.position().left+""+v.position().top){o=o.filter(":visible:not(:disabled, .ui-state-disabled, .ui-sortable-helper)");u=t.find(t.sortable("option","items")).filter(".ui-sortable-helper");o.each(function(){var t=e(this);if(t.is(".ui-sortable-placeholder")){r.push(P.extval(u))}else r.push(P.extval(t))});m.my()[i]=v.position().left+""+v.position().top;m.my()[i+"1"]=r}else r=m.my()[i+"1"];if(r==a)o.each(function(){r.push(P.extval(e(this)))})}else{o=t.find(t.sortable("option","items")).filter(":visible:not(:disabled, .ui-state-disabled)");o.each(function(){r.push(P.extval(e(this)))})}}return r},"input[type=date]":function(e,t){if(l(t)){if(t!="")n=Date.create(t).format(c);else n="";if(S(n)&&!/Invalid/.test(n))e.val(n);return n}var n=e.val();return n!=""?Date.create(n).format(c):""},"input[type=time]":function(e,t){if(l(t)){if(t!="")n=Date.create(t).format(h);else n="";if(S(n)&&!/Invalid/.test(n))e.val(n);return n}var n=e.val();return n!=""?Date.create(n).format(h):""},input:{"[type='text'],[type='number'],[type='search'],[type='hidden'],[type='password'],[type='button'],[type='range'],:not([type])":{".ui-slider-input":function(e,t){if(l(t))e.val(t).slider("refresh")},".tagstrip input.value":function(e,t){if(l(t))e.val(t).trigger("update")},"div.select2-container+input":function(e,t){if(l(t)&&JSON.stringify(t)!==JSON.stringify(e.select2("val")))e.select2("val",w(t)?t:[t]);return e.select2("val")},"":function(e,t){if(l(t))e.val(t+"")}},":radio":function(t,n){var r=-1;if(l(n)){t.each(function(t){var i=e(this).val();if(n+""===i+"")r=t});var i=t.eq(0).checkboxradio;if(i)t.each(function(t){var n=e(this);if(r!=t&&n.is(":checked"))n.prop("checked",false).checkboxradio("refresh")});if(r>-1){var s=t.eq(r);if(!s.is(":checked")){s.prop("checked",true);if(i)s.checkboxradio("refresh")}}else if(!i)t.each(function(){e(this).prop("checked",false)})}if(r==-1)for(var o=0;oForm init failed

',ru:'

Ошибка инициализации формы

'},badInput:{en:"Invalid input",ru:f},patternMismatch:{en:"Pattern mismatch",ru:"Не соответствует шаблону"},rangeOverflow:{en:"Over maximum",ru:"Больше максимума"},rangeUnderflow:{en:"Under minimum",ru:"Меньше минимума"},stepMismatch:{en:"Step mismatch",ru:"Не кратно шагу"},tooLong:{en:"Too long",ru:"Слишком длинно"},typeMismatch:{en:"Invalid type",ru:"Неверный тип"},valueMissing:{en:"Required",ru:"Обязательное поле"}},events:{".hasDatepicker":"change.my check.my",".my-form,.my-tags":"change.my check.my",".ui-slider":"slide.my check.my","div.redactor_box textarea":"redactor.my check.my",".my-codemirror":"codemirror.my check.my",".ace_editor":"ace.my check.my",".my-form-list":"sortupdate.my check.my",".ui-sortable":"sortchange.my sortupdate.my check.my",".ui-draggable":"drag.my dragstop.my check.my","a, .pseudolink, input[type=button], button":"click.my","img, :radio, :checkbox":"click.my check.my","div.select2-container+input,div.select2-container+select":"change.my check.my input.my",".ui-buttonset,input, select, textarea":"blur.my change.my check.my"+(navigator.appName.to(5)==="Micro"?" keyup.my":" input.my"),"":"check.my"},containers:{"*[data-role='fieldcontain'] *":{"input,textarea,select,button,:radio":function(e){return e.parents('[data-role="fieldcontain"]').eq(0)}},".tagstrip *.value":function(e){return e.parents(".tagstrip").eq(0)},"div.redactor_box textarea":function(e){return e.parents("div.redactor_box").eq(0).parent()},".my-tags,.hasDatepicker,.ui-widget,input,textarea,select,button":{".my-cleditor":function(e){return e.parents("div.cleditorMain").eq(0).parent()},"":function(t){var n=t[0].parentNode,r=n.nodeName;if(/^(div|span|a|p|form|fieldset|li|ul|td|th|h\d)$/i.test(r))return e(n);else return t.parents("div,span,a,p,form,fieldset,li,ul,td,th,h1,h2,h3,h4,h5,h6").eq(0)}},"":function(e){return e}},offon:{".ace_editor":function(e,t){ace.edit(t[0]).setReadOnly(e)},".ui-selectable":function(e,t){P.jquix(t,"selectable",e)},".ui-slider":function(e,t){P.jquix(t,"slider",e)},".ui-draggable":function(e,t){P.jquix(t,"draggable",e)},".ui-buttonset":function(e,t){P.jquix(t,"buttonset",e)},".hasDatepicker":function(e,t){P.jquix(t,"datepicker",e)},".my-form":function(e,t){t.my("disabled",!!e)},"div.select2-container+input,div.select2-container+select":function(e,t){P.jquix(t,"select2",e)},".my-cleditor":function(e,t){t.cleditor()[0].disable(!!e)},"":function(e,t){t.attr("disabled",!!e)}},destroy:{".hasDatepicker":function(e){e.datepicker("destroy")},".ui-slider":function(e){e.slider("destroy")},".ui-sortable":{".my-form-list":function(t){t.find(">.my-form").each(function(){e(this).my("remove")});t.removeClass("my-form-list");t.sortable("destroy")},"":function(e){e.sortable("destroy")}},".my-form-list":function(t){t.find(">.my-form").each(function(){e(this).my("remove")})},".ui-draggable":function(e){e.draggable("destroy")},".my-redactor-8":function(e){e.destroyEditor();e.removeClass("my-redactor-8")},"div.select2-container+input,div.select2-container+select":function(e){e.select2("destroy")},".my-form":function(e){e.my("remove")},textarea:{".my-codemirror":function(e){e[0].nextSibling.CodeMirror.toTextArea();e.removeClass("my-codemirror")}}}};D.params={container:function(e){return j(e,D.containers)(e)},change:a,recalcDepth:2,delay:0,strict:false,locale:f=(navigator.language||navigator.userLanguage||"en").substr(0,2),messages:Object.map(D.msg,function(e,t){return t[f]||t.en}),errorTip:".my-error-tip",errorCss:"my-error",animate:0,effect:function(e,t,n){if(t)return e.fadeIn(n);e.fadeOut(n)},remember:0,silent:false,history:{},historyDelay:100,loader:function(t,n){var r=e.Deferred(),i=L(t+"");if(i)r.resolve(i);else r.reject(null);return r.promise()},ajaxTimeout:1e4};var P=Y();P.require=H;var G={init:function(t,n,i){function G(){if(!g.strict)J(y,true);h=o(true,h,Object.reject(y,["data"]));m=K(o(true,{},y.ui||{}),h,g);l=Number.random(268435456,4294967295).toString(16);f=y.id||"my"+l;c=P.sdbmCode(f);h.id=f;g.form=X;if(y.params&&y.params.depth)g.recalcDepth=y.params.depth;for(b in h)if(C(h[b]))h[b].bind(h);if(y.error){if(S(y.error)){q=function(e,t){return y.error.assign(o({message:e+"",err:t+""},y))}}else if(C(y.error)){q=function(e,t){p=null;try{p=y.error(e,t)}catch(n){p=g.messages.initFailed}return p}}}o(X.data("my"),{id:f,cid:l,mid:c,errors:Object.extended(),ui:Object.extended(m),disabled:false,manifest:h,locFiles:[],modals:{}});X.addClass("my-form");T="my-manifest-"+c;N="my-form-"+l;X.addClass(N+" "+T)}function Y(){if(h.style){E=Q(X,h,T,N);if(E&&E[0].length){A=e("style#"+T);if(!A.size()){A=e('").appendTo(e("body"))}A.data("count",A.data("count")*1+1);X.data("my").style=A}if(E&&E[1].length){O=e("style#"+N);if(!O.size()){O=e('").appendTo(e("body"))}X.data("my").localStyle=O}}}function Z(){var t,n=e.Deferred(),i;i=_(h);if(S(i)){rt("Error decoding base64 to local Blob/URL",i);n.reject()}else{if(r)for(t=0;t*").clone();try{I=$(h,y.init,X,y)}catch(t){rt(S(t)?t:t.message,t.stack);return X}}if(k(I)){I.then(function(){tt()},function(e,t){rt(e,t)})}else tt();if(!j){if(!X.my())return rt("Internal error initializing controls",""),X;X.data("my").initial=o(true,{},v);if(e.mobile)e.mobile.changePage(e.mobile.activePage)}}function tt(){function n(n){if(!j){e[n]=B(X.find(n),a);t-=1;if(t<.5)nt(e)}}var e={},t=Object.size(m);X.addClass(R);Object.each(m,function(e){if(j)return;var t=X.find(e),r=W(t,X,m[e],e);if(k(r)){r.then(n.fill(e)).fail(function(t,n){rt("Error building "+e+", "+t,n)})}else if(!j)n(e)})}function nt(e){var t,n,r;for(var i in m){if(j)return;t=m[i];r=X.find(i);if(r.size()){try{n=F(v,a,t,r);if(n==a&&e[i]!=a&&n!==undefined)F(v,e[i],t,r)}catch(s){P.con("Transient fail linking "+i+" of form $('.my-form-"+l+"')",s.message,s.stack)}try{if(n!=a)B(r,n);r.eq(0).trigger("check.my")}catch(s){rt("Error linking "+i,s.message,s.stack)}}}X.removeClass(R);z=null;M.resolve(v)}function rt(e,t){var n;j=true;P.con("Form "+f+" failed to initialize: "+e,t);X.removeClass(R);n=q(e,t);if(S(n)||x(n)&&n.jquery)X.html(n);else if(n===true)X.html(z);if(!g.silent){if(!X.my().ddata){X.removeData("my");X.removeClass("my-form");if(A){if(A.data("count")=="1"){try{A.remove()}catch(r){}}else A.data("count",A.data("count")-1)}if(O){try{O.remove()}catch(r){}}}M.reject("Form "+f+" failed to initialize: "+e,t)}else M.resolve(v)}var s,u,f,l,c,h={},p,v={},m,g,y,b,w=[],E,T,N,A,O,M=e.Deferred(),j=false,I,q=function(){},R="my-form-init",U="std",z="";if(S(t)){s=L(t);if(s){if(x(i)&&x(n)){s=o(s,n);u=i}else u=n;U="repo"}else{M.reject("No manifest with id "+t+" found in repo.");return M.promise()}}else{s=t;u=n}if(!s)return this;if(x(u)&&U!="repo")y=o(true,{},s);else y=s;var X=this.eq(0),V=X.my();if(x(V)&&V.id&&V.ui){P.con("jQuery.my is already bind.",X);X.my("ui",y.ui);X.my(d,y.data);return M.resolve(X.my(d)).promise()}g=y.params||{};if(!g.strict){g=o(true,{},g);J(g)}g=o(true,{},D.params,g);M.fail(function(){X.removeClass(N+" "+T)});o(X,M.promise());if(x(u)){v=P.patch(u,y.data||{});y.data=v}else v=y.data||{};h.data=v;X.data("my",{data:v,params:g,promise:M.promise(),locktill:0});X.addClass(R);H(y,g).then(function(){G();Z().then(function(){Y();et()})}).fail(function(e){G();rt("Linker of ‘require’ property failed.",e)});return X},redraw:function(e,t){var n=this,r=n.my();if(r&&r.ui){r.ui.each(function(t){var i=n.find(t);U(i,e?a:undefined,r.params.recalcDepth);if(!e){if(i.is(".my-form"))i.my("redraw");if(i.is(".my-form-list"))i.trigger("redraw");else i.trigger("check.my")}});if(!t&&e)n.trigger(y)}return n},data:function(e,t){var n=this;if(x(e)){n.my().data=P.overlap(n.my().data,e);this.my("redraw",t)}return n.my().data},errors:function(){var t=e(this).my().errors,n={};for(var r in t){if(t[r]&&S(t[r]))n[r]=t[r];if(x(t[r])&&Object.keys(t[r]).length)n[r]=t[r]}return n},valid:function(){var t=e(this).my().errors,n=0;for(var r in t){if(t[r]&&S(t[r]))n++;else if(x(t[r])&&Object.keys(t[r]).length)n++}return!n},reset:function(){try{P.kickoff(this.my().data,this.my().initial);this.my("redraw")}catch(e){return false}return true},id:function(e,t){if(S(e))return L(e,t);else{var n=this.my();return n&&n.id?n.id:a}},remove:function(e){var t=this,n,r,i,s,o,u,f,l;if(!this.my())return a;if(this.my().root&&!this.my().ddata)t=this.my().root;i=t.my();o=i.data;f=i.cid;l=i.mid;if(t.data("modals")){}t.unbind(".my");if(n=i.style){if(n.data("count")=="1"){try{n.remove()}catch(c){}}else n.data("count",n.data("count")-1)}if(r=i.localStyle){try{r.remove()}catch(c){}}if(window.URL&&(s=i.locFiles)&&s.length){for(var h=0;h1&&h(n[1])){var i=n[0],s="",o,f,c,d,v=1,m,g,y,w;while(v'+(i?"<"+r.labelTag+' class="'+r.labelCss+'" '+(r.label?'style="display:inline-block;width:'+r.label+";margin-left:-"+r.label+'" ':"")+">"+i+"":"")+s+""}return e+s}return e}function E(e){var t=e;if(h(t)){t=t.split(/[\s,]/).compact(true)}if(l(t)){var n={};for(var r=0;r',inp:g+'text" {ext}/>',sli:g+'range" {ext}/>',dat:g+'date" {ext}/>',btn:g+'button" {ext}/>',div:"
{txt}
",spn:"{txt}",sel:"",mul:'',txt:"",err:' {txt}',msg:'
{txt}
',val:function(e){if(!l(e.vals))return"";var n=t({style:"",css:""},e);n.txt=e.vals.reduce(function(e,t){return e+'"+t+" "}," ");return'{txt}'.assign(n)},"":"<{_tag} {ext}>{txt}"},txt:{sel:function(e){if(!e.vals)return"";var t=E(e.vals);return Object.keys(t).reduce(function(e,n){return e+'"},"")}},params:{styles:{num:"width:30%;",dat:"width:30%;",inp:"width:100%",txt:"width:100%;max-width:100%;min-height:1px;word-break:break-word;",err:"display:none",msg:"display:none"},alias:{number:"num",date:"dat",slider:"sli",textarea:"txt",input:"inp",span:"spn",select:"select",vals:"val"},row:"",rowTag:"div",rowCss:"my-row",label:"",labelTag:"span",labelCss:"my-label"},defaults:{id:"","class":"",style:"",placeholder:"",value:"",rows:1},attnames:{css:"class",plc:"placeholder",val:"value",txt:"",vals:"",tip:"title"}};var x={init:function(t,n){return e(this).html(S(t,n))}};if(!e.my)e.my={};e.my.formgen=S;e.fn.formgen=function(t){if(h(t)&&x[t])return x[t].apply(this,Array.prototype.slice.call(arguments,1));else if(typeof t==="object"||!t)return x.init.apply(this,arguments);else e.error("Method "+t+" does not exist on jQuery.formgen")}})(jQuery);(function(e){function d(t,n,r,i){var o,u,a,c,h,p,d;if(typeof n=="object"&&n.jquery){if(n.is("img")){p=n;h=n.attr("alt")||n.attr("title")||n.data("text")||"";u=p[0].naturalWidth||p[0].width;o=p[0].naturalHeight||p[0].height;if(o<1)o=1;if(u<1)u=1;c=e(window).width()-90;a=e(window).height()-90;if(a'+'

',ui:{"img:eq(0)":"img",h4:{bind:"text",css:{hide:function(e,t){return!t}}}}},data:{img:p.attr("src"),text:h},esc:true,screen:true,width:i||d,focus:false,global:true},r)}}else if(l(n)&&n.manifest){s(t,n,r)}else if(f(n)){s(t,{source:"html",manifest:{init:function(e){e.html(this.HTML)},HTML:n,ui:{"div:eq(0)":function(){}}},data:{},esc:true,focus:false,global:true,screen:true,width:i},r)}else return null;return t}var t={},n="body",r,i=false,s=e.extend,o={},u=Object.isArray,a=Object.isBoolean,f=Object.isString,l=Object.isObject,c=Object.isNumber,h=Object.isRegExp,p=Object.isFunction;e(document).keydown(function(e){var t=e.keyCode,n,r;if(false!==i&&(t===13||t===27)){r=i.data("modal");n=r.form;if(t==27&&(r.esc||Object.equal(n.data("my").initial,n.my("data")))){i.modal(true);return false}else if(t==13&&r.enter){i.modal.delay(50);return false}}});t.modal=function(r,s,o){var u={},a=e(n),f,l=a.find(">.my-modal-proxy"),c={global:true,screen:true,done:p(s)?s:undefined};if(i){return l.modal(r,s,o)}else{if(!l.size()){l=e('
').prependTo(a);l.css({position:"absolute",top:"0",left:"0",margin:"0",padding:"0",width:"1px",height:"0"})}if(d(u,r,c,o))return l.modal(u);else{var h=e.Deferred();return h.reject("Invalid data").promise()}}};t.modal.loading=function(t){e(n).find(">.my-modal").toggleClass("my-modal-loading",!!t)};t.modal.parent=function(t){if(!t||!e(t).size())return e(n);n=t};t.modal.parentBack=function(t){if(!t||!e(t).size())return e(r||n);r=t};t.modal.visible=function(){return!!i};if(!e.my)e.my={};e.my.modal=t.modal;e.fn.modal=function(t,u,c){function O(){var t=window,n,r,i=!!C.global,s=b.offset(),o=y.offset();C.pos={px:s.left,py:s.top,pw:b.outerWidth(),ph:b.outerHeight(),ox:o.left,oy:o.top,ow:y.outerWidth(),oh:y.outerHeight(),ww:r,wh:n};var u=(C.x.match(/\-?\d+(\.\d+)?/)||[0])[0]*1,a=(C.y.match(/\-?\d+(\.\d+)?/)||[0])[0]*1,f=C.x.has("left")?-1:C.x.has("right")?1:0,l=C.y.has("top")?-1:C.y.has("bottom")?1:0,c=C.pos.ox+C.pos.ow/2-C.pos.px,h=C.pos.oy+C.pos.oh/2-C.pos.py;if(i){C.pos.wh=n=t.innerHeight||e(t).height();C.pos.ww=r=t.innerWidth||e(t).width();c=r/2;h=n/2.5}u=C.x.has("%")?C.pos.ow/100*u:u;a=C.y.has("%")?C.pos.oh/100*a:a;C.pos.pix=c;C.pos.piy=h;c=c+f*(C.pos.ow/2)+u*(f>0?-1:1)-(C.width+S)*(f+1)/2;if(i){h=(n-C.height-20)/3;if(h<10)h=10}else{h=h+l*(C.pos.oh/2)+a*(l>0?-1:1)-((C.height||0)+x)*(l+1)/2}c=c.round(1);h=h.round(1);C.pos.vx=c;C.pos.vy=h}function _(t){if(!t){C.height=m.outerHeight();if(C.source!=="manifest")C.width=m.width();O()}m.css({left:C.pos.vx+"px",width:C.width+S+"px",display:"block"});if(C.screen){if(!C.global)w.css({top:0,left:0,position:"absolute",width:C.pos.pw+"px",height:C.pos.ph+"px",display:"block",background:f(C.screen)?C.screen:"rgba(40,80,120,0.5)","z-index":C.z-1});else{w.css({top:0,left:0,width:C.pos.ww*2+"px",height:C.pos.wh*2+"px",display:"block",position:"fixed","z-index":C.z-1});if(f(C.screen))w.css({background:C.screen?C.screen:"rgba(30,65,100,0.8)"})}}else if(w.size())w.hide();if(C.height>C.pos.wh){m.height(C.pos.wh-30);g.css({"overflow-y":e.browser.webkit?"overlay":"scroll"})}else{g.css({"overflow-y":"none"})}m.animate({top:C.pos.vy+"px",opacity:"1"},C.animate)}function D(){try{g.my("remove")}catch(t){}b.data("modals")[C.cid]=null;g.parent().unbind(".my").remove();w.off(".my"+C.cid).hide();if(C.global){i=false;e("body").css({overflow:"auto"})}}function P(e){try{T(null,null)}catch(t){}(function(){h.reject(e)}).delay(0)}var h=e.Deferred(),v={},m,g,y=this,b,w,E,S=0,x=0,T=p(u)?u:function(){return false},N=l(t)?t:{},C=y.data("modal"),k,L;s(y,h.promise());if(C){if(t==null||a(t)){g=C.form;w=C.bg;b=C.root;T=C.done;k=g.my("data");L=false;if(!t){try{L=T(g.my("valid")?null:g.my("errors"),k)}catch(A){}if(!L){D();y.removeData("modal");(function(){if(o[C.cid])o[C.cid].resolve(k);delete o[C.cid];C=null}).delay(0)}}else{try{T(null,null)}catch(A){}D();y.removeData("modal");if(o[C.cid])o[C.cid].reject("Cancelled");delete o[C.cid];C=null}return y}else if(N){P("Locked");return y}}if(!y.is(":visible")){P("Object must be visible");return y}if(!(N=d(v,t,{}))){P("Invalid data");return y}if(N.global&&i){P("Locked");return y}C=s({type:"DOM",source:"manifest",form:null,modal:null,root:null,bgroot:null,caller:y,global:false,drag:false,focus:true,manifest:{},data:{},nose:"",close:true,esc:false,enter:false,screen:false,width:c||300,height:null,x:"0",y:"0",z:"1997",css:"",animate:200},N,{promise:h.promise(),cid:Number.random(268435456,4294967295).toString(16)});C.done=p(C.done)?C.done:T;if(f(C.align)&&C.align){C.x=(C.align.match(/(left|right):\-?\d+(\.\d+)?(%|px)?/g)||["0"])[0];C.y=(C.align.match(/(top|bottom):\-?\d+(\.\d+)?(%|px)?/g)||["0"])[0]}C.width=1*(e.my.f.getref(f(C.manifest)?e.my.cache(C.manifest):C.manifest,"params.width")||C.width);C.type="DOM";if(y.hasClass("my-form")){C.type="form";C.root=C.root||y}else if(y.data("my")){C.type="control";C.root=C.root||y.my().container}else{C.root=C.root||y.parents(".my-form").eq(0);if(!C.root.size())C.root=e(n)}if(C.global){C.root=e(n);C.bgroot=e(r||n)}else C.bgroot=C.root;b=C.root;if(!b.data("modals"))b.data("modals",{});O();m=e('
').prependTo(C.root);m.addClass("my-modal-"+C.cid);S=m.outerWidth();x=m.outerHeight();m.hide();m.html('
');g=m.find(".my-modal-form");if(C.close){E=e(f(C.close)?C.close:'
×
').prependTo(m).on("click.my",function(){y.modal(true)});E.css({"z-index":""+(C.z*1+1)})}w=C.bgroot.find(">.my-modal-screen");if(C.screen){if(!w.size()){w=e('').prependTo(C.root)}if(C.esc)w.on("click.my"+C.cid,function(){y.modal(true)})}y.data("modal",C);m.css({position:C.global?"fixed":"absolute",left:C.pos.vx+"px",top:C.pos.vy+"px",display:"block",height:"none",opacity:"0.005","z-index":C.z,width:"auto"});g.my(C.manifest,C.data).then(function(){var t,n,r,u,a;s(C,{form:g,bg:w,cancel:function(){y.modal(true)},commit:function(){y.modal()}});m.data("modal",C);C.height=m.outerHeight();if(C.source!=="manifest")C.width=m.width();O();m.css({top:C.pos.vy+"px"});_(true);b.data("modals")[C.cid]=C;o[C.cid]=h;g.bind("commit.my",function(){C.commit.delay(50);return false}).bind("cancel.my",function(){C.cancel.delay(50);return false});m.bind("layout.my",function(){_()}.debounce(50));if(C.global){i=y;e("body").css({overflow:"hidden"})}if(!C.global&&(C.esc||C.enter)){g.bind("keydown.my",function(e){var t=e.keyCode;if(t==27&&C.esc){C.cancel();return false}else if(t==13&&C.enter){C.commit.delay(50);return false}})}if(C.focus===true){u=false;a=C.manifest.ui;for(r in a){if(!u){n=g.find(r);if(n.size()&&n.is("input, textarea")){u=true;n.focus()}}}}else if(f(C.focus))g.find(C.focus).focus();t=g.find("img").filter(function(){return e(this).attr("src")!=""});if(t.size()){var l=function(){if(C.source!=="manifest")m.css({width:"auto"});_()}.after(t.size());t.each(function(){e(this).bind("load",l)})}if(C.drag&&e.fn.draggable){if(!f(C.drag))m.draggable();else m.draggable({handle:C.drag})}h.notify("Ready")}).fail(function(e){D();y.data("modal",null);h.reject(e)});return y}})(jQuery); diff --git a/Release/jquery.my.last.js b/Release/jquery.my.last.js index 0aee02b..d537f49 100644 --- a/Release/jquery.my.last.js +++ b/Release/jquery.my.last.js @@ -1,5 +1,5 @@ -/* jQuery.my 1.0.0 +/* jQuery.my 1.0.2 * Requires jQuery 1.11.0+, SugarJS 1.3.9-1.4.x * More details at jquerymy.com */ -;(function(e){function O(e,t){return(t||"").split(".").reduce(function(e,t){if(null!=e&&null!=e[t])return e[t];else return undefined},e)}function M(e,t){var n,r;if(x(t))return t;else if(S(t)){n=O(e,t);if(null==n)n=Object.clone(s._src[t],true);if(null==n){n=O(s,t);if(x(n)&&x(n._self))n=Object.clone(n._self,true);else if(x(n))n=Object.clone(n,true)}if(null==n&&O(e,"params.cache")){r=O(e,"params.cache");if(C(r))n=r(t);else if(x(r))n=A(t,r);if(x(n)){if(x(n._self))n=Object.clone(n._self,true);Object.merge(n,{params:{cache:r}},true)}}if(null!=n&&x(n)){r=r||O(e,"params.cache");if(r)Object.merge(n,{params:{cache:r}},true);return n}else throw"Component "+t+" not found"}else if(C(t)){return t.apply(e,Array.prototype.slice.call(arguments,2))}else return null}function _(e,t){var n,r,o=t||s,u=e,a,f,l,c;if(!(x(o)&&x(u)&&x(u.ui)&&S(u.id)))return"Invalid arguments.";if(!o.hasOwnProperty("_src"))o._src={};f=u.id;try{u=Object.clone(e,true)}catch(h){return"Can't mount circular-referencing obj."}try{if(!u.params||u.params&&!u.params.strict)K(u,true)}catch(h){return"Invalid manifest, parse error."}n=D(u);if(S(n)){H.con(n);return n}Object.merge(u,{params:{strict:true}},true);o._src[f]=u;if(l=H.mask(o,f)){if(l.params&&l.params.protect)return"Can't mount on protected";if(l._self)delete l._self}Object.merge(o,H.unmask(u,f),true);c=O(o,f);if(i)c["_self"]=o._src[f];else Object.defineProperty(c,"_self",{get:function(){return o._src[f]},set:function(){throw"Can not change repo"},enumerable:false,configurable:true});return c}function D(e){var t,n=[],i;if(x(e.files)&&Object.size(e.files)){for(t in e.files){i=e.files[t];if(x(i)&&i.data&&!i.url){if(r){try{H.base642blob(i.data,function(e){i.blob=e;i.url=r.createObjectURL(i.blob)},i.content_type||i.mime);n.push(t)}catch(s){return"Invalid base64 data in files/"+t+"."}}else{i.url="data:"+(i.content_type||i.mime)+";base64,"+i.data;n.push(t)}}}}return n}function B(t,n){function E(t,n){var r;if(S(t)){if(/[\/]/.test(t)){r=o(true,{},g,{ref:n,ajax:{url:t}});if(b.test(n))r.ajax.dataType="json"}else if(t.length){r=o(true,{},g,{ref:n,ajax:t})}}else if(x(t)){r=o(true,{},g,{ref:n,ajax:e.extend(true,{},Object.select(t,["accepts","async","cache","data","dataType","password","timeout","type","url","username"]))});if(!r.ajax.url)r=null}return r}function T(){u.reject(l)}function N(){y+=1;var e=a[y];if(!e){var n=L(f),r=Object.keys(Object.findAll(n,function(e,t){return!t}));if(r.length)l.push((r.length===1?"Key "+r[0]+" is":"Keys "+r.join(", ")+" are")+" not present after all.");if(l.length)T();else u.resolve(t)}else C(e).then(N).fail(T)}function C(n){function h(){a-=1;if(s)u.reject();else if(a<.5)u.resolve()}var r,i,s=false,u=e.Deferred(),a=n.length,f,c;for(i=0;ir){n=l;r=o;return}else if(c==p)s(e,l,o+1)}if(a!=t[""]&&typeof t[""]!=p&&o>r){n=t[""];r=o}}var n=a,r=0,i="";s(e,t,1);return n}function I(e,t,n,r){var i,s=[],o,f,l,c=n.bind,h=u(c);if(h==g){return c.call(R(r).manifest,e,t,r)}if(h===m||h===v){if(h===m&&!/\./.test(c)){if(t!=a)e[c]=t;else if(e[c]===undefined)e[c]=a;return e[c]}if(h===m)s=c.split(".").each(function(e,t){this[t]=e+""});if(h===v)s=c.slice(0).each(function(e,t){this[t]=e+""});if(s[0]==="this"){o=R(r).manifest;s.shift()}else o=e;for(i=0;i-1?"":h;case"s":return n==s?"":h;case"o":return s[n]?"":h;case"b":{if(i.is(".my-form-list,.ui-sortable")){var d=i.data("listSrc")||i.data("my").listSrc||">*",v={};i.find(d).filter("*:not(.ui-sortable-placeholder)").each(function(t){var n=e(this);if(n.data("my")&&!n.my("valid"))v[t]=n.my("errors")});return v}else if(i.hasClass("my-form")){return!s?"":i.my("valid")?"":i.my("errors")}return""}}return l.formError||"Error"}return""}function R(e){var t=e.my();if(!t)return null;return t.root?t.root.my():t}function U(t,n,r){var i=r.compact(),s=i.replace(/:disabled/g,"");n.each(function(){var r=e(this),o=r.my(),u=o?o.container:r;if(t){if(!u.is(s))u.addClass(s)}else u.removeClass(s);if(s!=i&&o!==undefined&&!!t!=!!o.disabled){r.my().disabled=!!t;if(!o._disable)r.my()._disable=F(n,P.offon).fill(undefined,n);o._disable(!!t)}});return n}function z(e,t,n){var r,i,s,u,f,c,h,p,d,v,m,g=false,y=false,b=e,w=b.my(),E="";if(w){p=w.selector;d=w.root;if(d.hasClass("my-form-init"))return{};v=d.find(p);m=d.my().ui;g=e.hasClass("my-form");y=e.hasClass("my-form-list");if(g){r=e;i=w.ddata;s=w.dui;u=w.dparams}else{r=w.container;i=w.data;s=w.ui;u=w.params}if(s.bind!=a){if(l(t))f=t;else f=j(v,I(i,a,s,v));if(a!=s.check){E="Unknown error";try{E=q(i,f,s,v)}catch(x){H.con("Error "+x.message+" validating "+p,d,x.stack)}}var T=u.errorCss;var k="ui-state-error";try{if(a!=t)f=j(v,I(i,t,s,v))}catch(x){E=u.messages.formError||"Error"}if(E===""){if(!g)w.errors[p]="";else w.derrors[p]="";r.removeClass(T);if(r.attr("title"))r.attr("title","");if(!g&&!y)u.effect(r.find(u.errorTip),false,u.animate/2);b.removeClass(k);b.find(".ui-widget").removeClass(k)}else{if(g)w.derrors[p]=E;else if(y)w.errors[p]=E;else{r.addClass(T);w.errors[p]=E;var L=r.find(u.errorTip).eq(0);if(L.size()){u.effect(L.addClass(T).html(E),true,u.animate)}else r.attr("title",(E||"").stripTags())}if(b.is(".hasDatepicker")){if(b.is("input"))b.addClass(k);else b.find(".ui-widget").addClass(k)}if(b.is(".ui-slider"))b.addClass(k)}}var A=t==a?f:t;if(s.css){for(c in s.css){h=s.css[c];if(N(h))U(h.test(A),v,c);else if(C(h))U(h.call(d.my().manifest,i,A,v),v,c)}}var O,M=s.recalc,_=[],D={},P;if(n&&s.recalc&&d.my()){m=d.my().ui;for(O=0;O=f*2){d={};for(o=f;o=u.length)l=u.length-1;p=Object.clone(i.history[u[u.length-l-1]],true);if(n){d={};for(o=0;o$/.test(l.list))u=l.list;else a=l.list||a;if(!u){var h=t.find(a);u="
";if(h.size()){u=e(u).append(h.eq(0).clone(true)).html();h.eq(0).remove()}}if(!t.data("formlist"))t.data("formlist",{});t.data("formlist").generator={manifest:v,delay:(l.delay||f.delay||10)/1.3,template:u,selector:a,parent:m,bind:l.bind,hash:C(l.hash)?l.hash.bind(m):L(l.hash),id:C(l.id)?l.id.bind(m):L(l.id),ext:!!(l.id||l.hash),stamp:0};t.on("insert.my",function(t,n){t.stopPropagation();var r={what:undefined,where:0};if(null==n)r.where=1e6;else if(x(n))Object.merge(r,n);else if(S(n)||T(n))r.where=n;e(t.target).my("insert",r.where,r.what)});t.on("remove.my",function(t){t.stopPropagation();e(t.target).my("remove")})}else{try{n=t.my(M(m,v),x(o)?o:undefined)}catch(p){N("$.my subform init of "+i+" failed: "+p.message,p.stack)}}}if(k(n)){n.then(A,function(e,t){N("Init of subform "+i+" failed with error: "+e,t)})}else A()}function N(e,t){H.con(e,t);if(c)c.reject(e,t)}function L(e){var t=u(e).to(3);return!e?null:t==="str"?O.fill(undefined,e):t==="arr"?H.mask.fill(undefined,e):null}function A(){t.each(function(){var u=e(this),c,h,d=false,v=u[0].nextSibling;h=v&&v.CodeMirror?v.CodeMirror:null;if(h)u.addClass("my-codemirror");c=l.events||F(u,P.events);if(!u.is(".my-form")){u.data("my",{events:c,selector:i,initial:p,previous:p,root:n,container:f.container(u),id:s.id,ui:l,data:s.data,params:f,errors:s.errors});r._update=l.delay?z.debounce(l.delay):a;d=true}else{o(u.data("my"),{dui:l,root:n,selector:i,dparams:f,devents:c,ddata:s.data,container:f.container(u),derrors:s.errors})}if(d){if(u.cleditor&&u.parent().is(".cleditorMain")){var m=u.cleditor()[0];if(m&&m.$frame&&m.$frame[0]){u.addClass("my-cleditor");o(u.data("my"),{container:f.container(u)});var b=function(e){u.val(e).trigger(y)};var w,E=Number.random(1e5,1e6-1);e(m.$frame[0]).attr("id","cleditCool"+E);if(!document.frames)w=e("#cleditCool"+E)[0].contentWindow.document;else w=document.frames["cleditCool"+E].document;var S=e(w).find("body");e(w).bind("keyup.my",function(){b(e(this).find("body").html())});u.parent().find("div.cleditorToolbar").bind("click.my mouseup.my",function(){b(S.html())});e("body").on("click","div.cleditorPopup",function(){b(S.html())})}}else if(u.is("div.redactor_box textarea")){var x,T="my-redactor-9";try{x=u.getEditor();T="my-redactor-8"}catch(N){x=u.redactor("getEditor")}if(x){u.addClass(T);x.bind("input.my keyup.my blur.my",function(e){e.trigger("redactor")}.fill(u))}}else if(u.is(".ace_editor"))ace.edit(t[0]).on(y,function(e){e.trigger("ace")}.fill(u));else if(h){h.on(y,function(e){e.trigger("codemirror")}.fill(u))}}u.my()._changed=V.debounce(g);u.my()._recalc=$;u.bind(c,function(e){if(e.type==y)e.stopPropagation();if(d)s.locktill=Date.now()+r.delay;u.my()._changed(u,n,r,f)});if(!/check(\.my)?/.test(c+""))u.on("check.my",function(e){u.my()._changed(u,n,r,f,true);return false});u.on("recalc.my, redraw.my",function(e){e.stopPropagation();u.my()._recalc(u,n,r,f)})});if(c)c.resolve()}var s=n.my(),f=(s||{}).params,l=r,c=null,h,p,d=0,v,m=s.manifest,g;if(!s){H.con("Failed to find $root building "+i+" selector.");return null}g=r.delay;if(t.size()){if(l.init!=a)h=J(m,l.init,t,s);if(k(h)){d+=1;c=e.Deferred();h.then(E,function(e,t){N("Init of "+i+" failed: "+e,t)})}else E()}else H.con("Not found "+i+" selector.",n);return c}function V(e,t,n,r,i){var s=e.data("my"),o=t.data("my");if(s&&!s.disabled){W(s.ddata||s.data,s.dparams||s.params);var u=t.find(s.selector);z(e,!i?j(u,a):a,n.recalcDepth||r.recalcDepth);if(undefined===o.orphan){if(s.root.parent().hasClass("ui-sortable")){o.orphan=!s.root.parent().hasClass("my-form-list")}}if(o.orphan)s.root.parent().trigger("check");if(r.change)r.change.call(e)}}function $(e,t,n,r){var i=e.my();if(i&&!i.disabled){var s=t.find(i.selector);if(s.is(".my-form"))s.my("redraw");else z(e,s.is(".my-form-list")?O(s.my().data,s.data("formlist").generator.bind):a,n.recalcDepth||r.recalcDepth)}}function J(e,t,n,r){var i;if(S(t)){i=O(e,t);if(undefined===i){n.html(t.assign(r.data));return null}}else i=t;if(C(i))return i.apply(e,Array.prototype.slice.call(arguments,2));else if(w(i)){try{n.formgen(i)}catch(s){}}return null}function K(e,t){var n="",r,i="",s=!t,o=[];for(n in e)if(e.hasOwnProperty(n)&&(s||!/^(data|files|require)$/.test(n))){r=e[n];i=u(r);if(/^(ob|ar)/.test(i))K(r);else if(i==="string"&&/^(function\s\(|new\sRegExp)/.test(r)){if(o=r.match(/^function\s\(([^\)]*)\)\s*\{([\s\S]*)\}$/)){if(o.length===3){try{e[n]=Function(o[1],o[2])}catch(a){console.log(a.message,a.stack,r)}}}else if(o=r.match(/^new\sRegExp\(\/([\s\S]+)\/([a-z]*)\)$/)){if(o.length===3){try{e[n]=RegExp(o[1],o[2])}catch(a){console.log(a.message,a.stack,r)}}}}}o=null}function Q(e,t,n){var r=x(t)?t:null;Object.each(e,function(t,n){var r=typeof n;if(/^str|^fu/.test(r))e[t]={bind:n}});Object.each(e,function(t,i){var s=[],o=[],u,a=/\s?[,;]\s?/,f,l;if(i.recalc){if(S(i.recalc))s=i.recalc.split(a);else if(w(i.recalc))s=i.recalc;s=s.compact(true).unique()}if(s.length)e[t].recalc=s;if(null==i.bind)i.bind=function(){};if(i.watch){if(S(i.watch))o=i.watch.split(a);else if(w(i.watch))o=i.watch.slice(0);o=o.compact(true).unique();for(l=0;l2){h=H.css2json(h)}else i.push(r+(/\{/.test(h)?h:"{"+h+"}"))}if(w(h)&&h.length){for(a=0;a.my-form",d=h.template||"
",v=/\{/.test(d),m=h.hash||H.sdbmCode,g=h.id||H.sdbmCode,y=h.ext,b=h.delay||50,E=t.is("."+a),S=!!t.children(f).size(),x=[],T=[],N,C,k=Date.now();var L=E?t.find(t.sortable("option","items")):t.find(p);if(l(n)&&w(n)){if(S)return n;i=[];L.each(function(){var t=e(this),n=t.data("my");if(n)i.push(n.data)});o=false;if(i.length===n.length)for(o=true,r=0;r1.4*b||k-h.stamp>100||!h.stashed||h.stashed.length!==L.size()-(S?1:0)){if(S)C=t.find(">."+a+"-helper");L.each(function(t){var n=e(this),r,i,s,o=false;if(!S||!n.hasClass(a+"-helper")){if(S&&n.hasClass(a+"-placeholder"))n=C;r=n.data("my");i=n.data("formlist");if(r&&i){x.push(r.data);if(u!=i.index){i.index=u;o=!0}if(y){s=m(r.data,u)+"";if(s!==i.hash){i.hash=s;o=!0}}u+=1;if(o)T.push(n)}}});for(r=0;r."+i+"-placeholder",o=t.find(t.sortable("option","items")),u;if(l(n)&&w(n)){var f={},c={},h=n.unique();if(t.find("input:focus:eq(0),textarea:focus:eq(0)").size()||t.find(s).size())return h;o.each(function(){f[H.sdbmCode(H.extval(e(this)))]=e(this)});for(var p=h.length-1;p>=0;p--){var d=H.sdbmCode(h[p]);if(f[d]){f[d].prependTo(t).show();c[d]=true;if(r.indexOf(h[p])==-1)r.push(h[p])}}r=r.reverse();for(p in f)if(!c[p])f[p].hide()}else{var v=t.find(s),m=t.eq(0);if(v.size()!=0){if(m.my()[i]!=v.position().left+""+v.position().top){o=o.filter(":visible:not(:disabled, .ui-state-disabled, .ui-sortable-helper)");u=t.find(t.sortable("option","items")).filter(".ui-sortable-helper");o.each(function(){var t=e(this);if(t.is(".ui-sortable-placeholder")){r.push(H.extval(u))}else r.push(H.extval(t))});m.my()[i]=v.position().left+""+v.position().top;m.my()[i+"1"]=r}else r=m.my()[i+"1"];if(r==a)o.each(function(){r.push(H.extval(e(this)))})}else{o=t.find(t.sortable("option","items")).filter(":visible:not(:disabled, .ui-state-disabled)");o.each(function(){r.push(H.extval(e(this)))})}}return r},"input[type=date]":function(e,t){if(l(t)){if(t!="")n=Date.create(t).format(c);else n="";if(S(n)&&!/Invalid/.test(n))e.val(n);return n}var n=e.val();return n!=""?Date.create(n).format(c):""},"input[type=time]":function(e,t){if(l(t)){if(t!="")n=Date.create(t).format(h);else n="";if(S(n)&&!/Invalid/.test(n))e.val(n);return n}var n=e.val();return n!=""?Date.create(n).format(h):""},input:{"[type='text'],[type='number'],[type='search'],[type='hidden'],[type='password'],[type='button'],[type='range'],:not([type])":{".ui-slider-input":function(e,t){if(l(t))e.val(t).slider("refresh")},".tagstrip input.value":function(e,t){if(l(t))e.val(t).trigger("update")},"div.select2-container+input":function(e,t){if(l(t)&&JSON.stringify(t)!==JSON.stringify(e.select2("val")))e.select2("val",w(t)?t:[t]);return e.select2("val")},"":function(e,t){if(l(t))e.val(t+"")}},":radio":function(t,n){var r=-1;if(l(n)){t.each(function(t){var i=e(this).val();if(n+""===i+"")r=t});var i=t.eq(0).checkboxradio;if(i)t.each(function(t){var n=e(this);if(r!=t&&n.is(":checked"))n.prop("checked",false).checkboxradio("refresh")});if(r>-1){var s=t.eq(r);if(!s.is(":checked")){s.prop("checked",true);if(i)s.checkboxradio("refresh")}}else if(!i)t.each(function(){e(this).prop("checked",false)})}if(r==-1)for(var o=0;oForm init failed

',ru:'

Ошибка инициализации формы

'},badInput:{en:"Invalid input",ru:f},patternMismatch:{en:"Pattern mismatch",ru:"Не соответствует шаблону"},rangeOverflow:{en:"Over maximum",ru:"Больше максимума"},rangeUnderflow:{en:"Under minimum",ru:"Меньше минимума"},stepMismatch:{en:"Step mismatch",ru:"Не кратно шагу"},tooLong:{en:"Too long",ru:"Слишком длинно"},typeMismatch:{en:"Invalid type",ru:"Неверный тип"},valueMissing:{en:"Required",ru:"Обязательное поле"}},events:{".hasDatepicker":"change.my check.my",".my-form,.my-tags":"change.my check.my",".ui-slider":"slide.my check.my","div.redactor_box textarea":"redactor.my check.my",".my-codemirror":"codemirror.my check.my",".ace_editor":"ace.my check.my",".my-form-list":"sortupdate.my check.my",".ui-sortable":"sortchange.my sortupdate.my check.my",".ui-draggable":"drag.my dragstop.my check.my","a, .pseudolink, input[type=button], button":"click.my","img, :radio, :checkbox":"click.my check.my","div.select2-container+input,div.select2-container+select":"change.my check.my input.my",".ui-buttonset,input, select, textarea":"blur.my change.my check.my"+(navigator.appName.to(5)==="Micro"?" keyup.my":" input.my"),"":"check.my"},containers:{"*[data-role='fieldcontain'] *":{"input,textarea,select,button,:radio":function(e){return e.parents('[data-role="fieldcontain"]').eq(0)}},".tagstrip *.value":function(e){return e.parents(".tagstrip").eq(0)},"div.redactor_box textarea":function(e){return e.parents("div.redactor_box").eq(0).parent()},".my-tags,.hasDatepicker,.ui-widget,input,textarea,select,button":{".my-cleditor":function(e){return e.parents("div.cleditorMain").eq(0).parent()},"":function(t){var n=t[0].parentNode,r=n.nodeName;if(/^(div|span|a|p|form|fieldset|li|ul|td|th|h\d)$/i.test(r))return e(n);else return t.parents("div,span,a,p,form,fieldset,li,ul,td,th,h1,h2,h3,h4,h5,h6").eq(0)}},"":function(e){return e}},offon:{".ace_editor":function(e,t){ace.edit(t[0]).setReadOnly(e)},".ui-selectable":function(e,t){H.jquix(t,"selectable",e)},".ui-slider":function(e,t){H.jquix(t,"slider",e)},".ui-draggable":function(e,t){H.jquix(t,"draggable",e)},".ui-buttonset":function(e,t){H.jquix(t,"buttonset",e)},".hasDatepicker":function(e,t){H.jquix(t,"datepicker",e)},".my-form":function(e,t){t.my("disabled",!!e)},"div.select2-container+input,div.select2-container+select":function(e,t){H.jquix(t,"select2",e)},".my-cleditor":function(e,t){t.cleditor()[0].disable(!!e)},"":function(e,t){t.attr("disabled",!!e)}},destroy:{".hasDatepicker":function(e){e.datepicker("destroy")},".ui-slider":function(e){e.slider("destroy")},".ui-sortable":{".my-form-list":function(t){t.find(">.my-form").each(function(){e(this).my("remove")});t.removeClass("my-form-list");t.sortable("destroy")},"":function(e){e.sortable("destroy")}},".my-form-list":function(t){t.find(">.my-form").each(function(){e(this).my("remove")})},".ui-draggable":function(e){e.draggable("destroy")},".my-redactor-8":function(e){e.destroyEditor();e.removeClass("my-redactor-8")},"div.select2-container+input,div.select2-container+select":function(e){e.select2("destroy")},".my-form":function(e){e.my("remove")},textarea:{".my-codemirror":function(e){e[0].nextSibling.CodeMirror.toTextArea();e.removeClass("my-codemirror")}}}};P.params={container:function(e){return F(e,P.containers)(e)},change:a,recalcDepth:2,delay:0,strict:false,locale:f=(navigator.language||navigator.userLanguage||"en").substr(0,2),messages:Object.map(P.msg,function(e,t){return t[f]||t.en}),errorTip:".my-error-tip",errorCss:"my-error",animate:0,effect:function(e,t,n){if(t)return e.fadeIn(n);e.fadeOut(n)},remember:0,silent:false,history:{},historyDelay:100,loader:function(t,n){var r=e.Deferred(),i=A(t+"");if(i)r.resolve(i);else r.reject(null);return r.promise()},ajaxTimeout:1e4};var H=Z();H.require=B;var Y={init:function(t,n,i){function $(){if(!g.strict)K(y,true);h=o(true,h,Object.reject(y,["data"]));m=Q(o(true,{},y.ui||{}),h,g);l=Number.random(268435456,4294967295).toString(16);f=y.id||"my"+l;c=H.sdbmCode(f);h.id=f;g.form=W;if(y.params&&y.params.depth)g.recalcDepth=y.params.depth;for(b in h)if(C(h[b]))h[b].bind(h);if(y.error){if(S(y.error)){q=function(e,t){return y.error.assign(o({message:e+"",err:t+""},y))}}else if(C(y.error)){q=function(e,t){p=null;try{p=y.error(e,t)}catch(n){p=g.messages.initFailed}return p}}}o(W.data("my"),{id:f,cid:l,mid:c,errors:Object.extended(),ui:Object.extended(m),disabled:false,manifest:h,locFiles:[]});W.addClass("my-form");T="my-manifest-"+c;N="my-form-"+l;W.addClass(N+" "+T)}function Y(){if(h.style){E=G(W,h,T,N);if(E&&E[0].length){L=e("style#"+T);if(!L.size()){L=e('").appendTo(e("body"))}L.data("count",L.data("count")*1+1);W.data("my").style=L}if(E&&E[1].length){O=e("style#"+N);if(!O.size()){O=e('").appendTo(e("body"))}W.data("my").localStyle=O}}}function Z(){var t,n=e.Deferred(),i;i=D(h);if(S(i)){rt("Error decoding base64 to local Blob/URL",i);n.reject()}else{if(r)for(t=0;t*").clone();try{F=J(h,y.init,W,y)}catch(t){rt(S(t)?t:t.message,t.stack);return W}}if(k(F)){F.then(function(){tt()},function(e,t){rt(e,t)})}else tt();if(!_){if(!W.my())return rt("Internal error initializing controls",""),W;W.data("my").initial=o(true,{},v);if(e.mobile)e.mobile.changePage(e.mobile.activePage)}}function tt(){function n(n){if(!_){e[n]=j(W.find(n),a);t-=1;if(t<.5)nt(e)}}var e={},t=Object.size(m);W.addClass(R);Object.each(m,function(e){if(_)return;var t=W.find(e),r=X(t,W,m[e],e);if(k(r)){r.then(n.fill(e)).fail(function(t,n){rt("Error building "+e+", "+t,n)})}else if(!_)n(e)})}function nt(e){var t,n,r;for(var i in m){if(_)return;t=m[i];r=W.find(i);if(r.size()){try{n=I(v,a,t,r);if(n==a&&e[i]!=a&&n!==undefined)I(v,e[i],t,r)}catch(s){H.con("Transient fail linking "+i+" of form $('.my-form-"+l+"')",s.message,s.stack)}try{if(n!=a)j(r,n);r.eq(0).trigger("check.my")}catch(s){rt("Error linking "+i,s.message,s.stack)}}}W.removeClass(R);z=null;M.resolve(v)}function rt(e,t){var n;_=true;H.con("Form "+f+" failed to initialize: "+e,t);W.removeClass(R);n=q(e,t);if(S(n)||x(n)&&n.jquery)W.html(n);else if(n===true)W.html(z);if(!g.silent){if(!W.my().ddata){W.removeData("my");W.removeClass("my-form");if(L){if(L.data("count")=="1"){try{L.remove()}catch(r){}}else L.data("count",L.data("count")-1)}if(O){try{O.remove()}catch(r){}}}M.reject("Form "+f+" failed to initialize: "+e,t)}else M.resolve(v)}var s,u,f,l,c,h={},p,v={},m,g,y,b,w=[],E,T,N,L,O,M=e.Deferred(),_=false,F,q=function(){},R="my-form-init",U="std",z="";if(S(t)){s=A(t);if(s){if(x(i)&&x(n)){s=o(s,n);u=i}else u=n;U="repo"}else{M.reject("No manifest with id "+t+" found in repo.");return M.promise()}}else{s=t;u=n}if(!s)return this;if(x(u)&&U!="repo")y=o(true,{},s);else y=s;var W=this.eq(0),V=W.my();if(x(V)&&V.id&&V.ui){H.con("jQuery.my is already bind.",W);W.my("ui",y.ui);W.my(d,y.data);return M.resolve(W.my(d)).promise()}g=y.params||{};if(!g.strict){g=o(true,{},g);K(g)}g=o(true,{},P.params,g);M.fail(function(){W.removeClass(N+" "+T)});e.extend(W,M.promise());if(x(u)){v=H.patch(u,y.data||{});y.data=v}else v=y.data||{};h.data=v;W.data("my",{data:v,params:g,promise:M.promise(),locktill:0});W.addClass(R);B(y,g).then(function(){$();Z().then(function(){Y();et()})}).fail(function(e){$();rt("Linker of ‘require’ property failed.",e)});return W},redraw:function(e,t){var n=this,r=n.my();if(r&&r.ui){r.ui.each(function(t){var i=n.find(t);z(i,e?a:undefined,r.params.recalcDepth);if(!e){if(i.is(".my-form"))i.my("redraw");if(i.is(".my-form-list"))i.trigger("redraw");else i.trigger("check.my")}});if(!t&&e)n.trigger(y)}return n},data:function(e,t){var n=this;if(x(e)){n.my().data=H.overlap(n.my().data,e);this.my("redraw",t)}return n.my().data},errors:function(){var t=e(this).my().errors,n={};for(var r in t){if(t[r]&&S(t[r]))n[r]=t[r];if(x(t[r])&&Object.keys(t[r]).length)n[r]=t[r]}return n},valid:function(){var t=e(this).my().errors,n=0;for(var r in t){if(t[r]&&S(t[r]))n++;else if(x(t[r])&&Object.keys(t[r]).length)n++}return!n},reset:function(){try{H.kickoff(this.my().data,this.my().initial);this.my("redraw")}catch(e){return false}return true},id:function(e,t){if(S(e))return A(e,t);else{var n=this.my();return n&&n.id?n.id:a}},remove:function(e){var t=this,n,r,i,s,o,u,f,l;if(!this.my())return a;if(this.my().root&&!this.my().ddata)t=this.my().root;i=t.my();o=i.data;f=i.cid;l=i.mid;t.unbind(".my");if(n=i.style){if(n.data("count")=="1"){try{n.remove()}catch(c){}}else n.data("count",n.data("count")-1)}if(r=i.localStyle){try{r.remove()}catch(c){}}if(window.URL&&(s=i.locFiles)&&s.length){for(var h=0;h1&&h(n[1])){var i=n[0],s="",o,f,c,d,v=1,m,g,y,w;while(v'+(i?"<"+r.labelTag+' class="'+r.labelCss+'" '+(r.label?'style="display:inline-block;width:'+r.label+";margin-left:-"+r.label+'" ':"")+">"+i+"":"")+s+""}return e+s}return e}function E(e){var t=e;if(h(t)){t=t.split(/[\s,]/).compact(true)}if(l(t)){var n={};for(var r=0;r',inp:g+'text" {ext}/>',sli:g+'range" {ext}/>',dat:g+'date" {ext}/>',btn:g+'button" {ext}/>',div:"
{txt}
",spn:"{txt}",sel:"",mul:'',txt:"",err:' {txt}',msg:'
{txt}
',val:function(e){if(!l(e.vals))return"";var n=t({style:"",css:""},e);n.txt=e.vals.reduce(function(e,t){return e+'"+t+" "}," ");return'{txt}'.assign(n)},"":"<{_tag} {ext}>{txt}"},txt:{sel:function(e){if(!e.vals)return"";var t=E(e.vals);return Object.keys(t).reduce(function(e,n){return e+'"},"")}},params:{styles:{num:"width:30%;",dat:"width:30%;",inp:"width:100%",txt:"width:100%;max-width:100%;min-height:1px;word-break:break-word;",err:"display:none",msg:"display:none"},alias:{number:"num",date:"dat",slider:"sli",textarea:"txt",input:"inp",span:"spn",select:"select",vals:"val"},row:"",rowTag:"div",rowCss:"my-row",label:"",labelTag:"span",labelCss:"my-label"},defaults:{id:"","class":"",style:"",placeholder:"",value:"",rows:1},attnames:{css:"class",plc:"placeholder",val:"value",txt:"",vals:"",tip:"title"}};var x={init:function(t,n){return e(this).html(S(t,n))}};if(!e.my)e.my={};e.my.formgen=S;e.fn.formgen=function(t){if(h(t)&&x[t])return x[t].apply(this,Array.prototype.slice.call(arguments,1));else if(typeof t==="object"||!t)return x.init.apply(this,arguments);else e.error("Method "+t+" does not exist on jQuery.formgen")}})(jQuery);(function(e){function v(i){var s=window,o=s.innerHeight||e(s).height(),u=s.innerWidth||e(s).width(),a=n.height(),f=i||r.width();n.removeClass("loading").css({left:(u-f-60)/2+"px",width:f*1+60+"px",display:"block"});t.css({width:u*2+"px",height:o*2+"px",display:"block"});if(a>o){n.height(o);r.css({"overflow-y":$.browser.webkit?"overlay":"scroll"})}else{r.css({"overflow-y":"none"})}n.animate({top:(a>=o?0:(o-a)/3.5)+"px"},parseFloat(n.css("top")).my-modal").is(":visible")){o=true;if(f(h)||h===null||h===undefined){if(d(n.data("done")))g=n.data("done");else g=function(){return false};b=false;E=true;if(!h){if(!r.is(".my-form"))b=g(null,true);else{b=g(r.my("valid")?null:r.my("errors"),r.my("data"));if(!b)E=r.my("remove")}}else if(h===true&&u.state()!="rejected"){if(r.is(".my-form"))r.my("remove");g(null,null);u.reject("Cancelled")}if(!b){r.html("");n.css({display:"none"});(function(){if(!o)t.css({display:"none"})}).delay(5);$("body").css({overflow:"auto"});o=false;n.data("done",null);(function(){u.resolve(E)}).delay(0)}return}y=$.Deferred();g(null,null);y.reject("Locked");return y.promise()}u=$.Deferred();o=true;if(!n||!$(s).find(">.my-modal").size()){n=$('').prependTo($(s))}n.html('
');r=n.find(".my-modal-form");$('
×
').prependTo(n).on("click",function(){i.modal(true)});if(!t||!$(s).find(">.my-modal-screen").size()){t=$('').prependTo($(s)).on("click",function(){if(!r.is(".my-form")||r.data("escapable"))i.modal(true)})}if(typeof h=="object"&&h.jquery){if(h.is("img")){S=h.attr("alt")||h.attr("title")||h.data("text");r.html(function(){var t=h,n=t[0].naturalWidth||t[0].width,r=t[0].naturalHeight||t[0].height,i=e(window).width()-90,s=e(window).height()-90,o;if(s';T=n<300?300:n;return o}()+(S?'

'+S+"

":""));r.find("img").on("click",function(){i.modal()});n.css({top:"3000px",display:"block"});N=n.height();w=1}}else if(c(h)&&h.manifest){E=h.data||{};g=d(h.done)?h.done:g;T=1*($.my.f.getref(l(h.manifest)?$.my.cache(h.manifest):h.manifest,"params.width")||h.width||T);n.css({top:"3000px",display:"block",height:"none"});r.data("my",null);w=1;r.my(h.manifest,E).then(function(){v.delay(20);u.notify("Ready")}).fail(function(e){u.reject(e);w=0;i.modal(true)});n.data("done",g);r.data("escapable",!!h.esc);r.data("allowenter",!!h.enter);r.bind("commit.my",function(){i.modal()}.debounce(50)).bind("cancel.my",function(){i.modal(true)}.debounce(50)).bind("layout.my",function(){v()})}else if(l(h)){r.html(h);n.css({top:"3000px",display:"block",width:"auto"});T=1*(n.width()||T);w=1}else if(h===true){$("body").css({overflow:"auto"});o=false;return u.reject("Cancelled").promise()}else{$("body").css({overflow:"auto"});o=false;return u.reject("Invalid data").promise()}if(w){v(T);x=r.find("img").filter(function(){return $(this).attr("src")!=""});if(x.size()){var C=function(){v(m);u.notify("Ready")}.after(x.size());x.each(function(){$(this).bind("load",C)})}else{u.notify("Ready")}$("body").css({overflow:"hidden"})}return u.promise()};i.modal.loading=function(e){$(s).find(">.my-modal").toggleClass("my-modal-loading",!!e)};i.modal.parent=function(e){if(!e||!$(e).size())return $(s);s=e};i.modal.visible=function(){return o};if(!e.my)e.my={};e.my.modal=i.modal})(jQuery); +;(function(e){function A(e,t){return(t||"").split(".").reduce(function(e,t){if(null!=e&&null!=e[t])return e[t];else return undefined},e)}function O(e,t){var n,r;if(x(t))return t;else if(S(t)){n=A(e,t);if(null==n)n=Object.clone(s._src[t],true);if(null==n){n=A(s,t);if(x(n)&&x(n._self))n=Object.clone(n._self,true);else if(x(n))n=Object.clone(n,true)}if(null==n&&A(e,"params.cache")){r=A(e,"params.cache");if(C(r))n=r(t);else if(x(r))n=L(t,r);if(x(n)){if(x(n._self))n=Object.clone(n._self,true);Object.merge(n,{params:{cache:r}},true)}}if(null!=n&&x(n)){r=r||A(e,"params.cache");if(r)Object.merge(n,{params:{cache:r}},true);return n}else throw"Component "+t+" not found"}else if(C(t)){return t.apply(e,Array.prototype.slice.call(arguments,2))}else return null}function M(e,t){var n,r,o=t||s,u=e,a,f,l,c;if(!(x(o)&&x(u)&&x(u.ui)&&S(u.id)))return"Invalid arguments.";if(!o.hasOwnProperty("_src"))o._src={};f=u.id;try{u=Object.clone(e,true)}catch(h){return"Can't mount circular-referencing obj."}try{if(!u.params||u.params&&!u.params.strict)J(u,true)}catch(h){return"Invalid manifest, parse error."}n=_(u);if(S(n)){P.con(n);return n}Object.merge(u,{params:{strict:true}},true);o._src[f]=u;if(l=P.mask(o,f)){if(l.params&&l.params.protect)return"Can't mount on protected";if(l._self)delete l._self}Object.merge(o,P.unmask(u,f),true);c=A(o,f);if(i)c["_self"]=o._src[f];else Object.defineProperty(c,"_self",{get:function(){return o._src[f]},set:function(){throw"Can not change repo"},enumerable:false,configurable:true});return c}function _(e){var t,n=[],i;if(x(e.files)&&Object.size(e.files)){for(t in e.files){i=e.files[t];if(x(i)&&i.data&&!i.url){if(r){try{P.base642blob(i.data,function(e){i.blob=e;i.url=r.createObjectURL(i.blob)},i.content_type||i.mime);n.push(t)}catch(s){return"Invalid base64 data in files/"+t+"."}}else{i.url="data:"+(i.content_type||i.mime)+";base64,"+i.data;n.push(t)}}}}return n}function H(t,n){function E(t,n){var r;if(S(t)){if(/[\/]/.test(t)){r=o(true,{},g,{ref:n,ajax:{url:t}});if(b.test(n))r.ajax.dataType="json"}else if(t.length){r=o(true,{},g,{ref:n,ajax:t})}}else if(x(t)){r=o(true,{},g,{ref:n,ajax:e.extend(true,{},Object.select(t,["accepts","async","cache","data","dataType","password","timeout","type","url","username"]))});if(!r.ajax.url)r=null}return r}function T(){u.reject(l)}function N(){y+=1;var e=a[y];if(!e){var n=L(f),r=Object.keys(Object.findAll(n,function(e,t){return!t}));if(r.length)l.push((r.length===1?"Key "+r[0]+" is":"Keys "+r.join(", ")+" are")+" not present after all.");if(l.length)T();else u.resolve(t)}else C(e).then(N).fail(T)}function C(n){function h(){a-=1;if(s)u.reject();else if(a<.5)u.resolve()}var r,i,s=false,u=e.Deferred(),a=n.length,f,c;for(i=0;ir){n=l;r=o;return}else if(c==p)s(e,l,o+1)}if(a!=t[""]&&typeof t[""]!=p&&o>r){n=t[""];r=o}}var n=a,r=0,i="";s(e,t,1);return n}function F(e,t,n,r){var i,s=[],o,f,l,c=n.bind,h=u(c);if(h==g){return c.call(q(r).manifest,e,t,r)}if(h===m||h===v){if(h===m&&!/\./.test(c)){if(t!=a)e[c]=t;else if(e[c]===undefined)e[c]=a;return e[c]}if(h===m)s=c.split(".").each(function(e,t){this[t]=e+""});if(h===v)s=c.slice(0).each(function(e,t){this[t]=e+""});if(s[0]==="this"){o=q(r).manifest;s.shift()}else o=e;for(i=0;i-1?"":h;case"s":return n==s?"":h;case"o":return s[n]?"":h;case"b":{if(i.is(".my-form-list,.ui-sortable")){var d=i.data("listSrc")||i.data("my").listSrc||">*",v={};i.find(d).filter("*:not(.ui-sortable-placeholder)").each(function(t){var n=e(this);if(n.data("my")&&!n.my("valid"))v[t]=n.my("errors")});return v}else if(i.hasClass("my-form")){return!s?"":i.my("valid")?"":i.my("errors")}return""}}return l.formError||"Error"}return""}function q(e){var t=e.my();if(!t)return null;return t.root?t.root.my():t}function R(t,n,r){var i=r.compact(),s=i.replace(/:disabled/g,"");n.each(function(){var r=e(this),o=r.my(),u=o?o.container:r;if(t){if(!u.is(s))u.addClass(s)}else u.removeClass(s);if(s!=i&&o!==undefined&&!!t!=!!o.disabled){r.my().disabled=!!t;if(!o._disable)r.my()._disable=j(n,D.offon).fill(undefined,n);o._disable(!!t)}});return n}function U(e,t,n){var r,i,s,u,f,c,h,p,d,v,m,g=false,y=false,b=e,w=b.my(),E="";if(w){p=w.selector;d=w.root;if(d.hasClass("my-form-init"))return{};v=d.find(p);m=d.my().ui;g=e.hasClass("my-form");y=e.hasClass("my-form-list");if(g){r=e;i=w.ddata;s=w.dui;u=w.dparams}else{r=w.container;i=w.data;s=w.ui;u=w.params}if(s.bind!=a){if(l(t))f=t;else f=B(v,F(i,a,s,v));if(a!=s.check){E="Unknown error";try{E=I(i,f,s,v)}catch(x){P.con("Error "+x.message+" validating "+p,d,x.stack)}}var T=u.errorCss;var k="ui-state-error";try{if(a!=t)f=B(v,F(i,t,s,v))}catch(x){E=u.messages.formError||"Error"}if(E===""){if(!g)w.errors[p]="";else w.derrors[p]="";r.removeClass(T);if(r.attr("title"))r.attr("title","");if(!g&&!y)u.effect(r.find(u.errorTip),false,u.animate/2);b.removeClass(k);b.find(".ui-widget").removeClass(k)}else{if(g)w.derrors[p]=E;else if(y)w.errors[p]=E;else{r.addClass(T);w.errors[p]=E;var L=r.find(u.errorTip).eq(0);if(L.size()){u.effect(L.addClass(T).html(E),true,u.animate)}else r.attr("title",(E||"").stripTags())}if(b.is(".hasDatepicker")){if(b.is("input"))b.addClass(k);else b.find(".ui-widget").addClass(k)}if(b.is(".ui-slider"))b.addClass(k)}}var A=t==a?f:t;if(s.css){for(c in s.css){h=s.css[c];if(N(h))R(h.test(A),v,c);else if(C(h))R(h.call(d.my().manifest,i,A,v),v,c)}}var O,M=s.recalc,_=[],D={},H;if(n&&s.recalc&&d.my()){m=d.my().ui;for(O=0;O=f*2){d={};for(o=f;o=u.length)l=u.length-1;p=Object.clone(i.history[u[u.length-l-1]],true);if(n){d={};for(o=0;o$/.test(l.list))u=l.list;else a=l.list||a;if(!u){var h=t.find(a);u="
";if(h.size()){u=e(u).append(h.eq(0).clone(true)).html();h.eq(0).remove()}}if(!t.data("formlist"))t.data("formlist",{});t.data("formlist").generator={manifest:v,delay:(l.delay||f.delay||10)/1.3,template:u,selector:a,parent:m,bind:l.bind,hash:C(l.hash)?l.hash.bind(m):L(l.hash),id:C(l.id)?l.id.bind(m):L(l.id),ext:!!(l.id||l.hash),stamp:0};t.on("insert.my",function(t,n){t.stopPropagation();var r={what:undefined,where:0};if(null==n)r.where=1e6;else if(x(n))Object.merge(r,n);else if(S(n)||T(n))r.where=n;e(t.target).my("insert",r.where,r.what)});t.on("remove.my",function(t){t.stopPropagation();e(t.target).my("remove")})}else{try{n=t.my(O(m,v),x(o)?o:undefined)}catch(p){N("$.my subform init of "+i+" failed: "+p.message,p.stack)}}}if(k(n)){n.then(M,function(e,t){N("Init of subform "+i+" failed with error: "+e,t)})}else M()}function N(e,t){P.con(e,t);if(c)c.reject(e,t)}function L(e){var t=u(e).to(3);return!e?null:t==="str"?A.fill(undefined,e):t==="arr"?P.mask.fill(undefined,e):null}function M(){t.each(function(){var u=e(this),c,h,d=false,v=u[0].nextSibling;h=v&&v.CodeMirror?v.CodeMirror:null;if(h)u.addClass("my-codemirror");c=l.events||j(u,D.events);if(!u.is(".my-form")){u.data("my",{events:c,selector:i,initial:p,previous:p,root:n,container:f.container(u),id:s.id,ui:l,data:s.data,params:f,errors:s.errors});r._update=l.delay?U.debounce(l.delay):a;d=true}else{o(u.data("my"),{dui:l,root:n,selector:i,dparams:f,devents:c,ddata:s.data,container:f.container(u),derrors:s.errors})}if(d){if(u.cleditor&&u.parent().is(".cleditorMain")){var m=u.cleditor()[0];if(m&&m.$frame&&m.$frame[0]){u.addClass("my-cleditor");o(u.data("my"),{container:f.container(u)});var b=function(e){u.val(e).trigger(y)};var w,E=Number.random(1e5,1e6-1);e(m.$frame[0]).attr("id","cleditCool"+E);if(!document.frames)w=e("#cleditCool"+E)[0].contentWindow.document;else w=document.frames["cleditCool"+E].document;var S=e(w).find("body");e(w).bind("keyup.my",function(){b(e(this).find("body").html())});u.parent().find("div.cleditorToolbar").bind("click.my mouseup.my",function(){b(S.html())});e("body").on("click","div.cleditorPopup",function(){b(S.html())})}}else if(u.is("div.redactor_box textarea")){var x,T="my-redactor-9";try{x=u.getEditor();T="my-redactor-8"}catch(N){x=u.redactor("getEditor")}if(x){u.addClass(T);x.bind("input.my keyup.my blur.my",function(e){e.trigger("redactor")}.fill(u))}}else if(u.is(".ace_editor"))ace.edit(t[0]).on(y,function(e){e.trigger("ace")}.fill(u));else if(h){h.on(y,function(e){e.trigger("codemirror")}.fill(u))}}u.my()._changed=X.debounce(g);u.my()._recalc=V.debounce(g);u.bind(c,function(e){if(e.type==y)e.stopPropagation();if(d)s.locktill=Date.now()+r.delay;u.my()._changed(u,n,r,f)});if(!/check(\.my)?/.test(c+""))u.on("check.my",function(e){u.my()._changed(u,n,r,f,true);return false});u.on("recalc.my, redraw.my",function(e){e.stopPropagation();u.my()._recalc(u,n,r,f)})});if(c)c.resolve()}var s=n.my(),f=(s||{}).params,l=r,c=null,h,p,d=0,v,m=s.manifest,g;if(!s){P.con("Failed to find $root building "+i+" selector.");return null}g=r.delay;if(t.size()){if(l.init!=a)h=$(m,l.init,t,s);if(k(h)){d+=1;c=e.Deferred();h.then(E,function(e,t){N("Init of "+i+" failed: "+e,t)})}else E()}else P.con("Not found "+i+" selector.",n);return c}function X(e,t,n,r,i){var s=e.data("my"),o=t.data("my");if(s&&!s.disabled){z(s.ddata||s.data,s.dparams||s.params);var u=t.find(s.selector);U(e,!i?B(u,a):a,n.recalcDepth||r.recalcDepth);if(undefined===o.orphan){if(s.root.parent().hasClass("ui-sortable")){o.orphan=!s.root.parent().hasClass("my-form-list")}}if(o.orphan)s.root.parent().trigger("check");if(r.change)r.change.call(e)}}function V(e,t,n,r){var i=e.my();if(i&&!i.disabled){var s=t.find(i.selector);if(s.is(".my-form"))s.my("redraw");else U(e,s.is(".my-form-list")?A(s.my().data,s.data("formlist").generator.bind):a,n.recalcDepth||r.recalcDepth)}}function $(e,t,n,r){var i;if(S(t)){i=A(e,t);if(undefined===i){n.html(t.assign(r.data));return null}}else i=t;if(C(i))return i.apply(e,Array.prototype.slice.call(arguments,2));else if(w(i)){try{n.formgen(i)}catch(s){}}return null}function J(e,t){var n="",r,i="",s=!t,o=[];for(n in e)if(e.hasOwnProperty(n)&&(s||!/^(data|files|require)$/.test(n))){r=e[n];i=u(r);if(/^(ob|ar)/.test(i))J(r);else if(i==="string"&&/^(function\s\(|new\sRegExp)/.test(r)){if(o=r.match(/^function\s\(([^\)]*)\)\s*\{([\s\S]*)\}$/)){if(o.length===3){try{e[n]=Function(o[1],o[2])}catch(a){console.log(a.message,a.stack,r)}}}else if(o=r.match(/^new\sRegExp\(\/([\s\S]+)\/([a-z]*)\)$/)){if(o.length===3){try{e[n]=RegExp(o[1],o[2])}catch(a){console.log(a.message,a.stack,r)}}}}}o=null}function K(e,t,n){var r=x(t)?t:null;Object.each(e,function(t,n){var r=typeof n;if(/^str|^fu/.test(r))e[t]={bind:n}});Object.each(e,function(t,i){var s=[],o=[],u,a=/\s?[,;]\s?/,f,l;if(i.recalc){if(S(i.recalc))s=i.recalc.split(a);else if(w(i.recalc))s=i.recalc;s=s.compact(true).unique()}if(s.length)e[t].recalc=s;if(null==i.bind)i.bind=function(){};if(i.watch){if(S(i.watch))o=i.watch.split(a);else if(w(i.watch))o=i.watch.slice(0);o=o.compact(true).unique();for(l=0;l2){h=P.css2json(h)}else i.push(r+(/\{/.test(h)?h:"{"+h+"}"))}if(w(h)&&h.length){for(a=0;a.my-form",d=h.template||"
",v=/\{/.test(d),m=h.hash||P.sdbmCode,g=h.id||P.sdbmCode,y=h.ext,b=h.delay||50,E=t.is("."+a),S=!!t.children(f).size(),x=[],T=[],N,C,k=Date.now();var L=E?t.find(t.sortable("option","items")):t.find(p);if(l(n)&&w(n)){if(S)return n;i=[];L.each(function(){var t=e(this),n=t.data("my");if(n)i.push(n.data)});o=false;if(i.length===n.length)for(o=true,r=0;r1.4*b||k-h.stamp>100||!h.stashed||h.stashed.length!==L.size()-(S?1:0)){if(S)C=t.find(">."+a+"-helper");L.each(function(t){var n=e(this),r,i,s,o=false;if(!S||!n.hasClass(a+"-helper")){if(S&&n.hasClass(a+"-placeholder"))n=C;r=n.data("my");i=n.data("formlist");if(r&&i){x.push(r.data);if(u!=i.index){i.index=u;o=!0}if(y){s=m(r.data,u)+"";if(s!==i.hash){i.hash=s;o=!0}}u+=1;if(o)T.push(n)}}});for(r=0;r."+i+"-placeholder",o=t.find(t.sortable("option","items")),u;if(l(n)&&w(n)){var f={},c={},h=n.unique();if(t.find("input:focus:eq(0),textarea:focus:eq(0)").size()||t.find(s).size())return h;o.each(function(){f[P.sdbmCode(P.extval(e(this)))]=e(this)});for(var p=h.length-1;p>=0;p--){var d=P.sdbmCode(h[p]);if(f[d]){f[d].prependTo(t).show();c[d]=true;if(r.indexOf(h[p])==-1)r.push(h[p])}}r=r.reverse();for(p in f)if(!c[p])f[p].hide()}else{var v=t.find(s),m=t.eq(0);if(v.size()!=0){if(m.my()[i]!=v.position().left+""+v.position().top){o=o.filter(":visible:not(:disabled, .ui-state-disabled, .ui-sortable-helper)");u=t.find(t.sortable("option","items")).filter(".ui-sortable-helper");o.each(function(){var t=e(this);if(t.is(".ui-sortable-placeholder")){r.push(P.extval(u))}else r.push(P.extval(t))});m.my()[i]=v.position().left+""+v.position().top;m.my()[i+"1"]=r}else r=m.my()[i+"1"];if(r==a)o.each(function(){r.push(P.extval(e(this)))})}else{o=t.find(t.sortable("option","items")).filter(":visible:not(:disabled, .ui-state-disabled)");o.each(function(){r.push(P.extval(e(this)))})}}return r},"input[type=date]":function(e,t){if(l(t)){if(t!="")n=Date.create(t).format(c);else n="";if(S(n)&&!/Invalid/.test(n))e.val(n);return n}var n=e.val();return n!=""?Date.create(n).format(c):""},"input[type=time]":function(e,t){if(l(t)){if(t!="")n=Date.create(t).format(h);else n="";if(S(n)&&!/Invalid/.test(n))e.val(n);return n}var n=e.val();return n!=""?Date.create(n).format(h):""},input:{"[type='text'],[type='number'],[type='search'],[type='hidden'],[type='password'],[type='button'],[type='range'],:not([type])":{".ui-slider-input":function(e,t){if(l(t))e.val(t).slider("refresh")},".tagstrip input.value":function(e,t){if(l(t))e.val(t).trigger("update")},"div.select2-container+input":function(e,t){if(l(t)&&JSON.stringify(t)!==JSON.stringify(e.select2("val")))e.select2("val",w(t)?t:[t]);return e.select2("val")},"":function(e,t){if(l(t))e.val(t+"")}},":radio":function(t,n){var r=-1;if(l(n)){t.each(function(t){var i=e(this).val();if(n+""===i+"")r=t});var i=t.eq(0).checkboxradio;if(i)t.each(function(t){var n=e(this);if(r!=t&&n.is(":checked"))n.prop("checked",false).checkboxradio("refresh")});if(r>-1){var s=t.eq(r);if(!s.is(":checked")){s.prop("checked",true);if(i)s.checkboxradio("refresh")}}else if(!i)t.each(function(){e(this).prop("checked",false)})}if(r==-1)for(var o=0;oForm init failed

',ru:'

Ошибка инициализации формы

'},badInput:{en:"Invalid input",ru:f},patternMismatch:{en:"Pattern mismatch",ru:"Не соответствует шаблону"},rangeOverflow:{en:"Over maximum",ru:"Больше максимума"},rangeUnderflow:{en:"Under minimum",ru:"Меньше минимума"},stepMismatch:{en:"Step mismatch",ru:"Не кратно шагу"},tooLong:{en:"Too long",ru:"Слишком длинно"},typeMismatch:{en:"Invalid type",ru:"Неверный тип"},valueMissing:{en:"Required",ru:"Обязательное поле"}},events:{".hasDatepicker":"change.my check.my",".my-form,.my-tags":"change.my check.my",".ui-slider":"slide.my check.my","div.redactor_box textarea":"redactor.my check.my",".my-codemirror":"codemirror.my check.my",".ace_editor":"ace.my check.my",".my-form-list":"sortupdate.my check.my",".ui-sortable":"sortchange.my sortupdate.my check.my",".ui-draggable":"drag.my dragstop.my check.my","a, .pseudolink, input[type=button], button":"click.my","img, :radio, :checkbox":"click.my check.my","div.select2-container+input,div.select2-container+select":"change.my check.my input.my",".ui-buttonset,input, select, textarea":"blur.my change.my check.my"+(navigator.appName.to(5)==="Micro"?" keyup.my":" input.my"),"":"check.my"},containers:{"*[data-role='fieldcontain'] *":{"input,textarea,select,button,:radio":function(e){return e.parents('[data-role="fieldcontain"]').eq(0)}},".tagstrip *.value":function(e){return e.parents(".tagstrip").eq(0)},"div.redactor_box textarea":function(e){return e.parents("div.redactor_box").eq(0).parent()},".my-tags,.hasDatepicker,.ui-widget,input,textarea,select,button":{".my-cleditor":function(e){return e.parents("div.cleditorMain").eq(0).parent()},"":function(t){var n=t[0].parentNode,r=n.nodeName;if(/^(div|span|a|p|form|fieldset|li|ul|td|th|h\d)$/i.test(r))return e(n);else return t.parents("div,span,a,p,form,fieldset,li,ul,td,th,h1,h2,h3,h4,h5,h6").eq(0)}},"":function(e){return e}},offon:{".ace_editor":function(e,t){ace.edit(t[0]).setReadOnly(e)},".ui-selectable":function(e,t){P.jquix(t,"selectable",e)},".ui-slider":function(e,t){P.jquix(t,"slider",e)},".ui-draggable":function(e,t){P.jquix(t,"draggable",e)},".ui-buttonset":function(e,t){P.jquix(t,"buttonset",e)},".hasDatepicker":function(e,t){P.jquix(t,"datepicker",e)},".my-form":function(e,t){t.my("disabled",!!e)},"div.select2-container+input,div.select2-container+select":function(e,t){P.jquix(t,"select2",e)},".my-cleditor":function(e,t){t.cleditor()[0].disable(!!e)},"":function(e,t){t.attr("disabled",!!e)}},destroy:{".hasDatepicker":function(e){e.datepicker("destroy")},".ui-slider":function(e){e.slider("destroy")},".ui-sortable":{".my-form-list":function(t){t.find(">.my-form").each(function(){e(this).my("remove")});t.removeClass("my-form-list");t.sortable("destroy")},"":function(e){e.sortable("destroy")}},".my-form-list":function(t){t.find(">.my-form").each(function(){e(this).my("remove")})},".ui-draggable":function(e){e.draggable("destroy")},".my-redactor-8":function(e){e.destroyEditor();e.removeClass("my-redactor-8")},"div.select2-container+input,div.select2-container+select":function(e){e.select2("destroy")},".my-form":function(e){e.my("remove")},textarea:{".my-codemirror":function(e){e[0].nextSibling.CodeMirror.toTextArea();e.removeClass("my-codemirror")}}}};D.params={container:function(e){return j(e,D.containers)(e)},change:a,recalcDepth:2,delay:0,strict:false,locale:f=(navigator.language||navigator.userLanguage||"en").substr(0,2),messages:Object.map(D.msg,function(e,t){return t[f]||t.en}),errorTip:".my-error-tip",errorCss:"my-error",animate:0,effect:function(e,t,n){if(t)return e.fadeIn(n);e.fadeOut(n)},remember:0,silent:false,history:{},historyDelay:100,loader:function(t,n){var r=e.Deferred(),i=L(t+"");if(i)r.resolve(i);else r.reject(null);return r.promise()},ajaxTimeout:1e4};var P=Y();P.require=H;var G={init:function(t,n,i){function G(){if(!g.strict)J(y,true);h=o(true,h,Object.reject(y,["data"]));m=K(o(true,{},y.ui||{}),h,g);l=Number.random(268435456,4294967295).toString(16);f=y.id||"my"+l;c=P.sdbmCode(f);h.id=f;g.form=X;if(y.params&&y.params.depth)g.recalcDepth=y.params.depth;for(b in h)if(C(h[b]))h[b].bind(h);if(y.error){if(S(y.error)){q=function(e,t){return y.error.assign(o({message:e+"",err:t+""},y))}}else if(C(y.error)){q=function(e,t){p=null;try{p=y.error(e,t)}catch(n){p=g.messages.initFailed}return p}}}o(X.data("my"),{id:f,cid:l,mid:c,errors:Object.extended(),ui:Object.extended(m),disabled:false,manifest:h,locFiles:[],modals:{}});X.addClass("my-form");T="my-manifest-"+c;N="my-form-"+l;X.addClass(N+" "+T)}function Y(){if(h.style){E=Q(X,h,T,N);if(E&&E[0].length){A=e("style#"+T);if(!A.size()){A=e('").appendTo(e("body"))}A.data("count",A.data("count")*1+1);X.data("my").style=A}if(E&&E[1].length){O=e("style#"+N);if(!O.size()){O=e('").appendTo(e("body"))}X.data("my").localStyle=O}}}function Z(){var t,n=e.Deferred(),i;i=_(h);if(S(i)){rt("Error decoding base64 to local Blob/URL",i);n.reject()}else{if(r)for(t=0;t*").clone();try{I=$(h,y.init,X,y)}catch(t){rt(S(t)?t:t.message,t.stack);return X}}if(k(I)){I.then(function(){tt()},function(e,t){rt(e,t)})}else tt();if(!j){if(!X.my())return rt("Internal error initializing controls",""),X;X.data("my").initial=o(true,{},v);if(e.mobile)e.mobile.changePage(e.mobile.activePage)}}function tt(){function n(n){if(!j){e[n]=B(X.find(n),a);t-=1;if(t<.5)nt(e)}}var e={},t=Object.size(m);X.addClass(R);Object.each(m,function(e){if(j)return;var t=X.find(e),r=W(t,X,m[e],e);if(k(r)){r.then(n.fill(e)).fail(function(t,n){rt("Error building "+e+", "+t,n)})}else if(!j)n(e)})}function nt(e){var t,n,r;for(var i in m){if(j)return;t=m[i];r=X.find(i);if(r.size()){try{n=F(v,a,t,r);if(n==a&&e[i]!=a&&n!==undefined)F(v,e[i],t,r)}catch(s){P.con("Transient fail linking "+i+" of form $('.my-form-"+l+"')",s.message,s.stack)}try{if(n!=a)B(r,n);r.eq(0).trigger("check.my")}catch(s){rt("Error linking "+i,s.message,s.stack)}}}X.removeClass(R);z=null;M.resolve(v)}function rt(e,t){var n;j=true;P.con("Form "+f+" failed to initialize: "+e,t);X.removeClass(R);n=q(e,t);if(S(n)||x(n)&&n.jquery)X.html(n);else if(n===true)X.html(z);if(!g.silent){if(!X.my().ddata){X.removeData("my");X.removeClass("my-form");if(A){if(A.data("count")=="1"){try{A.remove()}catch(r){}}else A.data("count",A.data("count")-1)}if(O){try{O.remove()}catch(r){}}}M.reject("Form "+f+" failed to initialize: "+e,t)}else M.resolve(v)}var s,u,f,l,c,h={},p,v={},m,g,y,b,w=[],E,T,N,A,O,M=e.Deferred(),j=false,I,q=function(){},R="my-form-init",U="std",z="";if(S(t)){s=L(t);if(s){if(x(i)&&x(n)){s=o(s,n);u=i}else u=n;U="repo"}else{M.reject("No manifest with id "+t+" found in repo.");return M.promise()}}else{s=t;u=n}if(!s)return this;if(x(u)&&U!="repo")y=o(true,{},s);else y=s;var X=this.eq(0),V=X.my();if(x(V)&&V.id&&V.ui){P.con("jQuery.my is already bind.",X);X.my("ui",y.ui);X.my(d,y.data);return M.resolve(X.my(d)).promise()}g=y.params||{};if(!g.strict){g=o(true,{},g);J(g)}g=o(true,{},D.params,g);M.fail(function(){X.removeClass(N+" "+T)});o(X,M.promise());if(x(u)){v=P.patch(u,y.data||{});y.data=v}else v=y.data||{};h.data=v;X.data("my",{data:v,params:g,promise:M.promise(),locktill:0});X.addClass(R);H(y,g).then(function(){G();Z().then(function(){Y();et()})}).fail(function(e){G();rt("Linker of ‘require’ property failed.",e)});return X},redraw:function(e,t){var n=this,r=n.my();if(r&&r.ui){r.ui.each(function(t){var i=n.find(t);U(i,e?a:undefined,r.params.recalcDepth);if(!e){if(i.is(".my-form"))i.my("redraw");if(i.is(".my-form-list"))i.trigger("redraw");else i.trigger("check.my")}});if(!t&&e)n.trigger(y)}return n},data:function(e,t){var n=this;if(x(e)){n.my().data=P.overlap(n.my().data,e);this.my("redraw",t)}return n.my().data},errors:function(){var t=e(this).my().errors,n={};for(var r in t){if(t[r]&&S(t[r]))n[r]=t[r];if(x(t[r])&&Object.keys(t[r]).length)n[r]=t[r]}return n},valid:function(){var t=e(this).my().errors,n=0;for(var r in t){if(t[r]&&S(t[r]))n++;else if(x(t[r])&&Object.keys(t[r]).length)n++}return!n},reset:function(){try{P.kickoff(this.my().data,this.my().initial);this.my("redraw")}catch(e){return false}return true},id:function(e,t){if(S(e))return L(e,t);else{var n=this.my();return n&&n.id?n.id:a}},remove:function(e){var t=this,n,r,i,s,o,u,f,l;if(!this.my())return a;if(this.my().root&&!this.my().ddata)t=this.my().root;i=t.my();o=i.data;f=i.cid;l=i.mid;if(t.data("modals")){}t.unbind(".my");if(n=i.style){if(n.data("count")=="1"){try{n.remove()}catch(c){}}else n.data("count",n.data("count")-1)}if(r=i.localStyle){try{r.remove()}catch(c){}}if(window.URL&&(s=i.locFiles)&&s.length){for(var h=0;h1&&h(n[1])){var i=n[0],s="",o,f,c,d,v=1,m,g,y,w;while(v'+(i?"<"+r.labelTag+' class="'+r.labelCss+'" '+(r.label?'style="display:inline-block;width:'+r.label+";margin-left:-"+r.label+'" ':"")+">"+i+"":"")+s+""}return e+s}return e}function E(e){var t=e;if(h(t)){t=t.split(/[\s,]/).compact(true)}if(l(t)){var n={};for(var r=0;r',inp:g+'text" {ext}/>',sli:g+'range" {ext}/>',dat:g+'date" {ext}/>',btn:g+'button" {ext}/>',div:"
{txt}
",spn:"{txt}",sel:"",mul:'',txt:"",err:' {txt}',msg:'
{txt}
',val:function(e){if(!l(e.vals))return"";var n=t({style:"",css:""},e);n.txt=e.vals.reduce(function(e,t){return e+'"+t+" "}," ");return'{txt}'.assign(n)},"":"<{_tag} {ext}>{txt}"},txt:{sel:function(e){if(!e.vals)return"";var t=E(e.vals);return Object.keys(t).reduce(function(e,n){return e+'"},"")}},params:{styles:{num:"width:30%;",dat:"width:30%;",inp:"width:100%",txt:"width:100%;max-width:100%;min-height:1px;word-break:break-word;",err:"display:none",msg:"display:none"},alias:{number:"num",date:"dat",slider:"sli",textarea:"txt",input:"inp",span:"spn",select:"select",vals:"val"},row:"",rowTag:"div",rowCss:"my-row",label:"",labelTag:"span",labelCss:"my-label"},defaults:{id:"","class":"",style:"",placeholder:"",value:"",rows:1},attnames:{css:"class",plc:"placeholder",val:"value",txt:"",vals:"",tip:"title"}};var x={init:function(t,n){return e(this).html(S(t,n))}};if(!e.my)e.my={};e.my.formgen=S;e.fn.formgen=function(t){if(h(t)&&x[t])return x[t].apply(this,Array.prototype.slice.call(arguments,1));else if(typeof t==="object"||!t)return x.init.apply(this,arguments);else e.error("Method "+t+" does not exist on jQuery.formgen")}})(jQuery);(function(e){function d(t,n,r,i){var o,u,a,c,h,p,d;if(typeof n=="object"&&n.jquery){if(n.is("img")){p=n;h=n.attr("alt")||n.attr("title")||n.data("text")||"";u=p[0].naturalWidth||p[0].width;o=p[0].naturalHeight||p[0].height;if(o<1)o=1;if(u<1)u=1;c=e(window).width()-90;a=e(window).height()-90;if(a'+'

',ui:{"img:eq(0)":"img",h4:{bind:"text",css:{hide:function(e,t){return!t}}}}},data:{img:p.attr("src"),text:h},esc:true,screen:true,width:i||d,focus:false,global:true},r)}}else if(l(n)&&n.manifest){s(t,n,r)}else if(f(n)){s(t,{source:"html",manifest:{init:function(e){e.html(this.HTML)},HTML:n,ui:{"div:eq(0)":function(){}}},data:{},esc:true,focus:false,global:true,screen:true,width:i},r)}else return null;return t}var t={},n="body",r,i=false,s=e.extend,o={},u=Object.isArray,a=Object.isBoolean,f=Object.isString,l=Object.isObject,c=Object.isNumber,h=Object.isRegExp,p=Object.isFunction;e(document).keydown(function(e){var t=e.keyCode,n,r;if(false!==i&&(t===13||t===27)){r=i.data("modal");n=r.form;if(t==27&&(r.esc||Object.equal(n.data("my").initial,n.my("data")))){i.modal(true);return false}else if(t==13&&r.enter){i.modal.delay(50);return false}}});t.modal=function(r,s,o){var u={},a=e(n),f,l=a.find(">.my-modal-proxy"),c={global:true,screen:true,done:p(s)?s:undefined};if(i){return l.modal(r,s,o)}else{if(!l.size()){l=e('
').prependTo(a);l.css({position:"absolute",top:"0",left:"0",margin:"0",padding:"0",width:"1px",height:"0"})}if(d(u,r,c,o))return l.modal(u);else{var h=e.Deferred();return h.reject("Invalid data").promise()}}};t.modal.loading=function(t){e(n).find(">.my-modal").toggleClass("my-modal-loading",!!t)};t.modal.parent=function(t){if(!t||!e(t).size())return e(n);n=t};t.modal.parentBack=function(t){if(!t||!e(t).size())return e(r||n);r=t};t.modal.visible=function(){return!!i};if(!e.my)e.my={};e.my.modal=t.modal;e.fn.modal=function(t,u,c){function O(){var t=window,n,r,i=!!C.global,s=b.offset(),o=y.offset();C.pos={px:s.left,py:s.top,pw:b.outerWidth(),ph:b.outerHeight(),ox:o.left,oy:o.top,ow:y.outerWidth(),oh:y.outerHeight(),ww:r,wh:n};var u=(C.x.match(/\-?\d+(\.\d+)?/)||[0])[0]*1,a=(C.y.match(/\-?\d+(\.\d+)?/)||[0])[0]*1,f=C.x.has("left")?-1:C.x.has("right")?1:0,l=C.y.has("top")?-1:C.y.has("bottom")?1:0,c=C.pos.ox+C.pos.ow/2-C.pos.px,h=C.pos.oy+C.pos.oh/2-C.pos.py;if(i){C.pos.wh=n=t.innerHeight||e(t).height();C.pos.ww=r=t.innerWidth||e(t).width();c=r/2;h=n/2.5}u=C.x.has("%")?C.pos.ow/100*u:u;a=C.y.has("%")?C.pos.oh/100*a:a;C.pos.pix=c;C.pos.piy=h;c=c+f*(C.pos.ow/2)+u*(f>0?-1:1)-(C.width+S)*(f+1)/2;if(i){h=(n-C.height-20)/3;if(h<10)h=10}else{h=h+l*(C.pos.oh/2)+a*(l>0?-1:1)-((C.height||0)+x)*(l+1)/2}c=c.round(1);h=h.round(1);C.pos.vx=c;C.pos.vy=h}function _(t){if(!t){C.height=m.outerHeight();if(C.source!=="manifest")C.width=m.width();O()}m.css({left:C.pos.vx+"px",width:C.width+S+"px",display:"block"});if(C.screen){if(!C.global)w.css({top:0,left:0,position:"absolute",width:C.pos.pw+"px",height:C.pos.ph+"px",display:"block",background:f(C.screen)?C.screen:"rgba(40,80,120,0.5)","z-index":C.z-1});else{w.css({top:0,left:0,width:C.pos.ww*2+"px",height:C.pos.wh*2+"px",display:"block",position:"fixed","z-index":C.z-1});if(f(C.screen))w.css({background:C.screen?C.screen:"rgba(30,65,100,0.8)"})}}else if(w.size())w.hide();if(C.height>C.pos.wh){m.height(C.pos.wh-30);g.css({"overflow-y":e.browser.webkit?"overlay":"scroll"})}else{g.css({"overflow-y":"none"})}m.animate({top:C.pos.vy+"px",opacity:"1"},C.animate)}function D(){try{g.my("remove")}catch(t){}b.data("modals")[C.cid]=null;g.parent().unbind(".my").remove();w.off(".my"+C.cid).hide();if(C.global){i=false;e("body").css({overflow:"auto"})}}function P(e){try{T(null,null)}catch(t){}(function(){h.reject(e)}).delay(0)}var h=e.Deferred(),v={},m,g,y=this,b,w,E,S=0,x=0,T=p(u)?u:function(){return false},N=l(t)?t:{},C=y.data("modal"),k,L;s(y,h.promise());if(C){if(t==null||a(t)){g=C.form;w=C.bg;b=C.root;T=C.done;k=g.my("data");L=false;if(!t){try{L=T(g.my("valid")?null:g.my("errors"),k)}catch(A){}if(!L){D();y.removeData("modal");(function(){if(o[C.cid])o[C.cid].resolve(k);delete o[C.cid];C=null}).delay(0)}}else{try{T(null,null)}catch(A){}D();y.removeData("modal");if(o[C.cid])o[C.cid].reject("Cancelled");delete o[C.cid];C=null}return y}else if(N){P("Locked");return y}}if(!y.is(":visible")){P("Object must be visible");return y}if(!(N=d(v,t,{}))){P("Invalid data");return y}if(N.global&&i){P("Locked");return y}C=s({type:"DOM",source:"manifest",form:null,modal:null,root:null,bgroot:null,caller:y,global:false,drag:false,focus:true,manifest:{},data:{},nose:"",close:true,esc:false,enter:false,screen:false,width:c||300,height:null,x:"0",y:"0",z:"1997",css:"",animate:200},N,{promise:h.promise(),cid:Number.random(268435456,4294967295).toString(16)});C.done=p(C.done)?C.done:T;if(f(C.align)&&C.align){C.x=(C.align.match(/(left|right):\-?\d+(\.\d+)?(%|px)?/g)||["0"])[0];C.y=(C.align.match(/(top|bottom):\-?\d+(\.\d+)?(%|px)?/g)||["0"])[0]}C.width=1*(e.my.f.getref(f(C.manifest)?e.my.cache(C.manifest):C.manifest,"params.width")||C.width);C.type="DOM";if(y.hasClass("my-form")){C.type="form";C.root=C.root||y}else if(y.data("my")){C.type="control";C.root=C.root||y.my().container}else{C.root=C.root||y.parents(".my-form").eq(0);if(!C.root.size())C.root=e(n)}if(C.global){C.root=e(n);C.bgroot=e(r||n)}else C.bgroot=C.root;b=C.root;if(!b.data("modals"))b.data("modals",{});O();m=e('
').prependTo(C.root);m.addClass("my-modal-"+C.cid);S=m.outerWidth();x=m.outerHeight();m.hide();m.html('
');g=m.find(".my-modal-form");if(C.close){E=e(f(C.close)?C.close:'
×
').prependTo(m).on("click.my",function(){y.modal(true)});E.css({"z-index":""+(C.z*1+1)})}w=C.bgroot.find(">.my-modal-screen");if(C.screen){if(!w.size()){w=e('').prependTo(C.root)}if(C.esc)w.on("click.my"+C.cid,function(){y.modal(true)})}y.data("modal",C);m.css({position:C.global?"fixed":"absolute",left:C.pos.vx+"px",top:C.pos.vy+"px",display:"block",height:"none",opacity:"0.005","z-index":C.z,width:"auto"});g.my(C.manifest,C.data).then(function(){var t,n,r,u,a;s(C,{form:g,bg:w,cancel:function(){y.modal(true)},commit:function(){y.modal()}});m.data("modal",C);C.height=m.outerHeight();if(C.source!=="manifest")C.width=m.width();O();m.css({top:C.pos.vy+"px"});_(true);b.data("modals")[C.cid]=C;o[C.cid]=h;g.bind("commit.my",function(){C.commit.delay(50);return false}).bind("cancel.my",function(){C.cancel.delay(50);return false});m.bind("layout.my",function(){_()}.debounce(50));if(C.global){i=y;e("body").css({overflow:"hidden"})}if(!C.global&&(C.esc||C.enter)){g.bind("keydown.my",function(e){var t=e.keyCode;if(t==27&&C.esc){C.cancel();return false}else if(t==13&&C.enter){C.commit.delay(50);return false}})}if(C.focus===true){u=false;a=C.manifest.ui;for(r in a){if(!u){n=g.find(r);if(n.size()&&n.is("input, textarea")){u=true;n.focus()}}}}else if(f(C.focus))g.find(C.focus).focus();t=g.find("img").filter(function(){return e(this).attr("src")!=""});if(t.size()){var l=function(){if(C.source!=="manifest")m.css({width:"auto"});_()}.after(t.size());t.each(function(){e(this).bind("load",l)})}if(C.drag&&e.fn.draggable){if(!f(C.drag))m.draggable();else m.draggable({handle:C.drag})}h.notify("Ready")}).fail(function(e){D();y.data("modal",null);h.reject(e)});return y}})(jQuery); diff --git a/bower.json b/bower.json index 9a71980..2268da5 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquerymy", - "version": "1.0.0", + "version": "1.0.2", "description": "jQuery plugin that binds HTML with JS objects in real time.", "main": "./jquerymy.js", "authors": [ diff --git a/jquerymy.js b/jquerymy.js index 035f588..f349d58 100644 --- a/jquerymy.js +++ b/jquerymy.js @@ -1,24 +1,15 @@ /* - * jQuery.my 1.0.0 + * jQuery.my 1.0.2 * Requires jQuery 1.11.0+, SugarJS 1.3.9-1.4.x * - * New features: - * — require property of manifest, allows resources preload - * — files property of manifest, container for binary resources, that obtain session URL when form starts - * — improvements of lists of nested forms - * — new properties hash and id - * — overall speed-up - * Optimizations: - * — ie8 compatibility improvements - * — no more eval() * * More details at jquerymy.com * * @ermouth, thanks @carpogoryanin, @ftescht - * 2014-08-04 + * 2014-09-11 ✈ */ -;(function ($) {var _version = "jQuery.my 1.0.0"; +;(function ($) {var _version = "jQuery.my 1.0.2"; // Some shortcuts and constants var lang = "en", @@ -38,8 +29,7 @@ isN = Object.isNumber, isR = Object.isRegExp, isF = Object.isFunction, - isP = function (a) {/*is promise*/return !!(null!=a&&(isO(a)||a.jquery)&&isF(a.then)&&isF(a.fail)&&isF(a.state));}, - isRej = function (p) {/*is promise rejected*/ return isP(p)?(p.state()==="rejected"):null;}; + isP = function (a) {/*is promise*/return !!(null!=a&&(isO(a)||a.jquery)&&isF(a.then)&&isF(a.fail)&&isF(a.state));}; //======================================= @@ -1657,7 +1647,7 @@ //create debounced change handler $this.my()._changed = (_changed).debounce(delay); - $this.my()._recalc = (_recalc);//.debounce(delay); + $this.my()._recalc = (_recalc).debounce(delay); //bind events to the control $this.bind(events, function (evt) { @@ -1938,7 +1928,7 @@ }); //extend root with promise methods - $.extend($root, pi.promise()); + $E($root, pi.promise()); //mount data if (isO(defaults)) { @@ -2030,7 +2020,8 @@ ui:Object.extended(ui), disabled:false, manifest:manifest, - locFiles:[] + locFiles:[], + modals:{} }); // mount classes and styles if any @@ -2320,6 +2311,10 @@ mid = m.mid; + // close modals if any + if ($o.data("modals")) {} + + // stop event listeners $o.unbind(".my"); @@ -2345,7 +2340,19 @@ ui = (m||{}).ui; if (ui) { ui.each(function (key){ - var $we = $o.find(key), f; + var $we = $o.find(key), f, mw, i; + + // close dependent modal + if (mw = $we.data("modal")) { + mw.cancel(); + $we.removeData("modal"); + } + + //close child modals + if (mw = $we.data("modals")) { + for (i in mw) if (mw[i]) mw[i].cancel(); + } + $we.unbind(".my"); try{ f = _traverse($we, MY.destroy); @@ -3012,13 +3019,14 @@ //############################################################################################# -/* jQuery.my.modal 0.5 - * Requires Sugar 1.4.1+, jQuery 1.11+, $.my 0.9.7+ +/* jQuery.my.modal 1.0.0 + * Requires Sugar 1.4.~, jQuery 1.11+, $.my 1.0.0+ * * Modal dialog constructor/manager. Singleton, allows only one instance of popup. * Returns promise, which is resolved on dialog normal close or rejected if modal fails to init. * After content is succesfully initialized promise progress receives notification "Ready". * + * $obj.modal or * $.my.modal (Obj, done, width) >> null or * promise [resolve(formData or true), reject (errMessage, errStack)] * @@ -3033,9 +3041,14 @@ * done: callback Function (formErrors, data) or none, * esc: false, enables/disables close on escape keypress, * enter: false, enables commit on Enter keypress + * nose:"", left|right|top|bottom – where to put nose + * global: false, force global modal + * screen: false, show/hide screen div + * drag: false, allows drag of modal if $ ui draggable plugin installed + * align:"top|bottom:NUM%|px;left|right:NUM%|px" * } - * will raise modal with $.my form inside. Form must call $.my.modal(false) or emit - * "commit" event on itself to close with sendind data. Calling $.my.modal(true) or + * will raise modal with $.my form inside. Form must call $obj.modal(false) or emit + * "commit" event on itself to close with sendind data. Calling $obj.modal(true) or * emitting "cancel" event on form will close modal sending null as data with no error. * * Callback in obj overlaps done provided as second arg, same for width. @@ -3050,274 +3063,587 @@ * 5. true (strict boolean) – close dialog and calls done (null, null), * then promise is rejected with "Cancelled" string * - * If modal is already open invoking $.my.modal return promise that is immidiately - * rejected with error "Locked", done is called with (null, null). + * If modal on $obj is already open, invoking $obj.modal return promise that is + * immediatly rejected with error "Locked", done is called with (null, null). * * $.my.modal.visible() >> Boolean - * Indicates if modal is opened. + * Indicates if global modal is opened. * * $.my.modal.parent (selector or null) >> jQuery object * Sets or gets parent DOM node, where all $.my.modal stuff is prepended. * To work good must be called prior to 1st $.my.modal call. */ -(function (jQuery){ +(function ($){ - var $bg, $m, $f, root={}, parent = "body", isOpen = false, promise, + var root={}, parent = "body", parentBack, isOpen = false, + $E = $.extend, M = {}, isA = Object.isArray, isB = Object.isBoolean, isS = Object.isString, isO = Object.isObject, isN = Object.isNumber, isR = Object.isRegExp, isF = Object.isFunction; //Close modal on escape $(document).keydown(function (e) { - var code = e.keyCode; - if (code ===13 || code === 27) { - if (code == 27 - // escape - && isOpen - //&& $(parent).find(">.my-modal").is(":visible") - && ( - !$f.is(".my-form") - || - $f.data("escapable") - || - Object.equal($f.data("my").initial, $f.my("data")) - ) - ) { - root.modal(true); + var code = e.keyCode, $f, m; + if (false!==isOpen && (code ===13 || code === 27)) { + m = isOpen.data("modal"); + $f = m.form; + if (code == 27 && ( m.esc || Object.equal($f.data("my").initial, $f.my("data")) ) ) { + isOpen.modal(true); return false; } - else if (code == 13 - // enter - && isOpen - //&& $(parent).find(">.my-modal").is(":visible") - && $f.is(".my-form") - &&$f.data("allowenter") - ) { - root.modal.delay(50); + else if (code == 13 && m.enter ) { + isOpen.modal.delay(50); return false; } } }); - root.modal = function modal (obj, done0, css0) { - var done = done0||(function () {return false;}), - proxy, - stop = false, - show = false, - data = true, - text="", - $img, - width=css0||820, - height=300; - - // check if opened - if ($(parent).find(">.my-modal").is(":visible")) { - isOpen = true; - // No obj – close - if (isB(obj) || obj===null || obj===undefined) { - if (isF($m.data("done"))) done = $m.data("done"); - else done = function () {return false;}; - - stop=false; data=true; - - if (!obj) { - if (!$f.is(".my-form")) stop=done(null,true); - else { - stop=done($f.my("valid")?null:$f.my("errors"),$f.my("data")); - if (!stop) data=$f.my("remove"); + // - - - - - - - - - - - - - - - - - - + + function _convert (o, obj, ovl, width0) { + var h, w,h0,w0,text,$i,width; + // $ image + if (typeof obj == "object" && obj.jquery) { + if (obj.is("img")) { + $i = obj; + text = obj.attr("alt") || obj.attr("title") || obj.data("text")||""; + w = $i[0].naturalWidth || $i[0].width; + h = $i[0].naturalHeight || $i[0].height; + if (h<1) h=1; + if (w<1) w=1; + w0=$(window).width()-90; + h0=$(window).height()-90; + if (h0' + +'

', + ui:{ + "img:eq(0)":"img", + "h4":{ + bind:"text", + css:{hide:function(d,v){return !v}} + } + } + }, + data:{img:$i.attr("src"),text:text}, + esc:true, + screen:true, + width:width0||width, + focus:false, + global:true + }, ovl); + } + } + + // $.my form + else if (isO(obj) && obj.manifest) { + $E(o, obj, ovl); + } + + //plain html + else if (isS(obj)) { + $E(o, { + source:"html", + manifest:{ + init: function($o){ $o.html(this.HTML); }, + HTML:obj, + ui:{ "div:eq(0)":function(){} } + }, + data:{}, + esc:true, + focus:false, + global:true, + screen:true, + width:width0 + }, ovl); + } + + else return null; + + return o; + } + + + // - - - - - - - - - - - - - - - - - - + + root.modal = function modal (obj, done0, w0) { + var o = {}, + $r = $(parent), $i, + $o=$r.find(">.my-modal-proxy"), + ovl = { + global:true, + screen:true, + done:isF(done0)?done0:undefined + }; + + if (isOpen) { return $o.modal(obj, done0, w0); } + else { + if (!$o.size()) { + $o = $('
').prependTo($r); + $o.css({position:"absolute",top:"0",left:"0",margin:"0",padding:"0",width:"1px",height:"0"}); + } + + if (_convert(o, obj, ovl, w0)) return $o.modal(o); + else { + var pi = $.Deferred(); + return pi.reject("Invalid data").promise(); + } + + } + } + + // - - - - - - - - - - - - - - - - - - + + + root.modal.loading = function (onoff) { + $(parent).find(">.my-modal").toggleClass("my-modal-loading",!!onoff); + } + + root.modal.parent = function (s) { + // sets parent DOM node selector for $.my.modal + if (!s || !$(s).size()) return $(parent); + parent = s; + } + + root.modal.parentBack = function (s) { + // sets parent DOM node selector for $.my.modal background + if (!s || !$(s).size()) return $(parentBack||parent); + parentBack = s; + } + + root.modal.visible = function () {return !!isOpen;} + + if (!$.my) $.my={}; + $.my.modal = root.modal; + + + // ############################### + // Extend jQuery with modal plugin + + $.fn.modal = function (obj0, done0, width0) { + var pi = $.Deferred(), o={}, + $m, $f, $o = this, $r, $bg, $cl, padx=0, pady=0, + done = isF(done0)?done0:function(){ return false; }, + obj = isO(obj0)?obj0:{}, + m = $o.data("modal"), + md, stop; + + $E($o, pi.promise()); + + // check if this already has modal + + if (m) { + if (obj0==null || isB(obj0)) { + + // ##### CLOSE MODAL ########## + + $f = m.form; + $bg = m.bg; $r = m.root; done = m.done; + md = $f.my("data"); + stop = false; + + if (!obj0) { + // check if we can close + try{ + stop = done ($f.my("valid")?null:$f.my("errors"), md); + }catch(e){} + if (!stop) { + _remove(); + $o.removeData("modal"); + // async resolve + (function () { + if (M[m.cid]) M[m.cid].resolve(md); + delete M[m.cid]; + m=null; + }).delay(0); } - } else if (obj===true && promise.state()!="rejected"){ - if ($f.is(".my-form")) $f.my("remove"); - done(null,null); - promise.reject("Cancelled"); - } - if (!stop) { - $f.html(""); - $m.css({display:"none"}); - (function () {if (!isOpen) $bg.css({display:"none"});}).delay(5); - $("body").css({overflow:"auto"}); - isOpen = false; - $m.data("done",null); - (function () {promise.resolve(data);}).delay(0); - } - return; - } - - // Trying to open new modal - // when prev is not closed - proxy=$.Deferred(); - done(null,null); - proxy.reject("Locked"); - return proxy.promise(); + } else { + // force close + try {done(null, null);} catch(e){} + _remove(); + $o.removeData("modal"); + if (M[m.cid]) M[m.cid].reject("Cancelled"); + delete M[m.cid]; + m=null; + } + + return $o; + + + } else if (obj) { + // reinit is not allowed + _f("Locked"); + return $o; + } } - promise = $.Deferred(); - isOpen = true; + // check if $o is visble + if (!$o.is(":visible")) { + _f("Object must be visible"); + return $o; + } - // create wrappers if none defined - if (!$m || !$(parent).find(">.my-modal").size()) { - $m= $('').prependTo($(parent)); + // convert + if (!(obj = _convert(o, obj0, {}))) { + _f("Invalid data"); + return $o; + } + + // check if fullscreen opened + if (obj.global && isOpen) { + _f("Locked"); + return $o; + } + + + // ##### NEW MODAL ########## + + m=$E({ + type:"DOM", source:"manifest", + form:null, // $obj of the form + modal:null, // $obj of the modal wrapper + root:null, // $obj, modal is appended to + bgroot:null, // $obj, root for bg + caller:$o, // $obj modal is linked with + + global:false, + drag:false, + focus:true, + manifest:{}, data:{}, + nose: "", close:true, esc: false, enter: false, + screen: false, width:width0||300, height:null, + x:"0", y:"0", z:"1997", css:"", + animate:200 + }, obj, { + promise: pi.promise(), + cid:Number.random(268435456,4294967295).toString(16) + }); + m.done = isF(m.done)? m.done:done; + + //parse align + if (isS(m.align) && m.align) { + m.x = (m.align.match(/(left|right):\-?\d+(\.\d+)?(%|px)?/g)||["0"])[0]; + m.y = (m.align.match(/(top|bottom):\-?\d+(\.\d+)?(%|px)?/g)||["0"])[0]; } + + //refine width + m.width=1*($.my.f.getref( + isS(m.manifest)?$.my.cache(m.manifest):m.manifest, + "params.width" + ) || m.width ); + + // guess if $o is ctrl, form or just dom node + // find parent container + + m.type = "DOM"; + if ($o.hasClass("my-form")) { + m.type = "form"; + m.root = m.root || $o; + } + else if ($o.data("my")) { + m.type = "control"; + m.root = m.root || $o.my().container; + } + else { + m.root = m.root || $o.parents(".my-form").eq(0); + if (!m.root.size()) m.root = $(parent); // global parent + } + + if (m.global) { + m.root = $(parent); + m.bgroot = $(parentBack||parent); + } else m.bgroot = m.root; + + $r = m.root; + if (!$r.data("modals")) $r.data("modals",{}); + + _measure(); + + // ##### Create modal DOM wrapper ##### + + // create wrappers if none defined + $m= $('
').prependTo(m.root); + $m.addClass("my-modal-"+ m.cid); + + padx=$m.outerWidth(); + pady = $m.outerHeight(); + $m.hide(); + //rebuild modal form obj $m.html('
'); $f = $m.find(".my-modal-form"); - $('
×
') - .prependTo($m).on("click",function () {root.modal(true);}); - if (!$bg || !$(parent).find(">.my-modal-screen").size()) { - $bg= $('') - .prependTo($(parent)).on("click", function () { - if (!$f.is(".my-form")||$f.data("escapable")) root.modal(true); - }); + // close btn + if (m.close) { + $cl = $(isS(m.close)? m.close:'
×
') + .prependTo($m).on("click.my",function () {$o.modal(true);}); + $cl.css({"z-index":""+(m.z*1+1)}); } - // jQuery image - if (typeof obj == "object" && obj.jquery) { - if (obj.is("img")) { + $bg = m.bgroot.find(">.my-modal-screen"); + if (m.screen) { + if (!$bg.size()) { + $bg = $('') + .prependTo(m.root); - text = obj.attr("alt") || obj.attr("title") || obj.data("text"); - - $f.html((function () { - var $i = obj, - w = $i[0].naturalWidth || $i[0].width, - h = $i[0].naturalHeight || $i[0].height, - w0=jQuery(window).width()-90, - h0=jQuery(window).height()-90, - html; - if (h0'; - width=w<300?300:w; - return html; - })() + (text?'

'+text+'

':"")); - - $f.find("img").on("click",function () {root.modal();}); - $m.css({top:"3000px",display:"block"}); - height=$m.height(); - show=1; } + + if (m.esc) $bg.on("click.my"+ m.cid, function () { $o.modal(true); }); } - // $.my form - else if (isO(obj) && obj.manifest) { - data = obj.data ||{}; - done = isF(obj.done)?obj.done:done; - width=1*($.my.f.getref( - isS(obj.manifest)?$.my.cache(obj.manifest):obj.manifest, - "params.width" - ) - ||obj.width||width); - $m.css({top:"3000px",display:"block",height:"none"}); - $f.data("my",null); - show=1; - $f.my(obj.manifest, data).then(function () { - _adjust.delay(20); - promise.notify("Ready"); - }).fail(function (err){ - promise.reject(err); - show=0; - root.modal(true); + // try to init form + $o.data("modal", m); + $m.css({ + position: m.global?"fixed":"absolute", + left: m.pos.vx+"px", + top: m.pos.vy+"px", + display:"block", + height:"none", + opacity:"0.005", + "z-index": m.z, + width:"auto" + }); + $f.my(m.manifest, m.data).then(function () { + var $img, $i, i, focus, ui; + //success + $E(m,{ + form: $f, + bg:$bg, + cancel: function(){$o.modal(true)}, + commit: function(){$o.modal()} }); - $m.data("done", done); - $f.data("escapable", !!obj.esc); - $f.data("allowenter", !!obj.enter); - $f.bind("commit.my", function () { - root.modal(); - }.debounce(50)) - .bind("cancel.my", function () { - root.modal(true); - }.debounce(50)) - .bind("layout.my", function () { - _adjust(); + $m.data("modal",m); + + // adjust form + m.height = $m.outerHeight(); + if (m.source !== "manifest") m.width = $m.width(); + _measure(); + $m.css({top:m.pos.vy+"px"}); + _adjust(true); + + // remember cid in parent form root + $r.data("modals")[m.cid] = m; + + // memoize modal promise + M[m.cid] = pi; + + // bind event listeners + $f.bind("commit.my", function(){ + m.commit.delay(50); + return false; + }).bind("cancel.my", function(){ + m.cancel.delay(50); + return false; }); - } - //plain html - else if (isS(obj)) { - $f.html(obj); - $m.css({top:"3000px", display:"block", width:"auto"}); - width=1*($m.width()||width); - show=1; - } + $m.bind("layout.my", function(){ + _adjust(); + }.debounce(50)); - else if (obj===true) { - $("body").css({overflow:"auto"}); - isOpen = false; - return promise.reject("Cancelled").promise(); - } - else { - $("body").css({overflow:"auto"}); - isOpen = false; - return promise.reject("Invalid data").promise(); - } + // fullscreen tuneups + if (m.global) { + isOpen = $o; + $("body").css({overflow:"hidden"}); + } + + // esc and enter monitors + if (!m.global && (m.esc || m.enter)) { + $f.bind("keydown.my", function(e) { + var code = e.keyCode; + if (code == 27 && m.esc) { + m.cancel(); + return false; + } + else if (code == 13 && m.enter){ + m.commit.delay(50); + return false; + } + }) + } + + // autofocus + if (m.focus===true) { + focus = false; + ui = m.manifest.ui; + for (i in ui) { + if (!focus) { + $i = $f.find(i); + if ($i.size() && $i.is("input, textarea")) { + focus = true; $i.focus(); + } + } + } + } + else if (isS(m.focus)) $f.find(m.focus).focus(); - //show all objs - if (show) { - _adjust(width); //If we have images, count them and reheight on load $img = $f.find("img").filter(function () {return $(this).attr("src")!="";}); if ($img.size()) { - var _imgdone = (function () { - _adjust(css0); - promise.notify("Ready"); - }).after($img.size()); + var _imgdone = function(){ + if (m.source !== "manifest") $m.css({width:"auto"}); + _adjust(); + }.after($img.size()); $img.each(function () {$(this).bind("load", _imgdone);}); - } else { - promise.notify("Ready"); } - $("body").css({overflow:"hidden"}); - } - return promise.promise(); - }; + // Draggable + if (m.drag && $.fn.draggable) { + if (!isS(m.drag)) $m.draggable(); + else $m.draggable({handle: m.drag}); + } - root.modal.loading = function (onoff) { - $(parent).find(">.my-modal").toggleClass("my-modal-loading",!!onoff); - }; + pi.notify("Ready"); + }) + .fail(function (err){ + _remove(); + $o.data("modal", null); + pi.reject(err); + }); + + return $o; - root.modal.parent = function (s) { - // sets parent DOM node selector for $.my.modal - if (!s || !$(s).size()) return $(parent); - parent = s; - }; - root.modal.visible = function () {return isOpen;}; + //### Helpers - if (!jQuery.my) jQuery.my={}; - jQuery.my.modal = root.modal; + function _measure(){ + // measure $o, its pos + // and modal offsets rel to container + var W = window, h, w, + isfs = !!m.global, + ro = $r.offset(), oo = $o.offset(); + m.pos = { + px: ro.left, py: ro.top, + pw: $r.outerWidth(), ph: $r.outerHeight(), - function _adjust (width0){ - //adjust modal position, - // centers it when content is ready + ox: oo.left, oy: oo.top, + ow: $o.outerWidth(), oh: $o.outerHeight(), - var W = window, - h=W.innerHeight || jQuery(W).height(), - w=W.innerWidth || jQuery(W).width(), - height = $m.height(), - width = width0||$f.width(); - $m.removeClass("loading") - .css({ - left:((w-width-60)/2)+"px", - width:(width*1+60)+"px", + ww:w, wh:h + }; + //if (m.width> m.pos.pw) m.width= m.pos.pw; + + // calculate offsets + var dx = (m.x.match(/\-?\d+(\.\d+)?/)||[0])[0]* 1, + dy = (m.y.match(/\-?\d+(\.\d+)?/)||[0])[0]* 1, + sx = m.x.has("left")?-1: m.x.has("right")?1: 0, + sy = m.y.has("top")?-1: m.y.has("bottom")?1: 0, + vx = m.pos.ox + m.pos.ow/2 - m.pos.px, + vy = m.pos.oy + m.pos.oh/2 - m.pos.py; + + if (isfs) { + m.pos.wh = h = W.innerHeight || $(W).height(); + m.pos.ww = w = W.innerWidth || $(W).width(); + vx = w/2; + vy = h/2.5; + } + dx = m.x.has("%")? m.pos.ow/100*dx:dx; + dy = m.y.has("%")? m.pos.oh/100*dy:dy; + + m.pos.pix = vx; m.pos.piy = vy; + + vx = vx + sx*(m.pos.ow/2) + + dx*(sx>0?-1:1) + - (m.width+padx)*(sx+1)/2; + + if (isfs) { + vy = (h - m.height-20)/3; + if (vy<10) vy=10; + } else { + vy = vy + sy*(m.pos.oh/2) + + dy*(sy>0?-1:1) + - ((m.height||0)+pady)*(sy+1)/2; + } + + vx = vx.round(1); vy = vy.round(1); + + m.pos.vx = vx; m.pos.vy = vy; + } + + // - - - - - - - - - - - - - - - - - - + + function _adjust (skipMeasure){ + //adjust modal position, + if (!skipMeasure) { + m.height = $m.outerHeight(); + if (m.source !== "manifest") m.width = $m.width(); + _measure(); + } + $m.css({ + left: m.pos.vx+"px", + width: (m.width+padx)+"px", display:"block" }); - $bg.css({width:(w*2)+"px", height:(h*2)+"px",display:"block"}); + if (m.screen) { + if (!m.global) $bg.css({ + top:0, left:0, position:"absolute", + width: m.pos.pw+"px", + height: m.pos.ph+"px", + display:"block", + background:isS(m.screen)? m.screen:'rgba(40,80,120,0.5)', + "z-index":m.z-1 + }); + else { + $bg.css({ + top:0, left:0, + width:(m.pos.ww*2)+"px", + height:(m.pos.wh*2)+"px", + display:"block", + position:"fixed", + "z-index":m.z-1 + }); + if (isS(m.screen)) $bg.css({ + background:m.screen? m.screen:'rgba(30,65,100,0.8)' + }); + } + } + else if ($bg.size()) $bg.hide(); - if (height>h) { - $m.height(h); - $f.css({"overflow-y":$.browser.webkit?"overlay":"scroll"}); - } else { - $f.css({"overflow-y":"none"}); + if (m.height> m.pos.wh) { + $m.height(m.pos.wh-30); + $f.css({"overflow-y":$.browser.webkit?"overlay":"scroll"}); + } else { + $f.css({"overflow-y":"none"}); + } + + $m.animate({top: m.pos.vy+"px", opacity:"1"}, m.animate); } - $m.animate( - {top:(height>=h?0:(h-height)/3.5)+"px"}, - parseFloat($m.css("top"))r){n=l;r=o;return}else if(c==p)s(e,l,o+1)}if(a!=t[""]&&typeof t[""]!=p&&o>r){n=t[""];r=o}}var n=a,r=0,i="";s(e,t,1);return n}function I(e,t,n,r){var i,s=[],o,f,l,c=n.bind,h=u(c);if(h==g){return c.call(R(r).manifest,e,t,r)}if(h===m||h===v){if(h===m&&!/\./.test(c)){if(t!=a)e[c]=t;else if(e[c]===undefined)e[c]=a;return e[c]}if(h===m)s=c.split(".").each(function(e,t){this[t]=e+""});if(h===v)s=c.slice(0).each(function(e,t){this[t]=e+""});if(s[0]==="this"){o=R(r).manifest;s.shift()}else o=e;for(i=0;i-1?"":h;case"s":return n==s?"":h;case"o":return s[n]?"":h;case"b":{if(i.is(".my-form-list,.ui-sortable")){var d=i.data("listSrc")||i.data("my").listSrc||">*",v={};i.find(d).filter("*:not(.ui-sortable-placeholder)").each(function(t){var n=e(this);if(n.data("my")&&!n.my("valid"))v[t]=n.my("errors")});return v}else if(i.hasClass("my-form")){return!s?"":i.my("valid")?"":i.my("errors")}return""}}return l.formError||"Error"}return""}function R(e){var t=e.my();if(!t)return null;return t.root?t.root.my():t}function U(t,n,r){var i=r.compact(),s=i.replace(/:disabled/g,"");n.each(function(){var r=e(this),o=r.my(),u=o?o.container:r;if(t){if(!u.is(s))u.addClass(s)}else u.removeClass(s);if(s!=i&&o!==undefined&&!!t!=!!o.disabled){r.my().disabled=!!t;if(!o._disable)r.my()._disable=F(n,P.offon).fill(undefined,n);o._disable(!!t)}});return n}function z(e,t,n){var r,i,s,u,f,c,h,p,d,v,m,g=false,y=false,b=e,w=b.my(),E="";if(w){p=w.selector;d=w.root;if(d.hasClass("my-form-init"))return{};v=d.find(p);m=d.my().ui;g=e.hasClass("my-form");y=e.hasClass("my-form-list");if(g){r=e;i=w.ddata;s=w.dui;u=w.dparams}else{r=w.container;i=w.data;s=w.ui;u=w.params}if(s.bind!=a){if(l(t))f=t;else f=j(v,I(i,a,s,v));if(a!=s.check){E="Unknown error";try{E=q(i,f,s,v)}catch(x){H.con("Error "+x.message+" validating "+p,d,x.stack)}}var T=u.errorCss;var k="ui-state-error";try{if(a!=t)f=j(v,I(i,t,s,v))}catch(x){E=u.messages.formError||"Error"}if(E===""){if(!g)w.errors[p]="";else w.derrors[p]="";r.removeClass(T);if(r.attr("title"))r.attr("title","");if(!g&&!y)u.effect(r.find(u.errorTip),false,u.animate/2);b.removeClass(k);b.find(".ui-widget").removeClass(k)}else{if(g)w.derrors[p]=E;else if(y)w.errors[p]=E;else{r.addClass(T);w.errors[p]=E;var L=r.find(u.errorTip).eq(0);if(L.size()){u.effect(L.addClass(T).html(E),true,u.animate)}else r.attr("title",(E||"").stripTags())}if(b.is(".hasDatepicker")){if(b.is("input"))b.addClass(k);else b.find(".ui-widget").addClass(k)}if(b.is(".ui-slider"))b.addClass(k)}}var A=t==a?f:t;if(s.css){for(c in s.css){h=s.css[c];if(N(h))U(h.test(A),v,c);else if(C(h))U(h.call(d.my().manifest,i,A,v),v,c)}}var O,M=s.recalc,_=[],D={},P;if(n&&s.recalc&&d.my()){m=d.my().ui;for(O=0;O=f*2){d={};for(o=f;o=u.length)l=u.length-1;p=Object.clone(i.history[u[u.length-l-1]],true);if(n){d={};for(o=0;o$/.test(l.list))u=l.list;else a=l.list||a;if(!u){var h=t.find(a);u="
";if(h.size()){u=e(u).append(h.eq(0).clone(true)).html();h.eq(0).remove()}}if(!t.data("formlist"))t.data("formlist",{});t.data("formlist").generator={manifest:v,delay:(l.delay||f.delay||10)/1.3,template:u,selector:a,parent:m,bind:l.bind,hash:C(l.hash)?l.hash.bind(m):L(l.hash),id:C(l.id)?l.id.bind(m):L(l.id),ext:!!(l.id||l.hash),stamp:0};t.on("insert.my",function(t,n){t.stopPropagation();var r={what:undefined,where:0};if(null==n)r.where=1e6;else if(x(n))Object.merge(r,n);else if(S(n)||T(n))r.where=n;e(t.target).my("insert",r.where,r.what)});t.on("remove.my",function(t){t.stopPropagation();e(t.target).my("remove")})}else{try{n=t.my(M(m,v),x(o)?o:undefined)}catch(p){N("$.my subform init of "+i+" failed: "+p.message,p.stack)}}}if(k(n)){n.then(A,function(e,t){N("Init of subform "+i+" failed with error: "+e,t)})}else A()}function N(e,t){H.con(e,t);if(c)c.reject(e,t)}function L(e){var t=u(e).to(3);return!e?null:t==="str"?O.fill(undefined,e):t==="arr"?H.mask.fill(undefined,e):null}function A(){t.each(function(){var u=e(this),c,h,d=false,v=u[0].nextSibling;h=v&&v.CodeMirror?v.CodeMirror:null;if(h)u.addClass("my-codemirror");c=l.events||F(u,P.events);if(!u.is(".my-form")){u.data("my",{events:c,selector:i,initial:p,previous:p,root:n,container:f.container(u),id:s.id,ui:l,data:s.data,params:f,errors:s.errors});r._update=l.delay?z.debounce(l.delay):a;d=true}else{o(u.data("my"),{dui:l,root:n,selector:i,dparams:f,devents:c,ddata:s.data,container:f.container(u),derrors:s.errors})}if(d){if(u.cleditor&&u.parent().is(".cleditorMain")){var m=u.cleditor()[0];if(m&&m.$frame&&m.$frame[0]){u.addClass("my-cleditor");o(u.data("my"),{container:f.container(u)});var b=function(e){u.val(e).trigger(y)};var w,E=Number.random(1e5,1e6-1);e(m.$frame[0]).attr("id","cleditCool"+E);if(!document.frames)w=e("#cleditCool"+E)[0].contentWindow.document;else w=document.frames["cleditCool"+E].document;var S=e(w).find("body");e(w).bind("keyup.my",function(){b(e(this).find("body").html())});u.parent().find("div.cleditorToolbar").bind("click.my mouseup.my",function(){b(S.html())});e("body").on("click","div.cleditorPopup",function(){b(S.html())})}}else if(u.is("div.redactor_box textarea")){var x,T="my-redactor-9";try{x=u.getEditor();T="my-redactor-8"}catch(N){x=u.redactor("getEditor")}if(x){u.addClass(T);x.bind("input.my keyup.my blur.my",function(e){e.trigger("redactor")}.fill(u))}}else if(u.is(".ace_editor"))ace.edit(t[0]).on(y,function(e){e.trigger("ace")}.fill(u));else if(h){h.on(y,function(e){e.trigger("codemirror")}.fill(u))}}u.my()._changed=V.debounce(g);u.my()._recalc=$;u.bind(c,function(e){if(e.type==y)e.stopPropagation();if(d)s.locktill=Date.now()+r.delay;u.my()._changed(u,n,r,f)});if(!/check(\.my)?/.test(c+""))u.on("check.my",function(e){u.my()._changed(u,n,r,f,true);return false});u.on("recalc.my, redraw.my",function(e){e.stopPropagation();u.my()._recalc(u,n,r,f)})});if(c)c.resolve()}var s=n.my(),f=(s||{}).params,l=r,c=null,h,p,d=0,v,m=s.manifest,g;if(!s){H.con("Failed to find $root building "+i+" selector.");return null}g=r.delay;if(t.size()){if(l.init!=a)h=J(m,l.init,t,s);if(k(h)){d+=1;c=e.Deferred();h.then(E,function(e,t){N("Init of "+i+" failed: "+e,t)})}else E()}else H.con("Not found "+i+" selector.",n);return c}function V(e,t,n,r,i){var s=e.data("my"),o=t.data("my");if(s&&!s.disabled){W(s.ddata||s.data,s.dparams||s.params);var u=t.find(s.selector);z(e,!i?j(u,a):a,n.recalcDepth||r.recalcDepth);if(undefined===o.orphan){if(s.root.parent().hasClass("ui-sortable")){o.orphan=!s.root.parent().hasClass("my-form-list")}}if(o.orphan)s.root.parent().trigger("check");if(r.change)r.change.call(e)}}function $(e,t,n,r){var i=e.my();if(i&&!i.disabled){var s=t.find(i.selector);if(s.is(".my-form"))s.my("redraw");else z(e,s.is(".my-form-list")?O(s.my().data,s.data("formlist").generator.bind):a,n.recalcDepth||r.recalcDepth)}}function J(e,t,n,r){var i;if(S(t)){i=O(e,t);if(undefined===i){n.html(t.assign(r.data));return null}}else i=t;if(C(i))return i.apply(e,Array.prototype.slice.call(arguments,2));else if(w(i)){try{n.formgen(i)}catch(s){}}return null}function K(e,t){var n="",r,i="",s=!t,o=[];for(n in e)if(e.hasOwnProperty(n)&&(s||!/^(data|files|require)$/.test(n))){r=e[n];i=u(r);if(/^(ob|ar)/.test(i))K(r);else if(i==="string"&&/^(function\s\(|new\sRegExp)/.test(r)){if(o=r.match(/^function\s\(([^\)]*)\)\s*\{([\s\S]*)\}$/)){if(o.length===3){try{e[n]=Function(o[1],o[2])}catch(a){console.log(a.message,a.stack,r)}}}else if(o=r.match(/^new\sRegExp\(\/([\s\S]+)\/([a-z]*)\)$/)){if(o.length===3){try{e[n]=RegExp(o[1],o[2])}catch(a){console.log(a.message,a.stack,r)}}}}}o=null}function Q(e,t,n){var r=x(t)?t:null;Object.each(e,function(t,n){var r=typeof n;if(/^str|^fu/.test(r))e[t]={bind:n}});Object.each(e,function(t,i){var s=[],o=[],u,a=/\s?[,;]\s?/,f,l;if(i.recalc){if(S(i.recalc))s=i.recalc.split(a);else if(w(i.recalc))s=i.recalc;s=s.compact(true).unique()}if(s.length)e[t].recalc=s;if(null==i.bind)i.bind=function(){};if(i.watch){if(S(i.watch))o=i.watch.split(a);else if(w(i.watch))o=i.watch.slice(0);o=o.compact(true).unique();for(l=0;l2){h=H.css2json(h)}else i.push(r+(/\{/.test(h)?h:"{"+h+"}"))}if(w(h)&&h.length){for(a=0;a.my-form",d=h.template||"
",v=/\{/.test(d),m=h.hash||H.sdbmCode,g=h.id||H.sdbmCode,y=h.ext,b=h.delay||50,E=t.is("."+a),S=!!t.children(f).size(),x=[],T=[],N,C,k=Date.now();var L=E?t.find(t.sortable("option","items")):t.find(p);if(l(n)&&w(n)){if(S)return n;i=[];L.each(function(){var t=e(this),n=t.data("my");if(n)i.push(n.data)});o=false;if(i.length===n.length)for(o=true,r=0;r1.4*b||k-h.stamp>100||!h.stashed||h.stashed.length!==L.size()-(S?1:0)){if(S)C=t.find(">."+a+"-helper");L.each(function(t){var n=e(this),r,i,s,o=false;if(!S||!n.hasClass(a+"-helper")){if(S&&n.hasClass(a+"-placeholder"))n=C;r=n.data("my");i=n.data("formlist");if(r&&i){x.push(r.data);if(u!=i.index){i.index=u;o=!0}if(y){s=m(r.data,u)+"";if(s!==i.hash){i.hash=s;o=!0}}u+=1;if(o)T.push(n)}}});for(r=0;r."+i+"-placeholder",o=t.find(t.sortable("option","items")),u;if(l(n)&&w(n)){var f={},c={},h=n.unique();if(t.find("input:focus:eq(0),textarea:focus:eq(0)").size()||t.find(s).size())return h;o.each(function(){f[H.sdbmCode(H.extval(e(this)))]=e(this)});for(var p=h.length-1;p>=0;p--){var d=H.sdbmCode(h[p]);if(f[d]){f[d].prependTo(t).show();c[d]=true;if(r.indexOf(h[p])==-1)r.push(h[p])}}r=r.reverse();for(p in f)if(!c[p])f[p].hide()}else{var v=t.find(s),m=t.eq(0);if(v.size()!=0){if(m.my()[i]!=v.position().left+""+v.position().top){o=o.filter(":visible:not(:disabled, .ui-state-disabled, .ui-sortable-helper)");u=t.find(t.sortable("option","items")).filter(".ui-sortable-helper");o.each(function(){var t=e(this);if(t.is(".ui-sortable-placeholder")){r.push(H.extval(u))}else r.push(H.extval(t))});m.my()[i]=v.position().left+""+v.position().top;m.my()[i+"1"]=r}else r=m.my()[i+"1"];if(r==a)o.each(function(){r.push(H.extval(e(this)))})}else{o=t.find(t.sortable("option","items")).filter(":visible:not(:disabled, .ui-state-disabled)");o.each(function(){r.push(H.extval(e(this)))})}}return r},"input[type=date]":function(e,t){if(l(t)){if(t!="")n=Date.create(t).format(c);else n="";if(S(n)&&!/Invalid/.test(n))e.val(n);return n}var n=e.val();return n!=""?Date.create(n).format(c):""},"input[type=time]":function(e,t){if(l(t)){if(t!="")n=Date.create(t).format(h);else n="";if(S(n)&&!/Invalid/.test(n))e.val(n);return n}var n=e.val();return n!=""?Date.create(n).format(h):""},input:{"[type='text'],[type='number'],[type='search'],[type='hidden'],[type='password'],[type='button'],[type='range'],:not([type])":{".ui-slider-input":function(e,t){if(l(t))e.val(t).slider("refresh")},".tagstrip input.value":function(e,t){if(l(t))e.val(t).trigger("update")},"div.select2-container+input":function(e,t){if(l(t)&&JSON.stringify(t)!==JSON.stringify(e.select2("val")))e.select2("val",w(t)?t:[t]);return e.select2("val")},"":function(e,t){if(l(t))e.val(t+"")}},":radio":function(t,n){var r=-1;if(l(n)){t.each(function(t){var i=e(this).val();if(n+""===i+"")r=t});var i=t.eq(0).checkboxradio;if(i)t.each(function(t){var n=e(this);if(r!=t&&n.is(":checked"))n.prop("checked",false).checkboxradio("refresh")});if(r>-1){var s=t.eq(r);if(!s.is(":checked")){s.prop("checked",true);if(i)s.checkboxradio("refresh")}}else if(!i)t.each(function(){e(this).prop("checked",false)})}if(r==-1)for(var o=0;oForm init failed

',ru:'

Ошибка инициализации формы

'},badInput:{en:"Invalid input",ru:f},patternMismatch:{en:"Pattern mismatch",ru:"Не соответствует шаблону"},rangeOverflow:{en:"Over maximum",ru:"Больше максимума"},rangeUnderflow:{en:"Under minimum",ru:"Меньше минимума"},stepMismatch:{en:"Step mismatch",ru:"Не кратно шагу"},tooLong:{en:"Too long",ru:"Слишком длинно"},typeMismatch:{en:"Invalid type",ru:"Неверный тип"},valueMissing:{en:"Required",ru:"Обязательное поле"}},events:{".hasDatepicker":"change.my check.my",".my-form,.my-tags":"change.my check.my",".ui-slider":"slide.my check.my","div.redactor_box textarea":"redactor.my check.my",".my-codemirror":"codemirror.my check.my",".ace_editor":"ace.my check.my",".my-form-list":"sortupdate.my check.my",".ui-sortable":"sortchange.my sortupdate.my check.my",".ui-draggable":"drag.my dragstop.my check.my","a, .pseudolink, input[type=button], button":"click.my","img, :radio, :checkbox":"click.my check.my","div.select2-container+input,div.select2-container+select":"change.my check.my input.my",".ui-buttonset,input, select, textarea":"blur.my change.my check.my"+(navigator.appName.to(5)==="Micro"?" keyup.my":" input.my"),"":"check.my"},containers:{"*[data-role='fieldcontain'] *":{"input,textarea,select,button,:radio":function(e){return e.parents('[data-role="fieldcontain"]').eq(0)}},".tagstrip *.value":function(e){return e.parents(".tagstrip").eq(0)},"div.redactor_box textarea":function(e){return e.parents("div.redactor_box").eq(0).parent()},".my-tags,.hasDatepicker,.ui-widget,input,textarea,select,button":{".my-cleditor":function(e){return e.parents("div.cleditorMain").eq(0).parent()},"":function(t){var n=t[0].parentNode,r=n.nodeName;if(/^(div|span|a|p|form|fieldset|li|ul|td|th|h\d)$/i.test(r))return e(n);else return t.parents("div,span,a,p,form,fieldset,li,ul,td,th,h1,h2,h3,h4,h5,h6").eq(0)}},"":function(e){return e}},offon:{".ace_editor":function(e,t){ace.edit(t[0]).setReadOnly(e)},".ui-selectable":function(e,t){H.jquix(t,"selectable",e)},".ui-slider":function(e,t){H.jquix(t,"slider",e)},".ui-draggable":function(e,t){H.jquix(t,"draggable",e)},".ui-buttonset":function(e,t){H.jquix(t,"buttonset",e)},".hasDatepicker":function(e,t){H.jquix(t,"datepicker",e)},".my-form":function(e,t){t.my("disabled",!!e)},"div.select2-container+input,div.select2-container+select":function(e,t){H.jquix(t,"select2",e)},".my-cleditor":function(e,t){t.cleditor()[0].disable(!!e)},"":function(e,t){t.attr("disabled",!!e)}},destroy:{".hasDatepicker":function(e){e.datepicker("destroy")},".ui-slider":function(e){e.slider("destroy")},".ui-sortable":{".my-form-list":function(t){t.find(">.my-form").each(function(){e(this).my("remove")});t.removeClass("my-form-list");t.sortable("destroy")},"":function(e){e.sortable("destroy")}},".my-form-list":function(t){t.find(">.my-form").each(function(){e(this).my("remove")})},".ui-draggable":function(e){e.draggable("destroy")},".my-redactor-8":function(e){e.destroyEditor();e.removeClass("my-redactor-8")},"div.select2-container+input,div.select2-container+select":function(e){e.select2("destroy")},".my-form":function(e){e.my("remove")},textarea:{".my-codemirror":function(e){e[0].nextSibling.CodeMirror.toTextArea();e.removeClass("my-codemirror")}}}};P.params={container:function(e){return F(e,P.containers)(e)},change:a,recalcDepth:2,delay:0,strict:false,locale:f=(navigator.language||navigator.userLanguage||"en").substr(0,2),messages:Object.map(P.msg,function(e,t){return t[f]||t.en}),errorTip:".my-error-tip",errorCss:"my-error",animate:0,effect:function(e,t,n){if(t)return e.fadeIn(n);e.fadeOut(n)},remember:0,silent:false,history:{},historyDelay:100,loader:function(t,n){var r=e.Deferred(),i=A(t+"");if(i)r.resolve(i);else r.reject(null);return r.promise()},ajaxTimeout:1e4};var H=Z();H.require=B;var Y={init:function(t,n,i){function $(){if(!g.strict)K(y,true);h=o(true,h,Object.reject(y,["data"]));m=Q(o(true,{},y.ui||{}),h,g);l=Number.random(268435456,4294967295).toString(16);f=y.id||"my"+l;c=H.sdbmCode(f);h.id=f;g.form=W;if(y.params&&y.params.depth)g.recalcDepth=y.params.depth;for(b in h)if(C(h[b]))h[b].bind(h);if(y.error){if(S(y.error)){q=function(e,t){return y.error.assign(o({message:e+"",err:t+""},y))}}else if(C(y.error)){q=function(e,t){p=null;try{p=y.error(e,t)}catch(n){p=g.messages.initFailed}return p}}}o(W.data("my"),{id:f,cid:l,mid:c,errors:Object.extended(),ui:Object.extended(m),disabled:false,manifest:h,locFiles:[]});W.addClass("my-form");T="my-manifest-"+c;N="my-form-"+l;W.addClass(N+" "+T)}function Y(){if(h.style){E=G(W,h,T,N);if(E&&E[0].length){L=e("style#"+T);if(!L.size()){L=e('").appendTo(e("body"))}L.data("count",L.data("count")*1+1);W.data("my").style=L}if(E&&E[1].length){O=e("style#"+N);if(!O.size()){O=e('").appendTo(e("body"))}W.data("my").localStyle=O}}}function Z(){var t,n=e.Deferred(),i;i=D(h);if(S(i)){rt("Error decoding base64 to local Blob/URL",i);n.reject()}else{if(r)for(t=0;t*").clone();try{F=J(h,y.init,W,y)}catch(t){rt(S(t)?t:t.message,t.stack);return W}}if(k(F)){F.then(function(){tt()},function(e,t){rt(e,t)})}else tt();if(!_){if(!W.my())return rt("Internal error initializing controls",""),W;W.data("my").initial=o(true,{},v);if(e.mobile)e.mobile.changePage(e.mobile.activePage)}}function tt(){function n(n){if(!_){e[n]=j(W.find(n),a);t-=1;if(t<.5)nt(e)}}var e={},t=Object.size(m);W.addClass(R);Object.each(m,function(e){if(_)return;var t=W.find(e),r=X(t,W,m[e],e);if(k(r)){r.then(n.fill(e)).fail(function(t,n){rt("Error building "+e+", "+t,n)})}else if(!_)n(e)})}function nt(e){var t,n,r;for(var i in m){if(_)return;t=m[i];r=W.find(i);if(r.size()){try{n=I(v,a,t,r);if(n==a&&e[i]!=a&&n!==undefined)I(v,e[i],t,r)}catch(s){H.con("Transient fail linking "+i+" of form $('.my-form-"+l+"')",s.message,s.stack)}try{if(n!=a)j(r,n);r.eq(0).trigger("check.my")}catch(s){rt("Error linking "+i,s.message,s.stack)}}}W.removeClass(R);z=null;M.resolve(v)}function rt(e,t){var n;_=true;H.con("Form "+f+" failed to initialize: "+e,t);W.removeClass(R);n=q(e,t);if(S(n)||x(n)&&n.jquery)W.html(n);else if(n===true)W.html(z);if(!g.silent){if(!W.my().ddata){W.removeData("my");W.removeClass("my-form");if(L){if(L.data("count")=="1"){try{L.remove()}catch(r){}}else L.data("count",L.data("count")-1)}if(O){try{O.remove()}catch(r){}}}M.reject("Form "+f+" failed to initialize: "+e,t)}else M.resolve(v)}var s,u,f,l,c,h={},p,v={},m,g,y,b,w=[],E,T,N,L,O,M=e.Deferred(),_=false,F,q=function(){},R="my-form-init",U="std",z="";if(S(t)){s=A(t);if(s){if(x(i)&&x(n)){s=o(s,n);u=i}else u=n;U="repo"}else{M.reject("No manifest with id "+t+" found in repo.");return M.promise()}}else{s=t;u=n}if(!s)return this;if(x(u)&&U!="repo")y=o(true,{},s);else y=s;var W=this.eq(0),V=W.my();if(x(V)&&V.id&&V.ui){H.con("jQuery.my is already bind.",W);W.my("ui",y.ui);W.my(d,y.data);return M.resolve(W.my(d)).promise()}g=y.params||{};if(!g.strict){g=o(true,{},g);K(g)}g=o(true,{},P.params,g);M.fail(function(){W.removeClass(N+" "+T)});e.extend(W,M.promise());if(x(u)){v=H.patch(u,y.data||{});y.data=v}else v=y.data||{};h.data=v;W.data("my",{data:v,params:g,promise:M.promise(),locktill:0});W.addClass(R);B(y,g).then(function(){$();Z().then(function(){Y();et()})}).fail(function(e){$();rt("Linker of ‘require’ property failed.",e)});return W},redraw:function(e,t){var n=this,r=n.my();if(r&&r.ui){r.ui.each(function(t){var i=n.find(t);z(i,e?a:undefined,r.params.recalcDepth);if(!e){if(i.is(".my-form"))i.my("redraw");if(i.is(".my-form-list"))i.trigger("redraw");else i.trigger("check.my")}});if(!t&&e)n.trigger(y)}return n},data:function(e,t){var n=this;if(x(e)){n.my().data=H.overlap(n.my().data,e);this.my("redraw",t)}return n.my().data},errors:function(){var t=e(this).my().errors,n={};for(var r in t){if(t[r]&&S(t[r]))n[r]=t[r];if(x(t[r])&&Object.keys(t[r]).length)n[r]=t[r]}return n},valid:function(){var t=e(this).my().errors,n=0;for(var r in t){if(t[r]&&S(t[r]))n++;else if(x(t[r])&&Object.keys(t[r]).length)n++}return!n},reset:function(){try{H.kickoff(this.my().data,this.my().initial);this.my("redraw")}catch(e){return false}return true},id:function(e,t){if(S(e))return A(e,t);else{var n=this.my();return n&&n.id?n.id:a}},remove:function(e){var t=this,n,r,i,s,o,u,f,l;if(!this.my())return a;if(this.my().root&&!this.my().ddata)t=this.my().root;i=t.my();o=i.data;f=i.cid;l=i.mid;t.unbind(".my");if(n=i.style){if(n.data("count")=="1"){try{n.remove()}catch(c){}}else n.data("count",n.data("count")-1)}if(r=i.localStyle){try{r.remove()}catch(c){}}if(window.URL&&(s=i.locFiles)&&s.length){for(var h=0;h1&&h(n[1])){var i=n[0],s="",o,f,c,d,v=1,m,g,y,w;while(v'+(i?"<"+r.labelTag+' class="'+r.labelCss+'" '+(r.label?'style="display:inline-block;width:'+r.label+";margin-left:-"+r.label+'" ':"")+">"+i+"":"")+s+""}return e+s}return e}function E(e){var t=e;if(h(t)){t=t.split(/[\s,]/).compact(true)}if(l(t)){var n={};for(var r=0;r',inp:g+'text" {ext}/>',sli:g+'range" {ext}/>',dat:g+'date" {ext}/>',btn:g+'button" {ext}/>',div:"
{txt}
",spn:"{txt}",sel:"",mul:'',txt:"",err:' {txt}',msg:'
{txt}
',val:function(e){if(!l(e.vals))return"";var n=t({style:"",css:""},e);n.txt=e.vals.reduce(function(e,t){return e+'"+t+" "}," ");return'{txt}'.assign(n)},"":"<{_tag} {ext}>{txt}"},txt:{sel:function(e){if(!e.vals)return"";var t=E(e.vals);return Object.keys(t).reduce(function(e,n){return e+'"},"")}},params:{styles:{num:"width:30%;",dat:"width:30%;",inp:"width:100%",txt:"width:100%;max-width:100%;min-height:1px;word-break:break-word;",err:"display:none",msg:"display:none"},alias:{number:"num",date:"dat",slider:"sli",textarea:"txt",input:"inp",span:"spn",select:"select",vals:"val"},row:"",rowTag:"div",rowCss:"my-row",label:"",labelTag:"span",labelCss:"my-label"},defaults:{id:"","class":"",style:"",placeholder:"",value:"",rows:1},attnames:{css:"class",plc:"placeholder",val:"value",txt:"",vals:"",tip:"title"}};var x={init:function(t,n){return e(this).html(S(t,n))}};if(!e.my)e.my={};e.my.formgen=S;e.fn.formgen=function(t){if(h(t)&&x[t])return x[t].apply(this,Array.prototype.slice.call(arguments,1));else if(typeof t==="object"||!t)return x.init.apply(this,arguments);else e.error("Method "+t+" does not exist on jQuery.formgen")}})(jQuery);(function(e){function v(i){var s=window,o=s.innerHeight||e(s).height(),u=s.innerWidth||e(s).width(),a=n.height(),f=i||r.width();n.removeClass("loading").css({left:(u-f-60)/2+"px",width:f*1+60+"px",display:"block"});t.css({width:u*2+"px",height:o*2+"px",display:"block"});if(a>o){n.height(o);r.css({"overflow-y":$.browser.webkit?"overlay":"scroll"})}else{r.css({"overflow-y":"none"})}n.animate({top:(a>=o?0:(o-a)/3.5)+"px"},parseFloat(n.css("top")).my-modal").is(":visible")){o=true;if(f(h)||h===null||h===undefined){if(d(n.data("done")))g=n.data("done");else g=function(){return false};b=false;E=true;if(!h){if(!r.is(".my-form"))b=g(null,true);else{b=g(r.my("valid")?null:r.my("errors"),r.my("data"));if(!b)E=r.my("remove")}}else if(h===true&&u.state()!="rejected"){if(r.is(".my-form"))r.my("remove");g(null,null);u.reject("Cancelled")}if(!b){r.html("");n.css({display:"none"});(function(){if(!o)t.css({display:"none"})}).delay(5);$("body").css({overflow:"auto"});o=false;n.data("done",null);(function(){u.resolve(E)}).delay(0)}return}y=$.Deferred();g(null,null);y.reject("Locked");return y.promise()}u=$.Deferred();o=true;if(!n||!$(s).find(">.my-modal").size()){n=$('').prependTo($(s))}n.html('
');r=n.find(".my-modal-form");$('
×
').prependTo(n).on("click",function(){i.modal(true)});if(!t||!$(s).find(">.my-modal-screen").size()){t=$('').prependTo($(s)).on("click",function(){if(!r.is(".my-form")||r.data("escapable"))i.modal(true)})}if(typeof h=="object"&&h.jquery){if(h.is("img")){S=h.attr("alt")||h.attr("title")||h.data("text");r.html(function(){var t=h,n=t[0].naturalWidth||t[0].width,r=t[0].naturalHeight||t[0].height,i=e(window).width()-90,s=e(window).height()-90,o;if(s';T=n<300?300:n;return o}()+(S?'

'+S+"

":""));r.find("img").on("click",function(){i.modal()});n.css({top:"3000px",display:"block"});N=n.height();w=1}}else if(c(h)&&h.manifest){E=h.data||{};g=d(h.done)?h.done:g;T=1*($.my.f.getref(l(h.manifest)?$.my.cache(h.manifest):h.manifest,"params.width")||h.width||T);n.css({top:"3000px",display:"block",height:"none"});r.data("my",null);w=1;r.my(h.manifest,E).then(function(){v.delay(20);u.notify("Ready")}).fail(function(e){u.reject(e);w=0;i.modal(true)});n.data("done",g);r.data("escapable",!!h.esc);r.data("allowenter",!!h.enter);r.bind("commit.my",function(){i.modal()}.debounce(50)).bind("cancel.my",function(){i.modal(true)}.debounce(50)).bind("layout.my",function(){v()})}else if(l(h)){r.html(h);n.css({top:"3000px",display:"block",width:"auto"});T=1*(n.width()||T);w=1}else if(h===true){$("body").css({overflow:"auto"});o=false;return u.reject("Cancelled").promise()}else{$("body").css({overflow:"auto"});o=false;return u.reject("Invalid data").promise()}if(w){v(T);x=r.find("img").filter(function(){return $(this).attr("src")!=""});if(x.size()){var C=function(){v(m);u.notify("Ready")}.after(x.size());x.each(function(){$(this).bind("load",C)})}else{u.notify("Ready")}$("body").css({overflow:"hidden"})}return u.promise()};i.modal.loading=function(e){$(s).find(">.my-modal").toggleClass("my-modal-loading",!!e)};i.modal.parent=function(e){if(!e||!$(e).size())return $(s);s=e};i.modal.visible=function(){return o};if(!e.my)e.my={};e.my.modal=i.modal})(jQuery); +;(function(e){function A(e,t){return(t||"").split(".").reduce(function(e,t){if(null!=e&&null!=e[t])return e[t];else return undefined},e)}function O(e,t){var n,r;if(x(t))return t;else if(S(t)){n=A(e,t);if(null==n)n=Object.clone(s._src[t],true);if(null==n){n=A(s,t);if(x(n)&&x(n._self))n=Object.clone(n._self,true);else if(x(n))n=Object.clone(n,true)}if(null==n&&A(e,"params.cache")){r=A(e,"params.cache");if(C(r))n=r(t);else if(x(r))n=L(t,r);if(x(n)){if(x(n._self))n=Object.clone(n._self,true);Object.merge(n,{params:{cache:r}},true)}}if(null!=n&&x(n)){r=r||A(e,"params.cache");if(r)Object.merge(n,{params:{cache:r}},true);return n}else throw"Component "+t+" not found"}else if(C(t)){return t.apply(e,Array.prototype.slice.call(arguments,2))}else return null}function M(e,t){var n,r,o=t||s,u=e,a,f,l,c;if(!(x(o)&&x(u)&&x(u.ui)&&S(u.id)))return"Invalid arguments.";if(!o.hasOwnProperty("_src"))o._src={};f=u.id;try{u=Object.clone(e,true)}catch(h){return"Can't mount circular-referencing obj."}try{if(!u.params||u.params&&!u.params.strict)J(u,true)}catch(h){return"Invalid manifest, parse error."}n=_(u);if(S(n)){P.con(n);return n}Object.merge(u,{params:{strict:true}},true);o._src[f]=u;if(l=P.mask(o,f)){if(l.params&&l.params.protect)return"Can't mount on protected";if(l._self)delete l._self}Object.merge(o,P.unmask(u,f),true);c=A(o,f);if(i)c["_self"]=o._src[f];else Object.defineProperty(c,"_self",{get:function(){return o._src[f]},set:function(){throw"Can not change repo"},enumerable:false,configurable:true});return c}function _(e){var t,n=[],i;if(x(e.files)&&Object.size(e.files)){for(t in e.files){i=e.files[t];if(x(i)&&i.data&&!i.url){if(r){try{P.base642blob(i.data,function(e){i.blob=e;i.url=r.createObjectURL(i.blob)},i.content_type||i.mime);n.push(t)}catch(s){return"Invalid base64 data in files/"+t+"."}}else{i.url="data:"+(i.content_type||i.mime)+";base64,"+i.data;n.push(t)}}}}return n}function H(t,n){function E(t,n){var r;if(S(t)){if(/[\/]/.test(t)){r=o(true,{},g,{ref:n,ajax:{url:t}});if(b.test(n))r.ajax.dataType="json"}else if(t.length){r=o(true,{},g,{ref:n,ajax:t})}}else if(x(t)){r=o(true,{},g,{ref:n,ajax:e.extend(true,{},Object.select(t,["accepts","async","cache","data","dataType","password","timeout","type","url","username"]))});if(!r.ajax.url)r=null}return r}function T(){u.reject(l)}function N(){y+=1;var e=a[y];if(!e){var n=L(f),r=Object.keys(Object.findAll(n,function(e,t){return!t}));if(r.length)l.push((r.length===1?"Key "+r[0]+" is":"Keys "+r.join(", ")+" are")+" not present after all.");if(l.length)T();else u.resolve(t)}else C(e).then(N).fail(T)}function C(n){function h(){a-=1;if(s)u.reject();else if(a<.5)u.resolve()}var r,i,s=false,u=e.Deferred(),a=n.length,f,c;for(i=0;ir){n=l;r=o;return}else if(c==p)s(e,l,o+1)}if(a!=t[""]&&typeof t[""]!=p&&o>r){n=t[""];r=o}}var n=a,r=0,i="";s(e,t,1);return n}function F(e,t,n,r){var i,s=[],o,f,l,c=n.bind,h=u(c);if(h==g){return c.call(q(r).manifest,e,t,r)}if(h===m||h===v){if(h===m&&!/\./.test(c)){if(t!=a)e[c]=t;else if(e[c]===undefined)e[c]=a;return e[c]}if(h===m)s=c.split(".").each(function(e,t){this[t]=e+""});if(h===v)s=c.slice(0).each(function(e,t){this[t]=e+""});if(s[0]==="this"){o=q(r).manifest;s.shift()}else o=e;for(i=0;i-1?"":h;case"s":return n==s?"":h;case"o":return s[n]?"":h;case"b":{if(i.is(".my-form-list,.ui-sortable")){var d=i.data("listSrc")||i.data("my").listSrc||">*",v={};i.find(d).filter("*:not(.ui-sortable-placeholder)").each(function(t){var n=e(this);if(n.data("my")&&!n.my("valid"))v[t]=n.my("errors")});return v}else if(i.hasClass("my-form")){return!s?"":i.my("valid")?"":i.my("errors")}return""}}return l.formError||"Error"}return""}function q(e){var t=e.my();if(!t)return null;return t.root?t.root.my():t}function R(t,n,r){var i=r.compact(),s=i.replace(/:disabled/g,"");n.each(function(){var r=e(this),o=r.my(),u=o?o.container:r;if(t){if(!u.is(s))u.addClass(s)}else u.removeClass(s);if(s!=i&&o!==undefined&&!!t!=!!o.disabled){r.my().disabled=!!t;if(!o._disable)r.my()._disable=j(n,D.offon).fill(undefined,n);o._disable(!!t)}});return n}function U(e,t,n){var r,i,s,u,f,c,h,p,d,v,m,g=false,y=false,b=e,w=b.my(),E="";if(w){p=w.selector;d=w.root;if(d.hasClass("my-form-init"))return{};v=d.find(p);m=d.my().ui;g=e.hasClass("my-form");y=e.hasClass("my-form-list");if(g){r=e;i=w.ddata;s=w.dui;u=w.dparams}else{r=w.container;i=w.data;s=w.ui;u=w.params}if(s.bind!=a){if(l(t))f=t;else f=B(v,F(i,a,s,v));if(a!=s.check){E="Unknown error";try{E=I(i,f,s,v)}catch(x){P.con("Error "+x.message+" validating "+p,d,x.stack)}}var T=u.errorCss;var k="ui-state-error";try{if(a!=t)f=B(v,F(i,t,s,v))}catch(x){E=u.messages.formError||"Error"}if(E===""){if(!g)w.errors[p]="";else w.derrors[p]="";r.removeClass(T);if(r.attr("title"))r.attr("title","");if(!g&&!y)u.effect(r.find(u.errorTip),false,u.animate/2);b.removeClass(k);b.find(".ui-widget").removeClass(k)}else{if(g)w.derrors[p]=E;else if(y)w.errors[p]=E;else{r.addClass(T);w.errors[p]=E;var L=r.find(u.errorTip).eq(0);if(L.size()){u.effect(L.addClass(T).html(E),true,u.animate)}else r.attr("title",(E||"").stripTags())}if(b.is(".hasDatepicker")){if(b.is("input"))b.addClass(k);else b.find(".ui-widget").addClass(k)}if(b.is(".ui-slider"))b.addClass(k)}}var A=t==a?f:t;if(s.css){for(c in s.css){h=s.css[c];if(N(h))R(h.test(A),v,c);else if(C(h))R(h.call(d.my().manifest,i,A,v),v,c)}}var O,M=s.recalc,_=[],D={},H;if(n&&s.recalc&&d.my()){m=d.my().ui;for(O=0;O=f*2){d={};for(o=f;o=u.length)l=u.length-1;p=Object.clone(i.history[u[u.length-l-1]],true);if(n){d={};for(o=0;o$/.test(l.list))u=l.list;else a=l.list||a;if(!u){var h=t.find(a);u="
";if(h.size()){u=e(u).append(h.eq(0).clone(true)).html();h.eq(0).remove()}}if(!t.data("formlist"))t.data("formlist",{});t.data("formlist").generator={manifest:v,delay:(l.delay||f.delay||10)/1.3,template:u,selector:a,parent:m,bind:l.bind,hash:C(l.hash)?l.hash.bind(m):L(l.hash),id:C(l.id)?l.id.bind(m):L(l.id),ext:!!(l.id||l.hash),stamp:0};t.on("insert.my",function(t,n){t.stopPropagation();var r={what:undefined,where:0};if(null==n)r.where=1e6;else if(x(n))Object.merge(r,n);else if(S(n)||T(n))r.where=n;e(t.target).my("insert",r.where,r.what)});t.on("remove.my",function(t){t.stopPropagation();e(t.target).my("remove")})}else{try{n=t.my(O(m,v),x(o)?o:undefined)}catch(p){N("$.my subform init of "+i+" failed: "+p.message,p.stack)}}}if(k(n)){n.then(M,function(e,t){N("Init of subform "+i+" failed with error: "+e,t)})}else M()}function N(e,t){P.con(e,t);if(c)c.reject(e,t)}function L(e){var t=u(e).to(3);return!e?null:t==="str"?A.fill(undefined,e):t==="arr"?P.mask.fill(undefined,e):null}function M(){t.each(function(){var u=e(this),c,h,d=false,v=u[0].nextSibling;h=v&&v.CodeMirror?v.CodeMirror:null;if(h)u.addClass("my-codemirror");c=l.events||j(u,D.events);if(!u.is(".my-form")){u.data("my",{events:c,selector:i,initial:p,previous:p,root:n,container:f.container(u),id:s.id,ui:l,data:s.data,params:f,errors:s.errors});r._update=l.delay?U.debounce(l.delay):a;d=true}else{o(u.data("my"),{dui:l,root:n,selector:i,dparams:f,devents:c,ddata:s.data,container:f.container(u),derrors:s.errors})}if(d){if(u.cleditor&&u.parent().is(".cleditorMain")){var m=u.cleditor()[0];if(m&&m.$frame&&m.$frame[0]){u.addClass("my-cleditor");o(u.data("my"),{container:f.container(u)});var b=function(e){u.val(e).trigger(y)};var w,E=Number.random(1e5,1e6-1);e(m.$frame[0]).attr("id","cleditCool"+E);if(!document.frames)w=e("#cleditCool"+E)[0].contentWindow.document;else w=document.frames["cleditCool"+E].document;var S=e(w).find("body");e(w).bind("keyup.my",function(){b(e(this).find("body").html())});u.parent().find("div.cleditorToolbar").bind("click.my mouseup.my",function(){b(S.html())});e("body").on("click","div.cleditorPopup",function(){b(S.html())})}}else if(u.is("div.redactor_box textarea")){var x,T="my-redactor-9";try{x=u.getEditor();T="my-redactor-8"}catch(N){x=u.redactor("getEditor")}if(x){u.addClass(T);x.bind("input.my keyup.my blur.my",function(e){e.trigger("redactor")}.fill(u))}}else if(u.is(".ace_editor"))ace.edit(t[0]).on(y,function(e){e.trigger("ace")}.fill(u));else if(h){h.on(y,function(e){e.trigger("codemirror")}.fill(u))}}u.my()._changed=X.debounce(g);u.my()._recalc=V.debounce(g);u.bind(c,function(e){if(e.type==y)e.stopPropagation();if(d)s.locktill=Date.now()+r.delay;u.my()._changed(u,n,r,f)});if(!/check(\.my)?/.test(c+""))u.on("check.my",function(e){u.my()._changed(u,n,r,f,true);return false});u.on("recalc.my, redraw.my",function(e){e.stopPropagation();u.my()._recalc(u,n,r,f)})});if(c)c.resolve()}var s=n.my(),f=(s||{}).params,l=r,c=null,h,p,d=0,v,m=s.manifest,g;if(!s){P.con("Failed to find $root building "+i+" selector.");return null}g=r.delay;if(t.size()){if(l.init!=a)h=$(m,l.init,t,s);if(k(h)){d+=1;c=e.Deferred();h.then(E,function(e,t){N("Init of "+i+" failed: "+e,t)})}else E()}else P.con("Not found "+i+" selector.",n);return c}function X(e,t,n,r,i){var s=e.data("my"),o=t.data("my");if(s&&!s.disabled){z(s.ddata||s.data,s.dparams||s.params);var u=t.find(s.selector);U(e,!i?B(u,a):a,n.recalcDepth||r.recalcDepth);if(undefined===o.orphan){if(s.root.parent().hasClass("ui-sortable")){o.orphan=!s.root.parent().hasClass("my-form-list")}}if(o.orphan)s.root.parent().trigger("check");if(r.change)r.change.call(e)}}function V(e,t,n,r){var i=e.my();if(i&&!i.disabled){var s=t.find(i.selector);if(s.is(".my-form"))s.my("redraw");else U(e,s.is(".my-form-list")?A(s.my().data,s.data("formlist").generator.bind):a,n.recalcDepth||r.recalcDepth)}}function $(e,t,n,r){var i;if(S(t)){i=A(e,t);if(undefined===i){n.html(t.assign(r.data));return null}}else i=t;if(C(i))return i.apply(e,Array.prototype.slice.call(arguments,2));else if(w(i)){try{n.formgen(i)}catch(s){}}return null}function J(e,t){var n="",r,i="",s=!t,o=[];for(n in e)if(e.hasOwnProperty(n)&&(s||!/^(data|files|require)$/.test(n))){r=e[n];i=u(r);if(/^(ob|ar)/.test(i))J(r);else if(i==="string"&&/^(function\s\(|new\sRegExp)/.test(r)){if(o=r.match(/^function\s\(([^\)]*)\)\s*\{([\s\S]*)\}$/)){if(o.length===3){try{e[n]=Function(o[1],o[2])}catch(a){console.log(a.message,a.stack,r)}}}else if(o=r.match(/^new\sRegExp\(\/([\s\S]+)\/([a-z]*)\)$/)){if(o.length===3){try{e[n]=RegExp(o[1],o[2])}catch(a){console.log(a.message,a.stack,r)}}}}}o=null}function K(e,t,n){var r=x(t)?t:null;Object.each(e,function(t,n){var r=typeof n;if(/^str|^fu/.test(r))e[t]={bind:n}});Object.each(e,function(t,i){var s=[],o=[],u,a=/\s?[,;]\s?/,f,l;if(i.recalc){if(S(i.recalc))s=i.recalc.split(a);else if(w(i.recalc))s=i.recalc;s=s.compact(true).unique()}if(s.length)e[t].recalc=s;if(null==i.bind)i.bind=function(){};if(i.watch){if(S(i.watch))o=i.watch.split(a);else if(w(i.watch))o=i.watch.slice(0);o=o.compact(true).unique();for(l=0;l2){h=P.css2json(h)}else i.push(r+(/\{/.test(h)?h:"{"+h+"}"))}if(w(h)&&h.length){for(a=0;a.my-form",d=h.template||"
",v=/\{/.test(d),m=h.hash||P.sdbmCode,g=h.id||P.sdbmCode,y=h.ext,b=h.delay||50,E=t.is("."+a),S=!!t.children(f).size(),x=[],T=[],N,C,k=Date.now();var L=E?t.find(t.sortable("option","items")):t.find(p);if(l(n)&&w(n)){if(S)return n;i=[];L.each(function(){var t=e(this),n=t.data("my");if(n)i.push(n.data)});o=false;if(i.length===n.length)for(o=true,r=0;r1.4*b||k-h.stamp>100||!h.stashed||h.stashed.length!==L.size()-(S?1:0)){if(S)C=t.find(">."+a+"-helper");L.each(function(t){var n=e(this),r,i,s,o=false;if(!S||!n.hasClass(a+"-helper")){if(S&&n.hasClass(a+"-placeholder"))n=C;r=n.data("my");i=n.data("formlist");if(r&&i){x.push(r.data);if(u!=i.index){i.index=u;o=!0}if(y){s=m(r.data,u)+"";if(s!==i.hash){i.hash=s;o=!0}}u+=1;if(o)T.push(n)}}});for(r=0;r."+i+"-placeholder",o=t.find(t.sortable("option","items")),u;if(l(n)&&w(n)){var f={},c={},h=n.unique();if(t.find("input:focus:eq(0),textarea:focus:eq(0)").size()||t.find(s).size())return h;o.each(function(){f[P.sdbmCode(P.extval(e(this)))]=e(this)});for(var p=h.length-1;p>=0;p--){var d=P.sdbmCode(h[p]);if(f[d]){f[d].prependTo(t).show();c[d]=true;if(r.indexOf(h[p])==-1)r.push(h[p])}}r=r.reverse();for(p in f)if(!c[p])f[p].hide()}else{var v=t.find(s),m=t.eq(0);if(v.size()!=0){if(m.my()[i]!=v.position().left+""+v.position().top){o=o.filter(":visible:not(:disabled, .ui-state-disabled, .ui-sortable-helper)");u=t.find(t.sortable("option","items")).filter(".ui-sortable-helper");o.each(function(){var t=e(this);if(t.is(".ui-sortable-placeholder")){r.push(P.extval(u))}else r.push(P.extval(t))});m.my()[i]=v.position().left+""+v.position().top;m.my()[i+"1"]=r}else r=m.my()[i+"1"];if(r==a)o.each(function(){r.push(P.extval(e(this)))})}else{o=t.find(t.sortable("option","items")).filter(":visible:not(:disabled, .ui-state-disabled)");o.each(function(){r.push(P.extval(e(this)))})}}return r},"input[type=date]":function(e,t){if(l(t)){if(t!="")n=Date.create(t).format(c);else n="";if(S(n)&&!/Invalid/.test(n))e.val(n);return n}var n=e.val();return n!=""?Date.create(n).format(c):""},"input[type=time]":function(e,t){if(l(t)){if(t!="")n=Date.create(t).format(h);else n="";if(S(n)&&!/Invalid/.test(n))e.val(n);return n}var n=e.val();return n!=""?Date.create(n).format(h):""},input:{"[type='text'],[type='number'],[type='search'],[type='hidden'],[type='password'],[type='button'],[type='range'],:not([type])":{".ui-slider-input":function(e,t){if(l(t))e.val(t).slider("refresh")},".tagstrip input.value":function(e,t){if(l(t))e.val(t).trigger("update")},"div.select2-container+input":function(e,t){if(l(t)&&JSON.stringify(t)!==JSON.stringify(e.select2("val")))e.select2("val",w(t)?t:[t]);return e.select2("val")},"":function(e,t){if(l(t))e.val(t+"")}},":radio":function(t,n){var r=-1;if(l(n)){t.each(function(t){var i=e(this).val();if(n+""===i+"")r=t});var i=t.eq(0).checkboxradio;if(i)t.each(function(t){var n=e(this);if(r!=t&&n.is(":checked"))n.prop("checked",false).checkboxradio("refresh")});if(r>-1){var s=t.eq(r);if(!s.is(":checked")){s.prop("checked",true);if(i)s.checkboxradio("refresh")}}else if(!i)t.each(function(){e(this).prop("checked",false)})}if(r==-1)for(var o=0;oForm init failed

',ru:'

Ошибка инициализации формы

'},badInput:{en:"Invalid input",ru:f},patternMismatch:{en:"Pattern mismatch",ru:"Не соответствует шаблону"},rangeOverflow:{en:"Over maximum",ru:"Больше максимума"},rangeUnderflow:{en:"Under minimum",ru:"Меньше минимума"},stepMismatch:{en:"Step mismatch",ru:"Не кратно шагу"},tooLong:{en:"Too long",ru:"Слишком длинно"},typeMismatch:{en:"Invalid type",ru:"Неверный тип"},valueMissing:{en:"Required",ru:"Обязательное поле"}},events:{".hasDatepicker":"change.my check.my",".my-form,.my-tags":"change.my check.my",".ui-slider":"slide.my check.my","div.redactor_box textarea":"redactor.my check.my",".my-codemirror":"codemirror.my check.my",".ace_editor":"ace.my check.my",".my-form-list":"sortupdate.my check.my",".ui-sortable":"sortchange.my sortupdate.my check.my",".ui-draggable":"drag.my dragstop.my check.my","a, .pseudolink, input[type=button], button":"click.my","img, :radio, :checkbox":"click.my check.my","div.select2-container+input,div.select2-container+select":"change.my check.my input.my",".ui-buttonset,input, select, textarea":"blur.my change.my check.my"+(navigator.appName.to(5)==="Micro"?" keyup.my":" input.my"),"":"check.my"},containers:{"*[data-role='fieldcontain'] *":{"input,textarea,select,button,:radio":function(e){return e.parents('[data-role="fieldcontain"]').eq(0)}},".tagstrip *.value":function(e){return e.parents(".tagstrip").eq(0)},"div.redactor_box textarea":function(e){return e.parents("div.redactor_box").eq(0).parent()},".my-tags,.hasDatepicker,.ui-widget,input,textarea,select,button":{".my-cleditor":function(e){return e.parents("div.cleditorMain").eq(0).parent()},"":function(t){var n=t[0].parentNode,r=n.nodeName;if(/^(div|span|a|p|form|fieldset|li|ul|td|th|h\d)$/i.test(r))return e(n);else return t.parents("div,span,a,p,form,fieldset,li,ul,td,th,h1,h2,h3,h4,h5,h6").eq(0)}},"":function(e){return e}},offon:{".ace_editor":function(e,t){ace.edit(t[0]).setReadOnly(e)},".ui-selectable":function(e,t){P.jquix(t,"selectable",e)},".ui-slider":function(e,t){P.jquix(t,"slider",e)},".ui-draggable":function(e,t){P.jquix(t,"draggable",e)},".ui-buttonset":function(e,t){P.jquix(t,"buttonset",e)},".hasDatepicker":function(e,t){P.jquix(t,"datepicker",e)},".my-form":function(e,t){t.my("disabled",!!e)},"div.select2-container+input,div.select2-container+select":function(e,t){P.jquix(t,"select2",e)},".my-cleditor":function(e,t){t.cleditor()[0].disable(!!e)},"":function(e,t){t.attr("disabled",!!e)}},destroy:{".hasDatepicker":function(e){e.datepicker("destroy")},".ui-slider":function(e){e.slider("destroy")},".ui-sortable":{".my-form-list":function(t){t.find(">.my-form").each(function(){e(this).my("remove")});t.removeClass("my-form-list");t.sortable("destroy")},"":function(e){e.sortable("destroy")}},".my-form-list":function(t){t.find(">.my-form").each(function(){e(this).my("remove")})},".ui-draggable":function(e){e.draggable("destroy")},".my-redactor-8":function(e){e.destroyEditor();e.removeClass("my-redactor-8")},"div.select2-container+input,div.select2-container+select":function(e){e.select2("destroy")},".my-form":function(e){e.my("remove")},textarea:{".my-codemirror":function(e){e[0].nextSibling.CodeMirror.toTextArea();e.removeClass("my-codemirror")}}}};D.params={container:function(e){return j(e,D.containers)(e)},change:a,recalcDepth:2,delay:0,strict:false,locale:f=(navigator.language||navigator.userLanguage||"en").substr(0,2),messages:Object.map(D.msg,function(e,t){return t[f]||t.en}),errorTip:".my-error-tip",errorCss:"my-error",animate:0,effect:function(e,t,n){if(t)return e.fadeIn(n);e.fadeOut(n)},remember:0,silent:false,history:{},historyDelay:100,loader:function(t,n){var r=e.Deferred(),i=L(t+"");if(i)r.resolve(i);else r.reject(null);return r.promise()},ajaxTimeout:1e4};var P=Y();P.require=H;var G={init:function(t,n,i){function G(){if(!g.strict)J(y,true);h=o(true,h,Object.reject(y,["data"]));m=K(o(true,{},y.ui||{}),h,g);l=Number.random(268435456,4294967295).toString(16);f=y.id||"my"+l;c=P.sdbmCode(f);h.id=f;g.form=X;if(y.params&&y.params.depth)g.recalcDepth=y.params.depth;for(b in h)if(C(h[b]))h[b].bind(h);if(y.error){if(S(y.error)){q=function(e,t){return y.error.assign(o({message:e+"",err:t+""},y))}}else if(C(y.error)){q=function(e,t){p=null;try{p=y.error(e,t)}catch(n){p=g.messages.initFailed}return p}}}o(X.data("my"),{id:f,cid:l,mid:c,errors:Object.extended(),ui:Object.extended(m),disabled:false,manifest:h,locFiles:[],modals:{}});X.addClass("my-form");T="my-manifest-"+c;N="my-form-"+l;X.addClass(N+" "+T)}function Y(){if(h.style){E=Q(X,h,T,N);if(E&&E[0].length){A=e("style#"+T);if(!A.size()){A=e('").appendTo(e("body"))}A.data("count",A.data("count")*1+1);X.data("my").style=A}if(E&&E[1].length){O=e("style#"+N);if(!O.size()){O=e('").appendTo(e("body"))}X.data("my").localStyle=O}}}function Z(){var t,n=e.Deferred(),i;i=_(h);if(S(i)){rt("Error decoding base64 to local Blob/URL",i);n.reject()}else{if(r)for(t=0;t*").clone();try{I=$(h,y.init,X,y)}catch(t){rt(S(t)?t:t.message,t.stack);return X}}if(k(I)){I.then(function(){tt()},function(e,t){rt(e,t)})}else tt();if(!j){if(!X.my())return rt("Internal error initializing controls",""),X;X.data("my").initial=o(true,{},v);if(e.mobile)e.mobile.changePage(e.mobile.activePage)}}function tt(){function n(n){if(!j){e[n]=B(X.find(n),a);t-=1;if(t<.5)nt(e)}}var e={},t=Object.size(m);X.addClass(R);Object.each(m,function(e){if(j)return;var t=X.find(e),r=W(t,X,m[e],e);if(k(r)){r.then(n.fill(e)).fail(function(t,n){rt("Error building "+e+", "+t,n)})}else if(!j)n(e)})}function nt(e){var t,n,r;for(var i in m){if(j)return;t=m[i];r=X.find(i);if(r.size()){try{n=F(v,a,t,r);if(n==a&&e[i]!=a&&n!==undefined)F(v,e[i],t,r)}catch(s){P.con("Transient fail linking "+i+" of form $('.my-form-"+l+"')",s.message,s.stack)}try{if(n!=a)B(r,n);r.eq(0).trigger("check.my")}catch(s){rt("Error linking "+i,s.message,s.stack)}}}X.removeClass(R);z=null;M.resolve(v)}function rt(e,t){var n;j=true;P.con("Form "+f+" failed to initialize: "+e,t);X.removeClass(R);n=q(e,t);if(S(n)||x(n)&&n.jquery)X.html(n);else if(n===true)X.html(z);if(!g.silent){if(!X.my().ddata){X.removeData("my");X.removeClass("my-form");if(A){if(A.data("count")=="1"){try{A.remove()}catch(r){}}else A.data("count",A.data("count")-1)}if(O){try{O.remove()}catch(r){}}}M.reject("Form "+f+" failed to initialize: "+e,t)}else M.resolve(v)}var s,u,f,l,c,h={},p,v={},m,g,y,b,w=[],E,T,N,A,O,M=e.Deferred(),j=false,I,q=function(){},R="my-form-init",U="std",z="";if(S(t)){s=L(t);if(s){if(x(i)&&x(n)){s=o(s,n);u=i}else u=n;U="repo"}else{M.reject("No manifest with id "+t+" found in repo.");return M.promise()}}else{s=t;u=n}if(!s)return this;if(x(u)&&U!="repo")y=o(true,{},s);else y=s;var X=this.eq(0),V=X.my();if(x(V)&&V.id&&V.ui){P.con("jQuery.my is already bind.",X);X.my("ui",y.ui);X.my(d,y.data);return M.resolve(X.my(d)).promise()}g=y.params||{};if(!g.strict){g=o(true,{},g);J(g)}g=o(true,{},D.params,g);M.fail(function(){X.removeClass(N+" "+T)});o(X,M.promise());if(x(u)){v=P.patch(u,y.data||{});y.data=v}else v=y.data||{};h.data=v;X.data("my",{data:v,params:g,promise:M.promise(),locktill:0});X.addClass(R);H(y,g).then(function(){G();Z().then(function(){Y();et()})}).fail(function(e){G();rt("Linker of ‘require’ property failed.",e)});return X},redraw:function(e,t){var n=this,r=n.my();if(r&&r.ui){r.ui.each(function(t){var i=n.find(t);U(i,e?a:undefined,r.params.recalcDepth);if(!e){if(i.is(".my-form"))i.my("redraw");if(i.is(".my-form-list"))i.trigger("redraw");else i.trigger("check.my")}});if(!t&&e)n.trigger(y)}return n},data:function(e,t){var n=this;if(x(e)){n.my().data=P.overlap(n.my().data,e);this.my("redraw",t)}return n.my().data},errors:function(){var t=e(this).my().errors,n={};for(var r in t){if(t[r]&&S(t[r]))n[r]=t[r];if(x(t[r])&&Object.keys(t[r]).length)n[r]=t[r]}return n},valid:function(){var t=e(this).my().errors,n=0;for(var r in t){if(t[r]&&S(t[r]))n++;else if(x(t[r])&&Object.keys(t[r]).length)n++}return!n},reset:function(){try{P.kickoff(this.my().data,this.my().initial);this.my("redraw")}catch(e){return false}return true},id:function(e,t){if(S(e))return L(e,t);else{var n=this.my();return n&&n.id?n.id:a}},remove:function(e){var t=this,n,r,i,s,o,u,f,l;if(!this.my())return a;if(this.my().root&&!this.my().ddata)t=this.my().root;i=t.my();o=i.data;f=i.cid;l=i.mid;if(t.data("modals")){}t.unbind(".my");if(n=i.style){if(n.data("count")=="1"){try{n.remove()}catch(c){}}else n.data("count",n.data("count")-1)}if(r=i.localStyle){try{r.remove()}catch(c){}}if(window.URL&&(s=i.locFiles)&&s.length){for(var h=0;h1&&h(n[1])){var i=n[0],s="",o,f,c,d,v=1,m,g,y,w;while(v'+(i?"<"+r.labelTag+' class="'+r.labelCss+'" '+(r.label?'style="display:inline-block;width:'+r.label+";margin-left:-"+r.label+'" ':"")+">"+i+"":"")+s+""}return e+s}return e}function E(e){var t=e;if(h(t)){t=t.split(/[\s,]/).compact(true)}if(l(t)){var n={};for(var r=0;r',inp:g+'text" {ext}/>',sli:g+'range" {ext}/>',dat:g+'date" {ext}/>',btn:g+'button" {ext}/>',div:"
{txt}
",spn:"{txt}",sel:"",mul:'',txt:"",err:' {txt}',msg:'
{txt}
',val:function(e){if(!l(e.vals))return"";var n=t({style:"",css:""},e);n.txt=e.vals.reduce(function(e,t){return e+'"+t+" "}," ");return'{txt}'.assign(n)},"":"<{_tag} {ext}>{txt}"},txt:{sel:function(e){if(!e.vals)return"";var t=E(e.vals);return Object.keys(t).reduce(function(e,n){return e+'"},"")}},params:{styles:{num:"width:30%;",dat:"width:30%;",inp:"width:100%",txt:"width:100%;max-width:100%;min-height:1px;word-break:break-word;",err:"display:none",msg:"display:none"},alias:{number:"num",date:"dat",slider:"sli",textarea:"txt",input:"inp",span:"spn",select:"select",vals:"val"},row:"",rowTag:"div",rowCss:"my-row",label:"",labelTag:"span",labelCss:"my-label"},defaults:{id:"","class":"",style:"",placeholder:"",value:"",rows:1},attnames:{css:"class",plc:"placeholder",val:"value",txt:"",vals:"",tip:"title"}};var x={init:function(t,n){return e(this).html(S(t,n))}};if(!e.my)e.my={};e.my.formgen=S;e.fn.formgen=function(t){if(h(t)&&x[t])return x[t].apply(this,Array.prototype.slice.call(arguments,1));else if(typeof t==="object"||!t)return x.init.apply(this,arguments);else e.error("Method "+t+" does not exist on jQuery.formgen")}})(jQuery);(function(e){function d(t,n,r,i){var o,u,a,c,h,p,d;if(typeof n=="object"&&n.jquery){if(n.is("img")){p=n;h=n.attr("alt")||n.attr("title")||n.data("text")||"";u=p[0].naturalWidth||p[0].width;o=p[0].naturalHeight||p[0].height;if(o<1)o=1;if(u<1)u=1;c=e(window).width()-90;a=e(window).height()-90;if(a'+'

',ui:{"img:eq(0)":"img",h4:{bind:"text",css:{hide:function(e,t){return!t}}}}},data:{img:p.attr("src"),text:h},esc:true,screen:true,width:i||d,focus:false,global:true},r)}}else if(l(n)&&n.manifest){s(t,n,r)}else if(f(n)){s(t,{source:"html",manifest:{init:function(e){e.html(this.HTML)},HTML:n,ui:{"div:eq(0)":function(){}}},data:{},esc:true,focus:false,global:true,screen:true,width:i},r)}else return null;return t}var t={},n="body",r,i=false,s=e.extend,o={},u=Object.isArray,a=Object.isBoolean,f=Object.isString,l=Object.isObject,c=Object.isNumber,h=Object.isRegExp,p=Object.isFunction;e(document).keydown(function(e){var t=e.keyCode,n,r;if(false!==i&&(t===13||t===27)){r=i.data("modal");n=r.form;if(t==27&&(r.esc||Object.equal(n.data("my").initial,n.my("data")))){i.modal(true);return false}else if(t==13&&r.enter){i.modal.delay(50);return false}}});t.modal=function(r,s,o){var u={},a=e(n),f,l=a.find(">.my-modal-proxy"),c={global:true,screen:true,done:p(s)?s:undefined};if(i){return l.modal(r,s,o)}else{if(!l.size()){l=e('
').prependTo(a);l.css({position:"absolute",top:"0",left:"0",margin:"0",padding:"0",width:"1px",height:"0"})}if(d(u,r,c,o))return l.modal(u);else{var h=e.Deferred();return h.reject("Invalid data").promise()}}};t.modal.loading=function(t){e(n).find(">.my-modal").toggleClass("my-modal-loading",!!t)};t.modal.parent=function(t){if(!t||!e(t).size())return e(n);n=t};t.modal.parentBack=function(t){if(!t||!e(t).size())return e(r||n);r=t};t.modal.visible=function(){return!!i};if(!e.my)e.my={};e.my.modal=t.modal;e.fn.modal=function(t,u,c){function O(){var t=window,n,r,i=!!C.global,s=b.offset(),o=y.offset();C.pos={px:s.left,py:s.top,pw:b.outerWidth(),ph:b.outerHeight(),ox:o.left,oy:o.top,ow:y.outerWidth(),oh:y.outerHeight(),ww:r,wh:n};var u=(C.x.match(/\-?\d+(\.\d+)?/)||[0])[0]*1,a=(C.y.match(/\-?\d+(\.\d+)?/)||[0])[0]*1,f=C.x.has("left")?-1:C.x.has("right")?1:0,l=C.y.has("top")?-1:C.y.has("bottom")?1:0,c=C.pos.ox+C.pos.ow/2-C.pos.px,h=C.pos.oy+C.pos.oh/2-C.pos.py;if(i){C.pos.wh=n=t.innerHeight||e(t).height();C.pos.ww=r=t.innerWidth||e(t).width();c=r/2;h=n/2.5}u=C.x.has("%")?C.pos.ow/100*u:u;a=C.y.has("%")?C.pos.oh/100*a:a;C.pos.pix=c;C.pos.piy=h;c=c+f*(C.pos.ow/2)+u*(f>0?-1:1)-(C.width+S)*(f+1)/2;if(i){h=(n-C.height-20)/3;if(h<10)h=10}else{h=h+l*(C.pos.oh/2)+a*(l>0?-1:1)-((C.height||0)+x)*(l+1)/2}c=c.round(1);h=h.round(1);C.pos.vx=c;C.pos.vy=h}function _(t){if(!t){C.height=m.outerHeight();if(C.source!=="manifest")C.width=m.width();O()}m.css({left:C.pos.vx+"px",width:C.width+S+"px",display:"block"});if(C.screen){if(!C.global)w.css({top:0,left:0,position:"absolute",width:C.pos.pw+"px",height:C.pos.ph+"px",display:"block",background:f(C.screen)?C.screen:"rgba(40,80,120,0.5)","z-index":C.z-1});else{w.css({top:0,left:0,width:C.pos.ww*2+"px",height:C.pos.wh*2+"px",display:"block",position:"fixed","z-index":C.z-1});if(f(C.screen))w.css({background:C.screen?C.screen:"rgba(30,65,100,0.8)"})}}else if(w.size())w.hide();if(C.height>C.pos.wh){m.height(C.pos.wh-30);g.css({"overflow-y":e.browser.webkit?"overlay":"scroll"})}else{g.css({"overflow-y":"none"})}m.animate({top:C.pos.vy+"px",opacity:"1"},C.animate)}function D(){try{g.my("remove")}catch(t){}b.data("modals")[C.cid]=null;g.parent().unbind(".my").remove();w.off(".my"+C.cid).hide();if(C.global){i=false;e("body").css({overflow:"auto"})}}function P(e){try{T(null,null)}catch(t){}(function(){h.reject(e)}).delay(0)}var h=e.Deferred(),v={},m,g,y=this,b,w,E,S=0,x=0,T=p(u)?u:function(){return false},N=l(t)?t:{},C=y.data("modal"),k,L;s(y,h.promise());if(C){if(t==null||a(t)){g=C.form;w=C.bg;b=C.root;T=C.done;k=g.my("data");L=false;if(!t){try{L=T(g.my("valid")?null:g.my("errors"),k)}catch(A){}if(!L){D();y.removeData("modal");(function(){if(o[C.cid])o[C.cid].resolve(k);delete o[C.cid];C=null}).delay(0)}}else{try{T(null,null)}catch(A){}D();y.removeData("modal");if(o[C.cid])o[C.cid].reject("Cancelled");delete o[C.cid];C=null}return y}else if(N){P("Locked");return y}}if(!y.is(":visible")){P("Object must be visible");return y}if(!(N=d(v,t,{}))){P("Invalid data");return y}if(N.global&&i){P("Locked");return y}C=s({type:"DOM",source:"manifest",form:null,modal:null,root:null,bgroot:null,caller:y,global:false,drag:false,focus:true,manifest:{},data:{},nose:"",close:true,esc:false,enter:false,screen:false,width:c||300,height:null,x:"0",y:"0",z:"1997",css:"",animate:200},N,{promise:h.promise(),cid:Number.random(268435456,4294967295).toString(16)});C.done=p(C.done)?C.done:T;if(f(C.align)&&C.align){C.x=(C.align.match(/(left|right):\-?\d+(\.\d+)?(%|px)?/g)||["0"])[0];C.y=(C.align.match(/(top|bottom):\-?\d+(\.\d+)?(%|px)?/g)||["0"])[0]}C.width=1*(e.my.f.getref(f(C.manifest)?e.my.cache(C.manifest):C.manifest,"params.width")||C.width);C.type="DOM";if(y.hasClass("my-form")){C.type="form";C.root=C.root||y}else if(y.data("my")){C.type="control";C.root=C.root||y.my().container}else{C.root=C.root||y.parents(".my-form").eq(0);if(!C.root.size())C.root=e(n)}if(C.global){C.root=e(n);C.bgroot=e(r||n)}else C.bgroot=C.root;b=C.root;if(!b.data("modals"))b.data("modals",{});O();m=e('
').prependTo(C.root);m.addClass("my-modal-"+C.cid);S=m.outerWidth();x=m.outerHeight();m.hide();m.html('
');g=m.find(".my-modal-form");if(C.close){E=e(f(C.close)?C.close:'
×
').prependTo(m).on("click.my",function(){y.modal(true)});E.css({"z-index":""+(C.z*1+1)})}w=C.bgroot.find(">.my-modal-screen");if(C.screen){if(!w.size()){w=e('').prependTo(C.root)}if(C.esc)w.on("click.my"+C.cid,function(){y.modal(true)})}y.data("modal",C);m.css({position:C.global?"fixed":"absolute",left:C.pos.vx+"px",top:C.pos.vy+"px",display:"block",height:"none",opacity:"0.005","z-index":C.z,width:"auto"});g.my(C.manifest,C.data).then(function(){var t,n,r,u,a;s(C,{form:g,bg:w,cancel:function(){y.modal(true)},commit:function(){y.modal()}});m.data("modal",C);C.height=m.outerHeight();if(C.source!=="manifest")C.width=m.width();O();m.css({top:C.pos.vy+"px"});_(true);b.data("modals")[C.cid]=C;o[C.cid]=h;g.bind("commit.my",function(){C.commit.delay(50);return false}).bind("cancel.my",function(){C.cancel.delay(50);return false});m.bind("layout.my",function(){_()}.debounce(50));if(C.global){i=y;e("body").css({overflow:"hidden"})}if(!C.global&&(C.esc||C.enter)){g.bind("keydown.my",function(e){var t=e.keyCode;if(t==27&&C.esc){C.cancel();return false}else if(t==13&&C.enter){C.commit.delay(50);return false}})}if(C.focus===true){u=false;a=C.manifest.ui;for(r in a){if(!u){n=g.find(r);if(n.size()&&n.is("input, textarea")){u=true;n.focus()}}}}else if(f(C.focus))g.find(C.focus).focus();t=g.find("img").filter(function(){return e(this).attr("src")!=""});if(t.size()){var l=function(){if(C.source!=="manifest")m.css({width:"auto"});_()}.after(t.size());t.each(function(){e(this).bind("load",l)})}if(C.drag&&e.fn.draggable){if(!f(C.drag))m.draggable();else m.draggable({handle:C.drag})}h.notify("Ready")}).fail(function(e){D();y.data("modal",null);h.reject(e)});return y}})(jQuery); diff --git a/my.jquery.json b/my.jquery.json index 986295f..f842259 100644 --- a/my.jquery.json +++ b/my.jquery.json @@ -5,7 +5,7 @@ "keywords": [ "ui", "form", "validation", "data-binding" ], - "version": "1.0.0", + "version": "1.0.2", "author": { "name": "ermouth", "url": "https://github.com/ermouth" diff --git a/package.json b/package.json index 07d07c4..3efa576 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquerymy", - "version": "1.0.0", + "version": "1.0.2", "description": "jQuery plugin that binds HTML with JS objects in real-time.", "homepage": "http://jquerymy.com/", "author": "ermouth ",