holder_rails 2.4.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c6b866c6e85aaf4b67a1afa8ae80bafac677aa9
4
- data.tar.gz: 120e28a448afb3baa39479aece13b8e9f4536281
3
+ metadata.gz: b8458524b714ef56be4456f9fd13afe86b0fd440
4
+ data.tar.gz: 735c3d50c8c194399bb7a5cbb3fa8a590271339d
5
5
  SHA512:
6
- metadata.gz: 72fe40df92a36478744121b9ce953e1db1aa7a4567e883ea3880be168ded7fbdf676ef75739ed280df95584d54a7bbe383d1fcb294cb1d8d7bbbd04c31dc2ef0
7
- data.tar.gz: 65a9d52aa64880e0c8d10a7487f010bf073097b44a10c234736b9557e2b7450af70397149f9383c196f29a3699ed11bd3915a708be1e7419a0cccb9ae65ec742
6
+ metadata.gz: cd1f488c57bf10db5654c12db604e122abe6d97d9e79e67c943ee01788218b55e40448f97888f98f19c7cba0c187e8a587e7e4c76a4885682bfbbca5284b5464
7
+ data.tar.gz: f1c5a0b1ebd469f39847dd400d5fe80216a78038600aaa447f31d5b2a01252021dd71608b756832271b7beab9c41810994757455c6e3507f11cb90fe9f455c2c
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Holder.js for Rails
2
2
 
