coolstrap-generator 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Rakefile +6 -0
- data/bin/coolstrap +5 -0
- data/coolstrap-generator.gemspec +42 -0
- data/lib/.DS_Store +0 -0
- data/lib/coolstrap-generator.rb +39 -0
- data/lib/coolstrap-generator/.DS_Store +0 -0
- data/lib/coolstrap-generator/builder/middleman.rb +0 -0
- data/lib/coolstrap-generator/cli.rb +71 -0
- data/lib/coolstrap-generator/generate/project.rb +96 -0
- data/lib/coolstrap-generator/generate/view.rb +54 -0
- data/lib/coolstrap-generator/logger.rb +13 -0
- data/lib/coolstrap-generator/middleman/helpers.rb +176 -0
- data/lib/coolstrap-generator/templates/.DS_Store +0 -0
- data/lib/coolstrap-generator/templates/app/.DS_Store +0 -0
- data/lib/coolstrap-generator/templates/app/assets/.DS_Store +0 -0
- data/lib/coolstrap-generator/templates/app/assets/fonts/fontawesome-webfont.eot +0 -0
- data/lib/coolstrap-generator/templates/app/assets/fonts/fontawesome-webfont.svg +255 -0
- data/lib/coolstrap-generator/templates/app/assets/fonts/fontawesome-webfont.ttf +0 -0
- data/lib/coolstrap-generator/templates/app/assets/fonts/fontawesome-webfont.woff +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/.DS_Store +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/coolstrap/arrow-list.png +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/coolstrap/arrow.png +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/coolstrap/menu.png +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/coolstrap/startup/smatphone.png +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/coolstrap/startup/smatphone@2x.png +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/coolstrap/startup/tablet-landscape.png +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/coolstrap/startup/tablet-landscape@2x.png +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/coolstrap/startup/tablet-portrait.png +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/coolstrap/startup/tablet-portrait@2x.png +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/startup/smatphone.png +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/startup/smatphone@2x.png +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/startup/tablet-landscape.png +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/startup/tablet-landscape@2x.png +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/startup/tablet-portrait.png +0 -0
- data/lib/coolstrap-generator/templates/app/assets/images/startup/tablet-portrait@2x.png +0 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/.DS_Store +0 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/app.js +18 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/_Coolstrap.App.coffee +39 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/_Coolstrap.Console.coffee +49 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/_Coolstrap.Constants.coffee +89 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/_Coolstrap.js +13 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/build/_wrap-start.js +18 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/coolstrap-0.1.js +20 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/coolstrap-0.1.packed.js +23 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/fallback/_Coolstrap.Fallback.Android.coffee +53 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/fallback/_Coolstrap.Fallback.iOS.coffee +29 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/framework/_Coolstrap.Framework.Articles.coffee +34 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/framework/_Coolstrap.Framework.Dialogs.coffee +33 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/framework/_Coolstrap.Framework.Navigation.coffee +118 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/framework/_Coolstrap.Framework.Sections.coffee +60 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/lib/iscroll.js +1076 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/lib/modernizr-2.5.3.js +1265 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/lib/zepto-1.0rc1.js +1357 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/navigate/_Coolstrap.Navigate.History.coffee +164 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/navigate/_Coolstrap.Navigate.coffee +105 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/plugins/_Coolstrap.Plugins.coffee +157 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/util/_Coolstrap.Util.Core.coffee +54 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/util/_Coolstrap.Util.Platform.coffee +89 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/util/_Coolstrap.Util.UI.coffee +96 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/util/_Coolstrap.Util.coffee +41 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/view/_Coolstrap.View.Article.coffee +43 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/view/_Coolstrap.View.Aside.coffee +65 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/view/_Coolstrap.View.Dialog.coffee +129 -0
- data/lib/coolstrap-generator/templates/app/assets/javascripts/coolstrap/view/_Coolstrap.View.Scroll.coffee +191 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/.DS_Store +0 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/_structure.scss +8 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/coolstrap.css.scss +2 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/_components.scss +5 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/_layout.scss +4 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/_utilities.scss +6 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/components/_dialog.scss +122 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/components/_formelements.scss +89 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/components/_listview.scss +76 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/components/_navigations.scss +192 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/components/_tools.scss +169 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/layout/_layers.scss +57 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/layout/_layout.scss +62 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/layout/_positions.scss +38 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/layout/_transitions.scss +35 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/utilities/_animate.scss +63 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/utilities/_helpers.scss +82 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/utilities/_icons.scss +336 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/utilities/_mixins.scss +45 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/utilities/_reset.scss +367 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/structure/utilities/_variables.scss +176 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/themes/_default.scss +255 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/coolstrap/themes/coolstrap.css.scss +164 -0
- data/lib/coolstrap-generator/templates/app/assets/stylesheets/customtheme.css.scss +19 -0
- data/lib/coolstrap-generator/templates/app/components/_formelements.html.haml +130 -0
- data/lib/coolstrap-generator/templates/app/components/_tabbar.html.haml +343 -0
- data/lib/coolstrap-generator/templates/app/components/_toolbar.html.haml +463 -0
- data/lib/coolstrap-generator/templates/app/components/formelements.html.haml +196 -0
- data/lib/coolstrap-generator/templates/app/components/listview/_complexlistavatar.html.haml.erb +77 -0
- data/lib/coolstrap-generator/templates/app/components/listview/_simplelist.html.haml.erb +31 -0
- data/lib/coolstrap-generator/templates/app/components/tabbar.html.haml.erb +16 -0
- data/lib/coolstrap-generator/templates/app/components/toolbar.html.haml.erb +32 -0
- data/lib/coolstrap-generator/templates/app/index.html.haml.erb +21 -0
- data/lib/coolstrap-generator/templates/app/layout.haml.erb +79 -0
- data/lib/coolstrap-generator/templates/app/views/.DS_Store +0 -0
- data/lib/coolstrap-generator/templates/app/views/_home.haml.erb +31 -0
- data/lib/coolstrap-generator/templates/app/views/shared/_aside_onbottom.haml +2 -0
- data/lib/coolstrap-generator/templates/app/views/shared/_aside_onleft.haml +56 -0
- data/lib/coolstrap-generator/templates/app/views/shared/_aside_onright.haml +66 -0
- data/lib/coolstrap-generator/templates/app/views/shared/_aside_ontop.haml +19 -0
- data/lib/coolstrap-generator/templates/defaults/Gemfile.erb +3 -0
- data/lib/coolstrap-generator/templates/defaults/LICENSE.erb +1 -0
- data/lib/coolstrap-generator/templates/defaults/Readme.mkd.erb +1 -0
- data/lib/coolstrap-generator/templates/defaults/config.erb +42 -0
- data/lib/coolstrap-generator/templates/defaults/gitignore.erb +2 -0
- data/lib/coolstrap-generator/templates/rakefile +102 -0
- data/lib/coolstrap-generator/templates/specs/app_spec.coffee +3 -0
- data/lib/coolstrap-generator/utils.rb +82 -0
- data/lib/coolstrap-generator/version.rb +5 -0
- data/readme.md +107 -0
- data/spec/cli/command_spec.rb +88 -0
- data/spec/coolstrap-generator/generate/project_spec.rb +126 -0
- data/spec/coolstrap-generator/generate/view_spec.rb +26 -0
- data/spec/coolstrap-generator/logger_spec.rb +25 -0
- data/spec/coolstrap-generator/middleman/helpers_spec.rb +16 -0
- data/spec/coolstrap-generator/utils_spec.rb +120 -0
- data/spec/spec_helper.rb +39 -0
- metadata +321 -0
@@ -0,0 +1,164 @@
|
|
1
|
+
###
|
2
|
+
* Stores the stack of displayed <sections>
|
3
|
+
* @namespace COOLSTRAP.Navigate
|
4
|
+
* @class History
|
5
|
+
*
|
6
|
+
* @author Abraham Barrera <abarrerac@gmail.com> || @abraham_barrera
|
7
|
+
###
|
8
|
+
|
9
|
+
COOLSTRAP.Navigate.History = ((cool, document, window) ->
|
10
|
+
TARGET = cool.Constants.TARGET
|
11
|
+
STACK =
|
12
|
+
main: []
|
13
|
+
container: {}
|
14
|
+
|
15
|
+
prevent_hash_change = false
|
16
|
+
console = cool.Console
|
17
|
+
_mainStack = ->
|
18
|
+
STACK[TARGET.MAIN]
|
19
|
+
|
20
|
+
_containerStack = (container_id) ->
|
21
|
+
STACK[TARGET.CONTAINER][container_id] = [] unless STACK[TARGET.CONTAINER][container_id]
|
22
|
+
STACK[TARGET.CONTAINER][container_id]
|
23
|
+
|
24
|
+
_containerStackLevel = (container_id) ->
|
25
|
+
if container_id
|
26
|
+
STACK[TARGET.CONTAINER][container_id + "_level"] = size: 0 unless STACK[TARGET.CONTAINER][container_id + "_level"]
|
27
|
+
STACK[TARGET.CONTAINER][container_id + "_level"]
|
28
|
+
else
|
29
|
+
size: 1
|
30
|
+
|
31
|
+
###
|
32
|
+
* Use pushState if is possible
|
33
|
+
*
|
34
|
+
* @method pushState
|
35
|
+
###
|
36
|
+
_pushState = (section_id, container_id) ->
|
37
|
+
prefix = "#main/"
|
38
|
+
prefix = "#" + container_id + "/" if container_id
|
39
|
+
window.history.pushState
|
40
|
+
state: size(container_id)
|
41
|
+
id: section_id
|
42
|
+
, section_id, prefix + cool.Util.cleanUrl(section_id)
|
43
|
+
|
44
|
+
_replaceState = (section_id, container_id) ->
|
45
|
+
prefix = "#main/"
|
46
|
+
prefix = "#" + container_id + "/" if container_id
|
47
|
+
window.history.replaceState
|
48
|
+
state: size(container_id)
|
49
|
+
id: section_id
|
50
|
+
, section_id, prefix + cool.Util.cleanUrl(section_id)
|
51
|
+
|
52
|
+
_back = ->
|
53
|
+
prevent_hash_change = true
|
54
|
+
window.history.back()
|
55
|
+
|
56
|
+
_go = (position) ->
|
57
|
+
prevent_hash_change = true
|
58
|
+
window.history.go position
|
59
|
+
|
60
|
+
_onPopState = (event) ->
|
61
|
+
unless prevent_hash_change
|
62
|
+
console.info "onpopstate"
|
63
|
+
console.info event.state
|
64
|
+
|
65
|
+
_onHashChange = (event) ->
|
66
|
+
unless prevent_hash_change
|
67
|
+
console.info event
|
68
|
+
to_main = /#main/.test(document.location.hash)
|
69
|
+
from_main = /#main/.test(event.oldURL)
|
70
|
+
to_aside = /#aside/.test(document.location.hash)
|
71
|
+
from_aside = /#aside/.test(event.oldURL)
|
72
|
+
console.info "cool.Navigate.back()" if to_main and from_main
|
73
|
+
console.info "back in ASIDE" if to_aside and from_aside
|
74
|
+
console.info "HIDE aside" if to_main and from_aside
|
75
|
+
prevent_hash_change = false
|
76
|
+
|
77
|
+
###
|
78
|
+
* Initializes the Navigation listeners.
|
79
|
+
*
|
80
|
+
* @method setup
|
81
|
+
*
|
82
|
+
###
|
83
|
+
setup = ->
|
84
|
+
window.onpopstate = _onPopState
|
85
|
+
window.onhashchange = _onHashChange
|
86
|
+
|
87
|
+
|
88
|
+
###
|
89
|
+
* Create a new element to the browsing history
|
90
|
+
*
|
91
|
+
* @method add
|
92
|
+
*
|
93
|
+
* @param {string} Id of the section.
|
94
|
+
###
|
95
|
+
add = (options) ->
|
96
|
+
section_id = options.section_id
|
97
|
+
container_id = options.container_id or null
|
98
|
+
replace_state = options.replace_state or false
|
99
|
+
stack = (if not container_id then _mainStack() else _containerStack(container_id))
|
100
|
+
stack.push section_id
|
101
|
+
_containerStackLevel(container_id).size += 1
|
102
|
+
if replace_state
|
103
|
+
_replaceState section_id, container_id
|
104
|
+
else
|
105
|
+
_pushState section_id, container_id
|
106
|
+
|
107
|
+
|
108
|
+
###
|
109
|
+
* Returns the current browsing history section id.
|
110
|
+
*
|
111
|
+
* @method current
|
112
|
+
*
|
113
|
+
* @return {string} Current section id.
|
114
|
+
###
|
115
|
+
current = (container_id) ->
|
116
|
+
stack = (if not container_id then _mainStack() else _containerStack(container_id))
|
117
|
+
stack[stack.length - 1]
|
118
|
+
###
|
119
|
+
* Removes the current item browsing history.
|
120
|
+
*
|
121
|
+
* @method removeLast
|
122
|
+
###
|
123
|
+
removeLast = (container_id) ->
|
124
|
+
stack = (if not container_id then _mainStack() else _containerStack(container_id))
|
125
|
+
stack.length -= 1
|
126
|
+
_containerStackLevel(container_id).size -= 1
|
127
|
+
if container_id and _containerStackLevel(container_id).size is 0
|
128
|
+
section_id = current(container_id)
|
129
|
+
_replaceState section_id, container_id
|
130
|
+
_containerStackLevel(container_id).size = 1
|
131
|
+
else
|
132
|
+
_back()
|
133
|
+
###
|
134
|
+
* Returns lenght of history stack
|
135
|
+
*
|
136
|
+
* @method size
|
137
|
+
###
|
138
|
+
size = (container_id) ->
|
139
|
+
stack = (if not container_id then _mainStack() else _containerStack(container_id))
|
140
|
+
stack.length
|
141
|
+
###
|
142
|
+
* Removes all history on container.
|
143
|
+
*
|
144
|
+
* @method clear
|
145
|
+
###
|
146
|
+
clear = (container_id) ->
|
147
|
+
console.info "clear" + container_id
|
148
|
+
container_id = cool.Util.cleanUrl(container_id) if container_id
|
149
|
+
stack = (if not container_id then _mainStack() else _containerStack(container_id))
|
150
|
+
stack.length -= 1
|
151
|
+
if container_id
|
152
|
+
if _containerStackLevel(container_id).size <= 0
|
153
|
+
_back()
|
154
|
+
else
|
155
|
+
_go -1 * _containerStackLevel(container_id).size
|
156
|
+
_containerStackLevel(container_id).size = 0
|
157
|
+
|
158
|
+
add: add
|
159
|
+
current: current
|
160
|
+
removeLast: removeLast
|
161
|
+
size: size
|
162
|
+
clear: clear
|
163
|
+
setup: setup
|
164
|
+
)(COOLSTRAP, document, window)
|
@@ -0,0 +1,105 @@
|
|
1
|
+
###
|
2
|
+
* Handles the <sections> , <articles> and <asides> to show
|
3
|
+
*
|
4
|
+
* @namespace COOLSTRAP
|
5
|
+
* @class Navigate
|
6
|
+
*
|
7
|
+
* @author Abraham Barrera <abarrerac@gmail.com> || @abraham_barrera
|
8
|
+
###
|
9
|
+
|
10
|
+
COOLSTRAP.Navigate = ((cool) ->
|
11
|
+
ATTRIBUTE = cool.Constants.ATTRIBUTE
|
12
|
+
CLASS = cool.Constants.CLASS
|
13
|
+
ELEMENT = cool.Constants.ELEMENT
|
14
|
+
TRIGGER = cool.Constants.TRIGGER
|
15
|
+
TRANSITION = cool.Constants.TRANSITION
|
16
|
+
COMMAND = cool.Constants.COMMAND
|
17
|
+
_console = cool.Console
|
18
|
+
_existsTarget = (target) ->
|
19
|
+
exists = false
|
20
|
+
if cool.dom(target).length > 0
|
21
|
+
exists = true
|
22
|
+
else
|
23
|
+
_console.warn "Hey! Target doesnt exists: " + target
|
24
|
+
exists
|
25
|
+
|
26
|
+
_getHistoryLength = (container_id) ->
|
27
|
+
cool.Navigate.History.size container_id
|
28
|
+
|
29
|
+
_getHistoryCurrent = (container_id) ->
|
30
|
+
cool.Navigate.History.current container_id
|
31
|
+
|
32
|
+
section = (section_id) ->
|
33
|
+
section_id = cool.Util.parseUrl(section_id)
|
34
|
+
container_id = cool.dom(section_id).parent(ELEMENT.ASIDE).attr(ATTRIBUTE.ID)
|
35
|
+
current = _getHistoryCurrent(container_id)
|
36
|
+
target = ELEMENT.SECTION + section_id
|
37
|
+
if current isnt section_id
|
38
|
+
if _existsTarget(target)
|
39
|
+
cool.dom(current).removeClass(CLASS.SHOW).addClass CLASS.HIDE
|
40
|
+
cool.dom(target).addClass(CLASS.CURRENT).addClass(CLASS.SHOW).trigger TRIGGER.LOAD
|
41
|
+
setTimeout (->
|
42
|
+
cool.dom(current).removeClass CLASS.CURRENT
|
43
|
+
), TRANSITION.DURATION
|
44
|
+
cool.Navigate.History.add
|
45
|
+
section_id: section_id
|
46
|
+
container_id: container_id
|
47
|
+
else
|
48
|
+
_console.warn "WTF! you are here!"
|
49
|
+
|
50
|
+
article = (section_id, article_id) ->
|
51
|
+
section_id = cool.Util.parseUrl(section_id)
|
52
|
+
article_id = cool.Util.parseUrl(article_id)
|
53
|
+
target = ELEMENT.SECTION + section_id + " " + ELEMENT.ARTICLE + article_id
|
54
|
+
if _existsTarget(target)
|
55
|
+
cool.dom(target).trigger TRIGGER.LOAD
|
56
|
+
cool.View.Article.show section_id, article_id
|
57
|
+
|
58
|
+
aside = (aside_id) ->
|
59
|
+
aside_id = cool.Util.parseUrl(aside_id)
|
60
|
+
target = ELEMENT.ASIDE + aside_id
|
61
|
+
if _existsTarget(target)
|
62
|
+
is_visible = cool.dom(target).hasClass(CLASS.CURRENT)
|
63
|
+
if is_visible
|
64
|
+
cool.View.Aside.hide aside_id
|
65
|
+
else
|
66
|
+
cool.View.Aside.show aside_id
|
67
|
+
|
68
|
+
dialog = (dialog_id, options) ->
|
69
|
+
target = ELEMENT.DIALOG + dialog_id
|
70
|
+
dialog_command = undefined
|
71
|
+
dialog_command = options if typeof options is "string"
|
72
|
+
if _existsTarget(target)
|
73
|
+
if dialog_command and dialog_command is COMMAND.CLOSE_DIALOG
|
74
|
+
cool.dom(target).trigger TRIGGER.UNLOAD
|
75
|
+
cool.View.Dialog.close dialog_id
|
76
|
+
else
|
77
|
+
cool.dom(target).trigger TRIGGER.LOAD
|
78
|
+
cool.View.Dialog.show dialog_id, options
|
79
|
+
|
80
|
+
back = (container_id) ->
|
81
|
+
if _getHistoryLength(container_id) > 1
|
82
|
+
current_section = ELEMENT.SECTION + _getHistoryCurrent(container_id)
|
83
|
+
cool.dom(current_section).removeClass(CLASS.SHOW).trigger TRIGGER.UNLOAD
|
84
|
+
setTimeout (->
|
85
|
+
cool.dom(current_section).removeClass CLASS.CURRENT
|
86
|
+
), TRANSITION.DURATION
|
87
|
+
cool.Navigate.History.removeLast container_id
|
88
|
+
cool.dom(_getHistoryCurrent(container_id)).addClass(CLASS.CURRENT).removeClass(CLASS.HIDE).addClass CLASS.SHOW
|
89
|
+
else
|
90
|
+
_console.warn "Hey! Nothing back"
|
91
|
+
|
92
|
+
URL = (url, options) ->
|
93
|
+
options = options or {}
|
94
|
+
options.new_window = options.new_window or false
|
95
|
+
if options.new_window
|
96
|
+
window.open url
|
97
|
+
else
|
98
|
+
|
99
|
+
section: section
|
100
|
+
article: article
|
101
|
+
aside: aside
|
102
|
+
dialog: dialog
|
103
|
+
back: back
|
104
|
+
URL: URL
|
105
|
+
)(COOLSTRAP)
|
@@ -0,0 +1,157 @@
|
|
1
|
+
###
|
2
|
+
* Coolstrapp Plugins
|
3
|
+
*
|
4
|
+
* @namespace COOLSTRAP
|
5
|
+
* @class Plugins
|
6
|
+
*
|
7
|
+
* @author Cristian Ferrari <cristianferrarig@gmail.com> || @energettico
|
8
|
+
* @author Abraham Barrera <abarrerac@gmail.com> || @abraham_barrera
|
9
|
+
*
|
10
|
+
###
|
11
|
+
|
12
|
+
COOLSTRAP.Plugins = ((cool, document) ->
|
13
|
+
# fn arg can be an object or a function, thanks to handleEvent
|
14
|
+
# read more about the explanation at: http://www.thecssninja.com/javascript/handleevent
|
15
|
+
addEvt = (el, evt, fn, bubble) ->
|
16
|
+
if "addEventListener" of el
|
17
|
+
# BBOS6 doesn't support handleEvent, catch and polyfill
|
18
|
+
try
|
19
|
+
el.addEventListener evt, fn, bubble
|
20
|
+
catch e
|
21
|
+
if typeof fn is "object" and fn.handleEvent
|
22
|
+
el.addEventListener evt, ((e) ->
|
23
|
+
# Bind fn as this and set first arg as event object
|
24
|
+
fn.handleEvent.call fn, e
|
25
|
+
), bubble
|
26
|
+
else
|
27
|
+
throw e
|
28
|
+
else if "attachEvent" of el
|
29
|
+
# check if the callback is an object and contains handleEvent
|
30
|
+
if typeof fn is "object" and fn.handleEvent
|
31
|
+
el.attachEvent "on" + evt, ->
|
32
|
+
# Bind fn as this
|
33
|
+
fn.handleEvent.call fn
|
34
|
+
else
|
35
|
+
el.attachEvent "on" + evt, fn
|
36
|
+
rmEvt = (el, evt, fn, bubble) ->
|
37
|
+
if "removeEventListener" of el
|
38
|
+
# BBOS6 doesn't support handleEvent, catch and polyfill
|
39
|
+
try
|
40
|
+
el.removeEventListener evt, fn, bubble
|
41
|
+
catch e
|
42
|
+
if typeof fn is "object" and fn.handleEvent
|
43
|
+
el.removeEventListener evt, ((e) ->
|
44
|
+
# Bind fn as this and set first arg as event object
|
45
|
+
fn.handleEvent.call fn, e
|
46
|
+
), bubble
|
47
|
+
else
|
48
|
+
throw e
|
49
|
+
else if "detachEvent" of el
|
50
|
+
# check if the callback is an object and contains handleEvent
|
51
|
+
if typeof fn is "object" and fn.handleEvent
|
52
|
+
el.detachEvent "on" + evt, ->
|
53
|
+
# Bind fn as this
|
54
|
+
fn.handleEvent.call fn
|
55
|
+
else
|
56
|
+
el.detachEvent "on" + evt, fn
|
57
|
+
hadTouchEvent = false
|
58
|
+
|
59
|
+
###
|
60
|
+
* Fast Buttons
|
61
|
+
* fastButton is used to make instant responsive buttons,
|
62
|
+
* 300ms faster to be exact.
|
63
|
+
*
|
64
|
+
* new COOLSTRAP.Plugins.fastButton(document.getElementById('myBtn'), function() { // do something });
|
65
|
+
*
|
66
|
+
* Inspired by MBP
|
67
|
+
* https://github.com/h5bp/mobile-boilerplate/blob/master/js/helper.js
|
68
|
+
###
|
69
|
+
|
70
|
+
fastButton = (element, handler) ->
|
71
|
+
@handler = handler
|
72
|
+
if element.length and element.length > 1
|
73
|
+
for singleElIdx of element
|
74
|
+
@addClickEvent element[singleElIdx]
|
75
|
+
else
|
76
|
+
@addClickEvent element
|
77
|
+
|
78
|
+
fastButton::handleEvent = (event) ->
|
79
|
+
event = event or window.event
|
80
|
+
switch event.type
|
81
|
+
when "touchstart"
|
82
|
+
@onTouchStart event
|
83
|
+
when "touchmove"
|
84
|
+
@onTouchMove event
|
85
|
+
when "touchend"
|
86
|
+
@onClick event
|
87
|
+
when "click"
|
88
|
+
@onClick event
|
89
|
+
|
90
|
+
fastButton::onTouchStart = (event) ->
|
91
|
+
element = event.srcElement
|
92
|
+
event.stopPropagation()
|
93
|
+
element.addEventListener "touchend", this, false
|
94
|
+
document.body.addEventListener "touchmove", this, false
|
95
|
+
@startX = event.touches[0].clientX
|
96
|
+
@startY = event.touches[0].clientY
|
97
|
+
element.style.backgroundColor = "rgba(0,0,0,.7)"
|
98
|
+
|
99
|
+
fastButton::onTouchMove = (event) ->
|
100
|
+
@reset element if Math.abs(event.touches[0].clientX - @startX) > 10 or Math.abs(event.touches[0].clientY - @startY) > 10
|
101
|
+
|
102
|
+
fastButton::onClick = (event) ->
|
103
|
+
event = event or window.event
|
104
|
+
element = event.srcElement
|
105
|
+
event.stopPropagation() if event.stopPropagation
|
106
|
+
@reset event
|
107
|
+
@handler.apply event.currentTarget, [ event ]
|
108
|
+
preventGhostClick @startX, @startY if event.type is "touchend"
|
109
|
+
element.style.backgroundColor = ""
|
110
|
+
|
111
|
+
fastButton::reset = (event) ->
|
112
|
+
element = event.srcElement
|
113
|
+
rmEvt element, "touchend", this, false
|
114
|
+
rmEvt document.body, "touchmove", this, false
|
115
|
+
element.style.backgroundColor = ""
|
116
|
+
|
117
|
+
fastButton::addClickEvent = (element) ->
|
118
|
+
addEvt element, "touchstart", this, false
|
119
|
+
addEvt element, "click", this, false
|
120
|
+
|
121
|
+
preventGhostClick = (x, y) ->
|
122
|
+
coords.push x, y
|
123
|
+
window.setTimeout (->
|
124
|
+
coords.splice 0, 2
|
125
|
+
), 2500
|
126
|
+
|
127
|
+
ghostClickHandler = (event) ->
|
128
|
+
if not hadTouchEvent and "ontouchstart" of window
|
129
|
+
###
|
130
|
+
This is a bit of fun for Android 2.3...
|
131
|
+
If you change window.location via fastButton, a click event will fire
|
132
|
+
on the new page, as if the events are continuing from the previous page.
|
133
|
+
We pick that event up here, but coords is empty, because it's a new page,
|
134
|
+
so we don't prevent it. Here's we're assuming that click events on touch devices
|
135
|
+
that occur without a preceding touchStart are to be ignored.
|
136
|
+
###
|
137
|
+
event.stopPropagation()
|
138
|
+
event.preventDefault()
|
139
|
+
return
|
140
|
+
i = 0
|
141
|
+
len = coords.length
|
142
|
+
|
143
|
+
while i < len
|
144
|
+
x = coords[i]
|
145
|
+
y = coords[i + 1]
|
146
|
+
if Math.abs(event.clientX - x) < 25 and Math.abs(event.clientY - y) < 25
|
147
|
+
event.stopPropagation()
|
148
|
+
event.preventDefault()
|
149
|
+
i += 2
|
150
|
+
|
151
|
+
document.addEventListener "click", ghostClickHandler, true if document.addEventListener
|
152
|
+
addEvt document.documentElement, "touchstart", (->
|
153
|
+
hadTouchEvent = true
|
154
|
+
), false
|
155
|
+
coords = []
|
156
|
+
fastButton: fastButton
|
157
|
+
)(COOLSTRAP, document)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
###
|
2
|
+
* Coolstrap Core functions
|
3
|
+
*
|
4
|
+
* @namespace COOLSTRAP.Util
|
5
|
+
* @class Core
|
6
|
+
*
|
7
|
+
* @author Abraham Barrera <abarrerac@gmail.com> || @abraham_barrera
|
8
|
+
* Inspired by LungoJS
|
9
|
+
###
|
10
|
+
|
11
|
+
COOLSTRAP.Util.Core = ((cool) ->
|
12
|
+
_toArray = (obj) ->
|
13
|
+
Array::slice.call obj, 0
|
14
|
+
|
15
|
+
_getType = (obj) ->
|
16
|
+
Object::toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
###
|
21
|
+
* Executes callbacks based on the parameters received.
|
22
|
+
*
|
23
|
+
* @method execute
|
24
|
+
*
|
25
|
+
* @param {Function} callback to execute
|
26
|
+
###
|
27
|
+
execute = ->
|
28
|
+
args = _toArray(arguments)
|
29
|
+
callback = args.shift()
|
30
|
+
callback.apply null, args if _getType(callback) is "function"
|
31
|
+
|
32
|
+
###
|
33
|
+
* Mix two objects
|
34
|
+
*
|
35
|
+
* @method extend
|
36
|
+
*
|
37
|
+
* @param {object} arguments to mix them all into a new object.
|
38
|
+
* @return {object} child a new object with all the objects from the arguments mixed.
|
39
|
+
###
|
40
|
+
extend = ->
|
41
|
+
child = child or {}
|
42
|
+
arg = 0
|
43
|
+
len = arguments.length
|
44
|
+
|
45
|
+
while arg < len
|
46
|
+
argument = arguments[arg]
|
47
|
+
for prop of argument
|
48
|
+
child[prop] = argument[prop]
|
49
|
+
arg++
|
50
|
+
child
|
51
|
+
|
52
|
+
execute: execute
|
53
|
+
extend: extend
|
54
|
+
)(COOLSTRAP)
|