pagination
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -52,7 +52,11 @@ exports.module = function(pagination, util) { | ||
var _escape = function(text) { | ||
return String(text).replace(/&(?!\w+;)/g, '&').replace(/</g, '<') | ||
.replace(/>/g, '>').replace(/"/g, '"'); | ||
return String(text) | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, '''); | ||
}; | ||
var _compile = function(str, options) { | ||
var fn = new Function('paginationData', parse(str, options)); | ||
var fn = new Function('paginationData, escape', parse(str, options)); | ||
return function(paginationData){ | ||
@@ -59,0 +63,0 @@ return fn.call(this, paginationData, _escape); |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"scripts": { | ||
@@ -17,0 +17,0 @@ "test": "vows --spec tests/*" |
@@ -1,1 +0,1 @@ | ||
window.pagination={},window.exports=pagination,window.pagination.util={inherits:function(t,e){if(!e||!t)throw new Error("extend failed, please check that all dependencies are included.");var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t,t.superclass=e.prototype,e.prototype.constructor===Object.prototype.constructor&&(e.prototype.constructor=e)}},Object.keys||(Object.keys=function(t){var e,r=[],n=Object.prototype.hasOwnProperty;if(t!==Object(t))throw new TypeError("Object.keys called on a non-object");for(e in t)n.call(t,e)&&r.push(e);return r}),function(t){"use strict";var e={},r={NEXT:"Next",PREVIOUS:"Previous",FIRST:"First",LAST:"Last",CURRENT_PAGE_REPORT:"Results {FromResult} - {ToResult} of {TotalResult}"},n=(t.translationKeys=Object.keys(r),function(t){return r[t]}),o=function(t){var e,r,o;for(this.options={totalResult:0,prelink:"",rowsPerPage:10,pageLinks:5,current:1,translator:n,translationCache:!1,translationCacheKey:"en",pageParamName:"page",slashSeparator:!1},e=Object.keys(t),r=0,o=e.length;o>r;r++)this.set(e[r],t[e[r]]);this._result=null};t.Paginator=o,o.prototype={getPaginationData:function(){return this._result||(this._result=this.calc()),this._result},calc:function(){var t,e,r,n,o,a=this.options.totalResult,s=this.options.pageLinks,i=this.options.rowsPerPage,l=this.options.current,u=s%2===0?1:0,p={prelink:this.options.prelink,current:l,previous:null,next:null,first:null,last:null,range:[],fromResult:null,toResult:null,totalResult:a,pageCount:null};if(0>=i)return p;if(r=Math.ceil(a/i),p.pageCount=r,2>r)return p.fromResult=1,p.toResult=a,p;for(l>r&&(l=r,p.current=l),o=Math.floor(s/2),t=l-o,e=l+o-u,1>t&&(t=1,e=t+s-1,e>r&&(e=r)),e>r&&(e=r,t=e-s+1,1>t&&(t=1)),n=t;e>=n;n++)p.range.push(n);return l>1&&(p.first=1,p.previous=l-1),r>l&&(p.last=r,p.next=l+1),p.fromResult=(l-1)*i+1,p.toResult=l===r?a:p.fromResult+i-1,p},set:function(t,e){if(this.options.hasOwnProperty(t)){switch(t){case"current":case"totalResult":case"pageLinks":case"rowsPerPage":if(e=parseInt(e,10),isNaN(e))throw new Error('Invalid value for "'+t+'", expected an integer');break;case"translator":if(!(e&&e.constructor&&e.call&&e.apply))throw new Error("Translator must be a function");break;case"translationCacheKey":case"pageParamName":case"prelink":e=String(e)}this.options[t]=e,this._result&&(this._result=null)}},preparePreLink:function(t){return this.options.slashSeparator?("/"!==t[t.length-1]&&(t+="/"),t+this.options.pageParamName+"/"):(-1!==t.indexOf("?")?"?"!==t[t.length-1]&&"&"!==t[t.length-1]&&(t+="&"):t+="?",t+this.options.pageParamName+"=")},render:function(){throw new Error("Implement")}},t.registerFactory=function(t,r){if(e.hasOwnProperty(t))throw new Error(t+" already exists");e[t]=r},t.create=function(t,r){if(e.hasOwnProperty(t))return new e[t](r);throw new Error("Paginator type"+t+" not found in register")}}(exports),exports.module=function(t){"use strict";var e={},r=function(t,e){var r,n,o,a,s,i,l,u,e=e||{},p=e.open||"<%",c=e.close||"%>",h=["var buf = [];","\nwith (paginationData) {","\n buf.push('"];for(o=0,s=t.length;s>o;++o)if(t.slice(o,p.length+o)===p){switch(o+=p.length,t.substr(o,1)){case"=":r="', escape(",n="), '",++o;break;case"-":r="', (",n="), '",++o;break;default:r="');",n="; buf.push('"}for(a=t.indexOf(c,o),i=t.substring(o,a),l=o,u=0;~(u=i.indexOf("\n",u));)u++;h.push(r,i,n),o+=a-l+c.length-1}else h.push("\\"===t.substr(o,1)?"\\\\":"'"===t.substr(o,1)?"\\'":"\r"===t.substr(o,1)?" ":"\n"===t.substr(o,1)?"\\n":t.substr(o,1));return h.push("');\n}\nreturn buf.join('');"),h.join("")},n=function(t){return String(t).replace(/&(?!\w+;)/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")},o=function(t,e){var o=new Function("paginationData",r(t,e));return function(t){return o.call(this,t,n)}},a=function(t,r){var n,r=r||{};if(r.cache){if(!r.id)throw new Error('"cache" option requires "id"');n=e[r.id]||(e[r.id]=o(t,r))}else n=o(t,r);return n};t.TemplateEngine={parse:r,compile:a}},exports.module(pagination,pagination.util),exports.module=function(t,e){"use strict";var r=t.TemplatePaginator=function(e){var r=e.template;if(!r)throw new Error("Template compile to function needed");r.constructor&&r.call&&r.apply||(r=t.TemplateEngine.compile(String(r),e)),t.Paginator.call(this,e),this.renderer=r};e.inherits(r,t.Paginator),r.prototype.render=function(){var e,r,n=this.getPaginationData();for(n.preparedPreLink=this.preparePreLink(n.prelink),n.translations={},e=0,r=t.translationKeys.length;r>e;e++)n.translations[t.translationKeys[e]]=this.options.translator(t.translationKeys[e]);return this.renderer(n)},t.registerFactory("template",r)},exports.module(pagination,pagination.util); | ||
window.pagination={},window.exports=pagination,window.pagination.util={inherits:function(t,e){if(!e||!t)throw new Error("extend failed, please check that all dependencies are included.");var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t,t.superclass=e.prototype,e.prototype.constructor===Object.prototype.constructor&&(e.prototype.constructor=e)}},Object.keys||(Object.keys=function(t){var e,r=[],n=Object.prototype.hasOwnProperty;if(t!==Object(t))throw new TypeError("Object.keys called on a non-object");for(e in t)n.call(t,e)&&r.push(e);return r}),function(t){"use strict";var e={},r={NEXT:"Next",PREVIOUS:"Previous",FIRST:"First",LAST:"Last",CURRENT_PAGE_REPORT:"Results {FromResult} - {ToResult} of {TotalResult}"},n=(t.translationKeys=Object.keys(r),function(t){return r[t]}),o=function(t){var e,r,o;for(this.options={totalResult:0,prelink:"",rowsPerPage:10,pageLinks:5,current:1,translator:n,translationCache:!1,translationCacheKey:"en",pageParamName:"page",slashSeparator:!1},e=Object.keys(t),r=0,o=e.length;o>r;r++)this.set(e[r],t[e[r]]);this._result=null};t.Paginator=o,o.prototype={getPaginationData:function(){return this._result||(this._result=this.calc()),this._result},calc:function(){var t,e,r,n,o,a=this.options.totalResult,s=this.options.pageLinks,i=this.options.rowsPerPage,l=this.options.current,u=s%2===0?1:0,p={prelink:this.options.prelink,current:l,previous:null,next:null,first:null,last:null,range:[],fromResult:null,toResult:null,totalResult:a,pageCount:null};if(0>=i)return p;if(r=Math.ceil(a/i),p.pageCount=r,2>r)return p.fromResult=1,p.toResult=a,p;for(l>r&&(l=r,p.current=l),o=Math.floor(s/2),t=l-o,e=l+o-u,1>t&&(t=1,e=t+s-1,e>r&&(e=r)),e>r&&(e=r,t=e-s+1,1>t&&(t=1)),n=t;e>=n;n++)p.range.push(n);return l>1&&(p.first=1,p.previous=l-1),r>l&&(p.last=r,p.next=l+1),p.fromResult=(l-1)*i+1,p.toResult=l===r?a:p.fromResult+i-1,p},set:function(t,e){if(this.options.hasOwnProperty(t)){switch(t){case"current":case"totalResult":case"pageLinks":case"rowsPerPage":if(e=parseInt(e,10),isNaN(e))throw new Error('Invalid value for "'+t+'", expected an integer');break;case"translator":if(!(e&&e.constructor&&e.call&&e.apply))throw new Error("Translator must be a function");break;case"translationCacheKey":case"pageParamName":case"prelink":e=String(e)}this.options[t]=e,this._result&&(this._result=null)}},preparePreLink:function(t){return this.options.slashSeparator?("/"!==t[t.length-1]&&(t+="/"),t+this.options.pageParamName+"/"):(-1!==t.indexOf("?")?"?"!==t[t.length-1]&&"&"!==t[t.length-1]&&(t+="&"):t+="?",t+this.options.pageParamName+"=")},render:function(){throw new Error("Implement")}},t.registerFactory=function(t,r){if(e.hasOwnProperty(t))throw new Error(t+" already exists");e[t]=r},t.create=function(t,r){if(e.hasOwnProperty(t))return new e[t](r);throw new Error("Paginator type"+t+" not found in register")}}(exports),exports.module=function(t){"use strict";var e={},r=function(t,e){var r,n,o,a,s,i,l,u,e=e||{},p=e.open||"<%",c=e.close||"%>",h=["var buf = [];","\nwith (paginationData) {","\n buf.push('"];for(o=0,s=t.length;s>o;++o)if(t.slice(o,p.length+o)===p){switch(o+=p.length,t.substr(o,1)){case"=":r="', escape(",n="), '",++o;break;case"-":r="', (",n="), '",++o;break;default:r="');",n="; buf.push('"}for(a=t.indexOf(c,o),i=t.substring(o,a),l=o,u=0;~(u=i.indexOf("\n",u));)u++;h.push(r,i,n),o+=a-l+c.length-1}else h.push("\\"===t.substr(o,1)?"\\\\":"'"===t.substr(o,1)?"\\'":"\r"===t.substr(o,1)?" ":"\n"===t.substr(o,1)?"\\n":t.substr(o,1));return h.push("');\n}\nreturn buf.join('');"),h.join("")},n=function(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")},o=function(t,e){var o=new Function("paginationData, escape",r(t,e));return function(t){return o.call(this,t,n)}},a=function(t,r){var n,r=r||{};if(r.cache){if(!r.id)throw new Error('"cache" option requires "id"');n=e[r.id]||(e[r.id]=o(t,r))}else n=o(t,r);return n};t.TemplateEngine={parse:r,compile:a}},exports.module(pagination,pagination.util),exports.module=function(t,e){"use strict";var r=t.TemplatePaginator=function(e){var r=e.template;if(!r)throw new Error("Template compile to function needed");r.constructor&&r.call&&r.apply||(r=t.TemplateEngine.compile(String(r),e)),t.Paginator.call(this,e),this.renderer=r};e.inherits(r,t.Paginator),r.prototype.render=function(){var e,r,n=this.getPaginationData();for(n.preparedPreLink=this.preparePreLink(n.prelink),n.translations={},e=0,r=t.translationKeys.length;r>e;e++)n.translations[t.translationKeys[e]]=this.options.translator(t.translationKeys[e]);return this.renderer(n)},t.registerFactory("template",r)},exports.module(pagination,pagination.util); |
@@ -1,1 +0,1 @@ | ||
window.pagination={},window.exports=pagination,window.pagination.util={inherits:function(t,r){if(!r||!t)throw new Error("extend failed, please check that all dependencies are included.");var e=function(){};e.prototype=r.prototype,t.prototype=new e,t.prototype.constructor=t,t.superclass=r.prototype,r.prototype.constructor===Object.prototype.constructor&&(r.prototype.constructor=r)}},Object.keys||(Object.keys=function(t){var r,e=[],n=Object.prototype.hasOwnProperty;if(t!==Object(t))throw new TypeError("Object.keys called on a non-object");for(r in t)n.call(t,r)&&e.push(r);return e}),function(t){"use strict";var r={},e={NEXT:"Next",PREVIOUS:"Previous",FIRST:"First",LAST:"Last",CURRENT_PAGE_REPORT:"Results {FromResult} - {ToResult} of {TotalResult}"},n=(t.translationKeys=Object.keys(e),function(t){return e[t]}),a=function(t){var r,e,a;for(this.options={totalResult:0,prelink:"",rowsPerPage:10,pageLinks:5,current:1,translator:n,translationCache:!1,translationCacheKey:"en",pageParamName:"page",slashSeparator:!1},r=Object.keys(t),e=0,a=r.length;a>e;e++)this.set(r[e],t[r[e]]);this._result=null};t.Paginator=a,a.prototype={getPaginationData:function(){return this._result||(this._result=this.calc()),this._result},calc:function(){var t,r,e,n,a,o=this.options.totalResult,s=this.options.pageLinks,i=this.options.rowsPerPage,l=this.options.current,p=s%2===0?1:0,u={prelink:this.options.prelink,current:l,previous:null,next:null,first:null,last:null,range:[],fromResult:null,toResult:null,totalResult:o,pageCount:null};if(0>=i)return u;if(e=Math.ceil(o/i),u.pageCount=e,2>e)return u.fromResult=1,u.toResult=o,u;for(l>e&&(l=e,u.current=l),a=Math.floor(s/2),t=l-a,r=l+a-p,1>t&&(t=1,r=t+s-1,r>e&&(r=e)),r>e&&(r=e,t=r-s+1,1>t&&(t=1)),n=t;r>=n;n++)u.range.push(n);return l>1&&(u.first=1,u.previous=l-1),e>l&&(u.last=e,u.next=l+1),u.fromResult=(l-1)*i+1,u.toResult=l===e?o:u.fromResult+i-1,u},set:function(t,r){if(this.options.hasOwnProperty(t)){switch(t){case"current":case"totalResult":case"pageLinks":case"rowsPerPage":if(r=parseInt(r,10),isNaN(r))throw new Error('Invalid value for "'+t+'", expected an integer');break;case"translator":if(!(r&&r.constructor&&r.call&&r.apply))throw new Error("Translator must be a function");break;case"translationCacheKey":case"pageParamName":case"prelink":r=String(r)}this.options[t]=r,this._result&&(this._result=null)}},preparePreLink:function(t){return this.options.slashSeparator?("/"!==t[t.length-1]&&(t+="/"),t+this.options.pageParamName+"/"):(-1!==t.indexOf("?")?"?"!==t[t.length-1]&&"&"!==t[t.length-1]&&(t+="&"):t+="?",t+this.options.pageParamName+"=")},render:function(){throw new Error("Implement")}},t.registerFactory=function(t,e){if(r.hasOwnProperty(t))throw new Error(t+" already exists");r[t]=e},t.create=function(t,e){if(r.hasOwnProperty(t))return new r[t](e);throw new Error("Paginator type"+t+" not found in register")}}(exports),exports.module=function(t){"use strict";var r={},e=function(t,r){var e,n,a,o,s,i,l,p,r=r||{},u=r.open||"<%",c=r.close||"%>",h=["var buf = [];","\nwith (paginationData) {","\n buf.push('"];for(a=0,s=t.length;s>a;++a)if(t.slice(a,u.length+a)===u){switch(a+=u.length,t.substr(a,1)){case"=":e="', escape(",n="), '",++a;break;case"-":e="', (",n="), '",++a;break;default:e="');",n="; buf.push('"}for(o=t.indexOf(c,a),i=t.substring(a,o),l=a,p=0;~(p=i.indexOf("\n",p));)p++;h.push(e,i,n),a+=o-l+c.length-1}else h.push("\\"===t.substr(a,1)?"\\\\":"'"===t.substr(a,1)?"\\'":"\r"===t.substr(a,1)?" ":"\n"===t.substr(a,1)?"\\n":t.substr(a,1));return h.push("');\n}\nreturn buf.join('');"),h.join("")},n=function(t){return String(t).replace(/&(?!\w+;)/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")},a=function(t,r){var a=new Function("paginationData",e(t,r));return function(t){return a.call(this,t,n)}},o=function(t,e){var n,e=e||{};if(e.cache){if(!e.id)throw new Error('"cache" option requires "id"');n=r[e.id]||(r[e.id]=a(t,e))}else n=a(t,e);return n};t.TemplateEngine={parse:e,compile:o}},exports.module(pagination,pagination.util),exports.module=function(t,r){"use strict";var e=t.TemplatePaginator=function(r){var e=r.template;if(!e)throw new Error("Template compile to function needed");e.constructor&&e.call&&e.apply||(e=t.TemplateEngine.compile(String(e),r)),t.Paginator.call(this,r),this.renderer=e};r.inherits(e,t.Paginator),e.prototype.render=function(){var r,e,n=this.getPaginationData();for(n.preparedPreLink=this.preparePreLink(n.prelink),n.translations={},r=0,e=t.translationKeys.length;e>r;r++)n.translations[t.translationKeys[r]]=this.options.translator(t.translationKeys[r]);return this.renderer(n)},t.registerFactory("template",e)},exports.module(pagination,pagination.util),exports.module=function(t,r){"use strict";var e=function(r){t.Paginator.call(this,r)};t.SearchPaginator=e,r.inherits(e,t.Paginator),e.prototype.render=function(){var t,r,e,n,a=this.getPaginationData(),o='<div class="paginator">';if(a.pageCount<2)return o+="</div>";if(n=this.preparePreLink(a.prelink),a.previous&&(o+='<a href="'+n+a.previous+'" class="paginator-previous">'+this.options.translator("PREVIOUS")+"</a>"),a.range.length)for(t=0,r=a.range.length;r>t;t++)e="paginator-page",a.range[t]===a.current&&(e="paginator-current"),0===t?e+=" paginator-page-first":t===r-1&&(e+=" paginator-page-last"),o+='<a href="'+n+a.range[t]+'" class="'+e+'">'+a.range[t]+"</a>";return a.next&&(o+='<a href="'+n+a.next+'" class="paginator-next">'+this.options.translator("NEXT")+"</a>"),o+="</div>"},t.registerFactory("search",e)},exports.module(pagination,pagination.util),exports.module=function(t,r){"use strict";var e={CURRENT_PAGE_REPORT:{}},n=t.ItemPaginator=function(r){t.Paginator.call(this,r),this.set("pageLinks",1)};r.inherits(n,t.Paginator),n.prototype.renderCurrentPageReport=function(t,r,n){var a;return this.options.translationCache?(e.CURRENT_PAGE_REPORT.hasOwnProperty(this.options.translationCacheKey)||(a="return '"+this.options.translator("CURRENT_PAGE_REPORT").replace("'","'").replace("{FromResult}","' + fromResult + '").replace("{ToResult}","' + toResult + '").replace("{TotalResult}","' + totalResult + '")+"';",e.CURRENT_PAGE_REPORT[this.options.translationCacheKey]=new Function("fromResult, toResult, totalResult",a)),e.CURRENT_PAGE_REPORT[this.options.translationCacheKey](t,r,n)):this.options.translator("CURRENT_PAGE_REPORT").replace("{FromResult}",t).replace("{ToResult}",r).replace("{TotalResult}",n)},n.prototype.render=function(){var t=this.getPaginationData(),r=this.preparePreLink(t.prelink),e='<div class="paginator">';return e+='<span class="paginator-current-report">',e+=this.renderCurrentPageReport(t.fromResult,t.toResult,t.totalResult),e+="</span>",e+=t.first?'<a href="'+r+t.first+'" class="paginator-first">'+this.options.translator("FIRST")+"</a>":'<span class="paginator-first">'+this.options.translator("FIRST")+"</span>",e+=t.previous?'<a href="'+r+t.previous+'" class="paginator-previous">'+this.options.translator("PREVIOUS")+"</a>":'<span class="paginator-previous">'+this.options.translator("PREVIOUS")+"</span>",e+=t.next?'<a href="'+r+t.next+'" class="paginator-next">'+this.options.translator("NEXT")+"</a>":'<span class="paginator-next">'+this.options.translator("NEXT")+"</span>",e+=t.last?'<a href="'+r+t.last+'" class="paginator-last">'+this.options.translator("LAST")+"</a>":'<span class="paginator-last">'+this.options.translator("LAST")+"</span>",e+="</div>"},t.registerFactory("item",n)},exports.module(pagination,pagination.util); | ||
window.pagination={},window.exports=pagination,window.pagination.util={inherits:function(t,r){if(!r||!t)throw new Error("extend failed, please check that all dependencies are included.");var e=function(){};e.prototype=r.prototype,t.prototype=new e,t.prototype.constructor=t,t.superclass=r.prototype,r.prototype.constructor===Object.prototype.constructor&&(r.prototype.constructor=r)}},Object.keys||(Object.keys=function(t){var r,e=[],n=Object.prototype.hasOwnProperty;if(t!==Object(t))throw new TypeError("Object.keys called on a non-object");for(r in t)n.call(t,r)&&e.push(r);return e}),function(t){"use strict";var r={},e={NEXT:"Next",PREVIOUS:"Previous",FIRST:"First",LAST:"Last",CURRENT_PAGE_REPORT:"Results {FromResult} - {ToResult} of {TotalResult}"},n=(t.translationKeys=Object.keys(e),function(t){return e[t]}),a=function(t){var r,e,a;for(this.options={totalResult:0,prelink:"",rowsPerPage:10,pageLinks:5,current:1,translator:n,translationCache:!1,translationCacheKey:"en",pageParamName:"page",slashSeparator:!1},r=Object.keys(t),e=0,a=r.length;a>e;e++)this.set(r[e],t[r[e]]);this._result=null};t.Paginator=a,a.prototype={getPaginationData:function(){return this._result||(this._result=this.calc()),this._result},calc:function(){var t,r,e,n,a,o=this.options.totalResult,s=this.options.pageLinks,i=this.options.rowsPerPage,l=this.options.current,p=s%2===0?1:0,u={prelink:this.options.prelink,current:l,previous:null,next:null,first:null,last:null,range:[],fromResult:null,toResult:null,totalResult:o,pageCount:null};if(0>=i)return u;if(e=Math.ceil(o/i),u.pageCount=e,2>e)return u.fromResult=1,u.toResult=o,u;for(l>e&&(l=e,u.current=l),a=Math.floor(s/2),t=l-a,r=l+a-p,1>t&&(t=1,r=t+s-1,r>e&&(r=e)),r>e&&(r=e,t=r-s+1,1>t&&(t=1)),n=t;r>=n;n++)u.range.push(n);return l>1&&(u.first=1,u.previous=l-1),e>l&&(u.last=e,u.next=l+1),u.fromResult=(l-1)*i+1,u.toResult=l===e?o:u.fromResult+i-1,u},set:function(t,r){if(this.options.hasOwnProperty(t)){switch(t){case"current":case"totalResult":case"pageLinks":case"rowsPerPage":if(r=parseInt(r,10),isNaN(r))throw new Error('Invalid value for "'+t+'", expected an integer');break;case"translator":if(!(r&&r.constructor&&r.call&&r.apply))throw new Error("Translator must be a function");break;case"translationCacheKey":case"pageParamName":case"prelink":r=String(r)}this.options[t]=r,this._result&&(this._result=null)}},preparePreLink:function(t){return this.options.slashSeparator?("/"!==t[t.length-1]&&(t+="/"),t+this.options.pageParamName+"/"):(-1!==t.indexOf("?")?"?"!==t[t.length-1]&&"&"!==t[t.length-1]&&(t+="&"):t+="?",t+this.options.pageParamName+"=")},render:function(){throw new Error("Implement")}},t.registerFactory=function(t,e){if(r.hasOwnProperty(t))throw new Error(t+" already exists");r[t]=e},t.create=function(t,e){if(r.hasOwnProperty(t))return new r[t](e);throw new Error("Paginator type"+t+" not found in register")}}(exports),exports.module=function(t){"use strict";var r={},e=function(t,r){var e,n,a,o,s,i,l,p,r=r||{},u=r.open||"<%",c=r.close||"%>",h=["var buf = [];","\nwith (paginationData) {","\n buf.push('"];for(a=0,s=t.length;s>a;++a)if(t.slice(a,u.length+a)===u){switch(a+=u.length,t.substr(a,1)){case"=":e="', escape(",n="), '",++a;break;case"-":e="', (",n="), '",++a;break;default:e="');",n="; buf.push('"}for(o=t.indexOf(c,a),i=t.substring(a,o),l=a,p=0;~(p=i.indexOf("\n",p));)p++;h.push(e,i,n),a+=o-l+c.length-1}else h.push("\\"===t.substr(a,1)?"\\\\":"'"===t.substr(a,1)?"\\'":"\r"===t.substr(a,1)?" ":"\n"===t.substr(a,1)?"\\n":t.substr(a,1));return h.push("');\n}\nreturn buf.join('');"),h.join("")},n=function(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")},a=function(t,r){var a=new Function("paginationData, escape",e(t,r));return function(t){return a.call(this,t,n)}},o=function(t,e){var n,e=e||{};if(e.cache){if(!e.id)throw new Error('"cache" option requires "id"');n=r[e.id]||(r[e.id]=a(t,e))}else n=a(t,e);return n};t.TemplateEngine={parse:e,compile:o}},exports.module(pagination,pagination.util),exports.module=function(t,r){"use strict";var e=t.TemplatePaginator=function(r){var e=r.template;if(!e)throw new Error("Template compile to function needed");e.constructor&&e.call&&e.apply||(e=t.TemplateEngine.compile(String(e),r)),t.Paginator.call(this,r),this.renderer=e};r.inherits(e,t.Paginator),e.prototype.render=function(){var r,e,n=this.getPaginationData();for(n.preparedPreLink=this.preparePreLink(n.prelink),n.translations={},r=0,e=t.translationKeys.length;e>r;r++)n.translations[t.translationKeys[r]]=this.options.translator(t.translationKeys[r]);return this.renderer(n)},t.registerFactory("template",e)},exports.module(pagination,pagination.util),exports.module=function(t,r){"use strict";var e=function(r){t.Paginator.call(this,r)};t.SearchPaginator=e,r.inherits(e,t.Paginator),e.prototype.render=function(){var t,r,e,n,a=this.getPaginationData(),o='<div class="paginator">';if(a.pageCount<2)return o+="</div>";if(n=this.preparePreLink(a.prelink),a.previous&&(o+='<a href="'+n+a.previous+'" class="paginator-previous">'+this.options.translator("PREVIOUS")+"</a>"),a.range.length)for(t=0,r=a.range.length;r>t;t++)e="paginator-page",a.range[t]===a.current&&(e="paginator-current"),0===t?e+=" paginator-page-first":t===r-1&&(e+=" paginator-page-last"),o+='<a href="'+n+a.range[t]+'" class="'+e+'">'+a.range[t]+"</a>";return a.next&&(o+='<a href="'+n+a.next+'" class="paginator-next">'+this.options.translator("NEXT")+"</a>"),o+="</div>"},t.registerFactory("search",e)},exports.module(pagination,pagination.util),exports.module=function(t,r){"use strict";var e={CURRENT_PAGE_REPORT:{}},n=t.ItemPaginator=function(r){t.Paginator.call(this,r),this.set("pageLinks",1)};r.inherits(n,t.Paginator),n.prototype.renderCurrentPageReport=function(t,r,n){var a;return this.options.translationCache?(e.CURRENT_PAGE_REPORT.hasOwnProperty(this.options.translationCacheKey)||(a="return '"+this.options.translator("CURRENT_PAGE_REPORT").replace("'","'").replace("{FromResult}","' + fromResult + '").replace("{ToResult}","' + toResult + '").replace("{TotalResult}","' + totalResult + '")+"';",e.CURRENT_PAGE_REPORT[this.options.translationCacheKey]=new Function("fromResult, toResult, totalResult",a)),e.CURRENT_PAGE_REPORT[this.options.translationCacheKey](t,r,n)):this.options.translator("CURRENT_PAGE_REPORT").replace("{FromResult}",t).replace("{ToResult}",r).replace("{TotalResult}",n)},n.prototype.render=function(){var t=this.getPaginationData(),r=this.preparePreLink(t.prelink),e='<div class="paginator">';return e+='<span class="paginator-current-report">',e+=this.renderCurrentPageReport(t.fromResult,t.toResult,t.totalResult),e+="</span>",e+=t.first?'<a href="'+r+t.first+'" class="paginator-first">'+this.options.translator("FIRST")+"</a>":'<span class="paginator-first">'+this.options.translator("FIRST")+"</span>",e+=t.previous?'<a href="'+r+t.previous+'" class="paginator-previous">'+this.options.translator("PREVIOUS")+"</a>":'<span class="paginator-previous">'+this.options.translator("PREVIOUS")+"</span>",e+=t.next?'<a href="'+r+t.next+'" class="paginator-next">'+this.options.translator("NEXT")+"</a>":'<span class="paginator-next">'+this.options.translator("NEXT")+"</span>",e+=t.last?'<a href="'+r+t.last+'" class="paginator-last">'+this.options.translator("LAST")+"</a>":'<span class="paginator-last">'+this.options.translator("LAST")+"</span>",e+="</div>"},t.registerFactory("item",n)},exports.module(pagination,pagination.util); |
@@ -25,5 +25,5 @@ var assert = require('assert'); | ||
escapeMarkup: function() { | ||
assert.equal('%3Cscript%3Ealert%280%29%3B%3C/script%3E', TemplateEngine.compile('<%=script%>')({script:'<script>alert(0);</script>'})); | ||
assert.equal('%3Ca%20href%3D%22javascript%3A%3Aalert%280%29%22%3Etest%3C/a%3E', TemplateEngine.compile('<%=tag%>')({tag:'<a href="javascript::alert(0)">test</a>'})); | ||
assert.equal('<script>alert('0');</script>', TemplateEngine.compile('<%=script%>')({script:"<script>alert('0');</script>"})); | ||
assert.equal('<a href="/?t=1&p=2&s=3" onclick="javascript::alert(0)">test</a>', TemplateEngine.compile('<%=tag%>')({tag:'<a href="/?t=1&p=2&s=3" onclick="javascript::alert(0)">test</a>'})); | ||
} | ||
}).export(module); |
87741
1299