holder_rails 1.7.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 15875671a6199f0e92ee28d6fa5aafe84a9a63fe
4
+ data.tar.gz: d0776426d64fdfefc3e49a10abca5ac1b72a74fa
5
+ SHA512:
6
+ metadata.gz: 767a5464fb7f1df7375aa5b17bcbe6aed5c2069aef19ac7c78bc5373e4896c3c30c9de0a03c2ed022e94257a9c4f211b6407676fb9661bd91a395a93275b8d65
7
+ data.tar.gz: 6c3474b927e2987d2a50c0f194e8b9118016c178ddc9e4a1e5a576113c376ae771ce0dc616b231ba8991cccfd47965dde332b5b2915ab530826a46cf2d9476be
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Nihad Abbasov / NARKOZ
1
+ Copyright (c) 2012-2013 Nihad Abbasov <mail@narkoz.me>
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -1,5 +1,8 @@
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)
5
+
3
6
  Provides Holder.js to render image placeholders entirely on the client side.
4
7
 
5
8
  ## Installation
@@ -45,6 +48,10 @@ holder_tag '500x800', 'Example text', 'gray', :id => 'new', :class => 'special'
45
48
 
46
49
  For more information, check out [holder readme](https://github.com/imsky/holder#readme).
47
50
 
51
+ ## Versioning
52
+
53
+ holder_rails 1.7.0 == Holder.js 1.7
54
+
48
55
  ## License
49
56
 
50
57
  Released under the BSD 2-clause license. See LICENSE.txt for details.
@@ -1,3 +1,3 @@
1
1
  module HolderRails
2
- VERSION = "1.7.0"
2
+ VERSION = "1.9.0"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  /*
2
2
 
3
- Holder - 1.7 - client side image placeholders
4
- (c) 2012 Ivan Malopinsky / http://imsky.co
3
+ Holder - 1.9 - client side image placeholders
4
+ (c) 2012-2013 Ivan Malopinsky / http://imsky.co
5
5
 
6
6
  Provided under the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0
7
7
  Commercial use requires attribution.
@@ -54,6 +54,7 @@ function draw(ctx, dimensions, template, ratio) {
54
54
  var ts = text_size(dimensions.width, dimensions.height, template);
55
55
  var text_height = ts.height;
56
56
  var width = dimensions.width * ratio, height = dimensions.height * ratio;
57
+ var font = template.font ? template.font : "sans-serif";
57
58
  canvas.width = width;
58
59
  canvas.height = height;
59
60
  ctx.textAlign = "center";
@@ -61,25 +62,24 @@ function draw(ctx, dimensions, template, ratio) {
61
62
  ctx.fillStyle = template.background;
62
63
  ctx.fillRect(0, 0, width, height);
63
64
  ctx.fillStyle = template.foreground;
64
- ctx.font = "bold " + text_height + "px sans-serif";
65
+ ctx.font = "bold " + text_height + "px "+font;
65
66
  var text = template.text ? template.text : (dimensions.width + "x" + dimensions.height);
66
67
  if (ctx.measureText(text).width / width > 1) {
67
68
  text_height = template.size / (ctx.measureText(text).width / width);
68
69
  }
69
- ctx.font = "bold " + (text_height * ratio) + "px sans-serif";
70
+ //Resetting font size if necessary
71
+ ctx.font = "bold " + (text_height * ratio) + "px "+font;
70
72
  ctx.fillText(text, (width / 2), (height / 2), width);
71
73
  return canvas.toDataURL("image/png");
72
74
  }
73
75
 
74
76
  function render(mode, el, holder, src) {
75
-
76
77
  var dimensions = holder.dimensions,
77
78
  theme = holder.theme,
78
- text = holder.text;
79
+ text = holder.text ? decodeURIComponent(holder.text) : holder.text;
79
80
  var dimensions_caption = dimensions.width + "x" + dimensions.height;
80
- theme = (text ? extend(theme, {
81
- text: text
82
- }) : theme);
81
+ theme = (text ? extend(theme, { text: text }) : theme);
82
+ theme = (holder.font ? extend(theme, {font: holder.font}) : theme);
83
83
 
84
84
  var ratio = 1;
85
85
  if(window.devicePixelRatio && window.devicePixelRatio > 1){
@@ -89,11 +89,15 @@ function render(mode, el, holder, src) {
89
89
  if (mode == "image") {
90
90
  el.setAttribute("data-src", src);
91
91
  el.setAttribute("alt", text ? text : theme.text ? theme.text + " [" + dimensions_caption + "]" : dimensions_caption);
92
- el.style.width = dimensions.width + "px";
93
- el.style.height = dimensions.height + "px";
94
-
92
+
93
+ if(fallback || !holder.auto){
94
+ el.style.width = dimensions.width + "px";
95
+ el.style.height = dimensions.height + "px";
96
+ }
97
+
95
98
  if (fallback) {
96
99
  el.style.backgroundColor = theme.background;
100
+
97
101
  }
98
102
  else{
99
103
  el.setAttribute("src", draw(ctx, dimensions, theme, ratio));
@@ -123,7 +127,10 @@ function fluid(el, holder, src) {
123
127
  fluid.style.width = holder.dimensions.width + (holder.dimensions.width.indexOf("%")>0?"":"px");
124
128
  fluid.style.height = holder.dimensions.height + (holder.dimensions.height.indexOf("%")>0?"":"px");
125
129
  fluid.id = el.id;
126
-
130
+
131
+ el.style.width=0;
132
+ el.style.height=0;
133
+
127
134
  if (theme.text) {
128
135
  fluid.appendChild(document.createTextNode(theme.text))
129
136
  } else {
@@ -132,7 +139,18 @@ function fluid(el, holder, src) {
132
139
  setTimeout(fluid_update, 0);
133
140
  }
134
141
 
135
- el.parentNode.replaceChild(fluid, el);
142
+ el.parentNode.insertBefore(fluid, el.nextSibling)
143
+
144
+ if(window.jQuery){
145
+ jQuery(function($){
146
+ $(el).on("load", function(){
147
+ el.style.width = fluid.style.width;
148
+ el.style.height = fluid.style.height;
149
+ $(el).show();
150
+ $(fluid).remove();
151
+ });
152
+ })
153
+ }
136
154
  }
137
155
 
138
156
  function fluid_update() {
@@ -168,6 +186,11 @@ function parse_flags(flags, options) {
168
186
  ret.theme = options.themes[flag];
169
187
  } else if (app.flags.text.match(flag)) {
170
188
  ret.text = app.flags.text.output(flag);
189
+ } else if(app.flags.font.match(flag)){
190
+ ret.font = app.flags.font.output(flag);
191
+ }
192
+ else if(app.flags.auto.match(flag)){
193
+ ret.auto = true;
171
194
  }
172
195
  }
173
196
 
@@ -192,7 +215,7 @@ var fluid_images = [];
192
215
  var settings = {
193
216
  domain: "holder.js",
194
217
  images: "img",
195
- elements: ".holderjs",
218
+ bgnodes: ".holderjs",
196
219
  themes: {
197
220
  "gray": {
198
221
  background: "#eee",
@@ -251,6 +274,15 @@ app.flags = {
251
274
  output: function (val) {
252
275
  return this.regex.exec(val)[1];
253
276
  }
277
+ },
278
+ font: {
279
+ regex: /font\:(.*)/,
280
+ output: function(val){
281
+ return this.regex.exec(val)[1];
282
+ }
283
+ },
284
+ auto: {
285
+ regex: /^auto$/
254
286
  }
255
287
  }
256
288
 
@@ -279,29 +311,58 @@ app.add_image = function (src, el) {
279
311
  };
280
312
 
281
313
  app.run = function (o) {
282
- var options = extend(settings, o),
283
- images_nodes = selector(options.images),
284
- elements = selector(options.elements),
285
- preempted = true,
286
- images = [];
287
-
288
- for (i = 0, l = images_nodes.length; i < l; i++) images.push(images_nodes[i]);
289
-
290
- var holdercss = document.createElement("style");
291
- holdercss.type = "text/css";
292
- holdercss.styleSheet ? holdercss.styleSheet.cssText = options.stylesheet : holdercss.textContent = options.stylesheet;
293
- document.getElementsByTagName("head")[0].appendChild(holdercss);
314
+ var options = extend(settings, o), images = [];
315
+
316
+ if(options.images instanceof window.NodeList){
317
+ imageNodes = options.images;
318
+ }
319
+ else if(options.images instanceof window.Node){
320
+ imageNodes = [options.images];
321
+ }
322
+ else{
323
+ imageNodes = selector(options.images);
324
+ }
325
+
326
+ if(options.elements instanceof window.NodeList){
327
+ bgnodes = options.bgnodes;
328
+ }
329
+ else if(options.bgnodes instanceof window.Node){
330
+ bgnodes = [options.bgnodes];
331
+ }
332
+ else{
333
+ bgnodes = selector(options.bgnodes);
334
+ }
335
+
336
+ preempted = true;
337
+
338
+ for (i = 0, l = imageNodes.length; i < l; i++) images.push(imageNodes[i]);
339
+
340
+ var holdercss = document.getElementById("holderjs-style");
341
+
342
+ if(!holdercss){
343
+ holdercss = document.createElement("style");
344
+ holdercss.setAttribute("id", "holderjs-style");
345
+ holdercss.type = "text/css";
346
+ document.getElementsByTagName("head")[0].appendChild(holdercss);
347
+ }
294
348
 
349
+ if(holdercss.styleSheet){
350
+ holdercss.styleSheet += options.stylesheet;
351
+ }
352
+ else{
353
+ holdercss.textContent+= options.stylesheet;
354
+ }
355
+
295
356
  var cssregex = new RegExp(options.domain + "\/(.*?)\"?\\)");
296
357
 
297
- for (var l = elements.length, i = 0; i < l; i++) {
298
- var src = window.getComputedStyle(elements[i], null)
358
+ for (var l = bgnodes.length, i = 0; i < l; i++) {
359
+ var src = window.getComputedStyle(bgnodes[i], null)
299
360
  .getPropertyValue("background-image");
300
361
  var flags = src.match(cssregex);
301
362
  if (flags) {
302
363
  var holder = parse_flags(flags[1].split("/"), options);
303
364
  if (holder) {
304
- render("background", elements[i], holder, src);
365
+ render("background", bgnodes[i], holder, src);
305
366
  }
306
367
  }
307
368
  }
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: holder_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
5
- prerelease:
4
+ version: 1.9.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nihad Abbasov
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-29 00:00:00.000000000 Z
11
+ date: 2013-04-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: railties
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.1.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 3.1.0
30
27
  description: Provides Holder.js to render image placeholders entirely on the client
@@ -48,33 +45,26 @@ files:
48
45
  - vendor/assets/javascripts/holder.js
49
46
  homepage: https://github.com/narkoz/holder_rails
50
47
  licenses: []
48
+ metadata: {}
51
49
  post_install_message:
52
50
  rdoc_options: []
53
51
  require_paths:
54
52
  - lib
55
53
  required_ruby_version: !ruby/object:Gem::Requirement
56
- none: false
57
54
  requirements:
58
- - - ! '>='
55
+ - - '>='
59
56
  - !ruby/object:Gem::Version
60
57
  version: '0'
61
- segments:
62
- - 0
63
- hash: -4350495992017316440
64
58
  required_rubygems_version: !ruby/object:Gem::Requirement
65
- none: false
66
59
  requirements:
67
- - - ! '>='
60
+ - - '>='
68
61
  - !ruby/object:Gem::Version
69
62
  version: '0'
70
- segments:
71
- - 0
72
- hash: -4350495992017316440
73
63
  requirements: []
74
64
  rubyforge_project:
75
- rubygems_version: 1.8.24
65
+ rubygems_version: 2.0.3
76
66
  signing_key:
77
- specification_version: 3
67
+ specification_version: 4
78
68
  summary: Holder.js for Rails 3.1 asset pipeline
79
69
  test_files:
80
70
  - test/holder_rails_test.rb