info@54
|
1 |
/*
|
info@54
|
2 |
|
info@54
|
3 |
Holder - 2.2 - client side image placeholders
|
info@54
|
4 |
(c) 2012-2013 Ivan Malopinsky / http://imsky.co
|
info@54
|
5 |
|
info@54
|
6 |
Provided under the MIT License.
|
info@54
|
7 |
Commercial use requires attribution.
|
info@54
|
8 |
|
info@54
|
9 |
*/
|
info@54
|
10 |
|
info@54
|
11 |
var Holder = Holder || {};
|
info@54
|
12 |
(function (app, win) {
|
info@54
|
13 |
|
info@54
|
14 |
var preempted = false,
|
info@54
|
15 |
fallback = false,
|
info@54
|
16 |
canvas = document.createElement('canvas');
|
info@54
|
17 |
var dpr = 1, bsr = 1;
|
info@54
|
18 |
var resizable_images = [];
|
info@54
|
19 |
|
info@54
|
20 |
if (!canvas.getContext) {
|
info@54
|
21 |
fallback = true;
|
info@54
|
22 |
} else {
|
info@54
|
23 |
if (canvas.toDataURL("image/png")
|
info@54
|
24 |
.indexOf("data:image/png") < 0) {
|
info@54
|
25 |
//Android doesn't support data URI
|
info@54
|
26 |
fallback = true;
|
info@54
|
27 |
} else {
|
info@54
|
28 |
var ctx = canvas.getContext("2d");
|
info@54
|
29 |
}
|
info@54
|
30 |
}
|
info@54
|
31 |
|
info@54
|
32 |
if(!fallback){
|
info@54
|
33 |
dpr = window.devicePixelRatio || 1,
|
info@54
|
34 |
bsr = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
|
info@54
|
35 |
}
|
info@54
|
36 |
|
info@54
|
37 |
var ratio = dpr / bsr;
|
info@54
|
38 |
|
info@54
|
39 |
var settings = {
|
info@54
|
40 |
domain: "holder.js",
|
info@54
|
41 |
images: "img",
|
info@54
|
42 |
bgnodes: ".holderjs",
|
info@54
|
43 |
themes: {
|
info@54
|
44 |
"gray": {
|
info@54
|
45 |
background: "#eee",
|
info@54
|
46 |
foreground: "#aaa",
|
info@54
|
47 |
size: 12
|
info@54
|
48 |
},
|
info@54
|
49 |
"social": {
|
info@54
|
50 |
background: "#3a5a97",
|
info@54
|
51 |
foreground: "#fff",
|
info@54
|
52 |
size: 12
|
info@54
|
53 |
},
|
info@54
|
54 |
"industrial": {
|
info@54
|
55 |
background: "#434A52",
|
info@54
|
56 |
foreground: "#C2F200",
|
info@54
|
57 |
size: 12
|
info@54
|
58 |
},
|
info@54
|
59 |
"sky": {
|
info@54
|
60 |
background: "#0D8FDB",
|
info@54
|
61 |
foreground: "#fff",
|
info@54
|
62 |
size: 12
|
info@54
|
63 |
},
|
info@54
|
64 |
"vine": {
|
info@54
|
65 |
background: "#39DBAC",
|
info@54
|
66 |
foreground: "#1E292C",
|
info@54
|
67 |
size: 12
|
info@54
|
68 |
},
|
info@54
|
69 |
"lava": {
|
info@54
|
70 |
background: "#F8591A",
|
info@54
|
71 |
foreground: "#1C2846",
|
info@54
|
72 |
size: 12
|
info@54
|
73 |
}
|
info@54
|
74 |
},
|
info@54
|
75 |
stylesheet: ""
|
info@54
|
76 |
};
|
info@54
|
77 |
app.flags = {
|
info@54
|
78 |
dimensions: {
|
info@54
|
79 |
regex: /^(\d+)x(\d+)$/,
|
info@54
|
80 |
output: function (val) {
|
info@54
|
81 |
var exec = this.regex.exec(val);
|
info@54
|
82 |
return {
|
info@54
|
83 |
width: +exec[1],
|
info@54
|
84 |
height: +exec[2]
|
info@54
|
85 |
}
|
info@54
|
86 |
}
|
info@54
|
87 |
},
|
info@54
|
88 |
fluid: {
|
info@54
|
89 |
regex: /^([0-9%]+)x([0-9%]+)$/,
|
info@54
|
90 |
output: function (val) {
|
info@54
|
91 |
var exec = this.regex.exec(val);
|
info@54
|
92 |
return {
|
info@54
|
93 |
width: exec[1],
|
info@54
|
94 |
height: exec[2]
|
info@54
|
95 |
}
|
info@54
|
96 |
}
|
info@54
|
97 |
},
|
info@54
|
98 |
colors: {
|
info@54
|
99 |
regex: /#([0-9a-f]{3,})\:#([0-9a-f]{3,})/i,
|
info@54
|
100 |
output: function (val) {
|
info@54
|
101 |
var exec = this.regex.exec(val);
|
info@54
|
102 |
return {
|
info@54
|
103 |
size: settings.themes.gray.size,
|
info@54
|
104 |
foreground: "#" + exec[2],
|
info@54
|
105 |
background: "#" + exec[1]
|
info@54
|
106 |
}
|
info@54
|
107 |
}
|
info@54
|
108 |
},
|
info@54
|
109 |
text: {
|
info@54
|
110 |
regex: /text\:(.*)/,
|
info@54
|
111 |
output: function (val) {
|
info@54
|
112 |
return this.regex.exec(val)[1];
|
info@54
|
113 |
}
|
info@54
|
114 |
},
|
info@54
|
115 |
font: {
|
info@54
|
116 |
regex: /font\:(.*)/,
|
info@54
|
117 |
output: function (val) {
|
info@54
|
118 |
return this.regex.exec(val)[1];
|
info@54
|
119 |
}
|
info@54
|
120 |
},
|
info@54
|
121 |
auto: {
|
info@54
|
122 |
regex: /^auto$/
|
info@54
|
123 |
},
|
info@54
|
124 |
textmode: {
|
info@54
|
125 |
regex: /textmode\:(.*)/,
|
info@54
|
126 |
output: function(val){
|
info@54
|
127 |
return this.regex.exec(val)[1];
|
info@54
|
128 |
}
|
info@54
|
129 |
}
|
info@54
|
130 |
}
|
info@54
|
131 |
|
info@54
|
132 |
//getElementsByClassName polyfill
|
info@54
|
133 |
document.getElementsByClassName||(document.getElementsByClassName=function(e){var t=document,n,r,i,s=[];if(t.querySelectorAll)return t.querySelectorAll("."+e);if(t.evaluate){r=".//*[contains(concat(' ', @class, ' '), ' "+e+" ')]",n=t.evaluate(r,t,null,0,null);while(i=n.iterateNext())s.push(i)}else{n=t.getElementsByTagName("*"),r=new RegExp("(^|\\s)"+e+"(\\s|$)");for(i=0;i<n.length;i++)r.test(n[i].className)&&s.push(n[i])}return s})
|
info@54
|
134 |
|
info@54
|
135 |
//getComputedStyle polyfill
|
info@54
|
136 |
window.getComputedStyle||(window.getComputedStyle=function(e){return this.el=e,this.getPropertyValue=function(t){var n=/(\-([a-z]){1})/g;return t=="float"&&(t="styleFloat"),n.test(t)&&(t=t.replace(n,function(){return arguments[2].toUpperCase()})),e.currentStyle[t]?e.currentStyle[t]:null},this})
|
info@54
|
137 |
|
info@54
|
138 |
//http://javascript.nwbox.com/ContentLoaded by Diego Perini with modifications
|
info@54
|
139 |
function contentLoaded(n,t){var l="complete",s="readystatechange",u=!1,h=u,c=!0,i=n.document,a=i.documentElement,e=i.addEventListener?"addEventListener":"attachEvent",v=i.addEventListener?"removeEventListener":"detachEvent",f=i.addEventListener?"":"on",r=function(e){(e.type!=s||i.readyState==l)&&((e.type=="load"?n:i)[v](f+e.type,r,u),!h&&(h=!0)&&t.call(n,null))},o=function(){try{a.doScroll("left")}catch(n){setTimeout(o,50);return}r("poll")};if(i.readyState==l)t.call(n,"lazy");else{if(i.createEventObject&&a.doScroll){try{c=!n.frameElement}catch(y){}c&&o()}i[e](f+"DOMContentLoaded",r,u),i[e](f+s,r,u),n[e](f+"load",r,u)}}
|
info@54
|
140 |
|
info@54
|
141 |
//https://gist.github.com/991057 by Jed Schmidt with modifications
|
info@54
|
142 |
function selector(a){
|
info@54
|
143 |
a=a.match(/^(\W)?(.*)/);var b=document["getElement"+(a[1]?a[1]=="#"?"ById":"sByClassName":"sByTagName")](a[2]);
|
info@54
|
144 |
var ret=[]; b!==null&&(b.length?ret=b:b.length===0?ret=b:ret=[b]); return ret;
|
info@54
|
145 |
}
|
info@54
|
146 |
|
info@54
|
147 |
//shallow object property extend
|
info@54
|
148 |
function extend(a,b){
|
info@54
|
149 |
var c={};
|
info@54
|
150 |
for(var i in a){
|
info@54
|
151 |
if(a.hasOwnProperty(i)){
|
info@54
|
152 |
c[i]=a[i];
|
info@54
|
153 |
}
|
info@54
|
154 |
}
|
info@54
|
155 |
for(var i in b){
|
info@54
|
156 |
if(b.hasOwnProperty(i)){
|
info@54
|
157 |
c[i]=b[i];
|
info@54
|
158 |
}
|
info@54
|
159 |
}
|
info@54
|
160 |
return c
|
info@54
|
161 |
}
|
info@54
|
162 |
|
info@54
|
163 |
//hasOwnProperty polyfill
|
info@54
|
164 |
if (!Object.prototype.hasOwnProperty)
|
info@54
|
165 |
/*jshint -W001, -W103 */
|
info@54
|
166 |
Object.prototype.hasOwnProperty = function(prop) {
|
info@54
|
167 |
var proto = this.__proto__ || this.constructor.prototype;
|
info@54
|
168 |
return (prop in this) && (!(prop in proto) || proto[prop] !== this[prop]);
|
info@54
|
169 |
}
|
info@54
|
170 |
/*jshint +W001, +W103 */
|
info@54
|
171 |
|
info@54
|
172 |
function text_size(width, height, template) {
|
info@54
|
173 |
height = parseInt(height, 10);
|
info@54
|
174 |
width = parseInt(width, 10);
|
info@54
|
175 |
var bigSide = Math.max(height, width)
|
info@54
|
176 |
var smallSide = Math.min(height, width)
|
info@54
|
177 |
var scale = 1 / 12;
|
info@54
|
178 |
var newHeight = Math.min(smallSide * 0.75, 0.75 * bigSide * scale);
|
info@54
|
179 |
return {
|
info@54
|
180 |
height: Math.round(Math.max(template.size, newHeight))
|
info@54
|
181 |
}
|
info@54
|
182 |
}
|
info@54
|
183 |
|
info@54
|
184 |
function draw(args) {
|
info@54
|
185 |
var ctx = args.ctx;
|
info@54
|
186 |
var dimensions = args.dimensions;
|
info@54
|
187 |
var template = args.template;
|
info@54
|
188 |
var ratio = args.ratio;
|
info@54
|
189 |
var holder = args.holder;
|
info@54
|
190 |
var literal = holder.textmode == "literal";
|
info@54
|
191 |
var exact = holder.textmode == "exact";
|
info@54
|
192 |
|
info@54
|
193 |
var ts = text_size(dimensions.width, dimensions.height, template);
|
info@54
|
194 |
var text_height = ts.height;
|
info@54
|
195 |
var width = dimensions.width * ratio,
|
info@54
|
196 |
height = dimensions.height * ratio;
|
info@54
|
197 |
var font = template.font ? template.font : "sans-serif";
|
info@54
|
198 |
canvas.width = width;
|
info@54
|
199 |
canvas.height = height;
|
info@54
|
200 |
ctx.textAlign = "center";
|
info@54
|
201 |
ctx.textBaseline = "middle";
|
info@54
|
202 |
ctx.fillStyle = template.background;
|
info@54
|
203 |
ctx.fillRect(0, 0, width, height);
|
info@54
|
204 |
ctx.fillStyle = template.foreground;
|
info@54
|
205 |
ctx.font = "bold " + text_height + "px " + font;
|
info@54
|
206 |
var text = template.text ? template.text : (Math.floor(dimensions.width) + "x" + Math.floor(dimensions.height));
|
info@54
|
207 |
if (literal) {
|
info@54
|
208 |
var dimensions = holder.dimensions;
|
info@54
|
209 |
text = dimensions.width + "x" + dimensions.height;
|
info@54
|
210 |
}
|
info@54
|
211 |
else if(exact && holder.exact_dimensions){
|
info@54
|
212 |
var dimensions = holder.exact_dimensions;
|
info@54
|
213 |
text = (Math.floor(dimensions.width) + "x" + Math.floor(dimensions.height));
|
info@54
|
214 |
}
|
info@54
|
215 |
var text_width = ctx.measureText(text).width;
|
info@54
|
216 |
if (text_width / width >= 0.75) {
|
info@54
|
217 |
text_height = Math.floor(text_height * 0.75 * (width / text_width));
|
info@54
|
218 |
}
|
info@54
|
219 |
//Resetting font size if necessary
|
info@54
|
220 |
ctx.font = "bold " + (text_height * ratio) + "px " + font;
|
info@54
|
221 |
ctx.fillText(text, (width / 2), (height / 2), width);
|
info@54
|
222 |
return canvas.toDataURL("image/png");
|
info@54
|
223 |
}
|
info@54
|
224 |
|
info@54
|
225 |
function render(mode, el, holder, src) {
|
info@54
|
226 |
|
info@54
|
227 |
var dimensions = holder.dimensions,
|
info@54
|
228 |
theme = holder.theme,
|
info@54
|
229 |
text = holder.text ? decodeURIComponent(holder.text) : holder.text;
|
info@54
|
230 |
var dimensions_caption = dimensions.width + "x" + dimensions.height;
|
info@54
|
231 |
theme = (text ? extend(theme, {
|
info@54
|
232 |
text: text
|
info@54
|
233 |
}) : theme);
|
info@54
|
234 |
theme = (holder.font ? extend(theme, {
|
info@54
|
235 |
font: holder.font
|
info@54
|
236 |
}) : theme);
|
info@54
|
237 |
el.setAttribute("data-src", src);
|
info@54
|
238 |
holder.theme = theme;
|
info@54
|
239 |
el.holder_data = holder;
|
info@54
|
240 |
|
info@54
|
241 |
if (mode == "image") {
|
info@54
|
242 |
el.setAttribute("alt", text ? text : theme.text ? theme.text + " [" + dimensions_caption + "]" : dimensions_caption);
|
info@54
|
243 |
if (fallback || !holder.auto) {
|
info@54
|
244 |
el.style.width = dimensions.width + "px";
|
info@54
|
245 |
el.style.height = dimensions.height + "px";
|
info@54
|
246 |
}
|
info@54
|
247 |
if (fallback) {
|
info@54
|
248 |
el.style.backgroundColor = theme.background;
|
info@54
|
249 |
} else {
|
info@54
|
250 |
el.setAttribute("src", draw({ctx: ctx, dimensions: dimensions, template: theme, ratio:ratio, holder: holder}));
|
info@54
|
251 |
|
info@54
|
252 |
if(holder.textmode && holder.textmode == "exact"){
|
info@54
|
253 |
resizable_images.push(el);
|
info@54
|
254 |
resizable_update(el);
|
info@54
|
255 |
}
|
info@54
|
256 |
|
info@54
|
257 |
}
|
info@54
|
258 |
} else if (mode == "background") {
|
info@54
|
259 |
if (!fallback) {
|
info@54
|
260 |
el.style.backgroundImage = "url(" + draw({ctx:ctx, dimensions: dimensions, template: theme, ratio: ratio, holder: holder}) + ")";
|
info@54
|
261 |
el.style.backgroundSize = dimensions.width + "px " + dimensions.height + "px";
|
info@54
|
262 |
}
|
info@54
|
263 |
} else if (mode == "fluid") {
|
info@54
|
264 |
el.setAttribute("alt", text ? text : theme.text ? theme.text + " [" + dimensions_caption + "]" : dimensions_caption);
|
info@54
|
265 |
if (dimensions.height.slice(-1) == "%") {
|
info@54
|
266 |
el.style.height = dimensions.height
|
info@54
|
267 |
} else {
|
info@54
|
268 |
el.style.height = dimensions.height + "px"
|
info@54
|
269 |
}
|
info@54
|
270 |
if (dimensions.width.slice(-1) == "%") {
|
info@54
|
271 |
el.style.width = dimensions.width
|
info@54
|
272 |
} else {
|
info@54
|
273 |
el.style.width = dimensions.width + "px"
|
info@54
|
274 |
}
|
info@54
|
275 |
if (el.style.display == "inline" || el.style.display === "" || el.style.display == "none") {
|
info@54
|
276 |
el.style.display = "block";
|
info@54
|
277 |
}
|
info@54
|
278 |
if (fallback) {
|
info@54
|
279 |
el.style.backgroundColor = theme.background;
|
info@54
|
280 |
} else {
|
info@54
|
281 |
resizable_images.push(el);
|
info@54
|
282 |
resizable_update(el);
|
info@54
|
283 |
}
|
info@54
|
284 |
}
|
info@54
|
285 |
}
|
info@54
|
286 |
|
info@54
|
287 |
function dimension_check(el, callback) {
|
info@54
|
288 |
var dimensions = {
|
info@54
|
289 |
height: el.clientHeight,
|
info@54
|
290 |
width: el.clientWidth
|
info@54
|
291 |
};
|
info@54
|
292 |
if (!dimensions.height && !dimensions.width) {
|
info@54
|
293 |
if (el.hasAttribute("data-holder-invisible")) {
|
info@54
|
294 |
throw new Error("Holder: placeholder is not visible");
|
info@54
|
295 |
} else {
|
info@54
|
296 |
el.setAttribute("data-holder-invisible", true)
|
info@54
|
297 |
setTimeout(function () {
|
info@54
|
298 |
callback.call(this, el)
|
info@54
|
299 |
}, 1)
|
info@54
|
300 |
return null;
|
info@54
|
301 |
}
|
info@54
|
302 |
} else {
|
info@54
|
303 |
el.removeAttribute("data-holder-invisible")
|
info@54
|
304 |
}
|
info@54
|
305 |
return dimensions;
|
info@54
|
306 |
}
|
info@54
|
307 |
|
info@54
|
308 |
function resizable_update(element) {
|
info@54
|
309 |
var images;
|
info@54
|
310 |
if (element.nodeType == null) {
|
info@54
|
311 |
images = resizable_images;
|
info@54
|
312 |
} else {
|
info@54
|
313 |
images = [element]
|
info@54
|
314 |
}
|
info@54
|
315 |
for (var i in images) {
|
info@54
|
316 |
if (!images.hasOwnProperty(i)) {
|
info@54
|
317 |
continue;
|
info@54
|
318 |
}
|
info@54
|
319 |
var el = images[i]
|
info@54
|
320 |
if (el.holder_data) {
|
info@54
|
321 |
var holder = el.holder_data;
|
info@54
|
322 |
var dimensions = dimension_check(el, resizable_update)
|
info@54
|
323 |
if(dimensions){
|
info@54
|
324 |
if(holder.fluid){
|
info@54
|
325 |
el.setAttribute("src", draw({
|
info@54
|
326 |
ctx: ctx,
|
info@54
|
327 |
dimensions: dimensions,
|
info@54
|
328 |
template: holder.theme,
|
info@54
|
329 |
ratio: ratio,
|
info@54
|
330 |
holder: holder
|
info@54
|
331 |
}))
|
info@54
|
332 |
}
|
info@54
|
333 |
if(holder.textmode && holder.textmode == "exact"){
|
info@54
|
334 |
holder.exact_dimensions = dimensions;
|
info@54
|
335 |
el.setAttribute("src", draw({
|
info@54
|
336 |
ctx: ctx,
|
info@54
|
337 |
dimensions: holder.dimensions,
|
info@54
|
338 |
template: holder.theme,
|
info@54
|
339 |
ratio: ratio,
|
info@54
|
340 |
holder: holder
|
info@54
|
341 |
}))
|
info@54
|
342 |
}
|
info@54
|
343 |
}
|
info@54
|
344 |
}
|
info@54
|
345 |
}
|
info@54
|
346 |
}
|
info@54
|
347 |
|
info@54
|
348 |
function parse_flags(flags, options) {
|
info@54
|
349 |
var ret = {
|
info@54
|
350 |
theme: extend(settings.themes.gray, {})
|
info@54
|
351 |
};
|
info@54
|
352 |
var render = false;
|
info@54
|
353 |
for (sl = flags.length, j = 0; j < sl; j++) {
|
info@54
|
354 |
var flag = flags[j];
|
info@54
|
355 |
if (app.flags.dimensions.match(flag)) {
|
info@54
|
356 |
render = true;
|
info@54
|
357 |
ret.dimensions = app.flags.dimensions.output(flag);
|
info@54
|
358 |
} else if (app.flags.fluid.match(flag)) {
|
info@54
|
359 |
render = true;
|
info@54
|
360 |
ret.dimensions = app.flags.fluid.output(flag);
|
info@54
|
361 |
ret.fluid = true;
|
info@54
|
362 |
} else if (app.flags.textmode.match(flag)) {
|
info@54
|
363 |
ret.textmode = app.flags.textmode.output(flag)
|
info@54
|
364 |
} else if (app.flags.colors.match(flag)) {
|
info@54
|
365 |
ret.theme = app.flags.colors.output(flag);
|
info@54
|
366 |
} else if (options.themes[flag]) {
|
info@54
|
367 |
//If a theme is specified, it will override custom colors
|
info@54
|
368 |
if(options.themes.hasOwnProperty(flag)){
|
info@54
|
369 |
ret.theme = extend(options.themes[flag], {});
|
info@54
|
370 |
}
|
info@54
|
371 |
} else if (app.flags.font.match(flag)) {
|
info@54
|
372 |
ret.font = app.flags.font.output(flag);
|
info@54
|
373 |
} else if (app.flags.auto.match(flag)) {
|
info@54
|
374 |
ret.auto = true;
|
info@54
|
375 |
} else if (app.flags.text.match(flag)) {
|
info@54
|
376 |
ret.text = app.flags.text.output(flag);
|
info@54
|
377 |
}
|
info@54
|
378 |
}
|
info@54
|
379 |
return render ? ret : false;
|
info@54
|
380 |
}
|
info@54
|
381 |
|
info@54
|
382 |
for (var flag in app.flags) {
|
info@54
|
383 |
if (!app.flags.hasOwnProperty(flag)) continue;
|
info@54
|
384 |
app.flags[flag].match = function (val) {
|
info@54
|
385 |
return val.match(this.regex)
|
info@54
|
386 |
}
|
info@54
|
387 |
}
|
info@54
|
388 |
app.add_theme = function (name, theme) {
|
info@54
|
389 |
name != null && theme != null && (settings.themes[name] = theme);
|
info@54
|
390 |
return app;
|
info@54
|
391 |
};
|
info@54
|
392 |
app.add_image = function (src, el) {
|
info@54
|
393 |
var node = selector(el);
|
info@54
|
394 |
if (node.length) {
|
info@54
|
395 |
for (var i = 0, l = node.length; i < l; i++) {
|
info@54
|
396 |
var img = document.createElement("img")
|
info@54
|
397 |
img.setAttribute("data-src", src);
|
info@54
|
398 |
node[i].appendChild(img);
|
info@54
|
399 |
}
|
info@54
|
400 |
}
|
info@54
|
401 |
return app;
|
info@54
|
402 |
};
|
info@54
|
403 |
app.run = function (o) {
|
info@54
|
404 |
preempted = true;
|
info@54
|
405 |
|
info@54
|
406 |
var options = extend(settings, o),
|
info@54
|
407 |
images = [],
|
info@54
|
408 |
imageNodes = [],
|
info@54
|
409 |
bgnodes = [];
|
info@54
|
410 |
if (typeof (options.images) == "string") {
|
info@54
|
411 |
imageNodes = selector(options.images);
|
info@54
|
412 |
} else if (window.NodeList && options.images instanceof window.NodeList) {
|
info@54
|
413 |
imageNodes = options.images;
|
info@54
|
414 |
} else if (window.Node && options.images instanceof window.Node) {
|
info@54
|
415 |
imageNodes = [options.images];
|
info@54
|
416 |
}
|
info@54
|
417 |
|
info@54
|
418 |
if (typeof (options.bgnodes) == "string") {
|
info@54
|
419 |
bgnodes = selector(options.bgnodes);
|
info@54
|
420 |
} else if (window.NodeList && options.elements instanceof window.NodeList) {
|
info@54
|
421 |
bgnodes = options.bgnodes;
|
info@54
|
422 |
} else if (window.Node && options.bgnodes instanceof window.Node) {
|
info@54
|
423 |
bgnodes = [options.bgnodes];
|
info@54
|
424 |
}
|
info@54
|
425 |
for (i = 0, l = imageNodes.length; i < l; i++) images.push(imageNodes[i]);
|
info@54
|
426 |
var holdercss = document.getElementById("holderjs-style");
|
info@54
|
427 |
if (!holdercss) {
|
info@54
|
428 |
holdercss = document.createElement("style");
|
info@54
|
429 |
holdercss.setAttribute("id", "holderjs-style");
|
info@54
|
430 |
holdercss.type = "text/css";
|
info@54
|
431 |
document.getElementsByTagName("head")[0].appendChild(holdercss);
|
info@54
|
432 |
}
|
info@54
|
433 |
if (!options.nocss) {
|
info@54
|
434 |
if (holdercss.styleSheet) {
|
info@54
|
435 |
holdercss.styleSheet.cssText += options.stylesheet;
|
info@54
|
436 |
} else {
|
info@54
|
437 |
holdercss.appendChild(document.createTextNode(options.stylesheet));
|
info@54
|
438 |
}
|
info@54
|
439 |
}
|
info@54
|
440 |
var cssregex = new RegExp(options.domain + "\/(.*?)\"?\\)");
|
info@54
|
441 |
for (var l = bgnodes.length, i = 0; i < l; i++) {
|
info@54
|
442 |
var src = window.getComputedStyle(bgnodes[i], null)
|
info@54
|
443 |
.getPropertyValue("background-image");
|
info@54
|
444 |
var flags = src.match(cssregex);
|
info@54
|
445 |
var bgsrc = bgnodes[i].getAttribute("data-background-src");
|
info@54
|
446 |
if (flags) {
|
info@54
|
447 |
var holder = parse_flags(flags[1].split("/"), options);
|
info@54
|
448 |
if (holder) {
|
info@54
|
449 |
render("background", bgnodes[i], holder, src);
|
info@54
|
450 |
}
|
info@54
|
451 |
} else if (bgsrc != null) {
|
info@54
|
452 |
var holder = parse_flags(bgsrc.substr(bgsrc.lastIndexOf(options.domain) + options.domain.length + 1)
|
info@54
|
453 |
.split("/"), options);
|
info@54
|
454 |
if (holder) {
|
info@54
|
455 |
render("background", bgnodes[i], holder, src);
|
info@54
|
456 |
}
|
info@54
|
457 |
}
|
info@54
|
458 |
}
|
info@54
|
459 |
for (l = images.length, i = 0; i < l; i++) {
|
info@54
|
460 |
var attr_data_src, attr_src;
|
info@54
|
461 |
attr_src = attr_data_src = src = null;
|
info@54
|
462 |
try {
|
info@54
|
463 |
attr_src = images[i].getAttribute("src");
|
info@54
|
464 |
attr_datasrc = images[i].getAttribute("data-src");
|
info@54
|
465 |
} catch (e) {}
|
info@54
|
466 |
if (attr_datasrc == null && !! attr_src && attr_src.indexOf(options.domain) >= 0) {
|
info@54
|
467 |
src = attr_src;
|
info@54
|
468 |
} else if ( !! attr_datasrc && attr_datasrc.indexOf(options.domain) >= 0) {
|
info@54
|
469 |
src = attr_datasrc;
|
info@54
|
470 |
}
|
info@54
|
471 |
if (src) {
|
info@54
|
472 |
var holder = parse_flags(src.substr(src.lastIndexOf(options.domain) + options.domain.length + 1)
|
info@54
|
473 |
.split("/"), options);
|
info@54
|
474 |
if (holder) {
|
info@54
|
475 |
if (holder.fluid) {
|
info@54
|
476 |
render("fluid", images[i], holder, src)
|
info@54
|
477 |
} else {
|
info@54
|
478 |
render("image", images[i], holder, src);
|
info@54
|
479 |
}
|
info@54
|
480 |
}
|
info@54
|
481 |
}
|
info@54
|
482 |
}
|
info@54
|
483 |
return app;
|
info@54
|
484 |
};
|
info@54
|
485 |
contentLoaded(win, function () {
|
info@54
|
486 |
if (window.addEventListener) {
|
info@54
|
487 |
window.addEventListener("resize", resizable_update, false);
|
info@54
|
488 |
window.addEventListener("orientationchange", resizable_update, false);
|
info@54
|
489 |
} else {
|
info@54
|
490 |
window.attachEvent("onresize", resizable_update)
|
info@54
|
491 |
}
|
info@54
|
492 |
preempted || app.run();
|
info@54
|
493 |
});
|
info@54
|
494 |
if (typeof define === "function" && define.amd) {
|
info@54
|
495 |
define([], function () {
|
info@54
|
496 |
return app;
|
info@54
|
497 |
});
|
info@54
|
498 |
}
|
info@54
|
499 |
|
info@54
|
500 |
})(Holder, window);
|