simply_load 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -23,4 +23,24 @@ On any of your views just use this code:
23
23
 
24
24
  <%= simply_load url_to_load, "Loading content if no block is provided", {other options} %>
25
25
 
26
+ Callbacks:
27
+
28
+ In order to react to a load success event, you will need to listen to the "simply_load:success" event like this:
29
+
30
+ $("#simply_load_object").live("simply_load:success", function(){
31
+ alert("Finished Loading")
32
+ }
33
+
34
+ Periodically Load:
35
+
36
+ You can also reload an element periodically using a function call:
37
+
38
+ simply_load_every_x_y
39
+
40
+ where x is the amount and y is the time unit.
41
+
42
+ examples:
43
+
44
+ simply_load_every_15_seconds or simply_load_every_1_minute or simply_load_every_3_hours
45
+
26
46
  Hope you like it!!
@@ -7,6 +7,16 @@ $(document).ready(function() {
7
7
 
8
8
  function simply_load(element){
9
9
  $.each($(element.find('.simply_load')), function(){
10
- $(this).load($(this).attr('data-href'));
10
+ $this = $(this);
11
+ $this.bind("reload", function(timer){
12
+ $this.load($this.attr('data-href'),function(data){
13
+ $this.trigger("simply_load:success", data);
14
+ });
15
+ });
16
+ $this.trigger("reload");
17
+ });
18
+
19
+ $.each($(element.find('.simply_load_timed')), function(){
20
+ window.setInterval('$this.trigger("reload");', $(this).attr("data-timer"));
11
21
  });
12
22
  }
@@ -1,3 +1,3 @@
1
1
  module SimplyLoad
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/simply_load.rb CHANGED
@@ -11,7 +11,24 @@ module SimplyLoad
11
11
  else
12
12
  content_tag :div, content_or_options_with_block, options, escape
13
13
  end
14
- end
14
+ end
15
+
16
+ def simply_load_timed(t, unit, url, content_or_options_with_block = nil, options = {}, escape = true, &block)
17
+ timer = t.send(unit).seconds * 1000
18
+ options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash) and block_given?
19
+ options[:class] = "#{options[:class]} simply_load simply_load_timed".strip
20
+ options.merge!(:"data-href" => url, :"data-timer" => timer)
21
+ if block_given?
22
+ content_tag :div, capture(&block), options, escape
23
+ else
24
+ content_tag :div, content_or_options_with_block, options, escape
25
+ end
26
+ end
27
+
28
+ def method_missing(method, *args, &block)
29
+ return simply_load_timed($1.to_i, $2.to_s, *args) if method =~ /^simply_load_every_+(.*\d)+_+(second|seconds|minute|minutes|hour|hours)$/ # Call has_role? with is_role_name?
30
+ super
31
+ end
15
32
 
16
33
  end
17
34
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: simply_load
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Firebait
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-15 00:00:00 Z
13
+ date: 2011-09-09 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jquery-rails