auto_js 0.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: ab8ce7dfe13e1771423e9ccdcfa319df2276b2b5
4
+ data.tar.gz: 61617b41c707b25ffe469f864aacdab91821a3eb
5
+ SHA512:
6
+ metadata.gz: 63e0820ff9ca118bc6a2411f997707637e574a97cc07b29e6beac9564281bd3e75a4b96f719d97751c11988e7722e910b3ddaf9957d41de45dc051370b2113f0
7
+ data.tar.gz: 5f6de79c1627382399541681df1c6c99e4fc905e7e69211dadbde4ec5accbdcb20c06ec45654acbd7a93d2dcab84cadfd31e385b08581fe978deb5272501584e
@@ -0,0 +1,134 @@
1
+ do ->
2
+
3
+ app_name = "auto_js_rails"
4
+ version_number = "0.9.0"
5
+
6
+ ###
7
+ # auto_js configuration
8
+ # The following variables set up the JS Organization environment
9
+ # Will be available at global scope i.e. accessible at window['my_rails_app']
10
+ ###
11
+ window['auto_js_rails'] = {}
12
+ window['auto_js_rails'].version = version_number
13
+ window['auto_js_rails'].app_name = app_name
14
+
15
+ ###
16
+ # The main object, at global scope, which contains all the JS code for the rails app.
17
+ ###
18
+ window[ app_name ] = {}
19
+ self = window[app_name]
20
+
21
+ ##
22
+ # window.app_name.scopes is a wrapper to keep all the page/controller specific code separated
23
+ # from any utility functions or app variables
24
+ ##
25
+ self.scopes = {}
26
+
27
+ ##
28
+ # window.app_name.utils is a wrapper for all the JS code that may be needed in multiple
29
+ # controllers / view combinations, such as form validators
30
+ ##
31
+ self.utils = {}
32
+
33
+ ##
34
+ # window.app_name.vars is a wrapper for all the app-wide variables that may be needed
35
+ ##
36
+ self.vars = {}
37
+
38
+
39
+ ###
40
+ # Convenience method for setting an alias to access auto_js.
41
+ # By default, the js code is accessible at window['auto_js_rails']
42
+ # By specifying an alias, the js code is acessible at 'alias'
43
+ ###
44
+ self.set_alias = (name) ->
45
+
46
+ if( window[ name ] )
47
+ console.error("Error: '" + name + "' is already used at the global scope and can't be used as an alias for auto_js_rails.")
48
+
49
+ else
50
+ window[ name ] = window['auto_js_rails']
51
+
52
+ return
53
+
54
+ ###
55
+ # Calls the appropriate block of JS for the provided controller and action.
56
+ # The second parameter is optional, with a default of "_init".
57
+ # If the provided controller and action don't resolve to a function, _exec silently returns
58
+ ###
59
+ self.scopes._exec = (controller, action) ->
60
+
61
+ action = if action == undefined then 'init' else action
62
+
63
+ valid_call = controller != '' and self.scopes[controller] and typeof self.scopes[controller][action] == 'function'
64
+
65
+ if valid_call
66
+ self.scopes[controller][action]()
67
+
68
+ return
69
+
70
+ ###
71
+ # Runs the common js code required for the main app
72
+ # Also calls _page_init() as, if _app_init() runs this is the first page load
73
+ ###
74
+ self.scopes._app_init = ->
75
+
76
+ if ! self.vars._app_initialized
77
+
78
+ self.scopes._exec '_application'
79
+
80
+ self.vars._app_initialized = true
81
+
82
+ self.scopes._page_init()
83
+
84
+ return
85
+
86
+
87
+ ###
88
+ # Runs the common js code required for the current page, which includes controller init
89
+ # as well as view specific code
90
+ ###
91
+ self.scopes._page_init = ->
92
+
93
+ if self.vars._page_initialized
94
+ return
95
+
96
+ controller = document.body.getAttribute('data-controller')
97
+ action = document.body.getAttribute('data-action')
98
+
99
+ self.scopes._exec controller
100
+ self.scopes._exec controller, action
101
+
102
+ self.vars._page_initialized = true
103
+
104
+ return
105
+
106
+
107
+ ###
108
+ # Keeps track of whether or not we need to re-run the page initializer (for turbolinks)
109
+ ###
110
+ self.vars._app_initialized = false
111
+ self.vars._page_initialized = false
112
+
113
+
114
+ ###
115
+ # If this is running, a full context reload was executed. The app needs reinitialized.
116
+ # This doesn't get fired if turbolinks is handling the navigation transition
117
+ ###
118
+ $(document).ready self.scopes._app_init
119
+
120
+
121
+ document.addEventListener 'page:before-unload', ->
122
+ self.vars._page_initialized = false
123
+
124
+ ###
125
+ # document.ready doesn't get fired on turbolinks load. Bind an event to handle the
126
+ # ajax page loading events triggered by turbolinks
127
+ ###
128
+ document.addEventListener 'page:change', ->
129
+
130
+ self.scopes._page_init()
131
+
132
+ return
133
+
134
+ return
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auto_js
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Fuller
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Easily organizes a project's custom javascript and executes appropriate
14
+ snippits automatically. Turbolinks compatible.
15
+ email: lasaldan@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - app/assets/javascripts/auto_js.coffee
21
+ homepage: http://rubygems.org/gems/auto_js
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.4.5
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Auto-executes javascript based on current view
45
+ test_files: []