11/*!
22
3- Holder - 2.3.1 - client side image placeholders
3+ Holder - 2.3.2 - client side image placeholders
44(c) 2012-2014 Ivan Malopinsky / http://imsky.co
55
66Provided under the MIT License.
@@ -249,10 +249,10 @@ function draw_svg(args){
249249 var text_height = ts . height ;
250250 var width = dimensions . width ,
251251 height = dimensions . height ;
252-
252+
253253 var font = template . font ? template . font : "Arial,Helvetica,sans-serif" ;
254254 var text = template . text ? template . text : ( Math . floor ( dimensions . width ) + "x" + Math . floor ( dimensions . height ) ) ;
255-
255+
256256 if ( literal ) {
257257 var dimensions = holder . dimensions ;
258258 text = dimensions . width + "x" + dimensions . height ;
@@ -262,14 +262,14 @@ function draw_svg(args){
262262 text = ( Math . floor ( dimensions . width ) + "x" + Math . floor ( dimensions . height ) ) ;
263263 }
264264 var string = svg_el ( {
265- text : text ,
266- width :width ,
267- height :height ,
268- text_height :text_height ,
269- font :font ,
265+ text : text ,
266+ width :width ,
267+ height :height ,
268+ text_height :text_height ,
269+ font :font ,
270270 template :template
271271 } )
272- return "data:image/svg+xml;base64," + btoa ( string ) ;
272+ return "data:image/svg+xml;base64," + btoa ( unescape ( encodeURIComponent ( string ) ) ) ;
273273}
274274
275275function draw ( args ) {
@@ -295,7 +295,7 @@ function render(mode, el, holder, src) {
295295 el . setAttribute ( "data-src" , src ) ;
296296 holder . theme = theme ;
297297 el . holder_data = holder ;
298-
298+
299299 if ( mode == "image" ) {
300300 el . setAttribute ( "alt" , text ? text : theme . text ? theme . text + " [" + dimensions_caption + "]" : dimensions_caption ) ;
301301 if ( instance_config . use_fallback || ! holder . auto ) {
@@ -306,12 +306,12 @@ function render(mode, el, holder, src) {
306306 el . style . backgroundColor = theme . background ;
307307 } else {
308308 el . setAttribute ( "src" , draw ( { ctx : ctx , dimensions : dimensions , template : theme , ratio :ratio , holder : holder } ) ) ;
309-
309+
310310 if ( holder . textmode && holder . textmode == "exact" ) {
311311 resizable_images . push ( el ) ;
312312 resizable_update ( el ) ;
313313 }
314-
314+
315315 }
316316 } else if ( mode == "background" ) {
317317 if ( ! instance_config . use_fallback ) {
@@ -333,9 +333,9 @@ function render(mode, el, holder, src) {
333333 if ( el . style . display == "inline" || el . style . display === "" || el . style . display == "none" ) {
334334 el . style . display = "block" ;
335335 }
336-
336+
337337 set_initial_dimensions ( el )
338-
338+
339339 if ( instance_config . use_fallback ) {
340340 el . style . backgroundColor = theme . background ;
341341 } else {
@@ -500,19 +500,20 @@ app.add_image = function (src, el) {
500500} ;
501501
502502app . run = function ( o ) {
503+
503504 instance_config = extend ( { } , system_config )
504505 preempted = true ;
505506
506507 var options = extend ( settings , o ) ,
507508 images = [ ] ,
508509 imageNodes = [ ] ,
509510 bgnodes = [ ] ;
510-
511+
511512 if ( options . use_canvas != null && options . use_canvas ) {
512513 instance_config . use_canvas = true ;
513514 instance_config . use_svg = false ;
514515 }
515-
516+
516517 if ( typeof ( options . images ) == "string" ) {
517518 imageNodes = selector ( options . images ) ;
518519 } else if ( window . NodeList && options . images instanceof window . NodeList ) {
@@ -531,20 +532,25 @@ app.run = function (o) {
531532 bgnodes = [ options . bgnodes ] ;
532533 }
533534 for ( i = 0 , l = imageNodes . length ; i < l ; i ++ ) images . push ( imageNodes [ i ] ) ;
535+
534536 var holdercss = document . getElementById ( "holderjs-style" ) ;
535537 if ( ! holdercss ) {
536538 holdercss = document . createElement ( "style" ) ;
537539 holdercss . setAttribute ( "id" , "holderjs-style" ) ;
538540 holdercss . type = "text/css" ;
539541 document . getElementsByTagName ( "head" ) [ 0 ] . appendChild ( holdercss ) ;
540542 }
543+
541544 if ( ! options . nocss ) {
542545 if ( holdercss . styleSheet ) {
543546 holdercss . styleSheet . cssText += options . stylesheet ;
544547 } else {
545- holdercss . appendChild ( document . createTextNode ( options . stylesheet ) ) ;
548+ if ( options . stylesheet . length ) {
549+ holdercss . appendChild ( document . createTextNode ( options . stylesheet ) ) ;
550+ }
546551 }
547552 }
553+
548554 var cssregex = new RegExp ( options . domain + "\/(.*?)\"?\\)" ) ;
549555 for ( var l = bgnodes . length , i = 0 ; i < l ; i ++ ) {
550556 var src = window . getComputedStyle ( bgnodes [ i ] , null )
@@ -598,6 +604,10 @@ contentLoaded(win, function () {
598604 window . attachEvent ( "onresize" , resizable_update )
599605 }
600606 preempted || app . run ( { } ) ;
607+
608+ if ( typeof window . Turbolinks === "object" ) {
609+ document . addEventListener ( "page:change" , function ( ) { app . run ( { } ) } )
610+ }
601611} ) ;
602612if ( typeof define === "function" && define . amd ) {
603613 define ( [ ] , function ( ) {
0 commit comments