holder_rails 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/holder_rails/version.rb +1 -1
- data/vendor/assets/javascripts/holder.js +80 -42
- metadata +4 -4
data/lib/holder_rails/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
|
3
|
-
Holder - 1.
|
3
|
+
Holder - 1.4 - client side image placeholders
|
4
4
|
(c) 2012 Ivan Malopinsky / http://imsky.co
|
5
5
|
|
6
6
|
Provided under the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0
|
@@ -10,11 +10,17 @@ Commercial use requires attribution.
|
|
10
10
|
|
11
11
|
var Holder = Holder || {};
|
12
12
|
(function (app, win) {
|
13
|
-
|
13
|
+
|
14
14
|
var preempted = false,
|
15
15
|
fallback = false,
|
16
16
|
canvas = document.createElement('canvas');
|
17
17
|
|
18
|
+
//getElementsByClassName polyfill
|
19
|
+
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})
|
20
|
+
|
21
|
+
//getComputedStyle polyfill
|
22
|
+
window.getComputedStyle||(window.getComputedStyle=function(e,t){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})
|
23
|
+
|
18
24
|
//http://javascript.nwbox.com/ContentLoaded by Diego Perini with modifications
|
19
25
|
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)}};
|
20
26
|
|
@@ -60,9 +66,59 @@ if (!canvas.getContext) {
|
|
60
66
|
}
|
61
67
|
}
|
62
68
|
|
69
|
+
function render(mode, el, holder, src){
|
70
|
+
|
71
|
+
var dimensions = holder.dimensions, theme = holder.theme, text = holder.text;
|
72
|
+
var dimensions_caption = dimensions.width + "x" + dimensions.height;
|
73
|
+
theme = (text ? extend(theme, { text: text }) : theme);
|
74
|
+
|
75
|
+
if(mode == "image"){
|
76
|
+
el.setAttribute("data-src", src);
|
77
|
+
el.setAttribute("alt", text ? text : theme.text ? theme.text + " [" + dimensions_caption + "]" : dimensions_caption);
|
78
|
+
el.style.width = dimensions.width + "px";
|
79
|
+
el.style.height = dimensions.height + "px";
|
80
|
+
el.style.backgroundColor = theme.background;
|
81
|
+
|
82
|
+
if(!fallback){
|
83
|
+
el.setAttribute("src", draw(ctx, dimensions, theme));
|
84
|
+
}
|
85
|
+
}
|
86
|
+
else {
|
87
|
+
if(!fallback){
|
88
|
+
el.style.backgroundImage = "url("+draw(ctx, dimensions, theme)+")";
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
};
|
93
|
+
|
94
|
+
function parse_flags(flags, options){
|
95
|
+
|
96
|
+
var ret = {
|
97
|
+
theme: settings.themes.gray
|
98
|
+
}, render = false;
|
99
|
+
|
100
|
+
for (sl = flags.length, j = 0; j < sl; j++) {
|
101
|
+
if (app.flags.dimensions.match(flags[j])) {
|
102
|
+
render = true;
|
103
|
+
ret.dimensions = app.flags.dimensions.output(flags[j]);
|
104
|
+
} else if (app.flags.colors.match(flags[j])) {
|
105
|
+
ret.theme = app.flags.colors.output(flags[j]);
|
106
|
+
} else if (options.themes[flags[j]]) {
|
107
|
+
//If a theme is specified, it will override custom colors
|
108
|
+
ret.theme = options.themes[flags[j]];
|
109
|
+
} else if (app.flags.text.match(flags[j])) {
|
110
|
+
ret.text = app.flags.text.output(flags[j]);
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
return render ? ret : false;
|
115
|
+
|
116
|
+
};
|
117
|
+
|
63
118
|
var settings = {
|
64
119
|
domain: "holder.js",
|
65
120
|
images: "img",
|
121
|
+
elements: ".holderjs",
|
66
122
|
themes: {
|
67
123
|
"gray": {
|
68
124
|
background: "#eee",
|
@@ -83,7 +139,6 @@ var settings = {
|
|
83
139
|
};
|
84
140
|
|
85
141
|
|
86
|
-
|
87
142
|
app.flags = {
|
88
143
|
dimensions: {
|
89
144
|
regex: /([0-9]+)x([0-9]+)/,
|
@@ -140,53 +195,36 @@ app.add_image = function (src, el) {
|
|
140
195
|
app.run = function (o) {
|
141
196
|
var options = extend(settings, o),
|
142
197
|
images = selector(options.images),
|
198
|
+
elements = selector(options.elements),
|
143
199
|
preempted = true;
|
144
|
-
|
200
|
+
|
201
|
+
var cssregex = new RegExp(options.domain+"\/(.*?)\"?\\)");
|
202
|
+
|
203
|
+
for(var l = elements.length, i = 0; i < l; i++){
|
204
|
+
var src = window.getComputedStyle(elements[i],null).getPropertyValue("background-image");
|
205
|
+
var flags = src.match(cssregex);
|
206
|
+
if(flags){
|
207
|
+
var holder = parse_flags(flags[1].split("/"), options);
|
208
|
+
if(holder){
|
209
|
+
render("background", elements[i], holder, src);
|
210
|
+
}
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
145
214
|
for (var l = images.length, i = 0; i < l; i++) {
|
146
|
-
var theme = settings.themes.gray;
|
147
215
|
var src = images[i].getAttribute("data-src") || images[i].getAttribute("src");
|
148
|
-
if (
|
149
|
-
var
|
150
|
-
|
151
|
-
|
152
|
-
var flags = src.substr(src.indexOf(options.domain) + options.domain.length + 1).split("/");
|
153
|
-
for (sl = flags.length, j = 0; j < sl; j++) {
|
154
|
-
if (app.flags.dimensions.match(flags[j])) {
|
155
|
-
render = true;
|
156
|
-
dimensions = app.flags.dimensions.output(flags[j]);
|
157
|
-
} else if (app.flags.colors.match(flags[j])) {
|
158
|
-
theme = app.flags.colors.output(flags[j]);
|
159
|
-
} else if (options.themes[flags[j]]) {
|
160
|
-
//If a theme is specified, it will override custom colors
|
161
|
-
theme = options.themes[flags[j]];
|
162
|
-
} else if (app.flags.text.match(flags[j])) {
|
163
|
-
text = app.flags.text.output(flags[j]);
|
164
|
-
}
|
165
|
-
}
|
166
|
-
if (render) {
|
167
|
-
images[i].setAttribute("data-src", src);
|
168
|
-
var dimensions_caption = dimensions.width + "x" + dimensions.height;
|
169
|
-
images[i].setAttribute("alt", text ? text : theme.text ? theme.text + " [" + dimensions_caption + "]" : dimensions_caption);
|
170
|
-
|
171
|
-
//Fallback
|
172
|
-
images[i].style.width = dimensions.width + "px";
|
173
|
-
images[i].style.height = dimensions.height + "px";
|
174
|
-
images[i].style.backgroundColor = theme.background;
|
175
|
-
|
176
|
-
var theme = (text ? extend(theme, {
|
177
|
-
text: text
|
178
|
-
}) : theme);
|
179
|
-
|
180
|
-
if (!fallback) {
|
181
|
-
images[i].setAttribute("src", draw(ctx, dimensions, theme));
|
182
|
-
}
|
216
|
+
if (src.indexOf(options.domain)>=0) {
|
217
|
+
var holder = parse_flags(src.substr(src.lastIndexOf(options.domain) + options.domain.length + 1).split("/"), options);
|
218
|
+
if (holder) {
|
219
|
+
render("image", images[i], holder, src);
|
183
220
|
}
|
184
221
|
}
|
185
222
|
}
|
186
223
|
return app;
|
187
224
|
};
|
225
|
+
|
188
226
|
contentLoaded(win, function () {
|
189
227
|
preempted || app.run()
|
190
|
-
})
|
228
|
+
});
|
191
229
|
|
192
|
-
})(Holder, window);
|
230
|
+
})(Holder, window);
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: holder_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
@@ -59,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
59
|
version: '0'
|
60
60
|
segments:
|
61
61
|
- 0
|
62
|
-
hash:
|
62
|
+
hash: 4343872938476998461
|
63
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
65
65
|
requirements:
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
version: '0'
|
69
69
|
segments:
|
70
70
|
- 0
|
71
|
-
hash:
|
71
|
+
hash: 4343872938476998461
|
72
72
|
requirements: []
|
73
73
|
rubyforge_project:
|
74
74
|
rubygems_version: 1.8.24
|