diff --git a/dist/nuclear.js b/dist/nuclear.js index f0ff4f368..ac94a7e81 100644 --- a/dist/nuclear.js +++ b/dist/nuclear.js @@ -78,6 +78,10 @@ Nuclear._mixObj = function (obj) { if (this.installed) this.installed(); } + obj.refresh = function () { + this._nuclearLocalRefresh(); + } + //加if防止子类赋值undefined,丢失父类方法 if (obj.render) { obj._nuclearTplGenerator = obj.render; diff --git a/dist/nuclear.min.js b/dist/nuclear.min.js index daea4762e..d90a3ccd8 100644 --- a/dist/nuclear.min.js +++ b/dist/nuclear.min.js @@ -3,4 +3,4 @@ * Github: https://github.com/AlloyTeam/Nuclear * MIT Licensed. */ -!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():"function"==typeof define&&define.cmd?define(function(e,n,r){r.exports=t()}):e.Nuclear=t()}(this,function(){var e={};return e.create=function(t){return e._mixObj(t),t.statics||(t.statics={}),t.statics.create=function(t){return e._mixObj(t),this.extend(t)},e.Class.extend(t)},e._mixObj=function(t){t.ctor=function(t,n){this._nuclearParentEmpty=!n,this.HTML="",this.option=t,this.parent=this._nuclearParentEmpty?document.createElement("div"):"string"==typeof n?document.querySelector(n):n,this.install&&this.install(),this._nuclearRef=[];for(var r in this)this.hasOwnProperty(r)&&this[r]&&this[r]._nuclearLocalRefresh&&(this[r]._nuclearParent=this,this._nuclearRef.push(this[r]));this._nuclearTimer=null,this._preNuclearTime=new Date,this.option&&e.observe(this.option,function(e,t,n,r){(!this.onOptionChange||this.onOptionChange&&this.onOptionChange(e,t,n,r))&&(clearTimeout(this._nuclearTimer),new Date-this._preNuclearTime>40?(this._nuclearLocalRefresh(),this._preNuclearTime=new Date):this._nuclearTimer=setTimeout(function(){this._nuclearLocalRefresh()}.bind(this),40))}.bind(this)),this._nuclearRenderInfo={tpl:this._nuclearTplGenerator(),data:this.option,parent:this.parent},this._nuclearRender(this._nuclearRenderInfo),this.installed&&this.installed()},t.render&&(t._nuclearTplGenerator=t.render),t.render=function(){return this._nuclearParentEmpty?this.HTML:this._nuclearTplGenerator()},t._nuclearRender=function(t){if(this.node){var n=e.str2Dom(e.Tpl.render(t.tpl,t.data));t.parent.replaceChild(n,this.node),this.node=n}else t.parent.insertAdjacentHTML("beforeEnd",e.Tpl.render(t.tpl,t.data)),this.node=t.parent.lastChild;this._nuclearId=e.getId(),this.node.setAttribute("data-nuclearId",this._nuclearId),this.onRefresh&&this.onRefresh(),t.refreshPart=this.node.querySelectorAll("*[nc-refresh]"),this.HTML=this.node.outerHTML,this._nuclearFix()},t._nuclearFix=function(){if(!this._nuclearParent){var e=this._nuclearGetTop(this);this._nuclearFixOne(e)}},t._nuclearFixOne=function(e){var t=e._nuclearRef.length;if(t>0)for(var n=0;t>n;n++){var r=e._nuclearRef[n];r.node=e.node.querySelector('*[data-nuclearId="'+r._nuclearId+'"]'),r.node&&(r._nuclearRenderInfo.refreshPart=r.node.querySelectorAll("*[nc-refresh]"),r._nuclearRenderInfo.parent=r.node.parentNode,r.onRefresh&&r.onRefresh(),r.installed&&r.installed(),this._nuclearFixOne(r))}},t._nuclearGetTop=function(e){return e._nuclearParent?this._nuclearGetTop(e._nuclearParent):e},t._nuclearLocalRefresh=function(){var t=this._nuclearRenderInfo,n=t.refreshPart.length;if(t.tpl=this._nuclearTplGenerator(),n>0){for(var r=e.str2Dom(e.Tpl.render(t.tpl,t.data)).querySelectorAll("*[nc-refresh]"),i=0;n>i;i++){var o=t.refreshPart[i];o.parentNode&&o.parentNode.replaceChild(r[i],o)}t.refreshPart=r,this.onRefresh&&this.onRefresh(),this.HTML=this.node.outerHTML,this._nuclearFix()}else this._nuclearRender(t)}},e._minActionObj=function(e){e.ctor=function(e){this.option=e,this.install&&this.install()}},e.createAction=function(t){return e._minActionObj(t),t.statics||(t.statics={}),t.statics.createAction=function(t){return e._minActionObj(t),this.extend(t)},e.Class.extend(t)},e.throttle=function(e,t,n){var r,i,o,s=null,a=0;n||(n={});var c=function(){a=n.leading===!1?0:Date.now(),s=null,o=e.apply(r,i),s||(r=i=null)};return function(){var l=Date.now();a||n.leading!==!1||(a=l);var u=t-(l-a);return r=this,i=arguments,0>=u||u>t?(clearTimeout(s),s=null,a=l,o=e.apply(r,i),s||(r=i=null)):s||n.trailing===!1||(s=setTimeout(c,u)),o}},e.isElement=function(e){return"object"==typeof HTMLElement?e instanceof HTMLElement:e&&"object"==typeof e&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName},e.str2Dom=function(e){var t={option:[1,""],legend:[1,"
","
"],area:[1,"",""],param:[1,"",""],thead:[1,"","
"],tr:[2,"","
"],col:[2,"","
"],td:[3,"","
"],body:[0,"",""],_default:[1,"
","
"]};t.optgroup=t.option,t.tbody=t.tfoot=t.colgroup=t.caption=t.thead,t.th=t.td;var n=/<\s*\w.*?>/g.exec(e),r=document.createElement("div");if(null!=n){var i=n[0].replace(//g,"").split(" ")[0];if("body"===i.toLowerCase()){var o=(document.implementation.createDocument("http://www.w3.org/1999/xhtml","html",null),document.createElement("body"));r.innerHTML=e.replace(//g,"");var s=r.firstChild.attributes;o.innerHTML=e;for(var a=0;a=0?e.removeClass(t,n):e.addClass(t,n)},e.trim=function(e){return e.replace(/^\s\s*/,"").replace(/\s\s*$/,"")},e._iteration=function(t,n){var n=Array.prototype.slice.call(n);e.each(n[0],function(r){var i=n[0];n[0]=n[0][r],e[t].apply(e,n),n[0]=i})},e.css=function(t,n,r){return t?e.isNodeList(t)?void e._iteration("css",arguments):(3==arguments.length&&t.style&&(t.style[n]=r),window.getComputedStyle(t,null)[n]):void 0},e.each=function(e,t){for(var n=0,r=e.length;r>n;n++)t.call(e[n],n)},e.offset=function(e){var t=0,n=0;if(!document.documentElement.getBoundingClientRect||!e.getBoundingClientRect){for(;e.offsetParent;)t+=e.offsetTop,n+=e.offsetLeft,e=e.offsetParent;return{left:n,top:t}}var r=e.getBoundingClientRect();return n=r.left,t=r.top,{left:n+Math.max(document.documentElement.scrollLeft,document.body.scrollLeft),top:t+Math.max(document.documentElement.scrollTop,document.body.scrollTop)}},e.getViewport=function(){var e=document.documentElement,t=document.body,n=window,r=document.createElement("div");r.innerHTML=" ";var i=3!==r.firstChild.nodeType?{left:t.scrollLeft||e.scrollLeft,top:t.scrollTop||e.scrollTop}:{left:n.pageXOffset,top:n.pageYOffset},o=n.innerWidth?{width:n.innerWidth,height:n.innerHeight}:e&&e.clientWidth&&0!=e.clientWidth?{width:e.clientWidth,height:e.clientHeight}:{width:t.clientWidth,height:t.clientHeight};return{left:i.left,top:i.top,width:o.width,height:o.height}},e.getLastNode=function(e,t){var n=e.querySelectorAll(t),r=n.length;return n[r-1]},e.isUndefined=function(e){return"undefined"==typeof e},e.domready=function(){var e,t=[],n=document,r=n.documentElement.doScroll,i="DOMContentLoaded",o=(r?/^loaded|^c/:/^loaded|^i|^c/).test(n.readyState);return o||n.addEventListener(i,e=function(){for(n.removeEventListener(i,e),o=1;e=t.shift();)e()}),function(e){o?setTimeout(e,0):t.push(e)}}(),function(){var t={},n=Object.prototype.toString;"Boolean Number String Function Array Date RegExp Object Error NodeList".split(" ").forEach(function(e){t["[object "+e+"]"]=e.toLowerCase()});var r=function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?t[n.call(e)]||"object":typeof e},i=function(e){return"nodelist"===r(e)},o=function(e){return"function"===r(e)},s=function(e){return"array"===r(e)},a=function(e){return null!=e&&e===e.window},c=function(e){return"object"!==r(e)||e.nodeType||a(e)?!1:e.constructor&&!hasOwn.call(e.constructor.prototype,"isPrototypeOf")?!1:!0};e.type=r,e.isFunction=o,e.isArray=s,e.isWindow=a,e.isPlainObject=c,e.isNodeList=i}(),e.merge=function(){var t,n,r,i,o,s,a=arguments[0]||{},c=1,l=arguments.length,u=!1;for("boolean"==typeof a&&(u=a,a=arguments[c]||{},c++),"object"==typeof a||e.isFunction(a)||(a={}),c===l&&(a=this,c--);l>c;c++)if(null!=(t=arguments[c]))for(n in t)r=a[n],i=t[n],a!==i&&(u&&i&&(e.isPlainObject(i)||(o=e.isArray(i)))?(o?(o=!1,s=r&&e.isArray(r)?r:[]):s=r&&e.isPlainObject(r)?r:{},a[n]=e.merge(u,s,i)):void 0!==i&&(a[n]=i));return a},e.uuid=function(){var e=(new Date).getTime(),t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?n:3&n|8).toString(16)});return t},e.createCanvas=function(t){return e._minCanvasObj(t),t.statics||(t.statics={}),t.statics.create=function(t){return e._minCanvasObj(t),this.extend(t)},e.Class.extend(t)},e._minCanvasObj=function(t){t.ctor=function(t,n,r,i){this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),this.canvas.width=t,this.canvas.height=n,this.parent="string"==typeof i?document.querySelector(i):i,this.option=r,this.install&&this.install(),this.option&&e.observe(this.option,e.throttle(this._nuclearRender.bind(this),15)),this._nuclearRender(),this.installed&&this.installed(),this.parent.appendChild(this.canvas)},t._nuclearRender=function(e){this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.render()}},e._nextID=0,e.getId=function(){return e._nextID++},function(t,n){e.Tpl={},n(e.Tpl)}(this,function(e){function t(e){return"function"==typeof e}function n(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function r(e,t){return d.call(e,t)}function i(e){return!r(v,e)}function o(e){return String(e).replace(/[&<>"'\/]/g,function(e){return g[e]})}function s(t,r){function o(){if(_&&!P)for(;g.length;)delete v[g.pop()];else g=[];_=!1,P=!1}function s(e){if("string"==typeof e&&(e=e.split(m,2)),!f(e)||2!==e.length)throw new Error("Invalid tags: "+e);u=new RegExp(n(e[0])+"\\s*"),h=new RegExp("\\s*"+n(e[1])),p=new RegExp("\\s*"+n("}"+e[1]))}if(!t)return[];var u,h,p,d=[],v=[],g=[],_=!1,P=!1;s(r||e.tags);for(var T,C,E,O,j,R,A=new l(t);!A.eos();){if(T=A.pos,E=A.scanUntil(u))for(var L=0,$=E.length;$>L;++L)O=E.charAt(L),i(O)?g.push(v.length):P=!0,v.push(["text",O,T,T+1]),T+=1,"\n"===O&&o();if(!A.scan(u))break;if(_=!0,C=A.scan(x)||"name",A.scan(y),"="===C?(E=A.scanUntil(b),A.scan(b),A.scanUntil(h)):"{"===C?(E=A.scanUntil(p),A.scan(w),A.scanUntil(h),C="&"):E=A.scanUntil(h),!A.scan(h))throw new Error("Unclosed tag at "+A.pos);if(j=[C,E,T,A.pos],v.push(j),"#"===C||"^"===C)d.push(j);else if("/"===C){if(R=d.pop(),!R)throw new Error('Unopened section "'+E+'" at '+T);if(R[1]!==E)throw new Error('Unclosed section "'+R[1]+'" at '+T)}else"name"===C||"{"===C||"&"===C?P=!0:"="===C&&s(E)}if(R=d.pop())throw new Error('Unclosed section "'+R[1]+'" at '+A.pos);return c(a(v))}function a(e){for(var t,n,r=[],i=0,o=e.length;o>i;++i)t=e[i],t&&("text"===t[0]&&n&&"text"===n[0]?(n[1]+=t[1],n[3]=t[3]):(r.push(t),n=t));return r}function c(e){for(var t,n,r=[],i=r,o=[],s=0,a=e.length;a>s;++s)switch(t=e[s],t[0]){case"#":case"^":i.push(t),o.push(t),i=t[4]=[];break;case"/":n=o.pop(),n[5]=t[2],i=o.length>0?o[o.length-1][4]:r;break;default:i.push(t)}return r}function l(e){this.string=e,this.tail=e,this.pos=0}function u(e,t){this.view=e,this.cache={".":this.view},this.parent=t}function h(){this.cache={}}var p=Object.prototype.toString,f=Array.isArray||function(e){return"[object Array]"===p.call(e)},d=RegExp.prototype.test,v=/\S/,g={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},y=/\s*/,m=/\s+/,b=/\s*=/,w=/\s*\}/,x=/#|\^|\/|>|\{|&|=|!/;l.prototype.eos=function(){return""===this.tail},l.prototype.scan=function(e){var t=this.tail.match(e);if(!t||0!==t.index)return"";var n=t[0];return this.tail=this.tail.substring(n.length),this.pos+=n.length,n},l.prototype.scanUntil=function(e){var t,n=this.tail.search(e);switch(n){case-1:t=this.tail,this.tail="";break;case 0:t="";break;default:t=this.tail.substring(0,n),this.tail=this.tail.substring(n)}return this.pos+=t.length,t},u.prototype.push=function(e){return new u(e,this)},u.prototype.lookup=function(e){var n,r=this.cache;if(e in r)n=r[e];else{for(var i,o,s=this,a=!1;s;){if(e.indexOf(".")>0)for(n=s.view,i=e.split("."),o=0;null!=n&&oc;++c)s=void 0,i=e[c],o=i[0],"#"===o?s=this.renderSection(i,t,n,r):"^"===o?s=this.renderInverted(i,t,n,r):">"===o?s=this.renderPartial(i,t,n,r):"&"===o?s=this.unescapedValue(i,t):"name"===o?s=this.escapedValue(i,t):"text"===o&&(s=this.rawValue(i)),void 0!==s&&(a+=s);return a},h.prototype.renderSection=function(e,n,r,i){function o(e){return s.render(e,n,r)}var s=this,a="",c=n.lookup(e[1]);if(c){if(f(c))for(var l=0,u=c.length;u>l;++l)a+=this.renderTokens(e[4],n.push(c[l]),r,i);else if("object"==typeof c||"string"==typeof c||"number"==typeof c)a+=this.renderTokens(e[4],n.push(c),r,i);else if(t(c)){if("string"!=typeof i)throw new Error("Cannot use higher-order sections without the original template");c=c.call(n.view,i.slice(e[3],e[5]),o),null!=c&&(a+=c)}else a+=this.renderTokens(e[4],n,r,i);return a}},h.prototype.renderInverted=function(e,t,n,r){var i=t.lookup(e[1]);return!i||f(i)&&0===i.length?this.renderTokens(e[4],t,n,r):void 0},h.prototype.renderPartial=function(e,n,r){if(r){var i=t(r)?r(e[1]):r[e[1]];return null!=i?this.renderTokens(this.parse(i),n,r,i):void 0}},h.prototype.unescapedValue=function(e,t){var n=t.lookup(e[1]);return null!=n?n:void 0},h.prototype.escapedValue=function(t,n){var r=n.lookup(t[1]);return null!=r?e.escape(r):void 0},h.prototype.rawValue=function(e){return e[1]},e.name="mustache.js",e.version="2.0.0",e.tags=["{{","}}"];var _=new h;e.clearCache=function(){return _.clearCache()},e.parse=function(e,t){return _.parse(e,t)},e.render=function(e,t,n){return _.render(e,t,n)},e.to_html=function(n,r,i,o){var s=e.render(n,r,i);return t(o)?void o(s):s},e.escape=o,e.Scanner=l,e.Context=u,e.Writer=h}),function(){var t=function(e,n,r){var i=function(e,n,r){e.$observer||(e.$observer=this);var i=e.$observer,o=[];t.isArray(e)&&(0===e.length&&(e.$observeProps={},e.$observeProps.$observerPath="#"),i.mock(e));for(var s in e)e.hasOwnProperty(s)&&(r?t.isArray(n)&&t.isInArray(n,s)?(o.push(s),i.watch(e,s)):t.isString(n)&&s==n&&(o.push(s),i.watch(e,s)):(o.push(s),i.watch(e,s)));i.target=e,i.propertyChangedHandler||(i.propertyChangedHandler=[]);var a=r?r:n;i.propertyChangedHandler.push({all:!r,propChanged:a,eventPropArr:o})};return i.prototype={onPropertyChanged:function(e,n,r,i,o){if(n!==r&&this.propertyChangedHandler)for(var s=t._getRootName(e,o),a=0,c=this.propertyChangedHandler.length;c>a;a++){var l=this.propertyChangedHandler[a];(l.all||t.isInArray(l.eventPropArr,s)||0===s.indexOf("Array-"))&&l.propChanged.call(this.target,e,n,r,o)}0!==e.indexOf("Array-")&&"object"==typeof n&&this.watch(i,e,i.$observeProps.$observerPath)},mock:function(e){var n=this;t.methods.forEach(function(r){e[r]=function(){var e=Array.prototype.slice.call(this,0),i=Array.prototype[r].apply(this,Array.prototype.slice.call(arguments));if(new RegExp("\\b"+r+"\\b").test(t.triggerStr)){for(var o in this)this.hasOwnProperty(o)&&!t.isFunction(this[o])&&n.watch(this,o,this.$observeProps.$observerPath);n.onPropertyChanged("Array-"+r,this,e,this,this.$observeProps.$observerPath)}return i}})},watch:function(e,n,r){if("$observeProps"!==n&&"$observer"!==n&&!t.isFunction(e[n])){e.$observeProps||(e.$observeProps={}),e.$observeProps.$observerPath=void 0!==r?r:"#";var i=this,o=e.$observeProps[n]=e[n];if(Object.defineProperty(e,n,{get:function(){return this.$observeProps[n]},set:function(t){var r=this.$observeProps[n];this.$observeProps[n]=t,i.onPropertyChanged(n,t,r,this,e.$observeProps.$observerPath)}}),"object"==typeof o){t.isArray(o)&&(this.mock(o),0===o.length&&(o.$observeProps||(o.$observeProps={}),o.$observeProps.$observerPath=void 0!==r?r:"#"));for(var s in o)o.hasOwnProperty(s)&&this.watch(o,s,e.$observeProps.$observerPath+"-"+n)}}}},new i(e,n,r)};t.methods=["concat","every","filter","forEach","indexOf","join","lastIndexOf","map","pop","push","reduce","reduceRight","reverse","shift","slice","some","sort","splice","unshift","toLocaleString","toString","size"],t.triggerStr=["concat","pop","push","reverse","shift","sort","splice","unshift","size"].join(","),t.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)},t.isString=function(e){return"string"==typeof e},t.isInArray=function(e,t){for(var n=e.length;--n>-1;)if(t===e[n])return!0;return!1},t.isFunction=function(e){return"[object Function]"==Object.prototype.toString.call(e)},t.twoWay=function(e,n,r,i){"object"==typeof e[n]&&"object"==typeof r[i]?(t(e,n,function(e,t){r[i]=this[n]}),t(r,i,function(t,r){e[n]=this[i]})):(t(e,n,function(e,t){r[i]=t}),t(r,i,function(t,r){e[n]=r}))},t._getRootName=function(e,t){return"#"===t?e:t.split("-")[1]},t.add=function(e,t,n){e[t]=n;var r=e.$observer;r.watch(e,t)},Array.prototype.size=function(e){this.length=e},e.observe=t}(),function(){var t=!1,n=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/,r=function(){};r.extend=function(e){function i(){!t&&this.ctor&&this.ctor.apply(this,arguments)}var o=this.prototype;t=!0;var s=new this;t=!1;for(var a in e)"statics"!=a&&(s[a]="function"==typeof e[a]&&"function"==typeof o[a]&&n.test(e[a])?function(e,t){return function(){var n=this._super;this._super=o[e];var r=t.apply(this,arguments);return this._super=n,r}}(a,e[a]):e[a]);for(var c in this)this.hasOwnProperty(c)&&"extend"!=c&&(i[c]=this[c]);if(i.prototype=s,e.statics)for(var a in e.statics)e.statics.hasOwnProperty(a)&&(i[a]=e.statics[a],"ctor"==a&&i[a]());return i.prototype.constructor=i,i.extend=r.extend,i.implement=function(e){for(var t in e)s[t]=e[t]},i},e.Class=r}(),e}); \ No newline at end of file +!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():"function"==typeof define&&define.cmd?define(function(e,n,r){r.exports=t()}):e.Nuclear=t()}(this,function(){var e={};return e.create=function(t){return e._mixObj(t),t.statics||(t.statics={}),t.statics.create=function(t){return e._mixObj(t),this.extend(t)},e.Class.extend(t)},e._mixObj=function(t){t.ctor=function(t,n){this._nuclearParentEmpty=!n,this.HTML="",this.option=t,this.parent=this._nuclearParentEmpty?document.createElement("div"):"string"==typeof n?document.querySelector(n):n,this.install&&this.install(),this._nuclearRef=[];for(var r in this)this.hasOwnProperty(r)&&this[r]&&this[r]._nuclearLocalRefresh&&(this[r]._nuclearParent=this,this._nuclearRef.push(this[r]));this._nuclearTimer=null,this._preNuclearTime=new Date,this.option&&e.observe(this.option,function(e,t,n,r){(!this.onOptionChange||this.onOptionChange&&this.onOptionChange(e,t,n,r))&&(clearTimeout(this._nuclearTimer),new Date-this._preNuclearTime>40?(this._nuclearLocalRefresh(),this._preNuclearTime=new Date):this._nuclearTimer=setTimeout(function(){this._nuclearLocalRefresh()}.bind(this),40))}.bind(this)),this._nuclearRenderInfo={tpl:this._nuclearTplGenerator(),data:this.option,parent:this.parent},this._nuclearRender(this._nuclearRenderInfo),this.installed&&this.installed()},t.refresh=function(){this._nuclearLocalRefresh()},t.render&&(t._nuclearTplGenerator=t.render),t.render=function(){return this._nuclearParentEmpty?this.HTML:this._nuclearTplGenerator()},t._nuclearRender=function(t){if(this.node){var n=e.str2Dom(e.Tpl.render(t.tpl,t.data));t.parent.replaceChild(n,this.node),this.node=n}else t.parent.insertAdjacentHTML("beforeEnd",e.Tpl.render(t.tpl,t.data)),this.node=t.parent.lastChild;this._nuclearId=e.getId(),this.node.setAttribute("data-nuclearId",this._nuclearId),this.onRefresh&&this.onRefresh(),t.refreshPart=this.node.querySelectorAll("*[nc-refresh]"),this.HTML=this.node.outerHTML,this._nuclearFix()},t._nuclearFix=function(){if(!this._nuclearParent){var e=this._nuclearGetTop(this);this._nuclearFixOne(e)}},t._nuclearFixOne=function(e){var t=e._nuclearRef.length;if(t>0)for(var n=0;t>n;n++){var r=e._nuclearRef[n];r.node=e.node.querySelector('*[data-nuclearId="'+r._nuclearId+'"]'),r.node&&(r._nuclearRenderInfo.refreshPart=r.node.querySelectorAll("*[nc-refresh]"),r._nuclearRenderInfo.parent=r.node.parentNode,r.onRefresh&&r.onRefresh(),r.installed&&r.installed(),this._nuclearFixOne(r))}},t._nuclearGetTop=function(e){return e._nuclearParent?this._nuclearGetTop(e._nuclearParent):e},t._nuclearLocalRefresh=function(){var t=this._nuclearRenderInfo,n=t.refreshPart.length;if(t.tpl=this._nuclearTplGenerator(),n>0){for(var r=e.str2Dom(e.Tpl.render(t.tpl,t.data)).querySelectorAll("*[nc-refresh]"),i=0;n>i;i++){var o=t.refreshPart[i];o.parentNode&&o.parentNode.replaceChild(r[i],o)}t.refreshPart=r,this.onRefresh&&this.onRefresh(),this.HTML=this.node.outerHTML,this._nuclearFix()}else this._nuclearRender(t)}},e._minActionObj=function(e){e.ctor=function(e){this.option=e,this.install&&this.install()}},e.createAction=function(t){return e._minActionObj(t),t.statics||(t.statics={}),t.statics.createAction=function(t){return e._minActionObj(t),this.extend(t)},e.Class.extend(t)},e.throttle=function(e,t,n){var r,i,o,s=null,a=0;n||(n={});var c=function(){a=n.leading===!1?0:Date.now(),s=null,o=e.apply(r,i),s||(r=i=null)};return function(){var l=Date.now();a||n.leading!==!1||(a=l);var u=t-(l-a);return r=this,i=arguments,0>=u||u>t?(clearTimeout(s),s=null,a=l,o=e.apply(r,i),s||(r=i=null)):s||n.trailing===!1||(s=setTimeout(c,u)),o}},e.isElement=function(e){return"object"==typeof HTMLElement?e instanceof HTMLElement:e&&"object"==typeof e&&null!==e&&1===e.nodeType&&"string"==typeof e.nodeName},e.str2Dom=function(e){var t={option:[1,""],legend:[1,"
","
"],area:[1,"",""],param:[1,"",""],thead:[1,"","
"],tr:[2,"","
"],col:[2,"","
"],td:[3,"","
"],body:[0,"",""],_default:[1,"
","
"]};t.optgroup=t.option,t.tbody=t.tfoot=t.colgroup=t.caption=t.thead,t.th=t.td;var n=/<\s*\w.*?>/g.exec(e),r=document.createElement("div");if(null!=n){var i=n[0].replace(//g,"").split(" ")[0];if("body"===i.toLowerCase()){var o=(document.implementation.createDocument("http://www.w3.org/1999/xhtml","html",null),document.createElement("body"));r.innerHTML=e.replace(//g,"");var s=r.firstChild.attributes;o.innerHTML=e;for(var a=0;a=0?e.removeClass(t,n):e.addClass(t,n)},e.trim=function(e){return e.replace(/^\s\s*/,"").replace(/\s\s*$/,"")},e._iteration=function(t,n){var n=Array.prototype.slice.call(n);e.each(n[0],function(r){var i=n[0];n[0]=n[0][r],e[t].apply(e,n),n[0]=i})},e.css=function(t,n,r){return t?e.isNodeList(t)?void e._iteration("css",arguments):(3==arguments.length&&t.style&&(t.style[n]=r),window.getComputedStyle(t,null)[n]):void 0},e.each=function(e,t){for(var n=0,r=e.length;r>n;n++)t.call(e[n],n)},e.offset=function(e){var t=0,n=0;if(!document.documentElement.getBoundingClientRect||!e.getBoundingClientRect){for(;e.offsetParent;)t+=e.offsetTop,n+=e.offsetLeft,e=e.offsetParent;return{left:n,top:t}}var r=e.getBoundingClientRect();return n=r.left,t=r.top,{left:n+Math.max(document.documentElement.scrollLeft,document.body.scrollLeft),top:t+Math.max(document.documentElement.scrollTop,document.body.scrollTop)}},e.getViewport=function(){var e=document.documentElement,t=document.body,n=window,r=document.createElement("div");r.innerHTML=" ";var i=3!==r.firstChild.nodeType?{left:t.scrollLeft||e.scrollLeft,top:t.scrollTop||e.scrollTop}:{left:n.pageXOffset,top:n.pageYOffset},o=n.innerWidth?{width:n.innerWidth,height:n.innerHeight}:e&&e.clientWidth&&0!=e.clientWidth?{width:e.clientWidth,height:e.clientHeight}:{width:t.clientWidth,height:t.clientHeight};return{left:i.left,top:i.top,width:o.width,height:o.height}},e.getLastNode=function(e,t){var n=e.querySelectorAll(t),r=n.length;return n[r-1]},e.isUndefined=function(e){return"undefined"==typeof e},e.domready=function(){var e,t=[],n=document,r=n.documentElement.doScroll,i="DOMContentLoaded",o=(r?/^loaded|^c/:/^loaded|^i|^c/).test(n.readyState);return o||n.addEventListener(i,e=function(){for(n.removeEventListener(i,e),o=1;e=t.shift();)e()}),function(e){o?setTimeout(e,0):t.push(e)}}(),function(){var t={},n=Object.prototype.toString;"Boolean Number String Function Array Date RegExp Object Error NodeList".split(" ").forEach(function(e){t["[object "+e+"]"]=e.toLowerCase()});var r=function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?t[n.call(e)]||"object":typeof e},i=function(e){return"nodelist"===r(e)},o=function(e){return"function"===r(e)},s=function(e){return"array"===r(e)},a=function(e){return null!=e&&e===e.window},c=function(e){return"object"!==r(e)||e.nodeType||a(e)?!1:e.constructor&&!hasOwn.call(e.constructor.prototype,"isPrototypeOf")?!1:!0};e.type=r,e.isFunction=o,e.isArray=s,e.isWindow=a,e.isPlainObject=c,e.isNodeList=i}(),e.merge=function(){var t,n,r,i,o,s,a=arguments[0]||{},c=1,l=arguments.length,u=!1;for("boolean"==typeof a&&(u=a,a=arguments[c]||{},c++),"object"==typeof a||e.isFunction(a)||(a={}),c===l&&(a=this,c--);l>c;c++)if(null!=(t=arguments[c]))for(n in t)r=a[n],i=t[n],a!==i&&(u&&i&&(e.isPlainObject(i)||(o=e.isArray(i)))?(o?(o=!1,s=r&&e.isArray(r)?r:[]):s=r&&e.isPlainObject(r)?r:{},a[n]=e.merge(u,s,i)):void 0!==i&&(a[n]=i));return a},e.uuid=function(){var e=(new Date).getTime(),t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?n:3&n|8).toString(16)});return t},e.createCanvas=function(t){return e._minCanvasObj(t),t.statics||(t.statics={}),t.statics.create=function(t){return e._minCanvasObj(t),this.extend(t)},e.Class.extend(t)},e._minCanvasObj=function(t){t.ctor=function(t,n,r,i){this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),this.canvas.width=t,this.canvas.height=n,this.parent="string"==typeof i?document.querySelector(i):i,this.option=r,this.install&&this.install(),this.option&&e.observe(this.option,e.throttle(this._nuclearRender.bind(this),15)),this._nuclearRender(),this.installed&&this.installed(),this.parent.appendChild(this.canvas)},t._nuclearRender=function(e){this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.render()}},e._nextID=0,e.getId=function(){return e._nextID++},function(t,n){e.Tpl={},n(e.Tpl)}(this,function(e){function t(e){return"function"==typeof e}function n(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function r(e,t){return d.call(e,t)}function i(e){return!r(v,e)}function o(e){return String(e).replace(/[&<>"'\/]/g,function(e){return g[e]})}function s(t,r){function o(){if(_&&!P)for(;g.length;)delete v[g.pop()];else g=[];_=!1,P=!1}function s(e){if("string"==typeof e&&(e=e.split(m,2)),!p(e)||2!==e.length)throw new Error("Invalid tags: "+e);u=new RegExp(n(e[0])+"\\s*"),h=new RegExp("\\s*"+n(e[1])),f=new RegExp("\\s*"+n("}"+e[1]))}if(!t)return[];var u,h,f,d=[],v=[],g=[],_=!1,P=!1;s(r||e.tags);for(var T,C,E,O,j,R,L=new l(t);!L.eos();){if(T=L.pos,E=L.scanUntil(u))for(var A=0,$=E.length;$>A;++A)O=E.charAt(A),i(O)?g.push(v.length):P=!0,v.push(["text",O,T,T+1]),T+=1,"\n"===O&&o();if(!L.scan(u))break;if(_=!0,C=L.scan(x)||"name",L.scan(y),"="===C?(E=L.scanUntil(b),L.scan(b),L.scanUntil(h)):"{"===C?(E=L.scanUntil(f),L.scan(w),L.scanUntil(h),C="&"):E=L.scanUntil(h),!L.scan(h))throw new Error("Unclosed tag at "+L.pos);if(j=[C,E,T,L.pos],v.push(j),"#"===C||"^"===C)d.push(j);else if("/"===C){if(R=d.pop(),!R)throw new Error('Unopened section "'+E+'" at '+T);if(R[1]!==E)throw new Error('Unclosed section "'+R[1]+'" at '+T)}else"name"===C||"{"===C||"&"===C?P=!0:"="===C&&s(E)}if(R=d.pop())throw new Error('Unclosed section "'+R[1]+'" at '+L.pos);return c(a(v))}function a(e){for(var t,n,r=[],i=0,o=e.length;o>i;++i)t=e[i],t&&("text"===t[0]&&n&&"text"===n[0]?(n[1]+=t[1],n[3]=t[3]):(r.push(t),n=t));return r}function c(e){for(var t,n,r=[],i=r,o=[],s=0,a=e.length;a>s;++s)switch(t=e[s],t[0]){case"#":case"^":i.push(t),o.push(t),i=t[4]=[];break;case"/":n=o.pop(),n[5]=t[2],i=o.length>0?o[o.length-1][4]:r;break;default:i.push(t)}return r}function l(e){this.string=e,this.tail=e,this.pos=0}function u(e,t){this.view=e,this.cache={".":this.view},this.parent=t}function h(){this.cache={}}var f=Object.prototype.toString,p=Array.isArray||function(e){return"[object Array]"===f.call(e)},d=RegExp.prototype.test,v=/\S/,g={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"},y=/\s*/,m=/\s+/,b=/\s*=/,w=/\s*\}/,x=/#|\^|\/|>|\{|&|=|!/;l.prototype.eos=function(){return""===this.tail},l.prototype.scan=function(e){var t=this.tail.match(e);if(!t||0!==t.index)return"";var n=t[0];return this.tail=this.tail.substring(n.length),this.pos+=n.length,n},l.prototype.scanUntil=function(e){var t,n=this.tail.search(e);switch(n){case-1:t=this.tail,this.tail="";break;case 0:t="";break;default:t=this.tail.substring(0,n),this.tail=this.tail.substring(n)}return this.pos+=t.length,t},u.prototype.push=function(e){return new u(e,this)},u.prototype.lookup=function(e){var n,r=this.cache;if(e in r)n=r[e];else{for(var i,o,s=this,a=!1;s;){if(e.indexOf(".")>0)for(n=s.view,i=e.split("."),o=0;null!=n&&oc;++c)s=void 0,i=e[c],o=i[0],"#"===o?s=this.renderSection(i,t,n,r):"^"===o?s=this.renderInverted(i,t,n,r):">"===o?s=this.renderPartial(i,t,n,r):"&"===o?s=this.unescapedValue(i,t):"name"===o?s=this.escapedValue(i,t):"text"===o&&(s=this.rawValue(i)),void 0!==s&&(a+=s);return a},h.prototype.renderSection=function(e,n,r,i){function o(e){return s.render(e,n,r)}var s=this,a="",c=n.lookup(e[1]);if(c){if(p(c))for(var l=0,u=c.length;u>l;++l)a+=this.renderTokens(e[4],n.push(c[l]),r,i);else if("object"==typeof c||"string"==typeof c||"number"==typeof c)a+=this.renderTokens(e[4],n.push(c),r,i);else if(t(c)){if("string"!=typeof i)throw new Error("Cannot use higher-order sections without the original template");c=c.call(n.view,i.slice(e[3],e[5]),o),null!=c&&(a+=c)}else a+=this.renderTokens(e[4],n,r,i);return a}},h.prototype.renderInverted=function(e,t,n,r){var i=t.lookup(e[1]);return!i||p(i)&&0===i.length?this.renderTokens(e[4],t,n,r):void 0},h.prototype.renderPartial=function(e,n,r){if(r){var i=t(r)?r(e[1]):r[e[1]];return null!=i?this.renderTokens(this.parse(i),n,r,i):void 0}},h.prototype.unescapedValue=function(e,t){var n=t.lookup(e[1]);return null!=n?n:void 0},h.prototype.escapedValue=function(t,n){var r=n.lookup(t[1]);return null!=r?e.escape(r):void 0},h.prototype.rawValue=function(e){return e[1]},e.name="mustache.js",e.version="2.0.0",e.tags=["{{","}}"];var _=new h;e.clearCache=function(){return _.clearCache()},e.parse=function(e,t){return _.parse(e,t)},e.render=function(e,t,n){return _.render(e,t,n)},e.to_html=function(n,r,i,o){var s=e.render(n,r,i);return t(o)?void o(s):s},e.escape=o,e.Scanner=l,e.Context=u,e.Writer=h}),function(){var t=function(e,n,r){var i=function(e,n,r){e.$observer||(e.$observer=this);var i=e.$observer,o=[];t.isArray(e)&&(0===e.length&&(e.$observeProps={},e.$observeProps.$observerPath="#"),i.mock(e));for(var s in e)e.hasOwnProperty(s)&&(r?t.isArray(n)&&t.isInArray(n,s)?(o.push(s),i.watch(e,s)):t.isString(n)&&s==n&&(o.push(s),i.watch(e,s)):(o.push(s),i.watch(e,s)));i.target=e,i.propertyChangedHandler||(i.propertyChangedHandler=[]);var a=r?r:n;i.propertyChangedHandler.push({all:!r,propChanged:a,eventPropArr:o})};return i.prototype={onPropertyChanged:function(e,n,r,i,o){if(n!==r&&this.propertyChangedHandler)for(var s=t._getRootName(e,o),a=0,c=this.propertyChangedHandler.length;c>a;a++){var l=this.propertyChangedHandler[a];(l.all||t.isInArray(l.eventPropArr,s)||0===s.indexOf("Array-"))&&l.propChanged.call(this.target,e,n,r,o)}0!==e.indexOf("Array-")&&"object"==typeof n&&this.watch(i,e,i.$observeProps.$observerPath)},mock:function(e){var n=this;t.methods.forEach(function(r){e[r]=function(){var e=Array.prototype.slice.call(this,0),i=Array.prototype[r].apply(this,Array.prototype.slice.call(arguments));if(new RegExp("\\b"+r+"\\b").test(t.triggerStr)){for(var o in this)this.hasOwnProperty(o)&&!t.isFunction(this[o])&&n.watch(this,o,this.$observeProps.$observerPath);n.onPropertyChanged("Array-"+r,this,e,this,this.$observeProps.$observerPath)}return i}})},watch:function(e,n,r){if("$observeProps"!==n&&"$observer"!==n&&!t.isFunction(e[n])){e.$observeProps||(e.$observeProps={}),e.$observeProps.$observerPath=void 0!==r?r:"#";var i=this,o=e.$observeProps[n]=e[n];if(Object.defineProperty(e,n,{get:function(){return this.$observeProps[n]},set:function(t){var r=this.$observeProps[n];this.$observeProps[n]=t,i.onPropertyChanged(n,t,r,this,e.$observeProps.$observerPath)}}),"object"==typeof o){t.isArray(o)&&(this.mock(o),0===o.length&&(o.$observeProps||(o.$observeProps={}),o.$observeProps.$observerPath=void 0!==r?r:"#"));for(var s in o)o.hasOwnProperty(s)&&this.watch(o,s,e.$observeProps.$observerPath+"-"+n)}}}},new i(e,n,r)};t.methods=["concat","every","filter","forEach","indexOf","join","lastIndexOf","map","pop","push","reduce","reduceRight","reverse","shift","slice","some","sort","splice","unshift","toLocaleString","toString","size"],t.triggerStr=["concat","pop","push","reverse","shift","sort","splice","unshift","size"].join(","),t.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)},t.isString=function(e){return"string"==typeof e},t.isInArray=function(e,t){for(var n=e.length;--n>-1;)if(t===e[n])return!0;return!1},t.isFunction=function(e){return"[object Function]"==Object.prototype.toString.call(e)},t.twoWay=function(e,n,r,i){"object"==typeof e[n]&&"object"==typeof r[i]?(t(e,n,function(e,t){r[i]=this[n]}),t(r,i,function(t,r){e[n]=this[i]})):(t(e,n,function(e,t){r[i]=t}),t(r,i,function(t,r){e[n]=r}))},t._getRootName=function(e,t){return"#"===t?e:t.split("-")[1]},t.add=function(e,t,n){e[t]=n;var r=e.$observer;r.watch(e,t)},Array.prototype.size=function(e){this.length=e},e.observe=t}(),function(){var t=!1,n=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/,r=function(){};r.extend=function(e){function i(){!t&&this.ctor&&this.ctor.apply(this,arguments)}var o=this.prototype;t=!0;var s=new this;t=!1;for(var a in e)"statics"!=a&&(s[a]="function"==typeof e[a]&&"function"==typeof o[a]&&n.test(e[a])?function(e,t){return function(){var n=this._super;this._super=o[e];var r=t.apply(this,arguments);return this._super=n,r}}(a,e[a]):e[a]);for(var c in this)this.hasOwnProperty(c)&&"extend"!=c&&(i[c]=this[c]);if(i.prototype=s,e.statics)for(var a in e.statics)e.statics.hasOwnProperty(a)&&(i[a]=e.statics[a],"ctor"==a&&i[a]());return i.prototype.constructor=i,i.extend=r.extend,i.implement=function(e){for(var t in e)s[t]=e[t]},i},e.Class=r}(),e}); \ No newline at end of file diff --git a/example/todo4.html b/example/todo4.html new file mode 100644 index 000000000..b77a983d4 --- /dev/null +++ b/example/todo4.html @@ -0,0 +1,47 @@ + + + + Todo + + +
+ + + + + + + diff --git a/src/nuclear.js b/src/nuclear.js index ab398f895..499db53f4 100644 --- a/src/nuclear.js +++ b/src/nuclear.js @@ -59,6 +59,10 @@ Nuclear._mixObj = function (obj) { if (this.installed) this.installed(); } + obj.refresh = function () { + this._nuclearLocalRefresh(); + } + //加if防止子类赋值undefined,丢失父类方法 if (obj.render) { obj._nuclearTplGenerator = obj.render;