holder_rails 2.0.0 → 2.1.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: a425bea370d6790d57fbfd7d79837aefa07f2ab0
4
- data.tar.gz: 0fd3ac07570b769d8135361be40c6e98e33d3c82
3
+ metadata.gz: 6d02d01436ba84ee6c50bc35b0644f606abc33ed
4
+ data.tar.gz: f6554f74633cff281227b93bfb21a47c8659b204
5
5
  SHA512:
6
- metadata.gz: 43a1b0c6540b84c901db902a5719439fd8fa42d648728b1a7d0d3527b4d2411e3acb9307b09f2e7f4bb2522b96e0cbb93f1832e377078788ee4fe40a9facf93e
7
- data.tar.gz: d4a4dfdd4fab142073d7cacd18e79afa81e74e4c9d5cd0b7a28972f89b46e442a20d40e5841349b7ad07e9effe7e0950449e0ba216beb1994621b711bdf52fcf
6
+ metadata.gz: 50202367d53117e067c6903ced20cd1b7770c8716b58e4cd6a9212a4d6eb3f36fc82f2c3393047853fe800e1de4465eb3023aadb18ae6243f143ae909fc14bed
7
+ data.tar.gz: bb32c417f69957e418875f2a54d02ab77b87eae23156e5bd5afab17c7e7aa3347fc8c87786016625982956aabbc4691185dfe2e7ea80ad138ae266e074ffb44c
data/README.md CHANGED
@@ -27,6 +27,14 @@ Add to your JavaScript manifest file:
27
27
  //= require holder
28
28
  ```
29
29
 
30
+ And if you're using [turbolinks](https://github.com/rails/turbolinks)
31
+ don't forget to run `Holder` after `page:change` event:
32
+
33
+ ```coffee
34
+ $(document).bind 'page:change', ->
35
+ Holder.run()
36
+ ```
37
+
30
38
  You can use `holder_tag` helper in your views:
31
39
 
32
40
  ```ruby
@@ -1,3 +1,3 @@
1
1
  module HolderRails
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -1,9 +1,9 @@
1
1
  /*
2
2
 
3
- Holder - 2.0 - client side image placeholders
3
+ Holder - 2.1 - client side image placeholders
4
4
  (c) 2012-2013 Ivan Malopinsky / http://imsky.co
5
5
 
6
- Provided under the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0
6
+ Provided under the MIT License.
7
7
  Commercial use requires attribution.
8
8
 
9
9
  */
@@ -15,19 +15,40 @@ var preempted = false,
15
15
  fallback = false,
16
16
  canvas = document.createElement('canvas');
17
17
 
18
+ if (!canvas.getContext) {
19
+ fallback = true;
20
+ } else {
21
+ if (canvas.toDataURL("image/png")
22
+ .indexOf("data:image/png") < 0) {
23
+ //Android doesn't support data URI
24
+ fallback = true;
25
+ } else {
26
+ var ctx = canvas.getContext("2d");
27
+ }
28
+ }
29
+
30
+ var dpr = 1, bsr = 1;
31
+
32
+ if(!fallback){
33
+ dpr = window.devicePixelRatio || 1,
34
+ bsr = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
35
+ }
36
+
37
+ var ratio = dpr / bsr;
38
+
18
39
  //getElementsByClassName polyfill
19
40
  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
41
 
21
42
  //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})
43
+ 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})
23
44
 
24
45
  //http://javascript.nwbox.com/ContentLoaded by Diego Perini with modifications
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)}};
46
+ 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)}}
26
47
 
27
48
  //https://gist.github.com/991057 by Jed Schmidt with modifications
28
49
  function selector(a){
29
50
  a=a.match(/^(\W)?(.*)/);var b=document["getElement"+(a[1]?a[1]=="#"?"ById":"sByClassName":"sByTagName")](a[2]);
30
- var ret=[]; b!=null&&(b.length?ret=b:b.length==0?ret=b:ret=[b]); return ret;
51
+ var ret=[]; b!==null&&(b.length?ret=b:b.length===0?ret=b:ret=[b]); return ret;
31
52
  }
32
53
 
33
54
  //shallow object property extend
