Skip to content

Commit

Permalink
1.2.11
Browse files Browse the repository at this point in the history
Fixes bug preventing modal to close when pivot node is no more in DOM
(removed).
  • Loading branch information
ermouth committed Oct 10, 2017
1 parent b08e3c4 commit 5bce4a0
Show file tree
Hide file tree
Showing 8 changed files with 4,641 additions and 96 deletions.
4,504 changes: 4,504 additions & 0 deletions Release/1.2/jquerymy-1.2.11.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Release/1.2/jquerymy-1.2.11.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 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.2.10",
"version": "1.2.11",
"description": "A lightweight jQuery plugin for complex two-way data binding in real time.",
"main": "./jquerymy.js",
"authors": [
Expand Down
210 changes: 123 additions & 87 deletions jquerymy.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/*
* jQuery.my 1.2.10
* jQuery.my 1.2.11
* Requires jQuery 2.0+, SugarJS 1.3.9-1.4.x
*
* — fixes #38, #39
* — fixed inability of $.my.modal to close popup
* when source pivot DOM node was removed
* — other minor fixes in $.my.modal
*
* More details at jquerymy.com
*
* (c) @ermouth, thanks @carpogoryanin, @ftescht
* 2017-04-09
* 2017-10-10
*/

;(function ($) {

var _version = "1.2.10";
var _version = "1.2.11";

// Some shortcuts and constants
var TMP, lang = "en",
Expand Down Expand Up @@ -3426,7 +3428,7 @@

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

/* jQuery.formgen 0.5.0
/* jQuery.formgen 0.6.0
* Generates forms markup for $.my from lean-syntax DSL.
* Returns html string.
*
Expand Down Expand Up @@ -3459,11 +3461,23 @@

(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 = '<input type="',
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,
iHead = '<input type="',
iTail = ' {ext} ';
var f = {
tmpl:{
Expand Down Expand Up @@ -3504,11 +3518,26 @@
}
},
params:{
styles:{num:"width:30%;", dat:"width:30%;", inp:"width:100%", pwd:"width:100%", but:"width:30%",
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"},
styles:{
num:"width:30%;",
dat:"width:30%;",
inp:"width:100%",
pwd:"width:100%",
but:"width:30%",
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",
Expand All @@ -3529,9 +3558,16 @@
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;
var lbl = b[0],
html="",
key,
type,
a0,b0,
i=1,j,p,
tmpl,
ext;

//iterate through row's inside items
//iterate through row inner items
while (i<b.length) {
if (isS(b[i])) {
b0 = b[i].replace(/\s/g,"");
Expand All @@ -3540,9 +3576,10 @@
key = b0.substr(a0[0].length);
if (/^[a-z0-9]+(#[a-z0-9\-_]+)?(\.[a-z0-9\-_]+)*$/i.test(b0)) {
tmpl = f.tmpl[type] || f.tmpl[""];
p={style:"","class":"",txt:""};ext="";
p = {style:"","class":"",txt:""};
ext="";

//mount params over p
//mount params on p
var isExt = isO(b[i+1]);
if (isExt) {
i+=1;
Expand Down Expand Up @@ -3579,8 +3616,8 @@
if (html) {
html =
'<'+sys.rowTag+' class="'+sys.rowCss+'" '
+(sys.row?'style="width:'+sys.row+'; ':"")
+(sys.label && lbl?'padding-left:'+sys.label+'; ':"")
+(sys.row?'style="width:'+sys.row+'; ':'')
+(sys.label && lbl?'padding-left:'+sys.label+'; ':'')
+'">'
+(lbl?(
'<'+sys.labelTag+' class="'+sys.labelCss+'" '
Expand Down Expand Up @@ -3652,8 +3689,8 @@

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

/* jQuery.my.modal 1.2.0
* Requires Sugar 1.4.~, jQuery 2.0+, $.my 1.2.8+
/* jQuery.my.modal 1.2.4
* Requires Sugar 1.4.~, jQuery 2.0+, $.my 1.2.10+
*
* Modal dialog constructor/manager.
*
Expand Down Expand Up @@ -3888,7 +3925,6 @@
$.fn.modal = function (obj0, done0, width0) {

// Detect Bootstrap

if (BTmodal) {
if (obj0 === void 0 && done0 === void 0 && width0 === void 0) return BTmodal.call(this);
else if (isO(obj0) && (
Expand All @@ -3913,46 +3949,8 @@

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.call ($f.my("manifest"), $f.my("valid")?null:$f.my("errors"), md);
}catch(e){}
if (!stop) {
try {_indom($f)?_remove():"";} catch(e){}
$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.call($f.my("manifest"),null, null);} catch(e){}
try {_indom($f)?_remove():"";} catch(e){}
$o.removeData("modal");
if (M[m.cid]) {
try {
M[m.cid].reject("Cancelled");
} catch (e) {}
}
delete M[m.cid];
m=null;
}

_close(obj0);
return $o;


} else if (obj) {
// reinit is not allowed
_f("Locked");
Expand Down Expand Up @@ -4083,7 +4081,7 @@
// close btn
if (m.close) {
$cl = $(isS(m.close)? m.close:'<div class="my-modal-close" title="Close">×</div>')
.prependTo($m).on("click.my",function () {$o.modal(m.hardClose);});
.prependTo($m).on("click.my",function () {_close(m.hardClose);});
$cl.css({"z-index":((m.z+"").to(1)==="+"?"+":"")+(m.z*1+1)});
}

Expand All @@ -4093,8 +4091,8 @@
if (!$bg.length) {
$bg = $('<div class="my-modal-screen" style="display:none;"></div>').prependTo(m.bgroot);
}

if (m.esc) $bg.on("click.my"+ m.cid, function () { $o.modal(true); });
$bg.toggleClass('my-modal-screen-global', !!m.global);
}

// mount data
Expand Down Expand Up @@ -4143,8 +4141,8 @@
$E(m,{
form: $f,
bg:$bg,
cancel: function(){$o.modal(true);},
commit: function(){$o.modal();}
cancel: function(){_close(true);},
commit: function(){_close();}
});
$m.data("modal",m);

Expand All @@ -4165,16 +4163,16 @@

// bind event listeners
$f.on("commit.my", function(){
m.commit.delay(50);
m.commit.delay(30);
return false;
}).on("cancel.my", function(){
m.cancel.delay(50);
m.cancel.delay(30);
return false;
});

$m.on("layout.my", function(){
_adjust();
}.debounce(50));
}.debounce(30));

// fullscreen tuneups
if (m.global) {
Expand Down Expand Up @@ -4263,6 +4261,47 @@


//### Helpers

function _close(obj0) {
// closes 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.call ($f.my('manifest'), $f.my('valid')?null:$f.my('errors'), md);
}catch(e){}
if (!stop) {
try {_indom($f)?_remove():'';} catch(e){}
if (_indom($o)) $o.removeData('modal');
// async resolve
(function () {
if (M[m.cid]) {
try { M[m.cid].resolve(md); } catch (e) {}
}
delete M[m.cid];
m = null;
}).delay(0);
}
} else {
// force close
try {done.call($f.my('manifest'),null, null);} catch(e){}
try {_indom($f)?_remove():'';} catch(e){}
if (_indom($o)) $o.removeData('modal');
if (M[m.cid]) {
try { M[m.cid].reject('Cancelled'); } catch (e) {}
}
delete M[m.cid];
m = null;
}
}

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

function _measure(){
// measure $o, its pos
Expand All @@ -4283,15 +4322,14 @@

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;
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();
Expand All @@ -4304,18 +4342,13 @@

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;
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;
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+rs).round(1);
Expand Down Expand Up @@ -4415,7 +4448,10 @@
"z-index":m.z-1
});
if (isS(m.screen)) $bg.css({
background:m.screen? m.screen:'rgba(25, 39, 59, 0.88)'
background:m.screen? m.screen:'rgba(18,41,72,0.88)'
});
else $bg.css({
background:m.screen?'rgba(18,41,72,0.88)':''
});
}
}
Expand All @@ -4440,13 +4476,13 @@
$r.data('modals')[m.cid] = null;
} catch(e){}
$f.parent().off('.my').remove();
$bg.off('.my'+ m.cid);
if (m.screen) {
if (_indom($bg)) $bg.off('.my'+ m.cid);
if (m.screen && _indom($bg)) {
(function(g){
if (!g || !isOpen) $bg.hide();
if (!!g && !isOpen) {
// repair screen color
$bg.css({background:'rgba(25, 39, 59, 0.88)'});
$bg.css({background:'rgba(18,41,72,0.88)'});
}
}).delay(50, m.global); // curry m.global
}
Expand All @@ -4463,6 +4499,6 @@
(function () { pi.reject(msg); }).delay(0);
}

};
}; // -- end $.fn.modal

})(jQuery);
6 changes: 3 additions & 3 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.2.10",
"version": "1.2.11",
"author": {
"name": "ermouth",
"url": "https://github.com/ermouth"
Expand Down
Loading

0 comments on commit 5bce4a0

Please sign in to comment.