3
- [![Build Status](https://travis-ci.org/NARKOZ/holder_rails.png)](https://travis-ci.org/NARKOZ/holder_rails)
4
- [![Gem Version](https://fury-badge.herokuapp.com/rb/holder_rails.png)](http://badge.fury.io/rb/holder_rails)
3
+ [![Build Status](https://img.shields.io/travis/NARKOZ/holder_rails.svg?style=flat)](https://travis-ci.org/NARKOZ/holder_rails)
4
+ [![Gem Version](https://img.shields.io/gem/v/holder_rails.svg?style=flat)](https://rubygems.org/gems/holder_rails)
5
5
 
6
6
  Provides Holder.js to render image placeholders entirely on the client side.
7
7
 
@@ -1,3 +1,3 @@
1
1
  module HolderRails
2
- VERSION = "2.4.1"
2
+ VERSION = "2.5.0"
3
3
  end
@@ -5,21 +5,21 @@ class HolderRailsTest < ActionView::TestCase
5
5
  include HolderRails::Helpers
6
6
 
7
7
  test "size" do
8
- assert_equal '<img data-src="holder.js/100x100/text:100x100/" src="" />', holder_tag(100)
9
- assert_equal '<img data-src="holder.js/200x300/text:200x300/" src="" />', holder_tag('200x300')
10
- assert_equal '<img data-src="holder.js/100%x75/text:100%x75/" src="" />', holder_tag('100%x75')
8
+ assert_dom_equal '<img data-src="holder.js/100x100/text:100x100/" src="" />', holder_tag(100)
9
+ assert_dom_equal '<img data-src="holder.js/200x300/text:200x300/" src="" />', holder_tag('200x300')
10
+ assert_dom_equal '<img data-src="holder.js/100%x75/text:100%x75/" src="" />', holder_tag('100%x75')
11
11
  end
12
12
 
13
13
  test "text" do
14
- assert_equal '<img data-src="holder.js/200x300/text:Lorem ipsum/" src="" />', holder_tag('200x300', 'Lorem ipsum')
14
+ assert_dom_equal '<img data-src="holder.js/200x300/text:Lorem ipsum/" src="" />', holder_tag('200x300', 'Lorem ipsum')
15
15
  end
16
16
 
17
17
  test "theme" do
18
- assert_equal '<img data-src="holder.js/200x300/text:Lorem ipsum/social" src="" />', holder_tag('200x300', 'Lorem ipsum', 'social')
18
+ assert_dom_equal '<img data-src="holder.js/200x300/text:Lorem ipsum/social" src="" />', holder_tag('200x300', 'Lorem ipsum', 'social')
19
19
  end
20
20
 
21
21
  test "html_options" do
22
- assert_equal '<img class="special" data-src="holder.js/500x800/text:Example text/gray" id="new" src="" />',
22
+ assert_dom_equal '<img class="special" data-src="holder.js/500x800/text:Example text/gray" id="new" src="" />',
23
23
  holder_tag('500x800', 'Example text', 'gray', :id => 'new', :class => 'special')
24
24
  end
25
25
  end
@@ -1,12 +1,2018 @@
1
1
  /*!
2
2
 
3
3
  Holder - client side image placeholders
4
- Version 2.4.1+f2l1h
5
- © 2014 Ivan Malopinsky - http://imsky.co
4
+ Version 2.5.0+1qnmg
5
+ © 2015 Ivan Malopinsky - http://imsky.co
6
6
 
7
7
  Site: http://imsky.github.io/holder
8
8
  Issues: https://github.com/imsky/holder/issues
9
9
  License: http://opensource.org/licenses/MIT
10
10
 
11
11
  */
12
- !function(e,t,r){t[e]=r}("onDomReady",this,function(e){"use strict";function t(e){if(!b){if(!a.body)return i(t);for(b=!0;e=S.shift();)i(e)}}function r(e){(y||e.type===s||a[c]===u)&&(n(),t())}function n(){y?(a[x](m,r,d),e[x](s,r,d)):(a[g](v,r),e[g](h,r))}function i(e,t){setTimeout(e,+t>=0?t:1)}function o(e){b?i(e):S.push(e)}null==document.readyState&&document.addEventListener&&(document.addEventListener("DOMContentLoaded",function E(){document.removeEventListener("DOMContentLoaded",E,!1),document.readyState="complete"},!1),document.readyState="loading");var a=e.document,l=a.documentElement,s="load",d=!1,h="on"+s,u="complete",c="readyState",f="attachEvent",g="detachEvent",p="addEventListener",m="DOMContentLoaded",v="onreadystatechange",x="removeEventListener",y=p in a,w=d,b=d,S=[];if(a[c]===u)i(t);else if(y)a[p](m,r,d),e[p](s,r,d);else{a[f](v,r),e[f](h,r);try{w=null==e.frameElement&&l}catch(C){}w&&w.doScroll&&!function k(){if(!b){try{w.doScroll("left")}catch(e){return i(k,50)}n(),t()}}()}return o.version="1.4.0",o.isReady=function(){return b},o}(this)),document.querySelectorAll||(document.querySelectorAll=function(e){var t,r=document.createElement("style"),n=[];for(document.documentElement.firstChild.appendChild(r),document._qsa=[],r.styleSheet.cssText=e+"{x-qsa:expression(document._qsa && document._qsa.push(this))}",window.scrollBy(0,0),r.parentNode.removeChild(r);document._qsa.length;)t=document._qsa.shift(),t.style.removeAttribute("x-qsa"),n.push(t);return document._qsa=null,n}),document.querySelector||(document.querySelector=function(e){var t=document.querySelectorAll(e);return t.length?t[0]:null}),document.getElementsByClassName||(document.getElementsByClassName=function(e){return e=String(e).replace(/^|\s+/g,"."),document.querySelectorAll(e)}),Object.keys||(Object.keys=function(e){if(e!==Object(e))throw TypeError("Object.keys called on non-object");var t,r=[];for(t in e)Object.prototype.hasOwnProperty.call(e,t)&&r.push(t);return r}),function(e){var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";e.atob=e.atob||function(e){e=String(e);var r,n=0,i=[],o=0,a=0;if(e=e.replace(/\s/g,""),e.length%4===0&&(e=e.replace(/=+$/,"")),e.length%4===1)throw Error("InvalidCharacterError");if(/[^+/0-9A-Za-z]/.test(e))throw Error("InvalidCharacterError");for(;n<e.length;)r=t.indexOf(e.charAt(n)),o=o<<6|r,a+=6,24===a&&(i.push(String.fromCharCode(o>>16&255)),i.push(String.fromCharCode(o>>8&255)),i.push(String.fromCharCode(255&o)),a=0,o=0),n+=1;return 12===a?(o>>=4,i.push(String.fromCharCode(255&o))):18===a&&(o>>=2,i.push(String.fromCharCode(o>>8&255)),i.push(String.fromCharCode(255&o))),i.join("")},e.btoa=e.btoa||function(e){e=String(e);var r,n,i,o,a,l,s,d=0,h=[];if(/[^\x00-\xFF]/.test(e))throw Error("InvalidCharacterError");for(;d<e.length;)r=e.charCodeAt(d++),n=e.charCodeAt(d++),i=e.charCodeAt(d++),o=r>>2,a=(3&r)<<4|n>>4,l=(15&n)<<2|i>>6,s=63&i,d===e.length+2?(l=64,s=64):d===e.length+1&&(s=64),h.push(t.charAt(o),t.charAt(a),t.charAt(l),t.charAt(s));return h.join("")}}(this),function(){function e(t,r,n){t.document;var i,o=t.currentStyle[r].match(/([\d\.]+)(%|cm|em|in|mm|pc|pt|)/)||[0,0,""],a=o[1],l=o[2];return n=n?/%|em/.test(l)&&t.parentElement?e(t.parentElement,"fontSize",null):16:n,i="fontSize"==r?n:/width/i.test(r)?t.clientWidth:t.clientHeight,"%"==l?a/100*i:"cm"==l?.3937*a*96:"em"==l?a*n:"in"==l?96*a:"mm"==l?.3937*a*96/10:"pc"==l?12*a*96/72:"pt"==l?96*a/72:a}function t(e,t){var r="border"==t?"Width":"",n=t+"Top"+r,i=t+"Right"+r,o=t+"Bottom"+r,a=t+"Left"+r;e[t]=(e[n]==e[i]&&e[n]==e[o]&&e[n]==e[a]?[e[n]]:e[n]==e[o]&&e[a]==e[i]?[e[n],e[i]]:e[a]==e[i]?[e[n],e[i],e[o]]:[e[n],e[i],e[o],e[a]]).join(" ")}function r(r){var n,i=this,o=r.currentStyle,a=e(r,"fontSize"),l=function(e){return"-"+e.toLowerCase()};for(n in o)if(Array.prototype.push.call(i,"styleFloat"==n?"float":n.replace(/[A-Z]/,l)),"width"==n)i[n]=r.offsetWidth+"px";else if("height"==n)i[n]=r.offsetHeight+"px";else if("styleFloat"==n)i.float=o[n];else if(/margin.|padding.|border.+W/.test(n)&&"auto"!=i[n])i[n]=Math.round(e(r,n,a))+"px";else if(/^outline/.test(n))try{i[n]=o[n]}catch(s){i.outlineColor=o.color,i.outlineStyle=i.outlineStyle||"none",i.outlineWidth=i.outlineWidth||"0px",i.outline=[i.outlineColor,i.outlineWidth,i.outlineStyle].join(" ")}else i[n]=o[n];t(i,"margin"),t(i,"padding"),t(i,"border"),i.fontSize=Math.round(a)+"px"}window.getComputedStyle||(r.prototype={constructor:r,getPropertyPriority:function(){throw new Error("NotSupportedError: DOM Exception 9")},getPropertyValue:function(e){var t=e.replace(/-([a-z])/g,function(e){return e=e.charAt?e.split(""):e,e[1].toUpperCase()}),r=this[t];return r},item:function(e){return this[e]},removeProperty:function(){throw new Error("NoModificationAllowedError: DOM Exception 7")},setProperty:function(){throw new Error("NoModificationAllowedError: DOM Exception 7")},getPropertyCSSValue:function(){throw new Error("NotSupportedError: DOM Exception 9")}},window.getComputedStyle=function(e){return new r(e)})}(),Object.prototype.hasOwnProperty||(Object.prototype.hasOwnProperty=function(e){var t=this.__proto__||this.constructor.prototype;return e in this&&(!(e in t)||t[e]!==this[e])}),function(e,t){e.augment=t()}(this,function(){"use strict";var e=function(){},t=Array.prototype.slice,r=function(r,n){var i=e.prototype="function"==typeof r?r.prototype:r,o=new e,a=n.apply(o,t.call(arguments,2).concat(i));if("object"==typeof a)for(var l in a)o[l]=a[l];if(!o.hasOwnProperty("constructor"))return o;var s=o.constructor;return s.prototype=o,s};return r.defclass=function(e){var t=e.constructor;return t.prototype=e,t},r.extend=function(e,t){return r(e,function(e){return this.uber=e,t})},r}),function(e,t){function r(e,t,r,o){var a=n(r.substr(r.lastIndexOf(e.domain)),e);a&&i(null,o,a,t)}function n(e,t){for(var r={theme:p(A.settings.themes.gray,null),stylesheets:t.stylesheets,holderURL:[]},n=!1,i=String.fromCharCode(11),o=e.replace(/([^\\])\//g,"$1"+i).split(i),a=/%[0-9a-f]{2}/gi,l=o.length,s=0;l>s;s++){var d=o[s];if(d.match(a))try{d=decodeURIComponent(d)}catch(h){d=o[s]}var u=!1;if(A.flags.dimensions.match(d))n=!0,r.dimensions=A.flags.dimensions.output(d),u=!0;else if(A.flags.fluid.match(d))n=!0,r.dimensions=A.flags.fluid.output(d),r.fluid=!0,u=!0;else if(A.flags.textmode.match(d))r.textmode=A.flags.textmode.output(d),u=!0;else if(A.flags.colors.match(d)){var c=A.flags.colors.output(d);r.theme=p(r.theme,c),u=!0}else if(t.themes[d])t.themes.hasOwnProperty(d)&&(r.theme=p(t.themes[d],null)),u=!0;else if(A.flags.font.match(d))r.font=A.flags.font.output(d),u=!0;else if(A.flags.auto.match(d))r.auto=!0,u=!0;else if(A.flags.text.match(d))r.text=A.flags.text.output(d),u=!0;else if(A.flags.random.match(d)){null==A.vars.cache.themeKeys&&(A.vars.cache.themeKeys=Object.keys(t.themes));var f=A.vars.cache.themeKeys[0|Math.random()*A.vars.cache.themeKeys.length];r.theme=p(t.themes[f],null),u=!0}u&&r.holderURL.push(d)}return r.holderURL.unshift(t.domain),r.holderURL=r.holderURL.join("/"),n?r:!1}function i(e,t,r,n){var i=r.dimensions,a=r.theme,l=i.width+"x"+i.height;if(e=null==e?r.fluid?"fluid":"image":e,null!=r.text&&(a.text=r.text,"object"===t.nodeName.toLowerCase())){for(var d=a.text.split("\\n"),u=0;u<d.length;u++)d[u]=b(d[u]);a.text=d.join("\\n")}var f=r.holderURL,g=p(n,null);r.font&&(a.font=r.font,!g.noFontFallback&&"img"===t.nodeName.toLowerCase()&&A.setup.supportsCanvas&&"svg"===g.renderer&&(g=p(g,{renderer:"canvas"}))),r.font&&"canvas"==g.renderer&&(g.reRender=!0),"background"==e?null==t.getAttribute("data-background-src")&&c(t,{"data-background-src":f}):c(t,{"data-src":f}),r.theme=a,t.holderData={flags:r,renderSettings:g},("image"==e||"fluid"==e)&&c(t,{alt:a.text?(a.text.length>16?a.text.substring(0,16)+"…":a.text)+" ["+l+"]":l}),"image"==e?("html"!=g.renderer&&r.auto||(t.style.width=i.width+"px",t.style.height=i.height+"px"),"html"==g.renderer?t.style.backgroundColor=a.background:(o(e,{dimensions:i,theme:a,flags:r},t,g),r.textmode&&"exact"==r.textmode&&(A.vars.resizableImages.push(t),s(t)))):"background"==e&&"html"!=g.renderer?o(e,{dimensions:i,theme:a,flags:r},t,g):"fluid"==e&&("%"==i.height.slice(-1)?t.style.height=i.height:null!=r.auto&&r.auto||(t.style.height=i.height+"px"),"%"==i.width.slice(-1)?t.style.width=i.width:null!=r.auto&&r.auto||(t.style.width=i.width+"px"),("inline"==t.style.display||""===t.style.display||"none"==t.style.display)&&(t.style.display="block"),h(t),"html"==g.renderer?t.style.backgroundColor=a.background:(A.vars.resizableImages.push(t),s(t)))}function o(e,t,r,n){function i(){var e=null;switch(n.renderer){case"canvas":e=L(s);break;case"svg":e=O(s,n);break;default:throw"Holder: invalid renderer: "+n.renderer}return e}var o=null;switch(n.renderer){case"svg":if(!A.setup.supportsSVG)return;break;case"canvas":if(!A.setup.supportsCanvas)return;break;default:return}{var l={width:t.dimensions.width,height:t.dimensions.height,theme:t.theme,flags:t.flags},s=a(l);({text:l.text,width:l.width,height:l.height,textHeight:l.font.size,font:l.font.family,fontWeight:l.font.weight,template:l.theme})}if(o=i(),null==o)throw"Holder: couldn't render placeholder";"background"==e?(r.style.backgroundImage="url("+o+")",r.style.backgroundSize=l.width+"px "+l.height+"px"):("img"===r.nodeName.toLowerCase()?c(r,{src:o}):"object"===r.nodeName.toLowerCase()&&(c(r,{data:o}),c(r,{type:"image/svg+xml"})),n.reRender&&setTimeout(function(){var e=i();if(null==e)throw"Holder: couldn't render placeholder";"img"===r.nodeName.toLowerCase()?c(r,{src:e}):"object"===r.nodeName.toLowerCase()&&(c(r,{data:e}),c(r,{type:"image/svg+xml"}))},100)),c(r,{"data-holder-rendered":!0})}function a(e){function t(e,t,r,n){t.width=r,t.height=n,e.width=Math.max(e.width,t.width),e.height+=t.height,e.add(t)}switch(e.font={family:e.theme.font?e.theme.font:"Arial, Helvetica, Open Sans, sans-serif",size:l(e.width,e.height,e.theme.size?e.theme.size:A.defaults.size),units:e.theme.units?e.theme.units:A.defaults.units,weight:e.theme.fontweight?e.theme.fontweight:"bold"},e.text=e.theme.text?e.theme.text:Math.floor(e.width)+"x"+Math.floor(e.height),e.flags.textmode){case"literal":e.text=e.flags.dimensions.width+"x"+e.flags.dimensions.height;break;case"exact":if(!e.flags.exactDimensions)break;e.text=Math.floor(e.flags.exactDimensions.width)+"x"+Math.floor(e.flags.exactDimensions.height)}var r=new z({width:e.width,height:e.height}),n=r.Shape,i=new n.Rect("holderBg",{fill:e.theme.background});i.resize(e.width,e.height),r.root.add(i);var o=new n.Group("holderTextGroup",{text:e.text,align:"center",font:e.font,fill:e.theme.foreground});o.moveTo(null,null,1),r.root.add(o);var a=o.textPositionData=T(r);if(!a)throw"Holder: staging fallback not supported yet.";o.properties.leading=a.boundingBox.height;var s=null,d=null;if(a.lineCount>1){var h=0,u=0,c=e.width*A.setup.lineWrapRatio,f=0;d=new n.Group("line"+f);for(var g=0;g<a.words.length;g++){var p=a.words[g];s=new n.Text(p.text);var m="\\n"==p.text;(h+p.width>=c||m===!0)&&(t(o,d,h,o.properties.leading),h=0,u+=o.properties.leading,f+=1,d=new n.Group("line"+f),d.y=u),m!==!0&&(s.moveTo(h,0),h+=a.spaceWidth+p.width,d.add(s))}t(o,d,h,o.properties.leading);for(var v in o.children)d=o.children[v],d.moveTo((o.width-d.width)/2,null,null);o.moveTo((e.width-o.width)/2,(e.height-o.height)/2,null),(e.height-o.height)/2<0&&o.moveTo(null,0,null)}else s=new n.Text(e.text),d=new n.Group("line0"),d.add(s),o.add(d),o.moveTo((e.width-a.boundingBox.width)/2,(e.height-a.boundingBox.height)/2,null);return r}function l(e,t,r){t=parseInt(t,10),e=parseInt(e,10);var n=Math.max(t,e),i=Math.min(t,e),o=A.defaults.scale,a=Math.min(.75*i,.75*n*o);return Math.round(Math.max(r,a))}function s(e){var t;t=null==e||null==e.nodeType?A.vars.resizableImages:[e];for(var r in t)if(t.hasOwnProperty(r)){var n=t[r];if(n.holderData){var i=n.holderData.flags,a=d(n,k.invisibleErrorFn(s));if(a){if(i.fluid&&i.auto){var l=n.holderData.fluidConfig;switch(l.mode){case"width":a.height=a.width/l.ratio;break;case"height":a.width=a.height*l.ratio}}var h={dimensions:a,theme:i.theme,flags:i};i.textmode&&"exact"==i.textmode&&(i.exactDimensions=a,h.dimensions=i.dimensions),o("image",h,n,n.holderData.renderSettings)}}}}function d(e,t){var r={height:e.clientHeight,width:e.clientWidth};return r.height||r.width?(e.removeAttribute("data-holder-invisible"),r):(c(e,{"data-holder-invisible":!0}),t.call(this,e),void 0)}function h(e){if(e.holderData){var t=d(e,k.invisibleErrorFn(h));if(t){var r=e.holderData.flags,n={fluidHeight:"%"==r.dimensions.height.slice(-1),fluidWidth:"%"==r.dimensions.width.slice(-1),mode:null,initialDimensions:t};n.fluidWidth&&!n.fluidHeight?(n.mode="width",n.ratio=n.initialDimensions.width/parseFloat(r.dimensions.height)):!n.fluidWidth&&n.fluidHeight&&(n.mode="height",n.ratio=parseFloat(r.dimensions.width)/n.initialDimensions.height),e.holderData.fluidConfig=n}}}function u(e,t){return null==t?E.createElement(e):E.createElementNS(t,e)}function c(e,t){for(var r in t)e.setAttribute(r,t[r])}function f(e,t,r){if(null==e){e=u("svg",C);var n=u("defs",C);e.appendChild(n)}return e.webkitMatchesSelector&&e.setAttribute("xmlns",C),c(e,{width:t,height:r,viewBox:"0 0 "+t+" "+r,preserveAspectRatio:"none"}),e}function g(e,r){if(t.XMLSerializer){{var n=new XMLSerializer,i="",o=r.stylesheets;e.querySelector("defs")}if(r.svgXMLStylesheet){for(var a=(new DOMParser).parseFromString("<xml />","application/xml"),l=o.length-1;l>=0;l--){var s=a.createProcessingInstruction("xml-stylesheet",'href="'+o[l]+'" rel="stylesheet"');a.insertBefore(s,a.firstChild)}var d=a.createProcessingInstruction("xml",'version="1.0" encoding="UTF-8" standalone="yes"');a.insertBefore(d,a.firstChild),a.removeChild(a.documentElement),i=n.serializeToString(a)}var h=n.serializeToString(e);return h=h.replace(/\&amp;(\#[0-9]{2,}\;)/g,"&$1"),i+h}}function p(e,t){var r={};for(var n in e)e.hasOwnProperty(n)&&(r[n]=e[n]);if(null!=t)for(var i in t)t.hasOwnProperty(i)&&(r[i]=t[i]);return r}function m(e){var t=[];for(var r in e)e.hasOwnProperty(r)&&t.push(r+":"+e[r]);return t.join(";")}function v(e){A.vars.debounceTimer||e.call(this),A.vars.debounceTimer&&clearTimeout(A.vars.debounceTimer),A.vars.debounceTimer=setTimeout(function(){A.vars.debounceTimer=null,e.call(this)},A.setup.debounce)}function x(){v(function(){s(null)})}function y(e){var r=null;return"string"==typeof e?r=E.querySelectorAll(e):t.NodeList&&e instanceof t.NodeList?r=e:t.Node&&e instanceof t.Node?r=[e]:t.HTMLCollection&&e instanceof t.HTMLCollection?r=e:null===e&&(r=[]),r}function w(e,t){var r=new Image;r.onerror=function(){t.call(this,!1)},r.onload=function(){t.call(this,!0)},r.src=e}function b(e){for(var t=[],r=0,n=e.length-1;n>=0;n--)r=e.charCodeAt(n),r>128?t.unshift(["&#",r,";"].join("")):t.unshift(e[n]);return t.join("")}function S(e){return e.replace(/&#(\d+);/g,function(e,t){return String.fromCharCode(t)})}var C="http://www.w3.org/2000/svg",E=t.document,k={addTheme:function(e,t){return null!=e&&null!=t&&(A.settings.themes[e]=t),delete A.vars.cache.themeKeys,this},addImage:function(e,t){var r=E.querySelectorAll(t);if(r.length)for(var n=0,i=r.length;i>n;n++){var o=u("img");c(o,{"data-src":e}),r[n].appendChild(o)}return this},run:function(e){e=e||{};var o={};A.vars.preempted=!0;var a=p(A.settings,e);o.renderer=a.renderer?a.renderer:A.setup.renderer,-1===A.setup.renderers.join(",").indexOf(o.renderer)&&(o.renderer=A.setup.supportsSVG?"svg":A.setup.supportsCanvas?"canvas":"html"),a.use_canvas?o.renderer="canvas":a.use_svg&&(o.renderer="svg");var l=y(a.images),s=y(a.bgnodes),d=y(a.stylenodes),h=y(a.objects);o.stylesheets=[],o.svgXMLStylesheet=!0,o.noFontFallback=a.noFontFallback?a.noFontFallback:!1;for(var c=0;c<d.length;c++){var f=d[c];if(f.attributes.rel&&f.attributes.href&&"stylesheet"==f.attributes.rel.value){var g=f.attributes.href.value,m=u("a");m.href=g;var v=m.protocol+"//"+m.host+m.pathname+m.search;o.stylesheets.push(v)}}for(c=0;c<s.length;c++){var x=t.getComputedStyle(s[c],null).getPropertyValue("background-image"),b=s[c].getAttribute("data-background-src"),S=null;S=null==b?x:b;var C=null,E="?"+a.domain+"/";if(0===S.indexOf(E))C=S.slice(1);else if(-1!=S.indexOf(E)){var k=S.substr(S.indexOf(E)).slice(1),T=k.match(/([^\"]*)"?\)/);null!=T&&(C=T[1])}if(null!=C){var L=n(C,a);L&&i("background",s[c],L,o)}}for(c=0;c<h.length;c++){var O=h[c],z={};try{z.data=O.getAttribute("data"),z.dataSrc=O.getAttribute("data-src")}catch(F){}var M=null!=z.data&&0===z.data.indexOf(a.domain),D=null!=z.dataSrc&&0===z.dataSrc.indexOf(a.domain);M?r(a,o,z.data,O):D&&r(a,o,z.dataSrc,O)}for(c=0;c<l.length;c++){var R=l[c],j={};try{j.src=R.getAttribute("src"),j.dataSrc=R.getAttribute("data-src"),j.rendered=R.getAttribute("data-holder-rendered")}catch(F){}var B=null!=j.src,P=null!=j.dataSrc&&0===j.dataSrc.indexOf(a.domain),N=null!=j.rendered&&"true"==j.rendered;B?0===j.src.indexOf(a.domain)?r(a,o,j.src,R):P&&(N?r(a,o,j.dataSrc,R):!function(e,t,n,i,o){w(e,function(e){e||r(t,n,i,o)})}(j.src,a,o,j.dataSrc,R)):P&&r(a,o,j.dataSrc,R)}return this},invisibleErrorFn:function(){return function(e){if(e.hasAttribute("data-holder-invisible"))throw"Holder: invisible placeholder"}}};k.add_theme=k.addTheme,k.add_image=k.addImage,k.invisible_error_fn=k.invisibleErrorFn;var A={settings:{domain:"holder.js",images:"img",objects:"object",bgnodes:"body .holderjs",stylenodes:"head link.holderjs",stylesheets:[],themes:{gray:{background:"#EEEEEE",foreground:"#AAAAAA"},social:{background:"#3a5a97",foreground:"#FFFFFF"},industrial:{background:"#434A52",foreground:"#C2F200"},sky:{background:"#0D8FDB",foreground:"#FFFFFF"},vine:{background:"#39DBAC",foreground:"#1E292C"},lava:{background:"#F8591A",foreground:"#1C2846"}}},defaults:{size:10,units:"pt",scale:1/16},flags:{dimensions:{regex:/^(\d+)x(\d+)$/,output:function(e){var t=this.regex.exec(e);return{width:+t[1],height:+t[2]}}},fluid:{regex:/^([0-9]+%?)x([0-9]+%?)$/,output:function(e){var t=this.regex.exec(e);return{width:t[1],height:t[2]}}},colors:{regex:/(?:#|\^)([0-9a-f]{3,})\:(?:#|\^)([0-9a-f]{3,})/i,output:function(e){var t=this.regex.exec(e);return{foreground:"#"+t[2],background:"#"+t[1]}}},text:{regex:/text\:(.*)/,output:function(e){return this.regex.exec(e)[1].replace("\\/","/")}},font:{regex:/font\:(.*)/,output:function(e){return this.regex.exec(e)[1]}},auto:{regex:/^auto$/},textmode:{regex:/textmode\:(.*)/,output:function(e){return this.regex.exec(e)[1]}},random:{regex:/^random$/}}},T=function(){var e=null,t=null,r=null;return function(n){var i=n.root;if(A.setup.supportsSVG){var o=!1,a=function(e){return E.createTextNode(e)};null==e&&(o=!0),e=f(e,i.properties.width,i.properties.height),o&&(t=u("text",C),r=a(null),c(t,{x:0}),t.appendChild(r),e.appendChild(t),E.body.appendChild(e),e.style.visibility="hidden",e.style.position="absolute",e.style.top="-100%",e.style.left="-100%");var l=i.children.holderTextGroup,s=l.properties;c(t,{y:s.font.size,style:m({"font-weight":s.font.weight,"font-size":s.font.size+s.font.units,"font-family":s.font.family,"dominant-baseline":"middle"})}),r.nodeValue=s.text;var d=t.getBBox(),h=Math.ceil(d.width/(i.properties.width*A.setup.lineWrapRatio)),g=s.text.split(" "),p=s.text.match(/\\n/g);h+=null==p?0:p.length,r.nodeValue=s.text.replace(/[ ]+/g,"");var v=t.getComputedTextLength(),x=d.width-v,y=Math.round(x/Math.max(1,g.length-1)),w=[];if(h>1){r.nodeValue="";for(var b=0;b<g.length;b++)if(0!==g[b].length){r.nodeValue=S(g[b]);var k=t.getBBox();w.push({text:g[b],width:k.width})}}return{spaceWidth:y,lineCount:h,boundingBox:d,words:w}}return!1}}(),L=function(){var e=u("canvas"),t=null;return function(r){null==t&&(t=e.getContext("2d"));var n=r.root;e.width=A.dpr(n.properties.width),e.height=A.dpr(n.properties.height),t.textBaseline="middle",t.fillStyle=n.children.holderBg.properties.fill,t.fillRect(0,0,A.dpr(n.children.holderBg.width),A.dpr(n.children.holderBg.height));{var i=n.children.holderTextGroup;i.properties}t.font=i.properties.font.weight+" "+A.dpr(i.properties.font.size)+i.properties.font.units+" "+i.properties.font.family+", monospace",t.fillStyle=i.properties.fill;for(var o in i.children){var a=i.children[o];for(var l in a.children){var s=a.children[l],d=A.dpr(i.x+a.x+s.x),h=A.dpr(i.y+a.y+s.y+i.properties.leading/2);t.fillText(s.properties.text,d,h)}}return e.toDataURL("image/png")}}(),O=function(){if(t.XMLSerializer){var e=f(null,0,0),r=u("rect",C);return e.appendChild(r),function(t,n){var i=t.root;f(e,i.properties.width,i.properties.height);for(var o=e.querySelectorAll("g"),a=0;a<o.length;a++)o[a].parentNode.removeChild(o[a]);c(r,{width:i.children.holderBg.width,height:i.children.holderBg.height,fill:i.children.holderBg.properties.fill});var l=i.children.holderTextGroup,s=l.properties,d=u("g",C);e.appendChild(d);for(var h in l.children){var p=l.children[h];for(var v in p.children){var x=p.children[v],y=l.x+p.x+x.x,w=l.y+p.y+x.y+l.properties.leading/2,b=u("text",C),S=E.createTextNode(null);c(b,{x:y,y:w,style:m({fill:s.fill,"font-weight":s.font.weight,"font-family":s.font.family+", monospace","font-size":s.font.size+s.font.units,"dominant-baseline":"central"})}),S.nodeValue=x.properties.text,b.appendChild(S),d.appendChild(b)}}var k="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(g(e,n))));return k}}}(),z=function(e){function t(e,t){for(var r in t)e[r]=t[r];return e}var r=1,n=augment.defclass({constructor:function(e){r++,this.parent=null,this.children={},this.id=r,this.name="n"+r,null!=e&&(this.name=e),this.x=0,this.y=0,this.z=0,this.width=0,this.height=0},resize:function(e,t){null!=e&&(this.width=e),null!=t&&(this.height=t)},moveTo:function(e,t,r){this.x=null!=e?e:this.x,this.y=null!=t?t:this.y,this.z=null!=r?r:this.z},add:function(e){var t=e.name;if(null!=this.children[t])throw"SceneGraph: child with that name already exists: "+t;this.children[t]=e,e.parent=this}}),i=augment(n,function(t){this.constructor=function(){t.constructor.call(this,"root"),this.properties=e}}),o=augment(n,function(e){function r(r,n){if(e.constructor.call(this,r),this.properties={fill:"#000"},null!=n)t(this.properties,n);else if(null!=r&&"string"!=typeof r)throw"SceneGraph: invalid node name"}this.Group=augment.extend(this,{constructor:r,type:"group"}),this.Rect=augment.extend(this,{constructor:r,type:"rect"}),this.Text=augment.extend(this,{constructor:function(e){r.call(this),this.properties.text=e},type:"text"})}),a=new i;return this.Shape=o,this.root=a,this};for(var F in A.flags)A.flags.hasOwnProperty(F)&&(A.flags[F].match=function(e){return e.match(this.regex)});A.setup={renderer:"html",debounce:100,ratio:1,supportsCanvas:!1,supportsSVG:!1,lineWrapRatio:.9,renderers:["html","canvas","svg"]},A.dpr=function(e){return e*A.setup.ratio},A.vars={preempted:!1,resizableImages:[],debounceTimer:null,cache:{}},function(){var e=1,r=1,n=u("canvas"),i=null;n.getContext&&-1!=n.toDataURL("image/png").indexOf("data:image/png")&&(A.setup.renderer="canvas",i=n.getContext("2d"),A.setup.supportsCanvas=!0),A.setup.supportsCanvas&&(e=t.devicePixelRatio||1,r=i.webkitBackingStorePixelRatio||i.mozBackingStorePixelRatio||i.msBackingStorePixelRatio||i.oBackingStorePixelRatio||i.backingStorePixelRatio||1),A.setup.ratio=e/r,E.createElementNS&&E.createElementNS(C,"svg").createSVGRect&&(A.setup.renderer="svg",A.setup.supportsSVG=!0)}(),e(k,"Holder",t),t.onDomReady&&t.onDomReady(function(){A.vars.preempted||k.run(),t.addEventListener?(t.addEventListener("resize",x,!1),t.addEventListener("orientationchange",x,!1)):t.attachEvent("onresize",x),"object"==typeof t.Turbolinks&&t.document.addEventListener("page:change",function(){k.run()})})}(function(e,t,r){var n="function"==typeof define&&define.amd;n?define(e):r[t]=e},this);
12
+ /*!
13
+ * onDomReady.js 1.4.0 (c) 2013 Tubal Martin - MIT license
14
+ *
15
+ * Specially modified to work with Holder.js
16
+ */
17
+
18
+ ;(function(name, global, callback){
19
+ global[name] = callback;
20
+ })("onDomReady", this,
21
+
22
+ (function(win) {
23
+
24
+ 'use strict';
25
+
26
+ //Lazy loading fix for Firefox < 3.6
27
+ //http://webreflection.blogspot.com/2009/11/195-chars-to-help-lazy-loading.html
28
+ if (document.readyState == null && document.addEventListener) {
29
+ document.addEventListener("DOMContentLoaded", function DOMContentLoaded() {
30
+ document.removeEventListener("DOMContentLoaded", DOMContentLoaded, false);
31
+ document.readyState = "complete";
32
+ }, false);
33
+ document.readyState = "loading";
34
+ }
35
+
36
+ var doc = win.document,
37
+ docElem = doc.documentElement,
38
+
39
+ LOAD = "load",
40
+ FALSE = false,
41
+ ONLOAD = "on"+LOAD,
42
+ COMPLETE = "complete",
43
+ READYSTATE = "readyState",
44
+ ATTACHEVENT = "attachEvent",
45
+ DETACHEVENT = "detachEvent",
46
+ ADDEVENTLISTENER = "addEventListener",
47
+ DOMCONTENTLOADED = "DOMContentLoaded",
48
+ ONREADYSTATECHANGE = "onreadystatechange",
49
+ REMOVEEVENTLISTENER = "removeEventListener",
50
+
51
+ // W3C Event model
52
+ w3c = ADDEVENTLISTENER in doc,
53
+ top = FALSE,
54
+
55
+ // isReady: Is the DOM ready to be used? Set to true once it occurs.
56
+ isReady = FALSE,
57
+
58
+ // Callbacks pending execution until DOM is ready
59
+ callbacks = [];
60
+
61
+ // Handle when the DOM is ready
62
+ function ready( fn ) {
63
+ if ( !isReady ) {
64
+
65
+ // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
66
+ if ( !doc.body ) {
67
+ return defer( ready );
68
+ }
69
+
70
+ // Remember that the DOM is ready
71
+ isReady = true;
72
+
73
+ // Execute all callbacks
74
+ while ( fn = callbacks.shift() ) {
75
+ defer( fn );
76
+ }
77
+ }
78
+ }
79
+
80
+ // The ready event handler
81
+ function completed( event ) {
82
+ // readyState === "complete" is good enough for us to call the dom ready in oldIE
83
+ if ( w3c || event.type === LOAD || doc[READYSTATE] === COMPLETE ) {
84
+ detach();
85
+ ready();
86
+ }
87
+ }
88
+
89
+ // Clean-up method for dom ready events
90
+ function detach() {
91
+ if ( w3c ) {
92
+ doc[REMOVEEVENTLISTENER]( DOMCONTENTLOADED, completed, FALSE );
93
+ win[REMOVEEVENTLISTENER]( LOAD, completed, FALSE );
94
+ } else {
95
+ doc[DETACHEVENT]( ONREADYSTATECHANGE, completed );
96
+ win[DETACHEVENT]( ONLOAD, completed );
97
+ }
98
+ }
99
+
100
+ // Defers a function, scheduling it to run after the current call stack has cleared.
101
+ function defer( fn, wait ) {
102
+ // Allow 0 to be passed
103
+ setTimeout( fn, +wait >= 0 ? wait : 1 );
104
+ }
105
+
106
+ // Attach the listeners:
107
+
108
+ // Catch cases where onDomReady is called after the browser event has already occurred.
109
+ // we once tried to use readyState "interactive" here, but it caused issues like the one
110
+ // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
111
+ if ( doc[READYSTATE] === COMPLETE ) {
112
+ // Handle it asynchronously to allow scripts the opportunity to delay ready
113
+ defer( ready );
114
+
115
+ // Standards-based browsers support DOMContentLoaded
116
+ } else if ( w3c ) {
117
+ // Use the handy event callback
118
+ doc[ADDEVENTLISTENER]( DOMCONTENTLOADED, completed, FALSE );
119
+
120
+ // A fallback to window.onload, that will always work
121
+ win[ADDEVENTLISTENER]( LOAD, completed, FALSE );
122
+
123
+ // If IE event model is used
124
+ } else {
125
+ // Ensure firing before onload, maybe late but safe also for iframes
126
+ doc[ATTACHEVENT]( ONREADYSTATECHANGE, completed );
127
+
128
+ // A fallback to window.onload, that will always work
129
+ win[ATTACHEVENT]( ONLOAD, completed );
130
+
131
+ // If IE and not a frame
132
+ // continually check to see if the document is ready
133
+ try {
134
+ top = win.frameElement == null && docElem;
135
+ } catch(e) {}
136
+
137
+ if ( top && top.doScroll ) {
138
+ (function doScrollCheck() {
139
+ if ( !isReady ) {
140
+ try {
141
+ // Use the trick by Diego Perini
142
+ // http://javascript.nwbox.com/IEContentLoaded/
143
+ top.doScroll("left");
144
+ } catch(e) {
145
+ return defer( doScrollCheck, 50 );
146
+ }
147
+
148
+ // detach all dom ready events
149
+ detach();
150
+
151
+ // and execute any waiting functions
152
+ ready();
153
+ }
154
+ })();
155
+ }
156
+ }
157
+
158
+ function onDomReady( fn ) {
159
+ // If DOM is ready, execute the function (async), otherwise wait
160
+ isReady ? defer( fn ) : callbacks.push( fn );
161
+ }
162
+
163
+ // Add version
164
+ onDomReady.version = "1.4.0";
165
+ // Add method to check if DOM is ready
166
+ onDomReady.isReady = function(){
167
+ return isReady;
168
+ };
169
+
170
+ return onDomReady;
171
+ })(this));
172
+
173
+ //https://github.com/inexorabletash/polyfill/blob/master/web.js
174
+ if (!document.querySelectorAll) {
175
+ document.querySelectorAll = function (selectors) {
176
+ var style = document.createElement('style'), elements = [], element;
177
+ document.documentElement.firstChild.appendChild(style);
178
+ document._qsa = [];
179
+
180
+ style.styleSheet.cssText = selectors + '{x-qsa:expression(document._qsa && document._qsa.push(this))}';
181
+ window.scrollBy(0, 0);
182
+ style.parentNode.removeChild(style);
183
+
184
+ while (document._qsa.length) {
185
+ element = document._qsa.shift();
186
+ element.style.removeAttribute('x-qsa');
187
+ elements.push(element);
188
+ }
189
+ document._qsa = null;
190
+ return elements;
191
+ };
192
+ }
193
+
194
+ if (!document.querySelector) {
195
+ document.querySelector = function (selectors) {
196
+ var elements = document.querySelectorAll(selectors);
197
+ return (elements.length) ? elements[0] : null;
198
+ };
199
+ }
200
+
201
+ if (!document.getElementsByClassName) {
202
+ document.getElementsByClassName = function (classNames) {
203
+ classNames = String(classNames).replace(/^|\s+/g, '.');
204
+ return document.querySelectorAll(classNames);
205
+ };
206
+ }
207
+
208
+ //https://github.com/inexorabletash/polyfill
209
+ // ES5 15.2.3.14 Object.keys ( O )
210
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/keys
211
+ if (!Object.keys) {
212
+ Object.keys = function (o) {
213
+ if (o !== Object(o)) { throw TypeError('Object.keys called on non-object'); }
214
+ var ret = [], p;
215
+ for (p in o) {
216
+ if (Object.prototype.hasOwnProperty.call(o, p)) {
217
+ ret.push(p);
218
+ }
219
+ }
220
+ return ret;
221
+ };
222
+ }
223
+
224
+ //https://github.com/inexorabletash/polyfill/blob/master/web.js
225
+ (function (global) {
226
+ var B64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
227
+ global.atob = global.atob || function (input) {
228
+ input = String(input);
229
+ var position = 0,
230
+ output = [],
231
+ buffer = 0, bits = 0, n;
232
+
233
+ input = input.replace(/\s/g, '');
234
+ if ((input.length % 4) === 0) { input = input.replace(/=+$/, ''); }
235
+ if ((input.length % 4) === 1) { throw Error("InvalidCharacterError"); }
236
+ if (/[^+/0-9A-Za-z]/.test(input)) { throw Error("InvalidCharacterError"); }
237
+
238
+ while (position < input.length) {
239
+ n = B64_ALPHABET.indexOf(input.charAt(position));
240
+ buffer = (buffer << 6) | n;
241
+ bits += 6;
242
+
243
+ if (bits === 24) {
244
+ output.push(String.fromCharCode((buffer >> 16) & 0xFF));
245
+ output.push(String.fromCharCode((buffer >> 8) & 0xFF));
246
+ output.push(String.fromCharCode(buffer & 0xFF));
247
+ bits = 0;
248
+ buffer = 0;
249
+ }
250
+ position += 1;
251
+ }
252
+
253
+ if (bits === 12) {
254
+ buffer = buffer >> 4;
255
+ output.push(String.fromCharCode(buffer & 0xFF));
256
+ } else if (bits === 18) {
257
+ buffer = buffer >> 2;
258
+ output.push(String.fromCharCode((buffer >> 8) & 0xFF));
259
+ output.push(String.fromCharCode(buffer & 0xFF));
260
+ }
261
+
262
+ return output.join('');
263
+ };
264
+
265
+ global.btoa = global.btoa || function (input) {
266
+ input = String(input);
267
+ var position = 0,
268
+ out = [],
269
+ o1, o2, o3,
270
+ e1, e2, e3, e4;
271
+
272
+ if (/[^\x00-\xFF]/.test(input)) { throw Error("InvalidCharacterError"); }
273
+
274
+ while (position < input.length) {
275
+ o1 = input.charCodeAt(position++);
276
+ o2 = input.charCodeAt(position++);
277
+ o3 = input.charCodeAt(position++);
278
+
279
+ // 111111 112222 222233 333333
280
+ e1 = o1 >> 2;
281
+ e2 = ((o1 & 0x3) << 4) | (o2 >> 4);
282
+ e3 = ((o2 & 0xf) << 2) | (o3 >> 6);
283
+ e4 = o3 & 0x3f;
284
+
285
+ if (position === input.length + 2) {
286
+ e3 = 64; e4 = 64;
287
+ }
288
+ else if (position === input.length + 1) {
289
+ e4 = 64;
290
+ }
291
+
292
+ out.push(B64_ALPHABET.charAt(e1),
293
+ B64_ALPHABET.charAt(e2),
294
+ B64_ALPHABET.charAt(e3),
295
+ B64_ALPHABET.charAt(e4));
296
+ }
297
+
298
+ return out.join('');
299
+ };
300
+ }(this));
301
+
302
+ //https://gist.github.com/jimeh/332357
303
+ if (!Object.prototype.hasOwnProperty){
304
+ /*jshint -W001, -W103 */
305
+ Object.prototype.hasOwnProperty = function(prop) {
306
+ var proto = this.__proto__ || this.constructor.prototype;
307
+ return (prop in this) && (!(prop in proto) || proto[prop] !== this[prop]);
308
+ }
309
+ /*jshint +W001, +W103 */
310
+ }
311
+
312
+ //requestAnimationFrame polyfill for older Firefox/Chrome versions
313
+ if (!window.requestAnimationFrame) {
314
+ if (window.webkitRequestAnimationFrame) {
315
+ //https://github.com/Financial-Times/polyfill-service/blob/master/polyfills/requestAnimationFrame/polyfill-webkit.js
316
+ (function (global) {
317
+ // window.requestAnimationFrame
318
+ global.requestAnimationFrame = function (callback) {
319
+ return webkitRequestAnimationFrame(function () {
320
+ callback(performance.now());
321
+ });
322
+ };
323
+
324
+ // window.cancelAnimationFrame
325
+ global.cancelAnimationFrame = webkitCancelAnimationFrame;
326
+ }(this));
327
+ } else if (window.mozRequestAnimationFrame) {
328
+ //https://github.com/Financial-Times/polyfill-service/blob/master/polyfills/requestAnimationFrame/polyfill-moz.js
329
+ (function (global) {
330
+ // window.requestAnimationFrame
331
+ global.requestAnimationFrame = function (callback) {
332
+ return mozRequestAnimationFrame(function () {
333
+ callback(performance.now());
334
+ });
335
+ };
336
+
337
+ // window.cancelAnimationFrame
338
+ global.cancelAnimationFrame = mozCancelAnimationFrame;
339
+ }(this));
340
+ }
341
+ }
342
+ (function (global, factory) {
343
+ global.augment = factory();
344
+ }(this, function () {
345
+ var Factory = function () {};
346
+ var slice = Array.prototype.slice;
347
+
348
+ var augment = function (base, body) {
349
+ var uber = Factory.prototype = typeof base === "function" ? base.prototype : base;
350
+ var prototype = new Factory(), properties = body.apply(prototype, slice.call(arguments, 2).concat(uber));
351
+ if (typeof properties === "object") for (var key in properties) prototype[key] = properties[key];
352
+ if (!prototype.hasOwnProperty("constructor")) return prototype;
353
+ var constructor = prototype.constructor;
354
+ constructor.prototype = prototype;
355
+ return constructor;
356
+ };
357
+
358
+ augment.defclass = function (prototype) {
359
+ var constructor = prototype.constructor;
360
+ constructor.prototype = prototype;
361
+ return constructor;
362
+ };
363
+
364
+ augment.extend = function (base, body) {
365
+ return augment(base, function (uber) {
366
+ this.uber = uber;
367
+ return body;
368
+ });
369
+ };
370
+
371
+ return augment;
372
+ }));
373
+
374
+ /*
375
+ Holder.js - client side image placeholders
376
+ © 2012-2015 Ivan Malopinsky - http://imsky.co
377
+ */
378
+ (function(register, global, undefined) {
379
+ //Constants and definitions
380
+ var SVG_NS = 'http://www.w3.org/2000/svg';
381
+ var NODE_TYPE_COMMENT = 8;
382
+ var document = global.document;
383
+ var version = '2.5.0';
384
+ var generatorComment = '\n' +
385
+ 'Created with Holder.js ' + version + '.\n' +
386
+ 'Learn more at http://holderjs.com\n' +
387
+ '(c) 2012-2015 Ivan Malopinsky - http://imsky.co\n';
388
+
389
+ var Holder = {
390
+ version: version,
391
+
392
+ /**
393
+ * Adds a theme to default settings
394
+ *
395
+ * @param {string} name Theme name
396
+ * @param {Object} theme Theme object, with foreground, background, size, font, and fontweight properties.
397
+ */
398
+ addTheme: function(name, theme) {
399
+ name != null && theme != null && (App.settings.themes[name] = theme);
400
+ delete App.vars.cache.themeKeys;
401
+ return this;
402
+ },
403
+
404
+ /**
405
+ * Appends a placeholder to an element
406
+ *
407
+ * @param {string} src Placeholder URL string
408
+ * @param {string} el Selector of target element(s)
409
+ */
410
+ addImage: function(src, el) {
411
+ var node = document.querySelectorAll(el);
412
+ if (node.length) {
413
+ for (var i = 0, l = node.length; i < l; i++) {
414
+ var img = newEl('img');
415
+ setAttr(img, {
416
+ 'data-src': src
417
+ });
418
+ node[i].appendChild(img);
419
+ }
420
+ }
421
+ return this;
422
+ },
423
+
424
+ /**
425
+ * Sets whether or not an image is updated on resize.
426
+ * If an image is set to be updated, it is immediately rendered.
427
+ *
428
+ * @param {Object} el Image DOM element
429
+ * @param {Boolean} value Resizable update flag value
430
+ */
431
+ setResizeUpdate: function(el, value) {
432
+ if (el.holderData) {
433
+ el.holderData.resizeUpdate = !!value;
434
+ if (el.holderData.resizeUpdate) {
435
+ updateResizableElements(el);
436
+ }
437
+ }
438
+ },
439
+
440
+ /**
441
+ * Runs Holder with options. By default runs Holder on all images with "holder.js" in their source attributes.
442
+ *
443
+ * @param {Object} userOptions Options object, can contain domain, themes, images, and bgnodes properties
444
+ */
445
+ run: function(userOptions) {
446
+ userOptions = userOptions || {};
447
+ var engineSettings = {};
448
+
449
+ App.vars.preempted = true;
450
+
451
+ var options = extend(App.settings, userOptions);
452
+
453
+ engineSettings.renderer = options.renderer ? options.renderer : App.setup.renderer;
454
+ if (App.setup.renderers.join(',').indexOf(engineSettings.renderer) === -1) {
455
+ engineSettings.renderer = App.setup.supportsSVG ? 'svg' : (App.setup.supportsCanvas ? 'canvas' : 'html');
456
+ }
457
+
458
+ var images = getNodeArray(options.images);
459
+ var bgnodes = getNodeArray(options.bgnodes);
460
+ var stylenodes = getNodeArray(options.stylenodes);
461
+ var objects = getNodeArray(options.objects);
462
+
463
+ engineSettings.stylesheets = [];
464
+ engineSettings.svgXMLStylesheet = true;
465
+ engineSettings.noFontFallback = options.noFontFallback ? options.noFontFallback : false;
466
+
467
+ for (var i = 0; i < stylenodes.length; i++) {
468
+ var styleNode = stylenodes[i];
469
+ if (styleNode.attributes.rel && styleNode.attributes.href && styleNode.attributes.rel.value == 'stylesheet') {
470
+ var href = styleNode.attributes.href.value;
471
+ //todo: write isomorphic relative-to-absolute URL function
472
+ var proxyLink = newEl('a');
473
+ proxyLink.href = href;
474
+ var stylesheetURL = proxyLink.protocol + '//' + proxyLink.host + proxyLink.pathname + proxyLink.search;
475
+ engineSettings.stylesheets.push(stylesheetURL);
476
+ }
477
+ }
478
+
479
+ for (i = 0; i < bgnodes.length; i++) {
480
+ //Skip processing background nodes if getComputedStyle is unavailable, since only modern browsers would be able to use canvas or SVG to render to background
481
+ if (!global.getComputedStyle) continue;
482
+ var backgroundImage = global.getComputedStyle(bgnodes[i], null).getPropertyValue('background-image');
483
+ var dataBackgroundImage = bgnodes[i].getAttribute('data-background-src');
484
+ var rawURL = null;
485
+
486
+ if (dataBackgroundImage == null) {
487
+ rawURL = backgroundImage;
488
+ } else {
489
+ rawURL = dataBackgroundImage;
490
+ }
491
+
492
+ var holderURL = null;
493
+ var holderString = '?' + options.domain + '/';
494
+
495
+ if (rawURL.indexOf(holderString) === 0) {
496
+ holderURL = rawURL.slice(1);
497
+ } else if (rawURL.indexOf(holderString) != -1) {
498
+ var fragment = rawURL.substr(rawURL.indexOf(holderString)).slice(1);
499
+ var fragmentMatch = fragment.match(/([^\"]*)"?\)/);
500
+
501
+ if (fragmentMatch != null) {
502
+ holderURL = fragmentMatch[1];
503
+ }
504
+ }
505
+
506
+ if (holderURL != null) {
507
+ var holderFlags = parseURL(holderURL, options);
508
+ if (holderFlags) {
509
+ prepareDOMElement({
510
+ mode: 'background',
511
+ el: bgnodes[i],
512
+ flags: holderFlags,
513
+ engineSettings: engineSettings
514
+ });
515
+ }
516
+ }
517
+ }
518
+
519
+ for (i = 0; i < objects.length; i++) {
520
+ var object = objects[i];
521
+ var objectAttr = {};
522
+
523
+ try {
524
+ objectAttr.data = object.getAttribute('data');
525
+ objectAttr.dataSrc = object.getAttribute('data-src');
526
+ } catch (e) {}
527
+
528
+ var objectHasSrcURL = objectAttr.data != null && objectAttr.data.indexOf(options.domain) === 0;
529
+ var objectHasDataSrcURL = objectAttr.dataSrc != null && objectAttr.dataSrc.indexOf(options.domain) === 0;
530
+
531
+ if (objectHasSrcURL) {
532
+ prepareImageElement(options, engineSettings, objectAttr.data, object);
533
+ } else if (objectHasDataSrcURL) {
534
+ prepareImageElement(options, engineSettings, objectAttr.dataSrc, object);
535
+ }
536
+ }
537
+
538
+ for (i = 0; i < images.length; i++) {
539
+ var image = images[i];
540
+ var imageAttr = {};
541
+
542
+ try {
543
+ imageAttr.src = image.getAttribute('src');
544
+ imageAttr.dataSrc = image.getAttribute('data-src');
545
+ imageAttr.rendered = image.getAttribute('data-holder-rendered');
546
+ } catch (e) {}
547
+
548
+ var imageHasSrc = imageAttr.src != null;
549
+ var imageHasDataSrcURL = imageAttr.dataSrc != null && imageAttr.dataSrc.indexOf(options.domain) === 0;
550
+ var imageRendered = imageAttr.rendered != null && imageAttr.rendered == 'true';
551
+
552
+ if (imageHasSrc) {
553
+ if (imageAttr.src.indexOf(options.domain) === 0) {
554
+ prepareImageElement(options, engineSettings, imageAttr.src, image);
555
+ } else if (imageHasDataSrcURL) {
556
+ //Image has a valid data-src and an invalid src
557
+ if (imageRendered) {
558
+ //If the placeholder has already been render, re-render it
559
+ prepareImageElement(options, engineSettings, imageAttr.dataSrc, image);
560
+ } else {
561
+ //If the placeholder has not been rendered, check if the image exists and render a fallback if it doesn't
562
+ (function(src, options, engineSettings, dataSrc, image) {
563
+ imageExists(src, function(exists) {
564
+ if (!exists) {
565
+ prepareImageElement(options, engineSettings, dataSrc, image);
566
+ }
567
+ });
568
+ })(imageAttr.src, options, engineSettings, imageAttr.dataSrc, image);
569
+ }
570
+ }
571
+ } else if (imageHasDataSrcURL) {
572
+ prepareImageElement(options, engineSettings, imageAttr.dataSrc, image);
573
+ }
574
+ }
575
+
576
+ return this;
577
+ }
578
+ };
579
+
580
+ var App = {
581
+ settings: {
582
+ domain: 'holder.js',
583
+ images: 'img',
584
+ objects: 'object',
585
+ bgnodes: 'body .holderjs',
586
+ stylenodes: 'head link.holderjs',
587
+ stylesheets: [],
588
+ themes: {
589
+ 'gray': {
590
+ background: '#EEEEEE',
591
+ foreground: '#AAAAAA'
592
+ },
593
+ 'social': {
594
+ background: '#3a5a97',
595
+ foreground: '#FFFFFF'
596
+ },
597
+ 'industrial': {
598
+ background: '#434A52',
599
+ foreground: '#C2F200'
600
+ },
601
+ 'sky': {
602
+ background: '#0D8FDB',
603
+ foreground: '#FFFFFF'
604
+ },
605
+ 'vine': {
606
+ background: '#39DBAC',
607
+ foreground: '#1E292C'
608
+ },
609
+ 'lava': {
610
+ background: '#F8591A',
611
+ foreground: '#1C2846'
612
+ }
613
+ }
614
+ },
615
+ defaults: {
616
+ size: 10,
617
+ units: 'pt',
618
+ scale: 1 / 16
619
+ },
620
+ flags: {
621
+ dimensions: {
622
+ regex: /^(\d+)x(\d+)$/,
623
+ output: function(val) {
624
+ var exec = this.regex.exec(val);
625
+ return {
626
+ width: +exec[1],
627
+ height: +exec[2]
628
+ };
629
+ }
630
+ },
631
+ fluid: {
632
+ regex: /^([0-9]+%?)x([0-9]+%?)$/,
633
+ output: function(val) {
634
+ var exec = this.regex.exec(val);
635
+ return {
636
+ width: exec[1],
637
+ height: exec[2]
638
+ };
639
+ }
640
+ },
641
+ colors: {
642
+ regex: /(?:#|\^)([0-9a-f]{3,})\:(?:#|\^)([0-9a-f]{3,})/i,
643
+ output: function(val) {
644
+ var exec = this.regex.exec(val);
645
+ return {
646
+ foreground: '#' + exec[2],
647
+ background: '#' + exec[1]
648
+ };
649
+ }
650
+ },
651
+ text: {
652
+ regex: /text\:(.*)/,
653
+ output: function(val) {
654
+ return this.regex.exec(val)[1].replace('\\/', '/');
655
+ }
656
+ },
657
+ font: {
658
+ regex: /font\:(.*)/,
659
+ output: function(val) {
660
+ return this.regex.exec(val)[1];
661
+ }
662
+ },
663
+ auto: {
664
+ regex: /^auto$/
665
+ },
666
+ textmode: {
667
+ regex: /textmode\:(.*)/,
668
+ output: function(val) {
669
+ return this.regex.exec(val)[1];
670
+ }
671
+ },
672
+ random: {
673
+ regex: /^random$/
674
+ },
675
+ size: {
676
+ regex: /size\:(\d+)/,
677
+ output: function(val){
678
+ return this.regex.exec(val)[1];
679
+ }
680
+ }
681
+ }
682
+ };
683
+
684
+ /**
685
+ * Processes provided source attribute and sets up the appropriate rendering workflow
686
+ *
687
+ * @private
688
+ * @param options Instance options from Holder.run
689
+ * @param renderSettings Instance configuration
690
+ * @param src Image URL
691
+ * @param el Image DOM element
692
+ */
693
+ function prepareImageElement(options, engineSettings, src, el) {
694
+ var holderFlags = parseURL(src.substr(src.lastIndexOf(options.domain)), options);
695
+ if (holderFlags) {
696
+ prepareDOMElement({
697
+ mode: null,
698
+ el: el,
699
+ flags: holderFlags,
700
+ engineSettings: engineSettings
701
+ });
702
+ }
703
+ }
704
+
705
+ /**
706
+ * Processes a Holder URL and extracts flags
707
+ *
708
+ * @private
709
+ * @param url URL
710
+ * @param options Instance options from Holder.run
711
+ */
712
+ function parseURL(url, options) {
713
+ var ret = {
714
+ theme: extend(App.settings.themes.gray, null),
715
+ stylesheets: options.stylesheets,
716
+ holderURL: []
717
+ };
718
+ var render = false;
719
+ var vtab = String.fromCharCode(11);
720
+ var flags = url.replace(/([^\\])\//g, '$1' + vtab).split(vtab);
721
+ var uriRegex = /%[0-9a-f]{2}/gi;
722
+ for (var fl = flags.length, j = 0; j < fl; j++) {
723
+ var flag = flags[j];
724
+ if (flag.match(uriRegex)) {
725
+ try {
726
+ flag = decodeURIComponent(flag);
727
+ } catch (e) {
728
+ flag = flags[j];
729
+ }
730
+ }
731
+
732
+ var push = false;
733
+
734
+ if (App.flags.dimensions.match(flag)) {
735
+ render = true;
736
+ ret.dimensions = App.flags.dimensions.output(flag);
737
+ push = true;
738
+ } else if (App.flags.fluid.match(flag)) {
739
+ render = true;
740
+ ret.dimensions = App.flags.fluid.output(flag);
741
+ ret.fluid = true;
742
+ push = true;
743
+ } else if (App.flags.textmode.match(flag)) {
744
+ ret.textmode = App.flags.textmode.output(flag);
745
+ push = true;
746
+ } else if (App.flags.colors.match(flag)) {
747
+ var colors = App.flags.colors.output(flag);
748
+ ret.theme = extend(ret.theme, colors);
749
+ //todo: convert implicit theme use to a theme: flag
750
+ push = true;
751
+ } else if (options.themes[flag]) {
752
+ //If a theme is specified, it will override custom colors
753
+ if (options.themes.hasOwnProperty(flag)) {
754
+ ret.theme = extend(options.themes[flag], null);
755
+ }
756
+ push = true;
757
+ } else if (App.flags.font.match(flag)) {
758
+ ret.font = App.flags.font.output(flag);
759
+ push = true;
760
+ } else if (App.flags.auto.match(flag)) {
761
+ ret.auto = true;
762
+ push = true;
763
+ } else if (App.flags.text.match(flag)) {
764
+ ret.text = App.flags.text.output(flag);
765
+ push = true;
766
+ } else if (App.flags.size.match(flag)) {
767
+ ret.size = App.flags.size.output(flag);
768
+ push = true;
769
+ } else if (App.flags.random.match(flag)) {
770
+ if (App.vars.cache.themeKeys == null) {
771
+ App.vars.cache.themeKeys = Object.keys(options.themes);
772
+ }
773
+ var theme = App.vars.cache.themeKeys[0 | Math.random() * App.vars.cache.themeKeys.length];
774
+ ret.theme = extend(options.themes[theme], null);
775
+ push = true;
776
+ }
777
+
778
+ if (push) {
779
+ ret.holderURL.push(flag);
780
+ }
781
+ }
782
+ ret.holderURL.unshift(options.domain);
783
+ ret.holderURL = ret.holderURL.join('/');
784
+ return render ? ret : false;
785
+ }
786
+
787
+ /**
788
+ * Modifies the DOM to fit placeholders and sets up resizable image callbacks (for fluid and automatically sized placeholders)
789
+ *
790
+ * @private
791
+ * @param settings DOM prep settings
792
+ */
793
+ function prepareDOMElement(prepSettings) {
794
+ var mode = prepSettings.mode;
795
+ var el = prepSettings.el;
796
+ var flags = prepSettings.flags;
797
+ var _engineSettings = prepSettings.engineSettings;
798
+ var dimensions = flags.dimensions,
799
+ theme = flags.theme;
800
+ var dimensionsCaption = dimensions.width + 'x' + dimensions.height;
801
+ mode = mode == null ? (flags.fluid ? 'fluid' : 'image') : mode;
802
+
803
+ if (flags.text != null) {
804
+ theme.text = flags.text;
805
+
806
+ //<object> SVG embedding doesn't parse Unicode properly
807
+ if (el.nodeName.toLowerCase() === 'object') {
808
+ var textLines = theme.text.split('\\n');
809
+ for (var k = 0; k < textLines.length; k++) {
810
+ textLines[k] = encodeHtmlEntity(textLines[k]);
811
+ }
812
+ theme.text = textLines.join('\\n');
813
+ }
814
+ }
815
+
816
+ var holderURL = flags.holderURL;
817
+ var engineSettings = extend(_engineSettings, null);
818
+
819
+ if (flags.font) {
820
+ theme.font = flags.font;
821
+ //Only run the <canvas> webfont fallback if noFontFallback is false, if the node is not an image, and if canvas is supported
822
+ if (!engineSettings.noFontFallback && el.nodeName.toLowerCase() === 'img' && App.setup.supportsCanvas && engineSettings.renderer === 'svg') {
823
+ engineSettings = extend(engineSettings, {
824
+ renderer: 'canvas'
825
+ });
826
+ }
827
+ }
828
+
829
+ //Chrome and Opera require a quick 10ms re-render if web fonts are used with canvas
830
+ if (flags.font && engineSettings.renderer == 'canvas') {
831
+ engineSettings.reRender = true;
832
+ }
833
+
834
+ if (mode == 'background') {
835
+ if (el.getAttribute('data-background-src') == null) {
836
+ setAttr(el, {
837
+ 'data-background-src': holderURL
838
+ });
839
+ }
840
+ } else {
841
+ setAttr(el, {
842
+ 'data-src': holderURL
843
+ });
844
+ }
845
+
846
+ flags.theme = theme;
847
+
848
+ //todo consider using all renderSettings in holderData
849
+ el.holderData = {
850
+ flags: flags,
851
+ engineSettings: engineSettings
852
+ };
853
+
854
+ if (mode == 'image' || mode == 'fluid') {
855
+ setAttr(el, {
856
+ 'alt': (theme.text ? theme.text + ' [' + dimensionsCaption + ']' : dimensionsCaption)
857
+ });
858
+ }
859
+
860
+ var renderSettings = {
861
+ mode: mode,
862
+ el: el,
863
+ holderSettings: {
864
+ dimensions: dimensions,
865
+ theme: theme,
866
+ flags: flags
867
+ },
868
+ engineSettings: engineSettings
869
+ };
870
+
871
+ if (mode == 'image') {
872
+ if (engineSettings.renderer == 'html' || !flags.auto) {
873
+ el.style.width = dimensions.width + 'px';
874
+ el.style.height = dimensions.height + 'px';
875
+ }
876
+ if (engineSettings.renderer == 'html') {
877
+ el.style.backgroundColor = theme.background;
878
+ } else {
879
+ render(renderSettings);
880
+
881
+ if (flags.textmode == 'exact') {
882
+ el.holderData.resizeUpdate = true;
883
+ App.vars.resizableImages.push(el);
884
+ updateResizableElements(el);
885
+ }
886
+ }
887
+ } else if (mode == 'background' && engineSettings.renderer != 'html') {
888
+ render(renderSettings);
889
+ } else if (mode == 'fluid') {
890
+ el.holderData.resizeUpdate = true;
891
+
892
+ if (dimensions.height.slice(-1) == '%') {
893
+ el.style.height = dimensions.height;
894
+ } else if (flags.auto == null || !flags.auto) {
895
+ el.style.height = dimensions.height + 'px';
896
+ }
897
+ if (dimensions.width.slice(-1) == '%') {
898
+ el.style.width = dimensions.width;
899
+ } else if (flags.auto == null || !flags.auto) {
900
+ el.style.width = dimensions.width + 'px';
901
+ }
902
+ if (el.style.display == 'inline' || el.style.display === '' || el.style.display == 'none') {
903
+ el.style.display = 'block';
904
+ }
905
+
906
+ setInitialDimensions(el);
907
+
908
+ if (engineSettings.renderer == 'html') {
909
+ el.style.backgroundColor = theme.background;
910
+ } else {
911
+ App.vars.resizableImages.push(el);
912
+ updateResizableElements(el);
913
+ }
914
+ }
915
+ }
916
+
917
+ /**
918
+ * Core function that takes output from renderers and sets it as the source or background-image of the target element
919
+ *
920
+ * @private
921
+ * @param renderSettings Renderer settings
922
+ */
923
+ function render(renderSettings) {
924
+ var image = null;
925
+ var mode = renderSettings.mode;
926
+ var holderSettings = renderSettings.holderSettings;
927
+ var el = renderSettings.el;
928
+ var engineSettings = renderSettings.engineSettings;
929
+
930
+ switch (engineSettings.renderer) {
931
+ case 'svg':
932
+ if (!App.setup.supportsSVG) return;
933
+ break;
934
+ case 'canvas':
935
+ if (!App.setup.supportsCanvas) return;
936
+ break;
937
+ default:
938
+ return;
939
+ }
940
+
941
+ //todo: move generation of scene up to flag generation to reduce extra object creation
942
+ var scene = {
943
+ width: holderSettings.dimensions.width,
944
+ height: holderSettings.dimensions.height,
945
+ theme: holderSettings.theme,
946
+ flags: holderSettings.flags
947
+ };
948
+
949
+ var sceneGraph = buildSceneGraph(scene);
950
+
951
+ function getRenderedImage() {
952
+ var image = null;
953
+ switch (engineSettings.renderer) {
954
+ case 'canvas':
955
+ image = sgCanvasRenderer(sceneGraph, renderSettings);
956
+ break;
957
+ case 'svg':
958
+ image = sgSVGRenderer(sceneGraph, renderSettings);
959
+ break;
960
+ default:
961
+ throw 'Holder: invalid renderer: ' + engineSettings.renderer;
962
+ }
963
+ return image;
964
+ }
965
+
966
+ image = getRenderedImage();
967
+
968
+ if (image == null) {
969
+ throw 'Holder: couldn\'t render placeholder';
970
+ }
971
+
972
+ //todo: add <object> canvas rendering
973
+ if (mode == 'background') {
974
+ el.style.backgroundImage = 'url(' + image + ')';
975
+ el.style.backgroundSize = scene.width + 'px ' + scene.height + 'px';
976
+ } else {
977
+ if (el.nodeName.toLowerCase() === 'img') {
978
+ setAttr(el, {
979
+ 'src': image
980
+ });
981
+ } else if (el.nodeName.toLowerCase() === 'object') {
982
+ setAttr(el, {
983
+ 'data': image
984
+ });
985
+ setAttr(el, {
986
+ 'type': 'image/svg+xml'
987
+ });
988
+ }
989
+ if (engineSettings.reRender) {
990
+ global.setTimeout(function() {
991
+ var image = getRenderedImage();
992
+ if (image == null) {
993
+ throw 'Holder: couldn\'t render placeholder';
994
+ }
995
+ if (el.nodeName.toLowerCase() === 'img') {
996
+ setAttr(el, {
997
+ 'src': image
998
+ });
999
+ } else if (el.nodeName.toLowerCase() === 'object') {
1000
+ setAttr(el, {
1001
+ 'data': image
1002
+ });
1003
+ setAttr(el, {
1004
+ 'type': 'image/svg+xml'
1005
+ });
1006
+ }
1007
+ }, 100);
1008
+ }
1009
+ }
1010
+ setAttr(el, {
1011
+ 'data-holder-rendered': true
1012
+ });
1013
+ }
1014
+
1015
+ /**
1016
+ * Core function that takes a Holder scene description and builds a scene graph
1017
+ *
1018
+ * @private
1019
+ * @param scene Holder scene object
1020
+ */
1021
+ function buildSceneGraph(scene) {
1022
+ var fontSize = App.defaults.size;
1023
+ if (parseFloat(scene.theme.size)) {
1024
+ fontSize = scene.theme.size;
1025
+ } else if (parseFloat(scene.flags.size)) {
1026
+ fontSize = scene.flags.size;
1027
+ }
1028
+
1029
+ scene.font = {
1030
+ family: scene.theme.font ? scene.theme.font : 'Arial, Helvetica, Open Sans, sans-serif',
1031
+ size: textSize(scene.width, scene.height, fontSize),
1032
+ units: scene.theme.units ? scene.theme.units : App.defaults.units,
1033
+ weight: scene.theme.fontweight ? scene.theme.fontweight : 'bold'
1034
+ };
1035
+ scene.text = scene.theme.text ? scene.theme.text : Math.floor(scene.width) + 'x' + Math.floor(scene.height);
1036
+
1037
+ switch (scene.flags.textmode) {
1038
+ case 'literal':
1039
+ scene.text = scene.flags.dimensions.width + 'x' + scene.flags.dimensions.height;
1040
+ break;
1041
+ case 'exact':
1042
+ if (!scene.flags.exactDimensions) break;
1043
+ scene.text = Math.floor(scene.flags.exactDimensions.width) + 'x' + Math.floor(scene.flags.exactDimensions.height);
1044
+ break;
1045
+ }
1046
+
1047
+ var sceneGraph = new SceneGraph({
1048
+ width: scene.width,
1049
+ height: scene.height
1050
+ });
1051
+
1052
+ var Shape = sceneGraph.Shape;
1053
+
1054
+ var holderBg = new Shape.Rect('holderBg', {
1055
+ fill: scene.theme.background
1056
+ });
1057
+
1058
+ holderBg.resize(scene.width, scene.height);
1059
+ sceneGraph.root.add(holderBg);
1060
+
1061
+ var holderTextGroup = new Shape.Group('holderTextGroup', {
1062
+ text: scene.text,
1063
+ align: 'center',
1064
+ font: scene.font,
1065
+ fill: scene.theme.foreground
1066
+ });
1067
+
1068
+ holderTextGroup.moveTo(null, null, 1);
1069
+ sceneGraph.root.add(holderTextGroup);
1070
+
1071
+ var tpdata = holderTextGroup.textPositionData = stagingRenderer(sceneGraph);
1072
+ if (!tpdata) {
1073
+ throw 'Holder: staging fallback not supported yet.';
1074
+ }
1075
+ holderTextGroup.properties.leading = tpdata.boundingBox.height;
1076
+
1077
+ //todo: alignment: TL, TC, TR, CL, CR, BL, BC, BR
1078
+ var textNode = null;
1079
+ var line = null;
1080
+
1081
+ function finalizeLine(parent, line, width, height) {
1082
+ line.width = width;
1083
+ line.height = height;
1084
+ parent.width = Math.max(parent.width, line.width);
1085
+ parent.height += line.height;
1086
+ parent.add(line);
1087
+ }
1088
+
1089
+ if (tpdata.lineCount > 1) {
1090
+ var offsetX = 0;
1091
+ var offsetY = 0;
1092
+ var maxLineWidth = scene.width * App.setup.lineWrapRatio;
1093
+ var lineIndex = 0;
1094
+ line = new Shape.Group('line' + lineIndex);
1095
+
1096
+ for (var i = 0; i < tpdata.words.length; i++) {
1097
+ var word = tpdata.words[i];
1098
+ textNode = new Shape.Text(word.text);
1099
+ var newline = word.text == '\\n';
1100
+ if (offsetX + word.width >= maxLineWidth || newline === true) {
1101
+ finalizeLine(holderTextGroup, line, offsetX, holderTextGroup.properties.leading);
1102
+ offsetX = 0;
1103
+ offsetY += holderTextGroup.properties.leading;
1104
+ lineIndex += 1;
1105
+ line = new Shape.Group('line' + lineIndex);
1106
+ line.y = offsetY;
1107
+ }
1108
+ if (newline === true) {
1109
+ continue;
1110
+ }
1111
+ textNode.moveTo(offsetX, 0);
1112
+ offsetX += tpdata.spaceWidth + word.width;
1113
+ line.add(textNode);
1114
+ }
1115
+
1116
+ finalizeLine(holderTextGroup, line, offsetX, holderTextGroup.properties.leading);
1117
+
1118
+ for (var lineKey in holderTextGroup.children) {
1119
+ line = holderTextGroup.children[lineKey];
1120
+ line.moveTo(
1121
+ (holderTextGroup.width - line.width) / 2,
1122
+ null,
1123
+ null);
1124
+ }
1125
+
1126
+ holderTextGroup.moveTo(
1127
+ (scene.width - holderTextGroup.width) / 2, (scene.height - holderTextGroup.height) / 2,
1128
+ null);
1129
+
1130
+ //If the text exceeds vertical space, move it down so the first line is visible
1131
+ if ((scene.height - holderTextGroup.height) / 2 < 0) {
1132
+ holderTextGroup.moveTo(null, 0, null);
1133
+ }
1134
+ } else {
1135
+ textNode = new Shape.Text(scene.text);
1136
+ line = new Shape.Group('line0');
1137
+ line.add(textNode);
1138
+ holderTextGroup.add(line);
1139
+
1140
+ holderTextGroup.moveTo(
1141
+ (scene.width - tpdata.boundingBox.width) / 2, (scene.height - tpdata.boundingBox.height) / 2,
1142
+ null);
1143
+ }
1144
+
1145
+ //todo: renderlist
1146
+
1147
+ return sceneGraph;
1148
+ }
1149
+
1150
+ /**
1151
+ * Adaptive text sizing function
1152
+ *
1153
+ * @private
1154
+ * @param width Parent width
1155
+ * @param height Parent height
1156
+ * @param fontSize Requested text size
1157
+ */
1158
+ function textSize(width, height, fontSize) {
1159
+ var stageWidth = parseInt(width, 10);
1160
+ var stageHeight = parseInt(height, 10);
1161
+
1162
+ var bigSide = Math.max(stageWidth, stageHeight);
1163
+ var smallSide = Math.min(stageWidth, stageHeight);
1164
+
1165
+ var newHeight = 0.8 * Math.min(smallSide, bigSide * App.defaults.scale);
1166
+ return Math.round(Math.max(fontSize, newHeight));
1167
+ }
1168
+
1169
+ /**
1170
+ * Iterates over resizable (fluid or auto) placeholders and renders them
1171
+ *
1172
+ * @private
1173
+ * @param element Optional element selector, specified only if a specific element needs to be re-rendered
1174
+ */
1175
+ function updateResizableElements(element) {
1176
+ var images;
1177
+ if (element == null || element.nodeType == null) {
1178
+ images = App.vars.resizableImages;
1179
+ } else {
1180
+ images = [element];
1181
+ }
1182
+ for (var i = 0, l = images.length; i < l; i++) {
1183
+ var el = images[i];
1184
+ if (el.holderData) {
1185
+ var flags = el.holderData.flags;
1186
+ var dimensions = dimensionCheck(el);
1187
+ if (dimensions) {
1188
+ if (!el.holderData.resizeUpdate) {
1189
+ continue;
1190
+ }
1191
+
1192
+ if (flags.fluid && flags.auto) {
1193
+ var fluidConfig = el.holderData.fluidConfig;
1194
+ switch (fluidConfig.mode) {
1195
+ case 'width':
1196
+ dimensions.height = dimensions.width / fluidConfig.ratio;
1197
+ break;
1198
+ case 'height':
1199
+ dimensions.width = dimensions.height * fluidConfig.ratio;
1200
+ break;
1201
+ }
1202
+ }
1203
+
1204
+ var settings = {
1205
+ mode: 'image',
1206
+ holderSettings: {
1207
+ dimensions: dimensions,
1208
+ theme: flags.theme,
1209
+ flags: flags
1210
+ },
1211
+ el: el,
1212
+ engineSettings: el.holderData.engineSettings
1213
+ };
1214
+
1215
+ if (flags.textmode == 'exact') {
1216
+ flags.exactDimensions = dimensions;
1217
+ settings.holderSettings.dimensions = flags.dimensions;
1218
+ }
1219
+
1220
+ render(settings);
1221
+ } else {
1222
+ setInvisible(el);
1223
+ }
1224
+ }
1225
+ }
1226
+ }
1227
+
1228
+ /**
1229
+ * Sets up aspect ratio metadata for fluid placeholders, in order to preserve proportions when resizing
1230
+ *
1231
+ * @private
1232
+ * @param el Image DOM element
1233
+ */
1234
+ function setInitialDimensions(el) {
1235
+ if (el.holderData) {
1236
+ var dimensions = dimensionCheck(el);
1237
+ if (dimensions) {
1238
+ var flags = el.holderData.flags;
1239
+
1240
+ var fluidConfig = {
1241
+ fluidHeight: flags.dimensions.height.slice(-1) == '%',
1242
+ fluidWidth: flags.dimensions.width.slice(-1) == '%',
1243
+ mode: null,
1244
+ initialDimensions: dimensions
1245
+ };
1246
+
1247
+ if (fluidConfig.fluidWidth && !fluidConfig.fluidHeight) {
1248
+ fluidConfig.mode = 'width';
1249
+ fluidConfig.ratio = fluidConfig.initialDimensions.width / parseFloat(flags.dimensions.height);
1250
+ } else if (!fluidConfig.fluidWidth && fluidConfig.fluidHeight) {
1251
+ fluidConfig.mode = 'height';
1252
+ fluidConfig.ratio = parseFloat(flags.dimensions.width) / fluidConfig.initialDimensions.height;
1253
+ }
1254
+
1255
+ el.holderData.fluidConfig = fluidConfig;
1256
+ } else {
1257
+ setInvisible(el);
1258
+ }
1259
+ }
1260
+ }
1261
+
1262
+ /**
1263
+ * Returns an element's dimensions if it's visible, `false` otherwise.
1264
+ *
1265
+ * @private
1266
+ * @param el DOM element
1267
+ */
1268
+ function dimensionCheck(el) {
1269
+ var dimensions = {
1270
+ height: el.clientHeight,
1271
+ width: el.clientWidth
1272
+ };
1273
+
1274
+ if (dimensions.height && dimensions.width) {
1275
+ return dimensions;
1276
+ }
1277
+ else{
1278
+ return false;
1279
+ }
1280
+ }
1281
+
1282
+ /**
1283
+ * Iterates through all current invisible images, and if they're visible, renders them and removes them from further checks. Runs every animation frame.
1284
+ *
1285
+ * @private
1286
+ */
1287
+ function visibilityCheck() {
1288
+ var renderableImages = [];
1289
+ var keys = Object.keys(App.vars.invisibleImages);
1290
+ var el;
1291
+ for (var i = 0, l = keys.length; i < l; i++) {
1292
+ el = App.vars.invisibleImages[keys[i]];
1293
+ if (dimensionCheck(el) && el.nodeName.toLowerCase() == 'img') {
1294
+ renderableImages.push(el);
1295
+ delete App.vars.invisibleImages[keys[i]];
1296
+ }
1297
+ }
1298
+
1299
+ if (renderableImages.length) {
1300
+ Holder.run({
1301
+ images: renderableImages
1302
+ });
1303
+ }
1304
+
1305
+ global.requestAnimationFrame(visibilityCheck);
1306
+ }
1307
+
1308
+ /**
1309
+ * Starts checking for invisible placeholders if not doing so yet. Does nothing otherwise.
1310
+ *
1311
+ * @private
1312
+ */
1313
+ function startVisibilityCheck() {
1314
+ if (!App.vars.visibilityCheckStarted) {
1315
+ global.requestAnimationFrame(visibilityCheck);
1316
+ App.vars.visibilityCheckStarted = true;
1317
+ }
1318
+ }
1319
+
1320
+ /**
1321
+ * Sets a unique ID for an image detected to be invisible and adds it to the map of invisible images checked by visibilityCheck
1322
+ *
1323
+ * @private
1324
+ * @param el Invisible DOM element
1325
+ */
1326
+ function setInvisible(el) {
1327
+ if (!el.holderData.invisibleId) {
1328
+ App.vars.invisibleId += 1;
1329
+ App.vars.invisibleImages['i' + App.vars.invisibleId] = el;
1330
+ el.holderData.invisibleId = App.vars.invisibleId;
1331
+ }
1332
+ }
1333
+
1334
+ //todo: see if possible to convert stagingRenderer to use HTML only
1335
+ var stagingRenderer = (function() {
1336
+ var svg = null,
1337
+ stagingText = null,
1338
+ stagingTextNode = null;
1339
+ return function(graph) {
1340
+ var rootNode = graph.root;
1341
+ if (App.setup.supportsSVG) {
1342
+ var firstTimeSetup = false;
1343
+ var tnode = function(text) {
1344
+ return document.createTextNode(text);
1345
+ };
1346
+ if (svg == null || svg.parentNode !== document.body) {
1347
+ firstTimeSetup = true;
1348
+ }
1349
+
1350
+ svg = initSVG(svg, rootNode.properties.width, rootNode.properties.height);
1351
+ //Show staging element before staging
1352
+ svg.style.display = 'block';
1353
+
1354
+ if (firstTimeSetup) {
1355
+ stagingText = newEl('text', SVG_NS);
1356
+ stagingTextNode = tnode(null);
1357
+ setAttr(stagingText, {
1358
+ x: 0
1359
+ });
1360
+ stagingText.appendChild(stagingTextNode);
1361
+ svg.appendChild(stagingText);
1362
+ document.body.appendChild(svg);
1363
+ svg.style.visibility = 'hidden';
1364
+ svg.style.position = 'absolute';
1365
+ svg.style.top = '-100%';
1366
+ svg.style.left = '-100%';
1367
+ //todo: workaround for zero-dimension <svg> tag in Opera 12
1368
+ //svg.setAttribute('width', 0);
1369
+ //svg.setAttribute('height', 0);
1370
+ }
1371
+
1372
+ var holderTextGroup = rootNode.children.holderTextGroup;
1373
+ var htgProps = holderTextGroup.properties;
1374
+ setAttr(stagingText, {
1375
+ 'y': htgProps.font.size,
1376
+ 'style': cssProps({
1377
+ 'font-weight': htgProps.font.weight,
1378
+ 'font-size': htgProps.font.size + htgProps.font.units,
1379
+ 'font-family': htgProps.font.family,
1380
+ 'dominant-baseline': 'middle'
1381
+ })
1382
+ });
1383
+
1384
+ //Get bounding box for the whole string (total width and height)
1385
+ stagingTextNode.nodeValue = htgProps.text;
1386
+ var stagingTextBBox = stagingText.getBBox();
1387
+
1388
+ //Get line count and split the string into words
1389
+ var lineCount = Math.ceil(stagingTextBBox.width / (rootNode.properties.width * App.setup.lineWrapRatio));
1390
+ var words = htgProps.text.split(' ');
1391
+ var newlines = htgProps.text.match(/\\n/g);
1392
+ lineCount += newlines == null ? 0 : newlines.length;
1393
+
1394
+ //Get bounding box for the string with spaces removed
1395
+ stagingTextNode.nodeValue = htgProps.text.replace(/[ ]+/g, '');
1396
+ var computedNoSpaceLength = stagingText.getComputedTextLength();
1397
+
1398
+ //Compute average space width
1399
+ var diffLength = stagingTextBBox.width - computedNoSpaceLength;
1400
+ var spaceWidth = Math.round(diffLength / Math.max(1, words.length - 1));
1401
+
1402
+ //Get widths for every word with space only if there is more than one line
1403
+ var wordWidths = [];
1404
+ if (lineCount > 1) {
1405
+ stagingTextNode.nodeValue = '';
1406
+ for (var i = 0; i < words.length; i++) {
1407
+ if (words[i].length === 0) continue;
1408
+ stagingTextNode.nodeValue = decodeHtmlEntity(words[i]);
1409
+ var bbox = stagingText.getBBox();
1410
+ wordWidths.push({
1411
+ text: words[i],
1412
+ width: bbox.width
1413
+ });
1414
+ }
1415
+ }
1416
+
1417
+ //Hide staging element after staging
1418
+ svg.style.display = 'none';
1419
+
1420
+ return {
1421
+ spaceWidth: spaceWidth,
1422
+ lineCount: lineCount,
1423
+ boundingBox: stagingTextBBox,
1424
+ words: wordWidths
1425
+ };
1426
+ } else {
1427
+ //todo: canvas fallback for measuring text on android 2.3
1428
+ return false;
1429
+ }
1430
+ };
1431
+ })();
1432
+
1433
+ var sgCanvasRenderer = (function() {
1434
+ var canvas = newEl('canvas');
1435
+ var ctx = null;
1436
+
1437
+ return function(sceneGraph) {
1438
+ if (ctx == null) {
1439
+ ctx = canvas.getContext('2d');
1440
+ }
1441
+ var root = sceneGraph.root;
1442
+ canvas.width = App.dpr(root.properties.width);
1443
+ canvas.height = App.dpr(root.properties.height);
1444
+ ctx.textBaseline = 'middle';
1445
+
1446
+ ctx.fillStyle = root.children.holderBg.properties.fill;
1447
+ ctx.fillRect(0, 0, App.dpr(root.children.holderBg.width), App.dpr(root.children.holderBg.height));
1448
+
1449
+ var textGroup = root.children.holderTextGroup;
1450
+ var tgProps = textGroup.properties;
1451
+ ctx.font = textGroup.properties.font.weight + ' ' + App.dpr(textGroup.properties.font.size) + textGroup.properties.font.units + ' ' + textGroup.properties.font.family + ', monospace';
1452
+ ctx.fillStyle = textGroup.properties.fill;
1453
+
1454
+ for (var lineKey in textGroup.children) {
1455
+ var line = textGroup.children[lineKey];
1456
+ for (var wordKey in line.children) {
1457
+ var word = line.children[wordKey];
1458
+ var x = App.dpr(textGroup.x + line.x + word.x);
1459
+ var y = App.dpr(textGroup.y + line.y + word.y + (textGroup.properties.leading / 2));
1460
+
1461
+ ctx.fillText(word.properties.text, x, y);
1462
+ }
1463
+ }
1464
+
1465
+ return canvas.toDataURL('image/png');
1466
+ };
1467
+ })();
1468
+
1469
+ var sgSVGRenderer = (function() {
1470
+ //Prevent IE <9 from initializing SVG renderer
1471
+ if (!global.XMLSerializer) return;
1472
+ var svg = initSVG(null, 0, 0);
1473
+ var bgEl = newEl('rect', SVG_NS);
1474
+ svg.appendChild(bgEl);
1475
+
1476
+ //todo: create a reusable pool for textNodes, resize if more words present
1477
+
1478
+ return function(sceneGraph, renderSettings) {
1479
+ var root = sceneGraph.root;
1480
+ var holderURL = renderSettings.holderSettings.flags.holderURL;
1481
+ var commentNode = document.createComment('\n' + 'Source URL: ' + holderURL + generatorComment);
1482
+
1483
+ initSVG(svg, root.properties.width, root.properties.height);
1484
+ svg.insertBefore(commentNode, svg.firstChild);
1485
+
1486
+ var groups = svg.querySelectorAll('g');
1487
+
1488
+ for (var i = 0; i < groups.length; i++) {
1489
+ groups[i].parentNode.removeChild(groups[i]);
1490
+ }
1491
+
1492
+ setAttr(bgEl, {
1493
+ 'width': root.children.holderBg.width,
1494
+ 'height': root.children.holderBg.height,
1495
+ 'fill': root.children.holderBg.properties.fill
1496
+ });
1497
+
1498
+ var textGroup = root.children.holderTextGroup;
1499
+ var tgProps = textGroup.properties;
1500
+ var textGroupEl = newEl('g', SVG_NS);
1501
+ svg.appendChild(textGroupEl);
1502
+
1503
+ for (var lineKey in textGroup.children) {
1504
+ var line = textGroup.children[lineKey];
1505
+ for (var wordKey in line.children) {
1506
+ var word = line.children[wordKey];
1507
+ var x = textGroup.x + line.x + word.x;
1508
+ var y = textGroup.y + line.y + word.y + (textGroup.properties.leading / 2);
1509
+
1510
+ var textEl = newEl('text', SVG_NS);
1511
+ var textNode = document.createTextNode(null);
1512
+
1513
+ setAttr(textEl, {
1514
+ 'x': x,
1515
+ 'y': y,
1516
+ 'style': cssProps({
1517
+ 'fill': tgProps.fill,
1518
+ 'font-weight': tgProps.font.weight,
1519
+ 'font-family': tgProps.font.family + ', monospace',
1520
+ 'font-size': tgProps.font.size + tgProps.font.units,
1521
+ 'dominant-baseline': 'central'
1522
+ })
1523
+ });
1524
+
1525
+ textNode.nodeValue = word.properties.text;
1526
+ textEl.appendChild(textNode);
1527
+ textGroupEl.appendChild(textEl);
1528
+ }
1529
+ }
1530
+
1531
+ var svgString = 'data:image/svg+xml;base64,' +
1532
+ btoa(unescape(encodeURIComponent(serializeSVG(svg, renderSettings.engineSettings))));
1533
+ return svgString;
1534
+ };
1535
+ })();
1536
+
1537
+ //Helpers
1538
+
1539
+ /**
1540
+ * Generic new DOM element function
1541
+ *
1542
+ * @private
1543
+ * @param tag Tag to create
1544
+ * @param namespace Optional namespace value
1545
+ */
1546
+ function newEl(tag, namespace) {
1547
+ if (namespace == null) {
1548
+ return document.createElement(tag);
1549
+ } else {
1550
+ return document.createElementNS(namespace, tag);
1551
+ }
1552
+ }
1553
+
1554
+ /**
1555
+ * Generic setAttribute function
1556
+ *
1557
+ * @private
1558
+ * @param el Reference to DOM element
1559
+ * @param attrs Object with attribute keys and values
1560
+ */
1561
+ function setAttr(el, attrs) {
1562
+ for (var a in attrs) {
1563
+ el.setAttribute(a, attrs[a]);
1564
+ }
1565
+ }
1566
+
1567
+ /**
1568
+ * Generic SVG element creation function
1569
+ *
1570
+ * @private
1571
+ * @param svg SVG context, set to null if new
1572
+ * @param width Document width
1573
+ * @param height Document height
1574
+ */
1575
+ function initSVG(svg, width, height) {
1576
+ if (svg == null) {
1577
+ svg = newEl('svg', SVG_NS);
1578
+ var defs = newEl('defs', SVG_NS);
1579
+ svg.appendChild(defs);
1580
+ }
1581
+ //IE throws an exception if this is set and Chrome requires it to be set
1582
+ if (svg.webkitMatchesSelector) {
1583
+ svg.setAttribute('xmlns', SVG_NS);
1584
+ }
1585
+ //Remove comment nodes
1586
+ for (var i = 0; i < svg.childNodes.length; i++) {
1587
+ if (svg.childNodes[i].nodeType === NODE_TYPE_COMMENT) {
1588
+ svg.removeChild(svg.childNodes[i]);
1589
+ }
1590
+ }
1591
+
1592
+ setAttr(svg, {
1593
+ 'width': width,
1594
+ 'height': height,
1595
+ 'viewBox': '0 0 ' + width + ' ' + height,
1596
+ 'preserveAspectRatio': 'none'
1597
+ });
1598
+ return svg;
1599
+ }
1600
+
1601
+ /**
1602
+ * Generic SVG serialization function
1603
+ *
1604
+ * @private
1605
+ * @param svg SVG context
1606
+ * @param stylesheets CSS stylesheets to include
1607
+ */
1608
+ function serializeSVG(svg, engineSettings) {
1609
+ if (!global.XMLSerializer) return;
1610
+ var serializer = new XMLSerializer();
1611
+ var svgCSS = '';
1612
+ var stylesheets = engineSettings.stylesheets;
1613
+ var defs = svg.querySelector('defs');
1614
+
1615
+ //External stylesheets: Processing Instruction method
1616
+ if (engineSettings.svgXMLStylesheet) {
1617
+ var xml = new DOMParser().parseFromString('<xml />', 'application/xml');
1618
+ //Add <?xml-stylesheet ?> directives
1619
+ for (var i = stylesheets.length - 1; i >= 0; i--) {
1620
+ var csspi = xml.createProcessingInstruction('xml-stylesheet', 'href="' + stylesheets[i] + '" rel="stylesheet"');
1621
+ xml.insertBefore(csspi, xml.firstChild);
1622
+ }
1623
+
1624
+ //Add <?xml ... ?> UTF-8 directive
1625
+ var xmlpi = xml.createProcessingInstruction('xml', 'version="1.0" encoding="UTF-8" standalone="yes"');
1626
+ xml.insertBefore(xmlpi, xml.firstChild);
1627
+ xml.removeChild(xml.documentElement);
1628
+ svgCSS = serializer.serializeToString(xml);
1629
+ }
1630
+
1631
+ /*
1632
+
1633
+ //External stylesheets: <link> method
1634
+ if (renderSettings.svgLinkStylesheet) {
1635
+
1636
+ defs.removeChild(defs.firstChild);
1637
+ for (i = 0; i < stylesheets.length; i++) {
1638
+ var link = document.createElementNS('http://www.w3.org/1999/xhtml', 'link');
1639
+ link.setAttribute('href', stylesheets[i]);
1640
+ link.setAttribute('rel', 'stylesheet');
1641
+ link.setAttribute('type', 'text/css');
1642
+ defs.appendChild(link);
1643
+ }
1644
+ }
1645
+
1646
+ //External stylesheets: <style> and @import method
1647
+ if (renderSettings.svgImportStylesheet) {
1648
+ var style = document.createElementNS(SVG_NS, 'style');
1649
+ var styleText = [];
1650
+
1651
+ for (i = 0; i < stylesheets.length; i++) {
1652
+ styleText.push('@import url(' + stylesheets[i] + ');');
1653
+ }
1654
+
1655
+ var styleTextNode = document.createTextNode(styleText.join('\n'));
1656
+ style.appendChild(styleTextNode);
1657
+ defs.appendChild(style);
1658
+ }
1659
+
1660
+ */
1661
+
1662
+ var svgText = serializer.serializeToString(svg);
1663
+ svgText = svgText.replace(/\&amp;(\#[0-9]{2,}\;)/g, '&$1');
1664
+ return svgCSS + svgText;
1665
+ }
1666
+
1667
+ /**
1668
+ * Shallow object clone and merge
1669
+ *
1670
+ * @param a Object A
1671
+ * @param b Object B
1672
+ * @returns {Object} New object with all of A's properties, and all of B's properties, overwriting A's properties
1673
+ */
1674
+ function extend(a, b) {
1675
+ var c = {};
1676
+ for (var x in a) {
1677
+ if (a.hasOwnProperty(x)) {
1678
+ c[x] = a[x];
1679
+ }
1680
+ }
1681
+ if (b != null) {
1682
+ for (var y in b) {
1683
+ if (b.hasOwnProperty(y)) {
1684
+ c[y] = b[y];
1685
+ }
1686
+ }
1687
+ }
1688
+ return c;
1689
+ }
1690
+
1691
+ /**
1692
+ * Takes a k/v list of CSS properties and returns a rule
1693
+ *
1694
+ * @param props CSS properties object
1695
+ */
1696
+ function cssProps(props) {
1697
+ var ret = [];
1698
+ for (var p in props) {
1699
+ if (props.hasOwnProperty(p)) {
1700
+ ret.push(p + ':' + props[p]);
1701
+ }
1702
+ }
1703
+ return ret.join(';');
1704
+ }
1705
+
1706
+ /**
1707
+ * Prevents a function from being called too often, waits until a timer elapses to call it again
1708
+ *
1709
+ * @param fn Function to call
1710
+ */
1711
+ function debounce(fn) {
1712
+ if (!App.vars.debounceTimer) fn.call(this);
1713
+ if (App.vars.debounceTimer) global.clearTimeout(App.vars.debounceTimer);
1714
+ App.vars.debounceTimer = global.setTimeout(function() {
1715
+ App.vars.debounceTimer = null;
1716
+ fn.call(this);
1717
+ }, App.setup.debounce);
1718
+ }
1719
+
1720
+ /**
1721
+ * Holder-specific resize/orientation change callback, debounced to prevent excessive execution
1722
+ */
1723
+ function resizeEvent() {
1724
+ debounce(function() {
1725
+ updateResizableElements(null);
1726
+ });
1727
+ }
1728
+
1729
+ /**
1730
+ * Converts a value into an array of DOM nodes
1731
+ *
1732
+ * @param val A string, a NodeList, a Node, or an HTMLCollection
1733
+ */
1734
+ function getNodeArray(val) {
1735
+ var retval = null;
1736
+ if (typeof(val) == 'string') {
1737
+ retval = document.querySelectorAll(val);
1738
+ } else if (global.NodeList && val instanceof global.NodeList) {
1739
+ retval = val;
1740
+ } else if (global.Node && val instanceof global.Node) {
1741
+ retval = [val];
1742
+ } else if (global.HTMLCollection && val instanceof global.HTMLCollection) {
1743
+ retval = val;
1744
+ } else if (val instanceof Array) {
1745
+ retval = val;
1746
+ } else if (val === null) {
1747
+ retval = [];
1748
+ }
1749
+ return retval;
1750
+ }
1751
+
1752
+ /**
1753
+ * Checks if an image exists
1754
+ *
1755
+ * @param src URL of image
1756
+ * @param callback Callback to call once image status has been found
1757
+ */
1758
+ function imageExists(src, callback) {
1759
+ var image = new Image();
1760
+ image.onerror = function() {
1761
+ callback.call(this, false);
1762
+ };
1763
+ image.onload = function() {
1764
+ callback.call(this, true);
1765
+ };
1766
+ image.src = src;
1767
+ }
1768
+
1769
+ /**
1770
+ * Encodes HTML entities in a string
1771
+ *
1772
+ * @param str Input string
1773
+ */
1774
+ function encodeHtmlEntity(str) {
1775
+ var buf = [];
1776
+ var charCode = 0;
1777
+ for (var i = str.length - 1; i >= 0; i--) {
1778
+ charCode = str.charCodeAt(i);
1779
+ if (charCode > 128) {
1780
+ buf.unshift(['&#', charCode, ';'].join(''));
1781
+ } else {
1782
+ buf.unshift(str[i]);
1783
+ }
1784
+ }
1785
+ return buf.join('');
1786
+ }
1787
+
1788
+ /**
1789
+ * Decodes HTML entities in a stirng
1790
+ *
1791
+ * @param str Input string
1792
+ */
1793
+ function decodeHtmlEntity(str) {
1794
+ return str.replace(/&#(\d+);/g, function(match, dec) {
1795
+ return String.fromCharCode(dec);
1796
+ });
1797
+ }
1798
+
1799
+ // Scene graph
1800
+
1801
+ var SceneGraph = function(sceneProperties) {
1802
+ var nodeCount = 1;
1803
+
1804
+ //todo: move merge to helpers section
1805
+ function merge(parent, child) {
1806
+ for (var prop in child) {
1807
+ parent[prop] = child[prop];
1808
+ }
1809
+ return parent;
1810
+ }
1811
+
1812
+ var SceneNode = augment.defclass({
1813
+ constructor: function(name) {
1814
+ nodeCount++;
1815
+ this.parent = null;
1816
+ this.children = {};
1817
+ this.id = nodeCount;
1818
+ this.name = 'n' + nodeCount;
1819
+ if (name != null) {
1820
+ this.name = name;
1821
+ }
1822
+ this.x = 0;
1823
+ this.y = 0;
1824
+ this.z = 0;
1825
+ this.width = 0;
1826
+ this.height = 0;
1827
+ },
1828
+ resize: function(width, height) {
1829
+ if (width != null) {
1830
+ this.width = width;
1831
+ }
1832
+ if (height != null) {
1833
+ this.height = height;
1834
+ }
1835
+ },
1836
+ moveTo: function(x, y, z) {
1837
+ this.x = x != null ? x : this.x;
1838
+ this.y = y != null ? y : this.y;
1839
+ this.z = z != null ? z : this.z;
1840
+ },
1841
+ add: function(child) {
1842
+ var name = child.name;
1843
+ if (this.children[name] == null) {
1844
+ this.children[name] = child;
1845
+ child.parent = this;
1846
+ } else {
1847
+ throw 'SceneGraph: child with that name already exists: ' + name;
1848
+ }
1849
+ }
1850
+ /*, // probably unnecessary in Holder
1851
+ remove: function(name){
1852
+ if(this.children[name] == null){
1853
+ throw 'SceneGraph: child with that name doesn\'t exist: '+name;
1854
+ }
1855
+ else{
1856
+ child.parent = null;
1857
+ delete this.children[name];
1858
+ }
1859
+ },
1860
+ removeAll: function(){
1861
+ for(var child in this.children){
1862
+ this.remove(child);
1863
+ }
1864
+ }*/
1865
+ });
1866
+
1867
+ var RootNode = augment(SceneNode, function(uber) {
1868
+ this.constructor = function() {
1869
+ uber.constructor.call(this, 'root');
1870
+ this.properties = sceneProperties;
1871
+ };
1872
+ });
1873
+
1874
+ var Shape = augment(SceneNode, function(uber) {
1875
+ function constructor(name, props) {
1876
+ uber.constructor.call(this, name);
1877
+ this.properties = {
1878
+ fill: '#000'
1879
+ };
1880
+ if (props != null) {
1881
+ merge(this.properties, props);
1882
+ } else if (name != null && typeof name !== 'string') {
1883
+ throw 'SceneGraph: invalid node name';
1884
+ }
1885
+ }
1886
+
1887
+ this.Group = augment.extend(this, {
1888
+ constructor: constructor,
1889
+ type: 'group'
1890
+ });
1891
+
1892
+ this.Rect = augment.extend(this, {
1893
+ constructor: constructor,
1894
+ type: 'rect'
1895
+ });
1896
+
1897
+ this.Text = augment.extend(this, {
1898
+ constructor: function(text) {
1899
+ constructor.call(this);
1900
+ this.properties.text = text;
1901
+ },
1902
+ type: 'text'
1903
+ });
1904
+ });
1905
+
1906
+ var root = new RootNode();
1907
+
1908
+ this.Shape = Shape;
1909
+ this.root = root;
1910
+
1911
+ return this;
1912
+ };
1913
+
1914
+ //Set up flags
1915
+
1916
+ for (var flag in App.flags) {
1917
+ if (!App.flags.hasOwnProperty(flag)) continue;
1918
+ App.flags[flag].match = function(val) {
1919
+ return val.match(this.regex);
1920
+ };
1921
+ }
1922
+
1923
+ //Properties set once on setup
1924
+
1925
+ App.setup = {
1926
+ renderer: 'html',
1927
+ debounce: 100,
1928
+ ratio: 1,
1929
+ supportsCanvas: false,
1930
+ supportsSVG: false,
1931
+ lineWrapRatio: 0.9,
1932
+ renderers: ['html', 'canvas', 'svg']
1933
+ };
1934
+
1935
+ App.dpr = function(val) {
1936
+ return val * App.setup.ratio;
1937
+ };
1938
+
1939
+ //Properties modified during runtime
1940
+
1941
+ App.vars = {
1942
+ preempted: false,
1943
+ resizableImages: [],
1944
+ invisibleImages: {},
1945
+ invisibleId: 0,
1946
+ visibilityCheckStarted: false,
1947
+ debounceTimer: null,
1948
+ cache: {}
1949
+ };
1950
+
1951
+ //Pre-flight
1952
+
1953
+ (function() {
1954
+ var devicePixelRatio = 1,
1955
+ backingStoreRatio = 1;
1956
+
1957
+ var canvas = newEl('canvas');
1958
+ var ctx = null;
1959
+
1960
+ if (canvas.getContext) {
1961
+ if (canvas.toDataURL('image/png').indexOf('data:image/png') != -1) {
1962
+ App.setup.renderer = 'canvas';
1963
+ ctx = canvas.getContext('2d');
1964
+ App.setup.supportsCanvas = true;
1965
+ }
1966
+ }
1967
+
1968
+ if (App.setup.supportsCanvas) {
1969
+ devicePixelRatio = global.devicePixelRatio || 1;
1970
+ backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
1971
+ }
1972
+
1973
+ App.setup.ratio = devicePixelRatio / backingStoreRatio;
1974
+
1975
+ if (!!document.createElementNS && !!document.createElementNS(SVG_NS, 'svg').createSVGRect) {
1976
+ App.setup.renderer = 'svg';
1977
+ App.setup.supportsSVG = true;
1978
+ }
1979
+ })();
1980
+
1981
+ //Starts checking for invisible placeholders
1982
+ startVisibilityCheck();
1983
+
1984
+ //Exposing to environment and setting up listeners
1985
+ register(Holder, 'Holder', global);
1986
+
1987
+ if (global.onDomReady) {
1988
+ global.onDomReady(function() {
1989
+ if (!App.vars.preempted) {
1990
+ Holder.run();
1991
+ }
1992
+ if (global.addEventListener) {
1993
+ global.addEventListener('resize', resizeEvent, false);
1994
+ global.addEventListener('orientationchange', resizeEvent, false);
1995
+ } else {
1996
+ global.attachEvent('onresize', resizeEvent);
1997
+ }
1998
+
1999
+ if (typeof global.Turbolinks == 'object') {
2000
+ global.document.addEventListener('page:change', function() {
2001
+ Holder.run();
2002
+ });
2003
+ }
2004
+ });
2005
+ }
2006
+
2007
+ })(function(fn, name, global) {
2008
+ var isAMD = (typeof define === 'function' && define.amd);
2009
+ var isNode = (typeof exports === 'object');
2010
+ var isWeb = !isNode;
2011
+
2012
+ if (isAMD) {
2013
+ define(fn);
2014
+ } else {
2015
+ //todo: npm/browserify registration
2016
+ global[name] = fn;
2017
+ }
2018
+ }, this);