Skip to content

Commit

Permalink
1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ermouth committed Apr 17, 2015
1 parent f93ee14 commit 3ddaa6f
Show file tree
Hide file tree
Showing 8 changed files with 4,154 additions and 74 deletions.
4,045 changes: 4,045 additions & 0 deletions Release/1.1/jquerymy-1.1.3.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Release/1.1/jquerymy-1.1.3.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Release/jquery.my.last.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jquerymy",
"version": "1.1.0",
"description": "jQuery plugin that binds HTML with JS objects in real time.",
"version": "1.1.3",
"description": "A lightweight jQuery plugin for complex two-way data binding in real time.",
"main": "./jquerymy.js",
"authors": [
"ermouth <[email protected]>",
Expand Down Expand Up @@ -33,7 +33,7 @@
"Release/**"
],

"license": "GPL-3.0",
"license": "MIT",
"scripts": [
"./jquerymy.js"
]
Expand Down
147 changes: 87 additions & 60 deletions jquerymy.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
/*
* jQuery.my 1.1.0
* jQuery.my 1.1.3
* Requires jQuery 1.11.0+, SugarJS 1.3.9-1.4.x
*
* $.my changes:
* — .radio and ui.#ctrl.listen pubsub functionality
* — new 'radio' event for pubsub
* — .inherit and .expose manifest properties
* — .die function, called on form disband
*
* Modal changes:
* — param .bound (default:false) if set to number defines how far must
* modal be kept from root bounds
* – nose is always aligned to callee
* — Unjson recognizes functions with trailing spaces
* — Fixed manifest versions weird interference on cache updates
* — Fixed issue with Chrome Function.toString for anonymous fns
* — $.my.ajax(newAjaxFn) allows to replace internal ajax
*
* More details at jquerymy.com
*
* @ermouth, thanks @carpogoryanin, @ftescht
* 2015-01-12
* 2015-04-17
*/

;(function ($) {var _version = "jQuery.my 1.1.0";
;(function ($) {var _version = "jQuery.my 1.1.3";

// Some shortcuts and constants
var lang = "en",
Expand Down Expand Up @@ -64,7 +58,6 @@
} else if (isO(A1)){
obj = _putmanifest (A1, A2);
if (!isO(obj)) {
console.log(obj);
return null;
}
return obj;
Expand All @@ -74,10 +67,14 @@
return Object.reject(forms,/^_/);
}else return null;
};

// - - - - - - - - - - - - - - - - - - - -

var _ajax = $.ajax;

// - - - - - - - - - - - - - - - - - - - -

function _getref(obj,ref) {
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];
Expand Down Expand Up @@ -143,7 +140,7 @@

//Returns direct link to entire branch obj or string error.

var i, file, root=root0||forms, obj=obj0, path, id, prev, res;
var i, j, keys, file, root=root0||forms, obj=obj0, path, id, prev, res;

if (!(isO(root) && isO(obj) && isO(obj.ui) && isS(obj.id)))
return "Invalid arguments.";
Expand Down Expand Up @@ -178,27 +175,55 @@


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);
//}
if (prev.params && prev.params.protect) return "Can’t mount on protected.";
else {
// Remove prev version
if (prev._self) delete prev._self;
$.extend(!0, root, f.unmask("",id));
}
}

// Mount new version
$.extend (!0, root, f.unmask(obj, id));

// Re-mount sub-manifests if any
keys = Object
.keys(root._src)
.filter(function(e){
return e.startsWith(id+'.');
});
keys.sort();
keys.forEach(function(id){
var prev;
if (prev=f.mask(root, id)) {
// Remove subform if any
if (prev._self) delete prev._self;
$.extend (!0, root, f.unmask("",id));
}
// Re-mount version from repo
$.extend (!0, root, f.unmask(root._src[id], id))
});

// Mount _self link to uncompiled manifest
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";},
set: function () { throw "Can not change repo.";},
enumerable : false,
configurable : true
});