@@ -35,14 +56,16 @@ function extend(a,b){var c={};for(var d in a)c[d]=a[d];for(var e in b)c[e]=b[e];
35
56
 
36
57
  //hasOwnProperty polyfill
37
58
  if (!Object.prototype.hasOwnProperty)
38
- Object.prototype.hasOwnProperty = function(prop) {
59
+ /*jshint -W001, -W103 */
60
+ Object.prototype.hasOwnProperty = function(prop) {
39
61
  var proto = this.__proto__ || this.constructor.prototype;
40
62
  return (prop in this) && (!(prop in proto) || proto[prop] !== this[prop]);
41
63
  }
64
+ /*jshint +W001, +W103 */
42
65
 
43
66
  function text_size(width, height, template) {
44
- height = parseInt(height,10);
45
- width = parseInt(width,10);
67
+ height = parseInt(height, 10);
68
+ width = parseInt(width, 10);
46
69
  var bigSide = Math.max(height, width)
47
70
  var smallSide = Math.min(height, width)
48
71
  var scale = 1 / 12;
@@ -52,7 +75,7 @@ function text_size(width, height, template) {
52
75
  }
53
76
  }
54
77
 
55
- function draw(ctx, dimensions, template, ratio) {
78
+ function draw(ctx, dimensions, template, ratio, literal) {
56
79
  var ts = text_size(dimensions.width, dimensions.height, template);
57
80
  var text_height = ts.height;
58
81
  var width = dimensions.width * ratio,
@@ -67,9 +90,12 @@ function draw(ctx, dimensions, template, ratio) {
67
90
  ctx.fillStyle = template.foreground;
68
91
  ctx.font = "bold " + text_height + "px " + font;
69
92
  var text = template.text ? template.text : (Math.floor(dimensions.width) + "x" + Math.floor(dimensions.height));
93
+ if (literal) {
94
+ text = template.literalText;
95
+ }
70
96
  var text_width = ctx.measureText(text).width;
71
97
  if (text_width / width >= 0.75) {
72
- text_height = Math.floor(text_height * 0.75 * (width/text_width));
98
+ text_height = Math.floor(text_height * 0.75 * (width / text_width));
73
99
  }
74
100
  //Resetting font size if necessary
75
101
  ctx.font = "bold " + (text_height * ratio) + "px " + font;
@@ -88,8 +114,12 @@ function render(mode, el, holder, src) {
88
114
  theme = (holder.font ? extend(theme, {
89
115
  font: holder.font
90
116
  }) : theme);
117
+ el.setAttribute("data-src", src);
118
+ theme.literalText = dimensions_caption;
119
+ holder.originalTheme = holder.theme;
120
+ holder.theme = theme;
121
+
91
122
  if (mode == "image") {
92
- el.setAttribute("data-src", src);
93
123
  el.setAttribute("alt", text ? text : theme.text ? theme.text + " [" + dimensions_caption + "]" : dimensions_caption);
94
124
  if (fallback || !holder.auto) {
95
125
  el.style.width = dimensions.width + "px";
@@ -106,19 +136,18 @@ function render(mode, el, holder, src) {
106
136
  el.style.backgroundSize = dimensions.width + "px " + dimensions.height + "px";
107
137
  }
108
138
  } else if (mode == "fluid") {
109
- el.setAttribute("data-src", src);
110
139
  el.setAttribute("alt", text ? text : theme.text ? theme.text + " [" + dimensions_caption + "]" : dimensions_caption);
111
- if (dimensions.height.substr(-1) == "%") {
140
+ if (dimensions.height.slice(-1) == "%") {
112
141
  el.style.height = dimensions.height
113
142
  } else {
114
143
  el.style.height = dimensions.height + "px"
115
144
  }
116
- if (dimensions.width.substr(-1) == "%") {
145
+ if (dimensions.width.slice(-1) == "%") {
117
146
  el.style.width = dimensions.width
118
147
  } else {
119
148
  el.style.width = dimensions.width + "px"
120
149
  }
121
- if (el.style.display == "inline" || el.style.display == "") {
150
+ if (el.style.display == "inline" || el.style.display === "") {
122
151
  el.style.display = "block";
123
152
  }
124
153
  if (fallback) {
@@ -129,7 +158,7 @@ function render(mode, el, holder, src) {
129
158
  fluid_update(el);
130
159
  }
131
160
  }
132
- };
161
+ }
133
162
 
134
163
  function fluid_update(element) {
135
164
  var images;
@@ -138,24 +167,23 @@ function fluid_update(element) {
138
167
  } else {
139
168
  images = [element]
140
169
  }
141
- for (i in images) {
170
+ for (var i in images) {
142
171
  var el = images[i]
143
172
  if (el.holderData) {
144
173
  var holder = el.holderData;
145
174
  el.setAttribute("src", draw(ctx, {
146
175
  height: el.clientHeight,
147
176
  width: el.clientWidth
148
- }, holder.theme, ratio));
177
+ }, holder.theme, ratio, !! holder.literal));
149
178
  }
150
179
  }
151
180
  }
152
181
 
153
182
  function parse_flags(flags, options) {
154
-
155
183
  var ret = {
156
184
  theme: settings.themes.gray
157
- }, render = false;
158
-
185
+ };
186
+ var render = false;
159
187
  for (sl = flags.length, j = 0; j < sl; j++) {
160
188
  var flag = flags[j];
161
189
  if (app.flags.dimensions.match(flag)) {
@@ -165,49 +193,24 @@ function parse_flags(flags, options) {
165
193
  render = true;
166
194
  ret.dimensions = app.flags.fluid.output(flag);
167
195
  ret.fluid = true;
196
+ } else if (app.flags.literal.match(flag)) {
197
+ ret.literal = true;
168
198
  } else if (app.flags.colors.match(flag)) {
169
199
  ret.theme = app.flags.colors.output(flag);
170
200
  } else if (options.themes[flag]) {
171
201
  //If a theme is specified, it will override custom colors
172
202
  ret.theme = options.themes[flag];
173
- } else if (app.flags.text.match(flag)) {
174
- ret.text = app.flags.text.output(flag);
175
203
  } else if (app.flags.font.match(flag)) {
176
204
  ret.font = app.flags.font.output(flag);
177
205
  } else if (app.flags.auto.match(flag)) {
178
206
  ret.auto = true;
207
+ } else if (app.flags.text.match(flag)) {
208
+ ret.text = app.flags.text.output(flag);
179
209
  }
180
210
  }
181
-
182
211
  return render ? ret : false;
183
-
184
- };
185
-
186
-
187
-
188
- if (!canvas.getContext) {
189
- fallback = true;
190
- } else {
191
- if (canvas.toDataURL("image/png")
192
- .indexOf("data:image/png") < 0) {
193
- //Android doesn't support data URI
194
- fallback = true;
195
- } else {
196
- var ctx = canvas.getContext("2d");
197
- }
198
212
  }
199
-
200
- var dpr = 1, bsr = 1;
201
-
202
- if(!fallback){
203
- dpr = window.devicePixelRatio || 1,
204
- bsr = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
205
- }
206
-
207
- var ratio = dpr / bsr;
208
-
209
213
  var fluid_images = [];
210
-
211
214
  var settings = {
212
215
  domain: "holder.js",
213
216
  images: "img",
@@ -231,8 +234,6 @@ var settings = {
231
234
  },
232
235
  stylesheet: ""
233
236
  };
234
-
235
-
236
237
  app.flags = {
237
238
  dimensions: {
238
239
  regex: /^(\d+)x(\d+)$/,
@@ -279,21 +280,21 @@ app.flags = {
279
280
  },
280
281
  auto: {
281
282
  regex: /^auto$/
283
+ },
284
+ literal: {
285
+ regex: /^literal$/
282
286
  }
283
287
  }
284
-
285
288
  for (var flag in app.flags) {
286
289
  if (!app.flags.hasOwnProperty(flag)) continue;
287
290
  app.flags[flag].match = function (val) {
288
291
  return val.match(this.regex)
289
292
  }
290
293
  }
291
-
292
294
  app.add_theme = function (name, theme) {
293
295
  name != null && theme != null && (settings.themes[name] = theme);
294
296
  return app;
295
297
  };
296
-
297
298
  app.add_image = function (src, el) {
298
299
  var node = selector(el);
299
300
  if (node.length) {
@@ -305,32 +306,27 @@ app.add_image = function (src, el) {
305
306
  }
306
307
  return app;
307
308
  };
308
-
309
309
  app.run = function (o) {
310
310
  var options = extend(settings, o),
311
- images = [], imageNodes = [], bgnodes = [];
312
-
313
- if(typeof(options.images) == "string"){
314
- imageNodes = selector(options.images);
315
- }
316
- else if (window.NodeList && options.images instanceof window.NodeList) {
311
+ images = [],
312
+ imageNodes = [],
313
+ bgnodes = [];
314
+ if (typeof (options.images) == "string") {
315
+ imageNodes = selector(options.images);
316
+ } else if (window.NodeList && options.images instanceof window.NodeList) {
317
317
  imageNodes = options.images;
318
318
  } else if (window.Node && options.images instanceof window.Node) {
319
319
  imageNodes = [options.images];
320
320
  }
321
-
322
- if(typeof(options.bgnodes) == "string"){
323
- bgnodes = selector(options.bgnodes);
321
+ if (typeof (options.bgnodes) == "string") {
322
+ bgnodes = selector(options.bgnodes);
324
323
  } else if (window.NodeList && options.elements instanceof window.NodeList) {
325
324
  bgnodes = options.bgnodes;
326
325
  } else if (window.Node && options.bgnodes instanceof window.Node) {
327
326
  bgnodes = [options.bgnodes];
328
327
  }
329
-
330
328
  preempted = true;
331
-
332
329
  for (i = 0, l = imageNodes.length; i < l; i++) images.push(imageNodes[i]);
333
-
334
330
  var holdercss = document.getElementById("holderjs-style");
335
331
  if (!holdercss) {
336
332
  holdercss = document.createElement("style");
@@ -338,53 +334,44 @@ app.run = function (o) {
338
334
  holdercss.type = "text/css";
339
335
  document.getElementsByTagName("head")[0].appendChild(holdercss);
340
336
  }
341
-
342
337
  if (!options.nocss) {
343
- if (holdercss.styleSheet) {
344
- holdercss.styleSheet.cssText += options.stylesheet;
345
- } else {
346
- holdercss.appendChild(document.createTextNode(options.stylesheet));
347
- }
338
+ if (holdercss.styleSheet) {
339
+ holdercss.styleSheet.cssText += options.stylesheet;
340
+ } else {
341
+ holdercss.appendChild(document.createTextNode(options.stylesheet));
342
+ }
348
343
  }
349
-
350
344
  var cssregex = new RegExp(options.domain + "\/(.*?)\"?\\)");
351
-
352
345
  for (var l = bgnodes.length, i = 0; i < l; i++) {
353
346
  var src = window.getComputedStyle(bgnodes[i], null)
354
347
  .getPropertyValue("background-image");
355
348
  var flags = src.match(cssregex);
356
349
  var bgsrc = bgnodes[i].getAttribute("data-background-src");
357
-
358
350
  if (flags) {
359
351
  var holder = parse_flags(flags[1].split("/"), options);
360
352
  if (holder) {
361
353
  render("background", bgnodes[i], holder, src);
362
354
  }
363
- }
364
- else if(bgsrc != null){
365
- var holder = parse_flags(bgsrc.substr(bgsrc.lastIndexOf(options.domain) + options.domain.length + 1)
355
+ } else if (bgsrc != null) {
356
+ var holder = parse_flags(bgsrc.substr(bgsrc.lastIndexOf(options.domain) + options.domain.length + 1)
366
357
  .split("/"), options);
367
- if(holder){
368
- render("background", bgnodes[i], holder, src);
369
- }
358
+ if (holder) {
359
+ render("background", bgnodes[i], holder, src);
360
+ }
370
361
  }
371
362
  }
372
-
373
363
  for (l = images.length, i = 0; i < l; i++) {
374
-
375
- var attr_src = attr_data_src = src = null;
376
-
377
- try{
378
- attr_src = images[i].getAttribute("src");
379
- attr_datasrc = images[i].getAttribute("data-src");
380
- }catch(e){}
381
-
364
+ var attr_data_src, attr_src;
365
+ attr_src = attr_data_src = src = null;
366
+ try {
367
+ attr_src = images[i].getAttribute("src");
368
+ attr_datasrc = images[i].getAttribute("data-src");
369
+ } catch (e) {}
382
370
  if (attr_datasrc == null && !! attr_src && attr_src.indexOf(options.domain) >= 0) {
383
371
  src = attr_src;
384
372
  } else if ( !! attr_datasrc && attr_datasrc.indexOf(options.domain) >= 0) {
385
373
  src = attr_datasrc;
386
374
  }
387
-
388
375
  if (src) {
389
376
  var holder = parse_flags(src.substr(src.lastIndexOf(options.domain) + options.domain.length + 1)
390
377
  .split("/"), options);
@@ -399,7 +386,6 @@ app.run = function (o) {
399
386
  }
400
387
  return app;
401
388
  };
402
-
403
389
  contentLoaded(win, function () {
404
390
  if (window.addEventListener) {
405
391
  window.addEventListener("resize", fluid_update, false);
@@ -409,9 +395,8 @@ contentLoaded(win, function () {
409
395
  }
410
396
  preempted || app.run();
411
397
  });
412
-
413
398
  if (typeof define === "function" && define.amd) {
414
- define("Holder", [], function () {
399
+ define([], function () {
415
400
  return app;
416
401
  });
417
402
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: holder_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nihad Abbasov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-06 00:00:00.000000000 Z
11
+ date: 2013-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  version: '0'
63
63
  requirements: []
64
64
  rubyforge_project:
65
- rubygems_version: 2.0.3
65
+ rubygems_version: 2.0.6
66
66
  signing_key:
67
67
  specification_version: 4
68
68
  summary: Holder.js for Rails 3.1 asset pipeline