Skip to content

Commit

Permalink
1.1.9
Browse files Browse the repository at this point in the history
Minor bug fix
  • Loading branch information
ermouth committed Sep 10, 2015
1 parent 02927c9 commit 00b6c40
Show file tree
Hide file tree
Showing 8 changed files with 4,330 additions and 80 deletions.
4,206 changes: 4,206 additions & 0 deletions Release/1.1/jquerymy-1.1.9.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Release/1.1/jquerymy-1.1.9.min.js

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions Release/jquery.my.last.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquerymy",
"version": "1.1.8",
"version": "1.1.9",
"description": "A lightweight jQuery plugin for complex two-way data binding in real time.",
"main": "./jquerymy.js",
"authors": [
Expand Down
179 changes: 110 additions & 69 deletions jquerymy.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
/*
* jQuery.my 1.1.8
* jQuery.my 1.1.9
* Requires jQuery 1.11.0+, SugarJS 1.3.9-1.4.x
*
* — Form can change own .error prop at runtime if it‘s a string in manifest
*
* — .tojson update – named functions and functions with comments in arg
* list or between () and {} body are jsonned correctly
*
* — .unjson update – named function strings now supported,
* they are parsed to functions that retain original names
*
* — _getref now can receive array as a path,
* also items.id=123.data queries are now supported
*
* — Auto-recalc of styles on window resize only
* touches visible forms
*
* — Implemented forced restyle of a form and all its
* childs, $o.my("restyle", skipChilds)
*
* — Modal starting drag deletes its nose, if it was any
* — js2txt removes 'anonymous' name from functions
* — $.my.f.unmask receives 3 args as well as 2
* — modal positioned correctly in scrollable container
* — lists redrawn are rebuild to be bound with objects newly passed
* — ... it means undo works on lists without bugs.
*
* More details at jquerymy.com
*
* (c) @ermouth, thanks @carpogoryanin, @ftescht
* 2015-07-17
* 2015-09-10
*/

;(function ($) {var _version = "jQuery.my 1.1.8";
;(function ($) {var _version = "jQuery.my 1.1.9";

// Some shortcuts and constants
var lang = "en",
Expand Down Expand Up @@ -193,14 +180,17 @@

id = obj.id;


//path = id.split(".");

try {obj=Object.clone(obj0, true);}
catch (e) {return "Can’t save circular-referencing object into cache.";}
try {
obj=Object.clone(obj0, true);
}
catch (e) {
return "Can’t save circular-referencing object into cache.";
}

//unwind string defs of functions
try {if (!obj.params || (obj.params && !obj.params.strict)) _unjson(obj, true);}
try {
if (!obj.params || (obj.params && !obj.params.strict)) _unjson(obj, true);
}
catch (e) {
return "Invalid manifest, parse error.";
}
Expand All @@ -218,7 +208,7 @@
root._src[id] = obj;


if (prev=f.mask(root, id)) {
if (prev = f.mask(root, id)) {
if (prev.params && prev.params.protect) return "Can’t save manifest into cache over protected one.";
else {
// Remove prev version
Expand Down Expand Up @@ -351,7 +341,7 @@

".my-form-list": function ($o,list) {
//object is list of forms
var i,old,mod,eq,ctr = 0,
var i,old,xold,mod,eq,ctr = 0,
sP = "ui-sortable", sPlc= "."+sP+"-placeholder",
od = $o.data("formlist")||{},
gen = od.generator||{},
Expand All @@ -374,14 +364,20 @@
// 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);
old= []; xold={};
$c.each(function (i) {
var $x = $(this), xd = $x.data("my"), dd;
if (xd) {
old.push(xd.data);
if (dd = $x.data("formlist")) {
xold[dd.oid] = xd.data;
}
}
});

//fast compare
eq=false;
if (old.length===list.length) for (eq=true, i=0;i<old.length;i++) if (old[i]!==list[i]) eq=false;
if (old && old.length===list.length) for (eq=true, i=0;i<old.length;i++) if (old[i]!==list[i]) eq=false;

if (!eq || extHasher){
// more comprehemsive compare, for example
Expand All @@ -405,7 +401,7 @@
var $x = $(this),
md = $x.data("formlist")||{},
coid = md.oid;
if (coid && xoid.hasOwnProperty(coid)) present[coid] = $(this);
if (coid && xoid.hasOwnProperty(coid) && list[xoid[coid]] === xold[coid]) present[coid] = $(this);
else {
if ($x.is(".my-form")) $x.my("remove", true);
else $x.remove();
Expand Down Expand Up @@ -445,9 +441,11 @@
for (i=0;i<redraw.length;i++) _redraw(redraw[i]);
redraw = [];
}
old=xold=mod=null;
return result;
}
}
xold=mod=null;
return old;

} else if ($c.size()) {
Expand Down Expand Up @@ -1288,7 +1286,7 @@
}

switch(T(pat).to(1)){
case "f": /*return pat.call(_form($formNode).manifest, data, val, $formNode);*/{
case "f": {
ret = pat.call(_form($formNode).manifest, data, val, $formNode);
return (ret === null || ret === undefined) ? "" : ret;
}
Expand Down Expand Up @@ -1363,7 +1361,7 @@
function _update ($o, value, depth) {
//validates and updates field and all dependent fields,
//applies conditional formatting
var $box, d, oui, p, val, css, oc,
var i, $box, d, oui, p, val, css, oc,
selector, $root, $we, ui,
isForm = false, isList = false,
$this = $o,
Expand Down Expand Up @@ -1675,11 +1673,14 @@
var $this = $(this),
events,
cm, isControl = false,
ns = $this[0].nextSibling;
ns;

//codemirror fix
cm = ( ns && ns.CodeMirror)?ns.CodeMirror:null;
if (cm) $this.addClass("my-codemirror");
if ($this[0].nodeName == "TEXTAREA") {
ns = $this[0].nextSibling;
cm = ( ns && ns.CodeMirror)?ns.CodeMirror:null;
if (cm) $this.addClass("my-codemirror");
}

//get events
events = ui.events||_traverse($this, MY.events);
Expand Down Expand Up @@ -1751,9 +1752,6 @@

//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();
Expand Down Expand Up @@ -1801,9 +1799,10 @@
});

//bind events to the control
if (!isControl) $this.off("redraw.my");
$this.on("recalc.my, redraw.my", function (evt) {
evt.stopPropagation();
$this.my()._recalc($this,$root,uiNode,p);
$this.my()._recalc($this, $root, uiNode, p);
});
});

Expand Down Expand Up @@ -2009,7 +2008,7 @@
//======================================

function _sa2obj (src){
var a = src, r={};
var i, a = src, r={};
if (isS(a)) a=a.split(/[,\s]+/);
if (isA(a)) {
a=a.compact(true);
Expand Down Expand Up @@ -2111,15 +2110,15 @@

if (!data0) return this;

if (isO(defaults) && mode!="repo") data = $E(true,{},data0);
if (isO(defaults) && mode!="repo") data = $E(true, {}, data0);
else data = data0;

var $root = this.eq(0), rd=$root.my();
var $root = this.eq(0), rd = $root.my();

if (isO(rd) && rd.id && rd.ui) {
_CON ("jQuery.my is already bound.", $root);
$root.my("ui",data.ui);
$root.my(Da,data.data);
$root.my("ui", data.ui);
$root.my(Da, data.data);
return pi.resolve($root.my(Da)).promise();
}

Expand Down Expand Up @@ -2164,7 +2163,8 @@
f.require(data, p)
.then(function(){
_makeup();
_files().then(function(){
_files()
.then(function(){
_styler();
_runInit();
});
Expand Down Expand Up @@ -2478,6 +2478,10 @@
}
}
$root.removeClass(initCss);
$root.on("recalc.my, redraw.my", function (evt) {
evt.stopPropagation();
$root.my("redraw");
});
backup=null;
pi.resolve(d);
}
Expand Down Expand Up @@ -3008,9 +3012,7 @@
switch((typeof w).substr(0,3)){
case 'str': return fj(w);case'num':return isFinite(w)?''+String(w)+'':'null';
case 'boo': case'nul':return String(w);
case 'fun': return fj(
_cleanFn(w.toString())
);
case 'fun': return fj( _cleanFn(w.toString()) );
case 'obj': if(!w) return'null';
if (typeof w.toJSON===Fu) return s4(w.toJSON(),ctab+(tab?1:0),tab);
a=[];
Expand All @@ -3033,7 +3035,7 @@
a = s.split(splitter,1),
head = a[0].from(8).replace(/[\s\n\t]+?|\/\/*.*?\*\/|\/\/[^\n]*\n/g,'')+")",
tail = "{"+s.from(a[0].length).replace(splitter,'').replace(/[^\}]+$/,'');
return "function "+head +" "+tail;
return ("function "+head).replace(/^function\sanonymous/,"function ") +" "+tail;
}

})(),
Expand Down Expand Up @@ -3068,32 +3070,69 @@
return dest;
}
},
"unmask": function (src, mask) {
"unmask": function (A1,A2,A3) {
// unfolds masked into obj
var res={};
// unmask ( {x:1, y:{}}, [{z:5},3], ["m.n","y.z"]) => {x:1, m:{n:{z:5}, y:{z:3}}},
// unmask ([1,2,3],["x","a.b","a.c"]) => {x:1, a:{b:2, c:3}}
// modifies dest

var dest, src, mask;

if (null==A3) dest = {}, src = A1, mask = A2;
else dest = A1, src = A2, mask = A3;

if (isO(src) && isO(mask)) return f.mask(src,mask);
else if (isA(src) && isA(mask)) {

if (isS(mask)) { mask = [mask]; src= [src]; }

if (!isA(mask) || !(isA(dest) || isO(dest))) return null;

if (isO(src)) {
src = mask.reduce(function(vals, path){
vals.push(_getref(src,path));
return vals;
},[]);
}

if (isA(src) && isA(mask)) {
for (var i=0;i<mask.length;i++) {
if (src[i]!=null) _blow(res, src[i], mask[i]);
if (src[i]!=null) _blow(dest, src[i], mask[i]);
}
return res;
} else if (isS(mask)) return _blow({}, src, mask);
return dest;
}
else return null;

//- - -
function _blow(data, src, ref) {
var ptr, path, preptr, val=Object.clone(src,true), i=0;

function _blow (data, val, ref) {
var ptr, path, preptr, i=0;
if (!/\./.test(ref)) {
//ref is flat
if (null!=src) data[ref] = val;
if (null != val) data[ref] = val;
} else {
path = ref.split(".").each(function (a,i){this[i]=String(a).compact();});
path = ref.split(".").each(function (a,i){ this[i] = String(a).compact(); });
ptr = data;
for (;i<path.length;i++) {
if (i===path.length-1) ptr[path[i]] = val; //we'r in the hole
if (i===0) ptr = data[path[0]], preptr= data;
else preptr = preptr[path[i-1]], ptr = ptr[path[i]];
if (undefined===ptr) ptr = preptr[path[i]] = {};
else {
if (i===0) {
ptr = data[path[0]];
preptr= data;
}
else {
preptr = preptr[path[i-1]];
ptr = ptr[path[i]];
}
if (
null == ptr
|| !(isO(ptr)
|| !(
isA(ptr)
&& !isNaN(path[i+1])
&& +path[i]>-1)
)
) ptr = preptr[path[i]] = {};
}
}
}
return data;
Expand Down Expand Up @@ -3405,7 +3444,7 @@

//#############################################################################################

/* jQuery.my.modal 1.1.2
/* jQuery.my.modal 1.1.3
* Requires Sugar 1.4.~, jQuery 1.11+, $.my 1.0.0+
*
* Modal dialog constructor/manager.
Expand Down Expand Up @@ -3968,7 +4007,9 @@

var W = window, h, w,
isfs = !!m.global,
ro = $r.offset(), oo = $o.offset();
ro = $r.offset(),
oo = $o.offset(),
rs = $r.scrollTop();

m.pos = {
px: ro.left, py: ro.top,
Expand Down Expand Up @@ -4014,7 +4055,7 @@
- ((m.height||0)/*+pady*/)*(sy+1)/2;
}

vx = vx.round(1); vy = vy.round(1);
vx = vx.round(1); vy = (vy+rs).round(1);

m.pos.vx = vx; m.pos.vy = vy;

Expand Down
7 changes: 3 additions & 4 deletions jquerymy.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion my.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": [
"MVVM", "framework", "ui", "form", "validation", "data binding"
],
"version": "1.1.8",
"version": "1.1.9",
"author": {
"name": "ermouth",
"url": "https://github.com/ermouth"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquerymy",
"version": "1.1.8",
"version": "1.1.9",
"description": "A lightweight jQuery plugin for complex two-way data binding in real time.",
"homepage": "http://jquerymy.com/",
"author": "ermouth <[email protected]>",
Expand Down

0 comments on commit 00b6c40

Please sign in to comment.