// End manifest

return res;
}


function _files2urls (obj) {
// Unwinds base64 representations of attached binaries
// into Blobs and objectURLs
var i, flist = [], file;
if (isO(obj.files) && Object.size(obj.files)) {
//blobify files
Expand Down Expand Up @@ -651,7 +676,7 @@
"":function ($o,v) {if(n(v)) $o.val(v+"");}
},

/**/ "fieldset,form,section,aside,.my-container": function ($o, v) {
/**/ "fieldset,form,section,footer,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(),
Expand Down Expand Up @@ -741,8 +766,8 @@
},


//different controls' events to watch for
//########################################################
// Different controls events to watch for
// ########################################################

events: {
".hasDatepicker":"change.my check.my",
Expand All @@ -762,8 +787,8 @@
"":"check.my"
},

//functions retrieving container for different controls
//########################################################
// Functions retrieving container for different controls
// ########################################################

containers: {
"*[data-role='fieldcontain'] *":{ //jQuery Mobile
Expand Down Expand Up @@ -791,8 +816,8 @@

},

//disablers and enablers
//########################################################
// Disablers and enablers
// ########################################################

offon: { //if x==true disables control else enables
".ace_editor": function (x,$o) {ace.edit($o[0]).setReadOnly(x);},
Expand All @@ -808,8 +833,8 @@
"": function (x, $o) {$o.attr("disabled", !!x);}
},

//destructors
//########################################################
// Destructors
// ########################################################
destroy:{
".hasDatepicker":function ($o){$o.datepicker("destroy");},
".ui-slider":function ($o){$o.slider("destroy");},
Expand Down Expand Up @@ -846,8 +871,8 @@
}
};

//default values for .params section of manifest
//########################################################
// Default values for .params section of manifest
// ########################################################

MY.params = {
container:function ($o) { // container getter
Expand Down Expand Up @@ -880,7 +905,6 @@
};

var f = _getHelpersLib();
f.require = _require;



Expand Down Expand Up @@ -917,7 +941,7 @@
//=======================================
// Require

function _require(man ,params0){
function _require(man, params0){
// Checks and loads required libs,
// returns promise resolved with manifest
// or rejected with err list.
Expand Down Expand Up @@ -992,7 +1016,12 @@
row = $E(true,{}, Row, {ref:j, ajax:$.extend(
true,
{},
Object.select( line, ["accepts","async","cache","data","dataType","xhrFields", "password","timeout","type","url","username"]
Object.select(
line,
[
"accepts","async","cache","data","dataType","xhrFields",
"password","timeout","type","url","username","headers"
]
)
)});
if (!row.ajax.url) row = null;
Expand Down Expand Up @@ -1031,11 +1060,10 @@
var row, i, stop = false,
pi = $.Deferred(),
ctr = chunk.length,
loader,script;
loader;
for (i=0;i<ctr;i++) {
row = chunk[i];
loader = isS(row.ajax)?params.loader:$.ajax,
script = isO(row.ajax) && /\.js$/i.test(row.ajax.url);
loader = isS(row.ajax)?params.loader:_ajax;
loader(row.ajax)
.then(function(data, row){
if (rthis.test(row.ref)) {
Expand All @@ -1047,7 +1075,7 @@
}
}
countdown();
}.fill(undefined, row)/*.debounce(script?100:0)*/)
}.fill(undefined, row))
.fail(function(e, row){
err.push('Failed to load ‘'+row.ref+'’ resource.');
stop = true;
Expand Down Expand Up @@ -1797,20 +1825,20 @@
//=======================================

function _unjson (node, exclude){
//recursively unwinds string def of funcs and regexps, modifies source obj!
// 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]*)\}$/)) {
else if (t==="string" && /^(function\s*\(|new\sRegExp)/.test(nd)) {
if (a = nd.match(/^function\s*\(([^\)]*)\)\s*\{([\s\S]*)\}[\s\n\r\t]*$/)) {
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]*)\)$/)) {
else if (a = nd.match(/^new\sRegExp\s*\(\/([\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); }
Expand All @@ -1826,8 +1854,8 @@
//=======================================

function _normalize (ui, manifest0, p) {
//unwinds ui recalcs, short defs and watch hooks, modifies source obj!
//move shorthand binds to bind attr
// Unwinds ui recalcs, short defs and watch hooks, modifies source obj!
// Moves shorthand binds to bind attr
var manifest = isO(manifest0)?manifest0:null;
Object.each(ui, function (i,v){
var t = typeof v;
Expand Down Expand Up @@ -2053,7 +2081,7 @@
if (data.inherit) _inherits(data);

// Start
_require(data, p)
f.require(data, p)
.then(function(){
_makeup();
_files().then(function(){
Expand Down Expand Up @@ -2166,13 +2194,12 @@
if (data.params && data.params.depth) p.recalcDepth=data.params.depth;

//bind ‘this’ to 1st level manifest functions
for (i in manifest) if (isF(manifest[i])) manifest[i] = manifest[i].bind(manifest);//manifest[i].bind(manifest);
for (i in manifest) if (isF(manifest[i])) manifest[i] = manifest[i].bind(manifest);

//mount error handler
if (data.error) {
if (isS(data.error)) {
ehandler = function (msg,err) {

return data.error.assign($E({
message:msg+"",
err:err+""
Expand Down Expand Up @@ -2222,9 +2249,6 @@
if (style && style[0].length && !onlyLocals) {
$style = $('style#' + manClass);
if (!$style.size()) {
/*$style = $('<style id="' + manClass + '" data-count="0">' +
"." + manClass + style[0].join(' \n.' + manClass) + '\n' +
'</style>').appendTo($("body"));*/
$style = $(html(style[0], manClass)).appendTo($("body"));
}

Expand All @@ -2235,10 +2259,6 @@
if (style && style[1].length) {
$locstyle = $('style#' + formClass);
if (!$locstyle.size()) {
/*$locstyle = $('<style id="' + formClass + '" data-count="0">' +
"." + formClass + style[1].join(' \n.' + formClass) + '\n' +
'</style>').appendTo($("body"));*/

$locstyle = $(html(style[1], formClass)).appendTo($("body"));
if (p.restyle>-1 && !restyles[cid]) {
restyles[cid] = (function restyle (){ _styler(true)}).debounce(p.restyle);
Expand Down Expand Up @@ -2733,7 +2753,11 @@
if (isF(A1)) return _cache = A1;
else return _cache(A1, A2);
},
version: function () {return _version;}
version: function () {return _version;},
ajax: function(A1){
if (isF(A1)) return _ajax = A1;
else return _ajax.apply(this, Array.prototype.slice.call(arguments));
}
});

// Chain runner
Expand Down Expand Up @@ -2799,7 +2823,9 @@
_broadcast($(document), data);
})
.on("resize.my", function myWindowResize () {
for (var i in restyles) restyles[i]();
for (var i in restyles) try {
restyles[i]();
} catch (e) {}
}.debounce(100));


Expand Down Expand Up @@ -2881,7 +2907,8 @@
case 'str': return fj(w);case'num':return isFinite(w)?''+String(w)+'':'null';
case 'boo': case'nul':return String(w);
case 'fun': return fj(
w.toString().replace(/^(function)([^\(]*)(\(.*)/,"$1 $3")
w.toString()
.replace(/^(function)([^\(]*)(\([^\)]*)([\n\t][^)]*)(\).*)/,"$1 $3$5")
.replace(/(})([^}]*$)/,'$1')
);
case 'obj': if(!w) return'null';
Expand Down
5 changes: 3 additions & 2 deletions jquerymy.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 3ddaa6f

Please sign in to comment.