diff --git a/README.md b/README.md
index 1cf4f3a..5f2f07b 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,12 @@
Manage commnunication between browser tabs.
this js lib can perform several actions on browser tabs like :
- - (*new) search and kill zombies tabs (enable onload by default)
+ - (*new) varset - set a stringifiable object on tabs
+ - (*new) varsync - synchro a object previously set with varset on an other tab
+ - (*new) prepend node
+ - (*new) synchro node attributes
+ - define custom before and after command functions
+ - search and kill zombies tabs (enable onload by default)
- append/rewrite/synchro node on all (other) tabs or a specific tab (and possibly on specific frame context) eventually with callback.
- reload all tabs or a specific tab with specified url or tab 's current url
- perform your custom actions on all tabs or specific tab
@@ -44,6 +49,15 @@
// perform a node synchro to specified browser tab on specific frame with callback
$bt.sync('#test', 'frameName', 'callbackname', '1449974562012');
+ // perform a node attr synchro to all browser tab
+ $bt.attr('#test', ['class', 'title']);
+
+ // perform a varset to all tabs
+ $bt.varset('myVar', { toto : tutu : { tata : "titi" }});
+
+ // perform a varsync from specific tab (for example after calling tab will reload)
+ $bt.varsync('myVar', '1449974562012');
+
// reload other browser tabs
$bt.reload();
diff --git a/demo.html b/demo.html
index 587fc6e..b36d0b2 100644
--- a/demo.html
+++ b/demo.html
@@ -4,15 +4,16 @@
pluie.org bt demo - v0.7
@@ -21,17 +22,25 @@
Manage commnunication between browser tabs.
this js lib can perform several actions on browser tabs like :
-
append/rewrite/synchro node on all (other) tabs or a specific tab (and possibly on specific frame context) eventually with callback.
+
append/rewrite/synchro node content on all (other) tabs or a specific tab (and possibly on specific frame context) eventually with callback.
reload all tabs or a specific tab with specified url or tab 's current url
perform your custom actions on all tabs or specific tab
kill zombies tabs onload
-
(*new) define custom before and after command functions
+
define custom before and after command functions
+
(*new) sync node attributes
+
(*new) prepend node content
+
(*new) varset - set a stringifiable object on tabs
+
(*new) varsync - synchro a object previously set with varset on an other tab
Static actions
+
+
+
+
Dynamic actions
enter txt or html :
@@ -42,6 +51,7 @@ enter txt or html :
+
@@ -65,6 +75,7 @@ $bt.on = function(cmd) {
break;
}
}
+$bt.vars['myVar'] = "start";
//
$(document).ready(function() {
$bt.init(function() {
@@ -113,9 +124,53 @@ $(document).ready(function() {
$('.cmd-tarsync').on('click', function(){
$bt.sync('#test');
});
+ $('.cmd-attr').on('click', function(){
+ $(this).toggle('syncAttrName');
+ $(this).attr('title', 'i have '+($(this).hasClass('syncAttrName') ? '' : 'not ')+' the class syncAttrName');
+ $bt.attr('.cmd-attr', ['class', 'title']);
+ });
$('.cmd-sta-append').on('click', function(){
eval(this.title);
});
+ $('.cmd-sta-prepend').on('click', function(){
+ eval(this.title);
+ });
+ $('.cmd-varset').on('click', function(){
+ var obj = {
+ toto : {
+ titi : {
+ tutu : 'cool',
+ tata : ['one', 2, 'three']
+ }
+ }
+ }
+ console.log(obj);
+ $('#test').html("varset : myVar json value : "+$j.str(obj));
+ $bt.varset('myVar', obj);
+ });
+ $('.cmd-varget').on('click', function(){
+ if (!$.isNone($bt.vars['myVar'])) {
+ $('#test').html("varget : myVar json value : "+$j.str($bt.vars['myVar']));
+ }
+ else {
+ $('#test').html("varget : myVar undefined");
+ $('#test').html("clic on varsync to sync myVar");
+ }
+ });
+ $('.cmd-varsync').on('click', function(){
+ if ($bt.list.length > 1) {
+ $bt.varsync('myVar', null, $bt.list[0] == $bt.id ? $bt.list[1] : $bt.list[0]);
+ if (!$.isNone($bt.vars['myVar'])) {
+ $('#test').html("varget : myVar json value : "+$j.str($bt.vars['myVar']));
+ }
+ else {
+ $('#test').html("varget : myVar undefined");
+ }
+ }
+ else {
+ $('#test').html("need one more tab to perform a bt varsync");
+ }
+ });
$('.cmd-sta-html').on('click', function(){
eval(this.title);
});
diff --git a/src/bt-min.js b/src/bt-min.js
index 65eb1d3..63c313c 100644
--- a/src/bt-min.js
+++ b/src/bt-min.js
@@ -1 +1 @@
-/* by a-sansara - v 0.7 - https://github.com/pluie-org/bt */var $l=function(){var a=localStorage;return{clear:function(){return a.clear()},get:function(n){return a.getItem(n)},rem:function(n){return a.removeItem(n)},set:function(n,o){return a.setItem(n,o)}}}(),$j=function(){var a=JSON;return{str:function(n){return a.stringify(n)},obj:function(s){return a.parse(s)}}}(),$bt={VERSION:.7,TRACE:!0&&!$.isNone(console),LS_TABS:"bt.list",LS_CURTAB:"bt.current",LS_CMD:"bt.event",CMD_SYNC:"bt.sync",CMD_VAR_SET:"bt.set",CMD_VAR_GET:"bt.get",CMD_APPEND:"bt.dom.append",CMD_HTML:"bt.dom.rewrite",CMD_RELOAD:"bt.reload",CMD_ZOMBKILL:"bt.zombkill",CMD_DONTKILL:"bt.dontkill",vars:[],callbacks:[],zomblist:[],zkillonload:!0,zombTimeout:250,init:function(n){this._init(n)},log:function(n){this.TRACE&&console.log(n)},send:function(n){n.uid=this.id+Math.random(),n.from=this.id,$.isNone(n.to)&&(n.to="*"),n=$j.str(n),$bt.log("sending cmd : "+this.LS_CMD+" : "+n),$l.set(this.LS_CMD,n),$l.rem(this.LS_CMD)},append:function(n,o,i,b,l){this._dom(this.CMD_APPEND,i,n,o,b,l)},html:function(n,o,i,b,l){this._dom(this.CMD_HTML,i,n,o,b,l)},sync:function(n,o,i,b){var l=$.isNone(o)||null==o?document:parent.frames[o].document;this._dom(this.CMD_HTML,o,n,$(n,l).html(),i,b)},reload:function(n,o){$bt.send({name:$bt.CMD_RELOAD,url:n,to:o?o:"*"})},setCallback:function(n,o){$.isNone($bt.callbacks[n])?$bt.callbacks[n]=o:console.log("BT ERROR : callback name already exist")},zombkill:function(n,o){var i=(new Date).getTime();$bt.zomblist[""+i]=[],$bt.list.forEach(function(n){n!=$bt.id&&($bt.zomblist[""+i]["ping"+n]="")}),$bt.send({name:$bt.CMD_ZOMBKILL,askid:i,to:"*"});var b=setTimeout(function(){$bt._refresh();for(var o in $bt.zomblist[""+i])if("pong"!=$bt.zomblist[""+i][o]){var l=$bt.list.indexOf(parseInt(o.substring(4)));l>-1&&$bt.list.splice(l,1)}$l.set($bt.LS_TABS,$j.str($bt.list)),$bt._broadcast(),$bt.log($bt.list),clearTimeout(b),$.isFunc(n)&&n()},o?o:$bt.zombTimeout)},_dontkill:function(n,o){$bt.send({name:$bt.CMD_DONTKILL,askid:n,to:o})},_refresh:function(){$bt.list=$j.obj($l.get($bt.LS_TABS))},_broadcast:function(){$bt.send({name:$bt.CMD_SYNC})},_remove:function(n){n||(n=$bt.id);var o=$bt.list.indexOf(n);o>-1&&$bt.list.splice(o,1)},_init:function(n){$(window).on("beforeunload",$bt._unload),$(window).on("storage",$bt._cmd),$(window).on("focus",$bt._focus),$bt.id=(new Date).getTime();var t=$l.get($bt.LS_TABS);$bt.list=null==t?[]:$j.obj(t),$bt.list.push($bt.id),$l.set($bt.LS_TABS,$j.str($bt.list)),$bt._broadcast(),$bt.log($bt.list),$bt.zkillonload?$bt.zombkill(n):$.isFunc(n)&&n()},_dom:function(n,o,s,i,b,l){$bt.send({name:n,context:o,selector:s,data:i,callback:b,to:l?l:"*"})},_unload:function(){return $bt._refresh(),$bt._remove(),$l.set($bt.LS_TABS,$j.str($bt.list)),$bt._broadcast(),null},_focus:function(){$l.set($bt.LS_CURTAB,$bt.id)},_cmd:function(o){if($.isNone(o.originalEvent)||(o=o.originalEvent),o.key==$bt.LS_CMD){var n=$j.obj(o.newValue);if(n&&("*"==n.to||n.to==$bt.id)){$bt.log("RECEIVING cmd "+n.name+" : "),$bt.log(n);try{n.context=$.isNone(n.context)||null==n.context||$.isNone(window.parent.frames[n.context])?document:window.parent.frames[n.context].document}catch(o){$bt.log("bad context "+n.context+" : "+o.message)}switch($.isFunc($bt.before)&&$bt.before(n),n.name){case $bt.CMD_SYNC:$bt._refresh(),$bt.log($bt.list);break;case $bt.CMD_APPEND:$(n.selector,n.context).append(n.data);break;case $bt.CMD_HTML:$(n.selector,n.context).html(n.data);break;case $bt.CMD_RELOAD:window.location=$.isNone(n.url)?window.location:n.url;break;case $bt.CMD_ZOMBKILL:$bt._dontkill(n.askid,n.from);break;case $bt.CMD_DONTKILL:$bt.zomblist[""+n.askid]["ping"+n.from]="pong";break;default:$.isFunc($bt.on)&&$bt.on(n)}$.isStr(n.callback)&&n.callback.length>0&&!$.isNone($bt.callbacks[n.callback])&&$.isFunc($bt.callbacks[n.callback])&&($bt.log(n.callback),$bt.callbacks[n.callback].call({},n)),$.isFunc($bt.after)&&$bt.after(n)}}}};
+/* by a-sansara - v 0.8 - https://github.com/pluie-org/bt */var $l=function(){var a=localStorage;return{clear:function(){return a.clear()},get:function(n){return a.getItem(n)},rem:function(n){return a.removeItem(n)},set:function(n,o){return a.setItem(n,o)}}}(),$j=function(){var a=JSON;return{str:function(n){return a.stringify(n)},obj:function(s){return a.parse(s)}}}(),$bt={VERSION:.8,TRACE:!0&&!$.isNone(console),LS_TABS:"bt.list",LS_CURTAB:"bt.current",LS_CMD:"bt.event",CMD_SYNC:"bt.sync",CMD_VAR_SET:"bt.varset",CMD_VAR_SYNC:"bt.varsync",CMD_ATTR_SYNC:"bt.attr",CMD_APPEND:"bt.dom.append",CMD_PREPEND:"bt.dom.prepend",CMD_HTML:"bt.dom.rewrite",CMD_RELOAD:"bt.reload",CMD_ZOMBKILL:"bt.zombkill",CMD_DONTKILL:"bt.dontkill",vars:[],callbacks:[],zomblist:[],zkillonload:!0,zombTimeout:250,init:function(n){this._init(n)},log:function(n){this.TRACE&&console.log(n)},send:function(n){n.uid=this.id+Math.random(),n.from=this.id,$.isNone(n.to)&&(n.to="*"),n=$j.str(n),$bt.log("sending cmd : "+this.LS_CMD+" : "+n),$l.set(this.LS_CMD,n),$l.rem(this.LS_CMD)},append:function(n,o,i,b,c){this._dom(this.CMD_APPEND,i,n,o,b,c)},prepend:function(n,o,i,b,c){this._dom(this.CMD_PREPEND,i,n,o,b,c)},html:function(n,o,i,b,c){this._dom(this.CMD_HTML,i,n,o,b,c)},sync:function(n,o,i,b){var c=$.isNone(o)||null==o?document:parent.frames[o].document;this._dom(this.CMD_HTML,o,n,$(n,c).html(),i,b)},reload:function(n,o){$bt.send({name:$bt.CMD_RELOAD,url:n,to:o?o:"*"})},setCallback:function(n,o){$.isNone($bt.callbacks[n])?$bt.callbacks[n]=o:console.log("BT ERROR : callback name already exist")},zombkill:function(n,o){var i=(new Date).getTime();$bt.zomblist[""+i]=[],$bt.list.forEach(function(n){n!=$bt.id&&($bt.zomblist[""+i]["ping"+n]="")}),$bt.send({name:$bt.CMD_ZOMBKILL,askid:i,to:"*"});var b=setTimeout(function(){$bt._refresh();for(var o in $bt.zomblist[""+i])if("pong"!=$bt.zomblist[""+i][o]){var c=$bt.list.indexOf(parseInt(o.substring(4)));c>-1&&$bt.list.splice(c,1)}$l.set($bt.LS_TABS,$j.str($bt.list)),$bt._broadcast(),$bt.log($bt.list),clearTimeout(b),$.isFunc(n)&&n()},o?o:$bt.zombTimeout)},varset:function(n,o,i,b){try{var c=$j.str(o);$bt.vars[n]=o,$bt.send({name:$bt.CMD_VAR_SET,varName:n,data:c,callback:i,to:b?b:"*"})}catch(l){console.log(l)}},varsync:function(n,o,i){$bt.send({name:$bt.CMD_VAR_SYNC,varName:n,data:"",callback:o,to:i})},attr:function(n,o,i,b,c){var l=i?window.parent.frames[i].document:document;$.isStr(o)&&(o=[o]);var r=[];o.forEach(function(o){r.push("disabled"!=o?$(n,l).attr(o):$(n,l).first().disabled)}),$bt.send({name:$bt.CMD_ATTR_SYNC,attr:o,selector:n,data:r,context:i,callback:b,to:c?c:"*"})},_dontkill:function(n,o){$bt.send({name:$bt.CMD_DONTKILL,askid:n,to:o})},_refresh:function(){$bt.list=$j.obj($l.get($bt.LS_TABS))},_broadcast:function(){$bt.send({name:$bt.CMD_SYNC})},_remove:function(n){n||(n=$bt.id);var o=$bt.list.indexOf(n);o>-1&&$bt.list.splice(o,1)},_init:function(n){$(window).on("beforeunload",$bt._unload),$(window).on("storage",$bt._cmd),$bt._defHandlerCurrentTab(),$bt.id=(new Date).getTime();var t=$l.get($bt.LS_TABS);$bt.list=null==t?[]:$j.obj(t),$bt.list.push($bt.id),$l.set($bt.LS_TABS,$j.str($bt.list)),$bt._broadcast(),$bt.log($bt.list),$bt.zkillonload?$bt.zombkill(n):$.isFunc(n)&&n()},_defHandlerCurrentTab:function(){var n="hidden",o="visibilitychange";$.isNone(document.mozHidden)?$.isNone(document.msHidden)?$.isNone(document.webkitHidden)||(n="webkitHidden",o="webkitvisibilitychange"):(n="msHidden",o="msvisibilitychange"):(n="mozHidden",o="mozvisibilitychange"),$(window).on(o,function(){document[n]||($bt.log("SET CURRENT TAB : "+$bt.id),$l.set($bt.LS_CURTAB,$bt.id))},!1)},_dom:function(n,o,s,i,b,c){$bt.send({name:n,context:o,selector:s,data:i,callback:b,to:c?c:"*"})},_unload:function(){return $bt._refresh(),$bt._remove(),$l.set($bt.LS_TABS,$j.str($bt.list)),$bt._broadcast(),null},_cmd:function(o){if($.isNone(o.originalEvent)||(o=o.originalEvent),o.key==$bt.LS_CMD){var n=$j.obj(o.newValue);if(n&&("*"==n.to||n.to==$bt.id)){$bt.log("RECEIVING cmd "+n.name+" : "),$bt.log(n);try{n.context=$.isNone(n.context)||null==n.context||$.isNone(window.parent.frames[n.context])?document:window.parent.frames[n.context].document}catch(o){$bt.log("bad context "+n.context+" : "+o.message)}switch($.isFunc($bt.before)&&$bt.before(n),n.name){case $bt.CMD_SYNC:$bt._refresh(),$bt.log($bt.list);break;case $bt.CMD_APPEND:$(n.selector,n.context).append(n.data);break;case $bt.CMD_HTML:$(n.selector,n.context).html(n.data);break;case $bt.CMD_PREPEND:$(n.selector,n.context).prepend(n.data);break;case $bt.CMD_RELOAD:window.location=$.isNone(n.url)?window.location:n.url;break;case $bt.CMD_ZOMBKILL:$bt._dontkill(n.askid,n.from);break;case $bt.CMD_DONTKILL:$bt.zomblist[""+n.askid]["ping"+n.from]="pong";break;case $bt.CMD_VAR_SET:$bt.vars[n.varName]=n.data;break;case $bt.CMD_VAR_SYNC:$bt.varset(n.varName,$bt.vars[n.varName]);break;case $bt.CMD_ATTR_SYNC:n.attr.forEach(function(o,i){"disabled"!=n.attr?$(n.selector,n.context).attr(o,n.data[i]):$(n.selector,n.context).first().disabled=n.data[i]});break;default:$.isFunc($bt.on)&&$bt.on(n)}$.isStr(n.callback)&&n.callback.length>0&&!$.isNone($bt.callbacks[n.callback])&&$.isFunc($bt.callbacks[n.callback])&&($bt.log(n.callback),$bt.callbacks[n.callback].call({},n)),$.isFunc($bt.after)&&$bt.after(n)}}}};
diff --git a/src/bt.js b/src/bt.js
index 49a173a..377f0c1 100644
--- a/src/bt.js
+++ b/src/bt.js
@@ -3,7 +3,7 @@
* @contributors :
* @copyright : pluie.org
* @date : 2015-12-10 22:22:34
- * @version : 0.7
+ * @version : 0.8
* @license : MIT
* @require : html5 localStorage svan (small vanilla jquery-like lib)
* @desc : manage communication between browser tabs
@@ -45,6 +45,15 @@
* // perform a node synchro to specified browser tab on specific frame with callback
* $bt.sync('#test', 'frameName', 'callbackname', '1449974562012');
*
+ * // perform a node attr synchro to all browser tab
+ * $bt.attr('#test', ['class', 'title']);
+ *
+ * // perform a varset to all tabs
+ * $bt.varset('myVar', { toto : tutu : { tata : "titi" }});
+ *
+ * // perform a varsync from specific tab (for example after calling tab will reload)
+ * $bt.varsync('myVar', '1449974562012');
+ *
* // reload other browser tabs
* $bt.reload();
*
@@ -117,7 +126,7 @@ var $j = (function alias() {
}());
var $bt = {
- VERSION : 0.7,
+ VERSION : 0.8,
TRACE : true && !$.isNone(console),
/*! @constant LS_TABS localStorage key for browsertabs list */
LS_TABS : 'bt.list',
@@ -128,11 +137,15 @@ var $bt = {
/*! @constant CMD_SYNC internal command to perform a browser tab synchro */
CMD_SYNC : 'bt.sync',
/*! @constant CMD_VAR_SET internal command to perform a browser tab var set */
- CMD_VAR_SET : 'bt.set',
- /*! @constant CMD_VAR_GET internal command to perform a browser tab var get */
- CMD_VAR_GET : 'bt.get',
+ CMD_VAR_SET : 'bt.varset',
+ /*! @constant CMD_VAR_SYNC internal command to perform a browser tab var sync */
+ CMD_VAR_SYNC : 'bt.varsync',
+ /*! @constant CMD_ATTR_SYNC internal command to perform a dom sync attribute */
+ CMD_ATTR_SYNC: 'bt.attr',
/*! @constant CMD_APPEND internal command to perform a dom append */
CMD_APPEND : 'bt.dom.append',
+ /*! @constant CMD_PREPEND internal command to perform a dom append */
+ CMD_PREPEND : 'bt.dom.prepend',
/*! @constant CMD_HTML internal command to perform a dom html */
CMD_HTML : 'bt.dom.rewrite',
/*! @constant CMD_RELOAD internal command to perform a browser tab reload */
@@ -215,6 +228,19 @@ var $bt = {
append : function(selector, data, ctx, callback, btid) {
this._dom(this.CMD_APPEND, ctx, selector, data, callback, btid);
},
+ /*!
+ * @desc perform a dom prepend command on other tabs
+ * @public
+ * @method append
+ * @param string selector the selector wich target the node(s)
+ * @param string data the data to append
+ * @param string ctx context name of selector (frame name relative to document wich match specified selector) or if not defined or null current document
+ * @param string callback callback name to fire on command
+ * @param int btid target browser tab id (if not defined all target all tabs)
+ */
+ prepend : function(selector, data, ctx, callback, btid) {
+ this._dom(this.CMD_PREPEND, ctx, selector, data, callback, btid);
+ },
/*!
* @desc perform a dom html command on other tabs
* @public
@@ -296,6 +322,55 @@ var $bt = {
if ($.isFunc(callback)) callback();
}, !timeout ? $bt.zombTimeout : timeout);
},
+ /*!
+ * @desc perform a var set command on other tabs
+ * @public
+ * @method varset
+ * @param string varName the var identifier
+ * @param object data the data object (wich need to be stringifiable via json)
+ * @param string callback callback name to fire on command
+ * @param int btid target browser tab id (if not defined all target all tabs)
+ */
+ varset : function(varName, data, callback, btid) {
+ try {
+ var djson = $j.str(data);
+ $bt.vars[varName] = data;
+ $bt.send({ name : $bt.CMD_VAR_SET, varName : varName, data : djson, callback : callback, to : !btid ? '*' : btid });
+ }
+ catch(e) {
+ console.log(e);
+ }
+ },
+ /*!
+ * @desc perform a var sync command on specified tab
+ * @public
+ * @method varset
+ * @param string varName the var identifier
+ * @param string callback callback name to fire on command
+ * @param int fromId target browser tab id (must be defined and uniq)
+ */
+ varsync : function(varName, callback, toId) {
+ $bt.send({ name : $bt.CMD_VAR_SYNC, varName : varName, data : '', callback : callback, to : toId });
+ },
+ /*!
+ * @desc perform a dom attribute synchro command on other tabs
+ * @public
+ * @method sync
+ * @param string selector the selector wich target the node(s) to synchro
+ * @param string|[string] attrName attribute name to sync
+ * @param string ctx context name of selector (frame name relative to document wich match specified selector) or if not defined or null current document
+ * @param string callback callback name to fire on command
+ * @param int btid target browser tab id (if not defined all target all tabs)
+ */
+ attr : function(selector, attrName, ctx, callback, btid) {
+ var context = !ctx ? document : window.parent.frames[ctx].document;
+ if ($.isStr(attrName)) attrName = [ attrName ];
+ var data = [];
+ attrName.forEach(function (attr, index) {
+ data.push(attr != "disabled" ? $(selector, context).attr(attr) : $(selector, context).first().disabled);
+ });
+ $bt.send({ name : $bt.CMD_ATTR_SYNC, attr : attrName, selector : selector, data : data, context : ctx, callback : callback, to : !btid ? '*' : btid });
+ },
_dontkill : function(askid, id) {
$bt.send({ name : $bt.CMD_DONTKILL, askid : askid, to : id });
},
@@ -317,7 +392,8 @@ var $bt = {
_init : function(fn) {
$(window).on('beforeunload', $bt._unload);
$(window).on('storage', $bt._cmd);
- $(window).on('focus', $bt._focus);
+ $bt._defHandlerCurrentTab();
+ // $(window).on('focus', $bt._focus); replace by _defHandlerCurrentTab to fix frame context
$bt.id = (new Date).getTime();
var t = $l.get($bt.LS_TABS);
$bt.list = t==null ? [] : $j.obj(t);
@@ -331,6 +407,27 @@ var $bt = {
}
},
/*! @private */
+ _defHandlerCurrentTab : function() {
+ var evcVal = "hidden";
+ var evcType = "visibilitychange";
+ if (!$.isNone(document.mozHidden)) {
+ evcVal = "mozHidden";
+ evcType = "mozvisibilitychange";
+ } else if (!$.isNone(document.msHidden)) {
+ evcVal = "msHidden";
+ evcType = "msvisibilitychange";
+ } else if (!$.isNone(document.webkitHidden)) {
+ evcVal = "webkitHidden";
+ evcType = "webkitvisibilitychange";
+ }
+ $(window).on(evcType, function() {
+ if (!document[evcVal]) {
+ $bt.log('SET CURRENT TAB : '+$bt.id);
+ $l.set($bt.LS_CURTAB, $bt.id);
+ }
+ }, false);
+ },
+ /*! @private */
_dom : function(n, c, s, d, cb, id) {
$bt.send({ name : n, context : c, selector : s, data : d, callback : cb, to : !id ? '*' : id });
},
@@ -343,9 +440,9 @@ var $bt = {
return null;
},
/*! @private */
- _focus : function(e) {
- $l.set($bt.LS_CURTAB, $bt.id);
- },
+ //~ _focus : function(e) {
+ //~ $l.set($bt.LS_CURTAB, $bt.id);
+ //~ },
/*! @private */
_cmd : function(e) {
if (!$.isNone(e.originalEvent)) e = e.originalEvent;
@@ -380,6 +477,10 @@ var $bt = {
$(cmd.selector, cmd.context).html(cmd.data);
break;
+ case $bt.CMD_PREPEND :
+ $(cmd.selector, cmd.context).prepend(cmd.data);
+ break;
+
case $bt.CMD_RELOAD :
window.location = !$.isNone(cmd.url) ? cmd.url : window.location;
break;
@@ -393,7 +494,26 @@ var $bt = {
case $bt.CMD_DONTKILL :
$bt.zomblist[''+cmd.askid]['ping'+cmd.from] = 'pong';
break;
-
+
+ case $bt.CMD_VAR_SET :
+ $bt.vars[cmd.varName] = cmd.data;
+ break;
+
+ case $bt.CMD_VAR_SYNC :
+ $bt.varset(cmd.varName, $bt.vars[cmd.varName]);
+ break;
+
+ case $bt.CMD_ATTR_SYNC :
+ cmd.attr.forEach(function(attr, index) {
+ if (cmd.attr != "disabled") {
+ $(cmd.selector, cmd.context).attr(attr, cmd.data[index]);
+ }
+ else {
+ $(cmd.selector, cmd.context).first().disabled = cmd.data[index];
+ }
+ });
+ break;
+
default :
// do your stuff here
if ($.isFunc($bt.on)) $bt.on(cmd);
diff --git a/src/svan-min.js b/src/svan-min.js
index 222030b..6c94793 100644
--- a/src/svan-min.js
+++ b/src/svan-min.js
@@ -1 +1 @@
-/* by a-sansara - v 0.4 - https://github.com/pluie-org/svan */!function(){var t=function(t,n){return typeof t==n},n=function(t,i){return new n.init(t,i)},i=n.isNone=function(n){return t(n,"undefined")},e=n.isStr=function(n){return t(n,"string")},s=n.isFunc=function(n){return t(n,"function")},o=n.isObj=function(n){return t(n,"object")},a=n.isNode=function(t){return o(t)&&!i(t.nodeType)},c=n.isWin=function(t){return!i(t.window)&&t.window==t};n.prototype={regsan:function(t){return t.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")},first:function(){return this.found?this.list[0]:null},last:function(){return this.found?this.list[this.list.length-1]:b},index:function(t){return this.found&&t>0&&t0,this};u.prototype=n.prototype,window.Svan=n,i(window.$)&&(window.$=n)}();
+/* by a-sansara - v 0.5 - https://github.com/pluie-org/svan */!function(){var n=function(n,i){return typeof n==i},i=function(n,o){return new i.init(n,o)},o=i.isNone=function(i){return n(i,"undefined")},l=i.isStr=function(i){return n(i,"string")},r=i.isFunc=function(i){return n(i,"function")},c=i.isObj=function(i){return n(i,"object")},u=i.isNode=function(n){return c(n)&&!o(n.nodeType)},f=i.isWin=function(n){return c(n)&&!o(n.window)&&n.window==n};i.prototype={regsan:function(n){return n.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")},first:function(){return this.found?this.list[0]:null},last:function(){return this.found?this.list[this.list.length-1]:b},index:function(n){return this.found&&n>0&&no;o++)if(i.options[o].value==n){i.options[o].selected=!0;break}}else i.value=n}):this.found?"select"==this.list[0].nodeName.toLowerCase()?this.list[0].options[this.list[0].selectedIndex].value:this.list[0].value:null},attr:function(n,i){return 1==arguments.length?this.found?"disabled"==n?this.list[0].disabled:this.list[0].getAttribute(n):null:void this.each(function(o){"disabled"==n?o.disabled=i:o.setAttribute(n,i)})},toggle:function(n){this.each(function(i){i.classList.toggle(n)})},hasClass:function(n){return this.found?this.list[0].classList.contains(n):this.found},removeClass:function(n){this.each(function(i){i.classList.contains(n)&&i.classList.toggle(n)})},addClass:function(n){this.each(function(i){i.classList.contains(n)||i.classList.toggle(n)})},fadeIn:function(n,i,o){if(this.found){n||(n=this.FADE_DURATION);var l=parseFloat(1/n*20),r=this.first();r.style.opacity=0,r.style.display=o||"block",function n(){var o=parseFloat(r.style.opacity);(o+=l)<1?(r.style.opacity=o,requestAnimationFrame(n)):"function"==typeof i&&i.call(r)}(n)}},fadeOut:function(n,i){if(this.found){n||(n=this.FADE_DURATION);var o=parseFloat(1/n*20),l=this.first();l.style.opacity=1,function n(){var r=parseFloat(l.style.opacity);(r-=o)<0?(l.style.display="none","function"==typeof i&&i.call(l)):(l.style.opacity=r,requestAnimationFrame(n))}(n)}},ready:function(n){this.context.addEventListener("DOMContentLoaded",n)}},i.eachObj=function(n,i,o){for(var l in n)n.hasOwnProperty(l)&&i.call(o,l,n[l])},i.ajax=function(n){this.eachObj(n,function(n,i){console.log(n),console.log(i)});var i=new XMLHttpRequest;i.onreadystatechange=function(){4==this.readyState&&(200==this.status?r(n.done)&&n.done.call(n.context,this.responseText,this.status):r(n.fail)&&n.fail.call(n.context,this.responseText,this.status),r(n.always)&&n.always.call(n.context,this.responseText,this.status))},!o(n.timeout)&&n.async&&(i.timeout=n.timeout),r(n.before)&&n.before.call(i),i.open(n.method,n.url,n.async),i.setRequestHeader("Content-Type","application/x-www-form-urlencoded");var l="";c(n.data)&&this.eachObj(n.data,function(n,i){l+=n+"="+encodeURIComponent(i)}),i.send(l)};var h=i.init=function(n,i){return this.FADE_DURATION=700,this.VERSION=.5,this.context=o(i)?document:i,this.list=l(n)?[].slice.call(this.context.querySelectorAll(n)):u(n)||f(n)?[n]:[],this.found=this.list.length>0,this};h.prototype=i.prototype,window.Svan=i,o(window.$)&&(window.$=i)}();