rjs_helpers 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/MIT-LICENSE +20 -0
- data/README.md +138 -0
- data/Rakefile +11 -0
- data/app/coffeescripts/rjs_helper.coffee +100 -0
- data/app/helpers/rjs_helper.rb +145 -0
- data/generators/rjs_helpers/rjs_helpers_generator.rb +13 -0
- data/generators/rjs_helpers/templates/assets/js/rjs_helper.js +79 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/rjs_helpers/version.rb +3 -0
- data/lib/rjs_helpers.rb +1 -0
- data/lib/tasks/rjs_helpers.rake +4 -0
- data/rails/init.rb +4 -0
- data/rjs_helpers.gemspec +24 -0
- data/test/rjs_helpers_test.rb +8 -0
- data/test/test_helper.rb +4 -0
- data/uninstall.rb +1 -0
- metadata +131 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Stefan Exner
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
RJS Helpers
|
2
|
+
==============
|
3
|
+
|
4
|
+
Some helper methods to perform standard JS library tasks from js.erb without having to write actual javascript
|
5
|
+
|
6
|
+
Installation
|
7
|
+
============
|
8
|
+
|
9
|
+
To install the plugin in your Rails 2.3 application, simply run
|
10
|
+
|
11
|
+
ruby script/plugin install https://github.com/Stex/rjs_helpers.git
|
12
|
+
|
13
|
+
This will automatically load the Rails helper into all your controllers.
|
14
|
+
As explained below, the plugin ships with a default JS adapter for jQuery
|
15
|
+
which can be automatically copied to your public/javascripts directory with
|
16
|
+
the following line:
|
17
|
+
|
18
|
+
ruby script/generate rjs_helpers js
|
19
|
+
|
20
|
+
Now you only have to include this js file into your application layout
|
21
|
+
and you're good to go.
|
22
|
+
|
23
|
+
Usage
|
24
|
+
=====
|
25
|
+
|
26
|
+
The plugin consists of two parts:
|
27
|
+
|
28
|
+
1. A Rails helper which is available in application views
|
29
|
+
2. A JS helper library which has to be included into your application scripts / layout
|
30
|
+
|
31
|
+
The JS file which is part of this plugin uses jQuery to perform its tasks.
|
32
|
+
If your application is using a different framework, feel free to write an
|
33
|
+
own adapter for it.
|
34
|
+
|
35
|
+
The Rails helper does not directly generate code for just one library, as jQuery might
|
36
|
+
not be used for all applications. Instead, it will generate calls to an own API which can be
|
37
|
+
found in the included javascript file.
|
38
|
+
|
39
|
+
Available Functions
|
40
|
+
===================
|
41
|
+
|
42
|
+
Update, Replace, Append, Prepend
|
43
|
+
--------------------------------
|
44
|
+
|
45
|
+
These content update functions always take a selector element and the new content.
|
46
|
+
|
47
|
+
The selector element may either be a string/symbol which is passed directly to the JS function
|
48
|
+
or something the `dom_id()` function would take as well (an instance of ActiveRecord or an Array).
|
49
|
+
|
50
|
+
The content may either be a string containing the new content or options for the
|
51
|
+
ActionView `render()` method.
|
52
|
+
|
53
|
+
js_update_element(element, content)
|
54
|
+
|
55
|
+
Updates the given element with the given content
|
56
|
+
|
57
|
+
js_replace_element(element, content)
|
58
|
+
|
59
|
+
Replaces the given element with the new content
|
60
|
+
|
61
|
+
js_append_element_to(element, content)
|
62
|
+
|
63
|
+
Appends the given content to the given container element
|
64
|
+
|
65
|
+
js_prepend_element_to(element, content)
|
66
|
+
|
67
|
+
Like `append`, but at the top of the container element
|
68
|
+
|
69
|
+
|
70
|
+
Removing DOM elements
|
71
|
+
---------------------
|
72
|
+
|
73
|
+
js_remove_element(element)
|
74
|
+
|
75
|
+
Removes the given element from the DOM.
|
76
|
+
|
77
|
+
|
78
|
+
Show, Hide and Toggle
|
79
|
+
---------------------
|
80
|
+
|
81
|
+
js_show_element(element)
|
82
|
+
|
83
|
+
Shows the given element, by default with `.show()`
|
84
|
+
|
85
|
+
js_hide_element(element)
|
86
|
+
|
87
|
+
Hides the given element, by default with `.hide()`
|
88
|
+
|
89
|
+
js_toggle_element(element)
|
90
|
+
|
91
|
+
Toggles the given element, by default with `.toggle()`
|
92
|
+
|
93
|
+
|
94
|
+
Various Actions
|
95
|
+
---------------
|
96
|
+
|
97
|
+
js_redirect_to(url)
|
98
|
+
|
99
|
+
Performs a javascript redirect to the given URL.
|
100
|
+
The argument may be everything that the `url_for()` function would accept, e.g. `[:admin, :users]` or `"http://www.google.com"`
|
101
|
+
|
102
|
+
js_scroll_to(element, offset_top = 0)
|
103
|
+
|
104
|
+
Scrolls to the given element on the page.
|
105
|
+
The optional second parameter can be used to set a top offset. This is e.g. useful
|
106
|
+
if you have a fixed top navbar (greetings to you, bootstrap).
|
107
|
+
|
108
|
+
If `:top` is given as the first argument, the page will simply scroll to the very top (+ offset).
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
Examples
|
119
|
+
========
|
120
|
+
```ruby
|
121
|
+
= js_update_element @user, :partial => 'user', :object => @user
|
122
|
+
#=> rjsHelpers.updateElementByDomId('user_123', ...)
|
123
|
+
#=> jQuery('#user_123').html(...)
|
124
|
+
|
125
|
+
= js_update_element [@user, :emails], :partial => 'emails'
|
126
|
+
#=> rjsHelpers.updateElementByDomId('emails_user_123', ...)
|
127
|
+
#=> jQuery('#emails_user_123').html(...)
|
128
|
+
|
129
|
+
= js_hide_element '#myContainer'
|
130
|
+
#=> rjsHelpers.hideElement('#myContainer')
|
131
|
+
#=> jQuery('#myContainer').hide()
|
132
|
+
|
133
|
+
= js_replace_element '#willBeOverridden', 'And now for something completely different'
|
134
|
+
#=> rjsHelpers.replaceElement('#willBeOverridden', 'And now for something completely different')
|
135
|
+
#=> jQuery('#willBeOverridden').replaceWith('And now for something completely different')
|
136
|
+
```
|
137
|
+
|
138
|
+
Copyright (c) 2013 Stex, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
desc "Compiles the plugin's coffeescript to a js file"
|
4
|
+
task :make do |t|
|
5
|
+
input_files = ['./app/coffeescripts/']
|
6
|
+
output_directory = './generators/rjs_helpers/templates/assets/js'
|
7
|
+
|
8
|
+
input_files.each do |file|
|
9
|
+
`coffee -l -c -o #{output_directory} #{file}`
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#This file contains different helpers for js.erb files throughout the application.
|
2
|
+
#Using this methods allows us to be able to replace the underlying js framework
|
3
|
+
|
4
|
+
window.rjsHelpers =
|
5
|
+
|
6
|
+
#----------------------------------------------------------------
|
7
|
+
# Update / Replace Elements
|
8
|
+
#----------------------------------------------------------------
|
9
|
+
|
10
|
+
updateElement: (element, content) ->
|
11
|
+
jQuery(element).html(content)
|
12
|
+
|
13
|
+
updateElementById: (element, content) ->
|
14
|
+
@.updateElement("##{element}", content)
|
15
|
+
|
16
|
+
replaceElement: (element, content) ->
|
17
|
+
jQuery(element).replaceWith(content)
|
18
|
+
|
19
|
+
replaceElementById: (element, content) ->
|
20
|
+
@.replaceElement("##{element}", content)
|
21
|
+
|
22
|
+
|
23
|
+
#----------------------------------------------------------------
|
24
|
+
# Remove Elements
|
25
|
+
#----------------------------------------------------------------
|
26
|
+
|
27
|
+
removeElement: (element) ->
|
28
|
+
jQuery(element).remove()
|
29
|
+
|
30
|
+
removeElementById: (element) ->
|
31
|
+
@.removeElement("##{element}")
|
32
|
+
|
33
|
+
#----------------------------------------------------------------
|
34
|
+
# Append / Prepend
|
35
|
+
#----------------------------------------------------------------
|
36
|
+
|
37
|
+
appendElement: (element, content) ->
|
38
|
+
jQuery(element).append(content)
|
39
|
+
|
40
|
+
appendElementById: (element, content) ->
|
41
|
+
@.appendElement("##{element}", content)
|
42
|
+
|
43
|
+
prependElement: (element, content) ->
|
44
|
+
jQuery(element).prepend(content)
|
45
|
+
|
46
|
+
prependElementById: (element, content) ->
|
47
|
+
@.prependElement("##{element}", content)
|
48
|
+
|
49
|
+
|
50
|
+
#----------------------------------------------------------------
|
51
|
+
# Show / Hide
|
52
|
+
#----------------------------------------------------------------
|
53
|
+
|
54
|
+
hideElement: (element) ->
|
55
|
+
jQuery(element).hide()
|
56
|
+
|
57
|
+
hideElementById: (element) ->
|
58
|
+
@.hideElement("##{element}")
|
59
|
+
|
60
|
+
showElement: (element) ->
|
61
|
+
jQuery(element).show()
|
62
|
+
|
63
|
+
showElementById: (element) ->
|
64
|
+
@.showElement("##{element}")
|
65
|
+
|
66
|
+
toggleElement: (element) ->
|
67
|
+
jQuery(element).toggle()
|
68
|
+
|
69
|
+
toggleElementById: (element) ->
|
70
|
+
@.toggleElement("##{element}")
|
71
|
+
|
72
|
+
#----------------------------------------------------------------
|
73
|
+
# Scrolling
|
74
|
+
#----------------------------------------------------------------
|
75
|
+
|
76
|
+
scrollToElement: (element, offsetTop) ->
|
77
|
+
offsetTop = 0 unless offsetTop?
|
78
|
+
jQuery('html, body').animate({
|
79
|
+
scrollTop: jQuery(element).offset().top - offsetTop
|
80
|
+
}, 1000)
|
81
|
+
false
|
82
|
+
|
83
|
+
scrollToElementById: (element) ->
|
84
|
+
@.scrollToElement("##{element}")
|
85
|
+
|
86
|
+
scrollToTop: (offsetTop) ->
|
87
|
+
offsetTop = 0 unless offsetTop?
|
88
|
+
jQuery("html, body").animate {scrollTop: offsetTop }, 600
|
89
|
+
false
|
90
|
+
|
91
|
+
#----------------------------------------------------------------
|
92
|
+
# Various
|
93
|
+
#----------------------------------------------------------------
|
94
|
+
|
95
|
+
# Redirects to the given URL
|
96
|
+
#--------------------------------------------------------------
|
97
|
+
redirectTo: (url) ->
|
98
|
+
window.location.href = url
|
99
|
+
|
100
|
+
|
@@ -0,0 +1,145 @@
|
|
1
|
+
module RjsHelper
|
2
|
+
#----------------------------------------------------------------
|
3
|
+
# Helpers for js.erb files
|
4
|
+
# Have a look at app/coffeescripts/rjs_helper.coffee
|
5
|
+
#----------------------------------------------------------------
|
6
|
+
|
7
|
+
# Updates the content of the given selector with the given content
|
8
|
+
#----------------------------------------------------------------------------
|
9
|
+
def js_update_element(element, content)
|
10
|
+
rjs_method :update_element, :element => element, :content => content
|
11
|
+
end
|
12
|
+
|
13
|
+
# Like js_update_element, but with the element's dom_id
|
14
|
+
#----------------------------------------------------------------------------
|
15
|
+
def js_update_element_by_dom_id(element, content)
|
16
|
+
js_update_element(element, content)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Appends the given content to the given element
|
20
|
+
#--------------------------------------------------------------
|
21
|
+
def js_append_element_to(element, content)
|
22
|
+
rjs_method :append_element, :element => element, :content => content
|
23
|
+
end
|
24
|
+
|
25
|
+
# Appends the given content to the given element
|
26
|
+
#--------------------------------------------------------------
|
27
|
+
def js_prepend_element_to(element, content)
|
28
|
+
rjs_method :prepend_element, :element => element, :content => content
|
29
|
+
end
|
30
|
+
|
31
|
+
# Replaces the given selector with the given content
|
32
|
+
#----------------------------------------------------------------------------
|
33
|
+
def js_replace_element(element, content)
|
34
|
+
rjs_method :replace_element, :element => element, :content => content
|
35
|
+
end
|
36
|
+
|
37
|
+
# Like js_replace_element, but with the element's dom_id
|
38
|
+
#----------------------------------------------------------------------------
|
39
|
+
def js_replace_element_by_dom_id(element, content)
|
40
|
+
js_replace_element(element, content)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Removes the given element from the DOM
|
44
|
+
#--------------------------------------------------------------
|
45
|
+
def js_remove_element(element)
|
46
|
+
rjs_method :remove_element, element
|
47
|
+
end
|
48
|
+
|
49
|
+
# Like +js_remove_element+, but with the element's dom_id
|
50
|
+
#--------------------------------------------------------------
|
51
|
+
def js_remove_element_by_dom_id(element)
|
52
|
+
js_remove_element(element)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Redirects the user to the given URL using javascript
|
56
|
+
#--------------------------------------------------------------
|
57
|
+
def js_redirect_to(url)
|
58
|
+
rjs_method :redirect_to, url_for(url)
|
59
|
+
end
|
60
|
+
|
61
|
+
#----------------------------------------------------------------
|
62
|
+
# Show / Hide / Toggle
|
63
|
+
#----------------------------------------------------------------
|
64
|
+
|
65
|
+
def js_show_element(element)
|
66
|
+
rjs_method :show_element, element
|
67
|
+
end
|
68
|
+
|
69
|
+
def js_hide_element(element)
|
70
|
+
rjs_method :hide_element, element
|
71
|
+
end
|
72
|
+
|
73
|
+
def js_show_element_by_dom_id(element)
|
74
|
+
js_show_element(element)
|
75
|
+
end
|
76
|
+
|
77
|
+
def js_hide_element_by_dom_id(element)
|
78
|
+
js_hide_element(element)
|
79
|
+
end
|
80
|
+
|
81
|
+
def js_toggle_element(element)
|
82
|
+
rjs_method :toggle_element, element
|
83
|
+
end
|
84
|
+
|
85
|
+
#----------------------------------------------------------------
|
86
|
+
# Other GUI Actions
|
87
|
+
#----------------------------------------------------------------
|
88
|
+
|
89
|
+
# Scrolls to the given element on the page.
|
90
|
+
# If the symbol +:top+ is given, the page will scroll to
|
91
|
+
# top without having to specify a certain element
|
92
|
+
#
|
93
|
+
# Additionally, an offset can be given as the second parameter.
|
94
|
+
# This is e.g. useful in cases of layouts with a fixed top navbar.
|
95
|
+
#--------------------------------------------------------------
|
96
|
+
def js_scroll_to(element, offset_top = 0)
|
97
|
+
if element == :top
|
98
|
+
rjs_method :scroll_to_top, offset_top
|
99
|
+
else
|
100
|
+
rjs_method :scroll_to_element, :element => element, :args => [offset_top]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
def rjs_method(func, element_or_options = {})
|
107
|
+
if element_or_options.is_a?(Hash)
|
108
|
+
element = element_or_options.delete(:element)
|
109
|
+
content = element_or_options.delete(:content)
|
110
|
+
args = element_or_options.delete(:args) || []
|
111
|
+
else
|
112
|
+
element = element_or_options
|
113
|
+
content = nil
|
114
|
+
args = []
|
115
|
+
end
|
116
|
+
|
117
|
+
if element.is_a?(ActiveRecord::Base) || element.is_a?(Array)
|
118
|
+
elem = dom_id(*Array(element))
|
119
|
+
js_function = "#{func}_by_id".camelize(:lower)
|
120
|
+
else
|
121
|
+
elem = element.to_s
|
122
|
+
js_function = func.to_s.camelize(:lower)
|
123
|
+
end
|
124
|
+
js_args = []
|
125
|
+
js_args << elem if elem
|
126
|
+
js_args << rendered_content(content) if content
|
127
|
+
js_args += args
|
128
|
+
|
129
|
+
%{rjsHelpers.#{js_function}(#{string_args(js_args)});}
|
130
|
+
end
|
131
|
+
|
132
|
+
def string_args(args)
|
133
|
+
args.map {|a| a.is_a?(Numeric) ? a : "'#{a}'"}.join(', ')
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
# Processes the given content.
|
138
|
+
# Strings are simply forwarded while Hashes
|
139
|
+
# are passed to Rails' +render+ function.
|
140
|
+
# Also, it automatically escapes javascript in the given content
|
141
|
+
#--------------------------------------------------------------
|
142
|
+
def rendered_content(content)
|
143
|
+
escape_javascript(content.is_a?(Hash) ? render(content) : content)
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class RjsHelpersGenerator < Rails::Generator::NamedBase
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
m.file File.join('assets', 'js', 'rjs_helper.js'), File.join('public', 'javascripts', 'rjs_helper.js')
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def banner
|
11
|
+
"Usage: #{$0} rjs_helpers js"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
// Generated by CoffeeScript 1.3.3
|
2
|
+
(function() {
|
3
|
+
|
4
|
+
window.rjsHelpers = {
|
5
|
+
updateElement: function(element, content) {
|
6
|
+
return jQuery(element).html(content);
|
7
|
+
},
|
8
|
+
updateElementById: function(element, content) {
|
9
|
+
return this.updateElement("#" + element, content);
|
10
|
+
},
|
11
|
+
replaceElement: function(element, content) {
|
12
|
+
return jQuery(element).replaceWith(content);
|
13
|
+
},
|
14
|
+
replaceElementById: function(element, content) {
|
15
|
+
return this.replaceElement("#" + element, content);
|
16
|
+
},
|
17
|
+
removeElement: function(element) {
|
18
|
+
return jQuery(element).remove();
|
19
|
+
},
|
20
|
+
removeElementById: function(element) {
|
21
|
+
return this.removeElement("#" + element);
|
22
|
+
},
|
23
|
+
appendElement: function(element, content) {
|
24
|
+
return jQuery(element).append(content);
|
25
|
+
},
|
26
|
+
appendElementById: function(element, content) {
|
27
|
+
return this.appendElement("#" + element, content);
|
28
|
+
},
|
29
|
+
prependElement: function(element, content) {
|
30
|
+
return jQuery(element).prepend(content);
|
31
|
+
},
|
32
|
+
prependElementById: function(element, content) {
|
33
|
+
return this.prependElement("#" + element, content);
|
34
|
+
},
|
35
|
+
hideElement: function(element) {
|
36
|
+
return jQuery(element).hide();
|
37
|
+
},
|
38
|
+
hideElementById: function(element) {
|
39
|
+
return this.hideElement("#" + element);
|
40
|
+
},
|
41
|
+
showElement: function(element) {
|
42
|
+
return jQuery(element).show();
|
43
|
+
},
|
44
|
+
showElementById: function(element) {
|
45
|
+
return this.showElement("#" + element);
|
46
|
+
},
|
47
|
+
toggleElement: function(element) {
|
48
|
+
return jQuery(element).toggle();
|
49
|
+
},
|
50
|
+
toggleElementById: function(element) {
|
51
|
+
return this.toggleElement("#" + element);
|
52
|
+
},
|
53
|
+
scrollToElement: function(element, offsetTop) {
|
54
|
+
if (offsetTop == null) {
|
55
|
+
offsetTop = 0;
|
56
|
+
}
|
57
|
+
jQuery('html, body').animate({
|
58
|
+
scrollTop: jQuery(element).offset().top - offsetTop
|
59
|
+
}, 1000);
|
60
|
+
return false;
|
61
|
+
},
|
62
|
+
scrollToElementById: function(element) {
|
63
|
+
return this.scrollToElement("#" + element);
|
64
|
+
},
|
65
|
+
scrollToTop: function(offsetTop) {
|
66
|
+
if (offsetTop == null) {
|
67
|
+
offsetTop = 0;
|
68
|
+
}
|
69
|
+
jQuery("html, body").animate({
|
70
|
+
scrollTop: offsetTop
|
71
|
+
}, 600);
|
72
|
+
return false;
|
73
|
+
},
|
74
|
+
redirectTo: function(url) {
|
75
|
+
return window.location.href = url;
|
76
|
+
}
|
77
|
+
};
|
78
|
+
|
79
|
+
}).call(this);
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/rails/init'
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/rjs_helpers.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# RailsJsHelpers
|
data/rails/init.rb
ADDED
data/rjs_helpers.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rjs_helpers/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rjs_helpers'
|
8
|
+
spec.version = RjsHelpers::VERSION
|
9
|
+
spec.authors = ['Stefan Exner']
|
10
|
+
spec.email = ['stexmedia@googlemail.com']
|
11
|
+
spec.description = %q{Some helper methods to perform standard JS library tasks from js.erb without having to write actual javascript}
|
12
|
+
spec.summary = %q{Some helper methods to perform standard JS library tasks from js.erb without having to write actual javascript}
|
13
|
+
spec.homepage = 'https://github.com/Stex/rjs_helpers'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake', '0.9.2.2'
|
23
|
+
spec.add_development_dependency 'barista'
|
24
|
+
end
|
data/test/test_helper.rb
ADDED
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rjs_helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Stefan Exner
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-09-10 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 9
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 3
|
32
|
+
version: "1.3"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rake
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - "="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 11
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
- 9
|
47
|
+
- 2
|
48
|
+
- 2
|
49
|
+
version: 0.9.2.2
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: barista
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
description: Some helper methods to perform standard JS library tasks from js.erb without having to write actual javascript
|
67
|
+
email:
|
68
|
+
- stexmedia@googlemail.com
|
69
|
+
executables: []
|
70
|
+
|
71
|
+
extensions: []
|
72
|
+
|
73
|
+
extra_rdoc_files: []
|
74
|
+
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- MIT-LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- app/coffeescripts/rjs_helper.coffee
|
83
|
+
- app/helpers/rjs_helper.rb
|
84
|
+
- generators/rjs_helpers/rjs_helpers_generator.rb
|
85
|
+
- generators/rjs_helpers/templates/assets/js/rjs_helper.js
|
86
|
+
- init.rb
|
87
|
+
- install.rb
|
88
|
+
- lib/rjs_helpers.rb
|
89
|
+
- lib/rjs_helpers/version.rb
|
90
|
+
- lib/tasks/rjs_helpers.rake
|
91
|
+
- rails/init.rb
|
92
|
+
- rjs_helpers.gemspec
|
93
|
+
- test/rjs_helpers_test.rb
|
94
|
+
- test/test_helper.rb
|
95
|
+
- uninstall.rb
|
96
|
+
homepage: https://github.com/Stex/rjs_helpers
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 3
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
version: "0"
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
hash: 3
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
version: "0"
|
122
|
+
requirements: []
|
123
|
+
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 1.8.26
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: Some helper methods to perform standard JS library tasks from js.erb without having to write actual javascript
|
129
|
+
test_files:
|
130
|
+
- test/rjs_helpers_test.rb
|
131
|
+
- test/test_helper.rb
|