2017-06-04 07:43:41 +02:00
// @source https://github.com/NyaaPantsu/nyaa/tree/dev/public/js
// @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt Expat
2017-05-30 00:28:21 +02:00
// Templates variable
var Templates = {
2017-07-16 06:43:09 +02:00
tmpl : [ ] ,
2017-07-23 04:50:36 +02:00
Add : function ( templateName , template ) {
2017-07-16 06:43:09 +02:00
this . tmpl [ templateName ] = template
} ,
2017-07-23 04:50:36 +02:00
Render : function ( templateName , model ) {
2017-07-17 14:20:18 +02:00
if ( this . tmpl [ templateName ] === undefined ) {
console . log ( "The template with name '%s' doesn't exist" , templateName )
return
}
2017-07-16 06:43:09 +02:00
return this . tmpl [ templateName ] ( model )
} ,
2017-07-23 04:50:36 +02:00
ApplyItemListRenderer : function ( params ) {
return function ( models ) {
for ( var i = models . length - 1 ; i >= 0 ; i -- ) {
2017-07-16 06:43:09 +02:00
var object = Templates . Render ( params . templateName , models [ i ] ) ;
if ( params . method == "append" ) {
params . element . innerHTML = params . element . innerHTML + object
} else if ( params . method == "prepend" ) {
params . element . innerHTML = object + params . element . innerHTML
}
}
} ;
} ,
2017-07-23 04:50:36 +02:00
EncodeEntities : function ( value ) {
2017-07-16 06:43:09 +02:00
return value .
replace ( /&/g , '&' ) .
2017-07-23 04:50:36 +02:00
replace ( /[\uD800-\uDBFF][\uDC00-\uDFFF]/g , function ( value ) {
2017-07-16 06:43:09 +02:00
var hi = value . charCodeAt ( 0 ) ;
var low = value . charCodeAt ( 1 ) ;
return '&#' + ( ( ( hi - 0xD800 ) * 0x400 ) + ( low - 0xDC00 ) + 0x10000 ) + ';' ;
} ) .
2017-07-23 04:50:36 +02:00
replace ( /([^\#-~| |!])/g , function ( value ) {
2017-07-16 06:43:09 +02:00
return '&#' + value . charCodeAt ( 0 ) + ';' ;
} ) .
replace ( /</g , '<' ) .
replace ( />/g , '>' ) ;
2017-07-21 01:47:36 +02:00
} ,
2017-07-23 04:50:36 +02:00
FlagCode : function ( language ) {
2017-07-21 01:47:36 +02:00
var split = language . split ( "-" )
if ( split . length > 1 ) {
return split [ 1 ]
}
return language
2017-07-16 06:43:09 +02:00
}
2017-05-30 00:28:21 +02:00
} ;
2017-06-04 07:43:41 +02:00
// @license-end