forked from garrett/magicmockup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagicmockup.coffee.bak
212 lines (150 loc) · 5.9 KB
/
magicmockup.coffee.bak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* $ = @jQuery */
/* @magicmockup = do -> */
/* $doc = $(@document) */
/* layers = {} */
/* filter = {} */
/* defaultLayer = '' */
/* # Convenience function to grab attributes from the Inkscape namespace */
/* _getInk = (el, attr) -> */
/* inkNS = 'http://www.inkscape.org/namespaces/inkscape' */
/* el.getAttributeNS(inkNS, attr) */
/* # Add each layer to the layer object (if it contains a an Inkscape label) */
/* _initLayers = ($layers = $('g')) -> */
/* $layers.each -> */
/* group = _getInk(@, 'groupmode') */
/* label = _getInk(@, 'label') */
/* if group is 'layer' */
/* layers[label] = $ @ */
/* return */
/* # Find all filters and store in the filter object */
/* _findFilters = -> */
/* $doc.find('filter').each -> */
/* label = _getInk(@, 'label') */
/* filter[label] = @id */
/* # Convenience function to get jQuery object of group by id */
/* # If id isn't found, try layer labels */
/* $group = (id) -> */
/* group = $ "##{id}" */
/* if group.length > 0 */
/* group */
/* else */
/* layers[id] */
/* # Do the heavy lifting */
/* # (right now, there's only "next" for switching pages; more to come) */
/* _dispatch = (context, [command, val]) -> */
/* act = */
/* load: (url) -> */
/* url = url.shift() */
/* window.location = url || val */
/* next: (location) -> */
/* location = location.shift() */
/* if location.match /#/ */
/* # if "#" is added, then load the new page */
/* act.load(location) */
/* else */
/* # Hide the current visible layer */
/* $(context).parents('g').not('[style=display:none]').last().hide() */
/* # Show the specified layer */
/* $group(location).show?() */
/* window.location.hash = location */
/* show: (showgroups) -> */
/* for group in showgroups */
/* $group(group).show?() */
/* hide: (hidegroups) -> */
/* for group in hidegroups */
/* $group(group).hide?() */
/* toggle: (togglegroups) -> */
/* for group in togglegroups */
/* $group(group).toggle?() */
/* fadeOut: (params) -> */
/* if params? and params.length > 0 */
/* # Capture parameters with defaults */
/* id = params[0] */
/* time = params[1] ? 1 */
/* easing = params[2] ? 'linear' */
/* # Convert time from seconds to milliseconds */
/* time = parseInt(time) * 1000 */
/* $group(id) */
/* .attr('opacity', 1) */
/* .animate svgOpacity: 0.0, time, easing, () -> */
/* # Reset opacity but hide */
/* $(this).hide().attr 'opacity', 1 */
/* params = val?.split ',' */
/* act[command]?(params) */
/* # Return the description for an element */
/* _getDescription = (el) -> */
/* $(el).children('desc').text() */
/* # If there's inline JS, strip it (and provide warnings) */
/* _stripInlineJS = -> */
/* $onclick = $('[onclick]') */
/* return unless $onclick.length */
/* # Warn about inline JS (if console.warn is available) */
/* if console and console.warn */
/* console.group? 'Warning: inline JavaScript found (and deactivated)' */
/* $onclick.each -> console.warn @id, ':', @onclick */
/* console.groupEnd?() */
/* # Strip the inline JS */
/* $onclick.each -> @onclick = undefined */
/* return */
/* # Return the URL fragment */
/* _getHash = -> */
/* window.location.hash.substr(1) */
/* # Hide all top-level groups */
/* _hideGroups = -> */
/* $('svg > g').hide() */
/* # Make a group visible */
/* _showGroup = (group) -> */
/* if typeof group isnt 'string' */
/* group = _getHash() */
/* # Make sure the group exists */
/* return unless $group(group).length > 0 or group is '' */
/* _hideGroups() */
/* _dispatch @, ['next', group] */
/* # If a hash is specified, view the appropriate group */
/* _setInitialPage = -> */
/* group = _getHash() */
/* if group */
/* _showGroup group */
/* # Handle clicks on items with instructions */
/* _handleClick = (e) -> */
/* actions = _getDescription(e.currentTarget) */
/* # Skip if there's no description */
/* return unless actions */
/* for action in actions.split /([\s\n]+)/ */
/* _dispatch @, action.split /\=/ */
/* return */
/* # Change the cursor for interactive elements */
/* _handleHover = (e) -> */
/* $this = $(this) */
/* isHovered = e.type is "mouseenter" */
/* # Skip if there's no description */
/* return unless _getDescription(e.currentTarget) */
/* # Alter hover CSS if there's a hover filter */
/* if filter.hover */
/* hover = if isHovered then "url(##{filter.hover})" else "none" */
/* $this.css filter: hover */
/* # Skip if already hoverable */
/* return if $this.data('hoverable') */
/* # We're handling the hoverable state now */
/* $this.data('hoverable', true).css(cursor: 'pointer') */
/* return */
/* # This function binds the correct events to trigger elements. */
/* # Trigger elements are any element with a 'desc' child element. */
/* # If new trigger elements will be added to the SVG DOM, */
/* # this function should be called afterwards to */
/* # ensure they are correctly bound. */
/* bindTriggers = () -> */
/* ($ 'desc').parent() */
/* .click(_handleClick) */
/* .hover(_handleHover) */
/* # Run on page load */
/* init = (loadEvent) -> */
/* _initLayers() */
/* _setInitialPage() */
/* _findFilters() */
/* _stripInlineJS() */
/* $(window).bind 'hashchange', _showGroup */
/* bindTriggers() */
/* {init, bindTriggers} # Public exports */
/* # Hack to attach the init to <svg/> for an unobtrusive SVG onload */
/* $('svg').attr onload: 'magicmockup.init()' */