fomantic-ui-sass 2.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +27 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +5 -0
  5. data/CHANGELOG.md +370 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +177 -0
  9. data/Rakefile +8 -0
  10. data/app/assets/fonts/semantic-ui/brand-icons.eot +0 -0
  11. data/app/assets/fonts/semantic-ui/brand-icons.svg +1008 -0
  12. data/app/assets/fonts/semantic-ui/brand-icons.ttf +0 -0
  13. data/app/assets/fonts/semantic-ui/brand-icons.woff +0 -0
  14. data/app/assets/fonts/semantic-ui/brand-icons.woff2 +0 -0
  15. data/app/assets/fonts/semantic-ui/icons.eot +0 -0
  16. data/app/assets/fonts/semantic-ui/icons.otf +0 -0
  17. data/app/assets/fonts/semantic-ui/icons.svg +1518 -0
  18. data/app/assets/fonts/semantic-ui/icons.ttf +0 -0
  19. data/app/assets/fonts/semantic-ui/icons.woff +0 -0
  20. data/app/assets/fonts/semantic-ui/icons.woff2 +0 -0
  21. data/app/assets/fonts/semantic-ui/outline-icons.eot +0 -0
  22. data/app/assets/fonts/semantic-ui/outline-icons.svg +366 -0
  23. data/app/assets/fonts/semantic-ui/outline-icons.ttf +0 -0
  24. data/app/assets/fonts/semantic-ui/outline-icons.woff +0 -0
  25. data/app/assets/fonts/semantic-ui/outline-icons.woff2 +0 -0
  26. data/app/assets/images/semantic-ui/flags.png +0 -0
  27. data/app/assets/javascripts/semantic-ui.js +27 -0
  28. data/app/assets/javascripts/semantic-ui/accordion.js +613 -0
  29. data/app/assets/javascripts/semantic-ui/api.js +1167 -0
  30. data/app/assets/javascripts/semantic-ui/calendar.js +1476 -0
  31. data/app/assets/javascripts/semantic-ui/checkbox.js +828 -0
  32. data/app/assets/javascripts/semantic-ui/colorize.js +280 -0
  33. data/app/assets/javascripts/semantic-ui/dimmer.js +735 -0
  34. data/app/assets/javascripts/semantic-ui/dropdown.js +4030 -0
  35. data/app/assets/javascripts/semantic-ui/embed.js +706 -0
  36. data/app/assets/javascripts/semantic-ui/form.js +1707 -0
  37. data/app/assets/javascripts/semantic-ui/modal.js +1090 -0
  38. data/app/assets/javascripts/semantic-ui/nag.js +507 -0
  39. data/app/assets/javascripts/semantic-ui/popup.js +1532 -0
  40. data/app/assets/javascripts/semantic-ui/progress.js +923 -0
  41. data/app/assets/javascripts/semantic-ui/range.js +278 -0
  42. data/app/assets/javascripts/semantic-ui/rating.js +511 -0
  43. data/app/assets/javascripts/semantic-ui/search.js +1515 -0
  44. data/app/assets/javascripts/semantic-ui/shape.js +921 -0
  45. data/app/assets/javascripts/semantic-ui/sidebar.js +1033 -0
  46. data/app/assets/javascripts/semantic-ui/site.js +490 -0
  47. data/app/assets/javascripts/semantic-ui/state.js +708 -0
  48. data/app/assets/javascripts/semantic-ui/sticky.js +959 -0
  49. data/app/assets/javascripts/semantic-ui/tab.js +952 -0
  50. data/app/assets/javascripts/semantic-ui/toast.js +592 -0
  51. data/app/assets/javascripts/semantic-ui/transition.js +1106 -0
  52. data/app/assets/javascripts/semantic-ui/video.js +532 -0
  53. data/app/assets/javascripts/semantic-ui/visibility.js +1311 -0
  54. data/app/assets/javascripts/semantic-ui/visit.js +525 -0
  55. data/app/assets/stylesheets/semantic-ui.scss +5 -0
  56. data/app/assets/stylesheets/semantic-ui/collections/_all.scss +6 -0
  57. data/app/assets/stylesheets/semantic-ui/collections/_breadcrumb.scss +124 -0
  58. data/app/assets/stylesheets/semantic-ui/collections/_form.scss +1158 -0
  59. data/app/assets/stylesheets/semantic-ui/collections/_grid.scss +2093 -0
  60. data/app/assets/stylesheets/semantic-ui/collections/_menu.scss +2193 -0
  61. data/app/assets/stylesheets/semantic-ui/collections/_message.scss +606 -0
  62. data/app/assets/stylesheets/semantic-ui/collections/_table.scss +1117 -0
  63. data/app/assets/stylesheets/semantic-ui/elements/_all.scss +16 -0
  64. data/app/assets/stylesheets/semantic-ui/elements/_button.scss +4530 -0
  65. data/app/assets/stylesheets/semantic-ui/elements/_container.scss +145 -0
  66. data/app/assets/stylesheets/semantic-ui/elements/_divider.scss +259 -0
  67. data/app/assets/stylesheets/semantic-ui/elements/_flag.scss +1036 -0
  68. data/app/assets/stylesheets/semantic-ui/elements/_header.scss +762 -0
  69. data/app/assets/stylesheets/semantic-ui/elements/_icon.scss +6330 -0
  70. data/app/assets/stylesheets/semantic-ui/elements/_image.scss +310 -0
  71. data/app/assets/stylesheets/semantic-ui/elements/_input.scss +519 -0
  72. data/app/assets/stylesheets/semantic-ui/elements/_label.scss +1395 -0
  73. data/app/assets/stylesheets/semantic-ui/elements/_list.scss +959 -0
  74. data/app/assets/stylesheets/semantic-ui/elements/_loader.scss +458 -0
  75. data/app/assets/stylesheets/semantic-ui/elements/_placeholder.scss +242 -0
  76. data/app/assets/stylesheets/semantic-ui/elements/_rail.scss +152 -0
  77. data/app/assets/stylesheets/semantic-ui/elements/_reveal.scss +295 -0
  78. data/app/assets/stylesheets/semantic-ui/elements/_segment.scss +884 -0
  79. data/app/assets/stylesheets/semantic-ui/elements/_step.scss +675 -0
  80. data/app/assets/stylesheets/semantic-ui/globals/_all.scss +3 -0
  81. data/app/assets/stylesheets/semantic-ui/globals/_reset.scss +485 -0
  82. data/app/assets/stylesheets/semantic-ui/globals/_site.scss +206 -0
  83. data/app/assets/stylesheets/semantic-ui/globals/_variables.scss +4 -0
  84. data/app/assets/stylesheets/semantic-ui/modules/_accordion.scss +247 -0
  85. data/app/assets/stylesheets/semantic-ui/modules/_all.scss +20 -0
  86. data/app/assets/stylesheets/semantic-ui/modules/_calendar.scss +165 -0
  87. data/app/assets/stylesheets/semantic-ui/modules/_checkbox.scss +718 -0
  88. data/app/assets/stylesheets/semantic-ui/modules/_dimmer.scss +464 -0
  89. data/app/assets/stylesheets/semantic-ui/modules/_dropdown.scss +1745 -0
  90. data/app/assets/stylesheets/semantic-ui/modules/_embed.scss +165 -0
  91. data/app/assets/stylesheets/semantic-ui/modules/_modal.scss +646 -0
  92. data/app/assets/stylesheets/semantic-ui/modules/_nag.scss +148 -0
  93. data/app/assets/stylesheets/semantic-ui/modules/_popup.scss +789 -0
  94. data/app/assets/stylesheets/semantic-ui/modules/_progress.scss +523 -0
  95. data/app/assets/stylesheets/semantic-ui/modules/_range.scss +192 -0
  96. data/app/assets/stylesheets/semantic-ui/modules/_rating.scss +263 -0
  97. data/app/assets/stylesheets/semantic-ui/modules/_search.scss +445 -0
  98. data/app/assets/stylesheets/semantic-ui/modules/_shape.scss +154 -0
  99. data/app/assets/stylesheets/semantic-ui/modules/_sidebar.scss +626 -0
  100. data/app/assets/stylesheets/semantic-ui/modules/_sticky.scss +78 -0
  101. data/app/assets/stylesheets/semantic-ui/modules/_tab.scss +92 -0
  102. data/app/assets/stylesheets/semantic-ui/modules/_toast.scss +291 -0
  103. data/app/assets/stylesheets/semantic-ui/modules/_transition.scss +2059 -0
  104. data/app/assets/stylesheets/semantic-ui/modules/_video.scss +125 -0
  105. data/app/assets/stylesheets/semantic-ui/views/_ad.scss +275 -0
  106. data/app/assets/stylesheets/semantic-ui/views/_all.scss +6 -0
  107. data/app/assets/stylesheets/semantic-ui/views/_card.scss +1124 -0
  108. data/app/assets/stylesheets/semantic-ui/views/_comment.scss +296 -0
  109. data/app/assets/stylesheets/semantic-ui/views/_feed.scss +314 -0
  110. data/app/assets/stylesheets/semantic-ui/views/_item.scss +555 -0
  111. data/app/assets/stylesheets/semantic-ui/views/_statistic.scss +583 -0
  112. data/app/helpers/semantic_breadcrumbs_helper.rb +10 -0
  113. data/app/helpers/semantic_flash_helper.rb +22 -0
  114. data/app/helpers/semantic_icon_helper.rb +8 -0
  115. data/app/views/semantic/_breadcrumbs.html.erb +12 -0
  116. data/fomantic-ui-sass.gemspec +31 -0
  117. data/lib/fomantic-ui-sass.rb +62 -0
  118. data/lib/fomantic/ui/sass/breadcrumbs.rb +41 -0
  119. data/lib/fomantic/ui/sass/engine.rb +23 -0
  120. data/lib/fomantic/ui/sass/version.rb +8 -0
  121. data/spec/dummy/README.rdoc +28 -0
  122. data/spec/dummy/Rakefile +6 -0
  123. data/spec/dummy/app/assets/images/.keep +0 -0
  124. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  125. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  126. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  127. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  128. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  129. data/spec/dummy/app/mailers/.keep +0 -0
  130. data/spec/dummy/app/models/.keep +0 -0
  131. data/spec/dummy/app/models/concerns/.keep +0 -0
  132. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  133. data/spec/dummy/bin/bundle +3 -0
  134. data/spec/dummy/bin/rails +4 -0
  135. data/spec/dummy/bin/rake +4 -0
  136. data/spec/dummy/config.ru +4 -0
  137. data/spec/dummy/config/application.rb +28 -0
  138. data/spec/dummy/config/boot.rb +5 -0
  139. data/spec/dummy/config/environment.rb +5 -0
  140. data/spec/dummy/config/environments/development.rb +29 -0
  141. data/spec/dummy/config/environments/production.rb +80 -0
  142. data/spec/dummy/config/environments/test.rb +36 -0
  143. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  144. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  145. data/spec/dummy/config/initializers/inflections.rb +16 -0
  146. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  147. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  148. data/spec/dummy/config/initializers/session_store.rb +3 -0
  149. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  150. data/spec/dummy/config/locales/en.yml +23 -0
  151. data/spec/dummy/config/routes.rb +2 -0
  152. data/spec/dummy/lib/assets/.keep +0 -0
  153. data/spec/dummy/log/.keep +0 -0
  154. data/spec/dummy/public/404.html +58 -0
  155. data/spec/dummy/public/422.html +58 -0
  156. data/spec/dummy/public/500.html +57 -0
  157. data/spec/dummy/public/favicon.ico +0 -0
  158. data/spec/helpers/semantic_breadcrumbs_helper_spec.rb +38 -0
  159. data/spec/helpers/semantic_flash_helper_spec.rb +36 -0
  160. data/spec/helpers/semantic_icon_helper_spec.rb +48 -0
  161. data/spec/spec_helper.rb +17 -0
  162. data/tasks/converter.rb +216 -0
  163. data/templates/project/manifest.rb +29 -0
  164. data/templates/project/styles.scss +1 -0
  165. metadata +390 -0
@@ -0,0 +1,952 @@
1
+ /*!
2
+ * # Semantic UI - Tab
3
+ * http://github.com/semantic-org/semantic-ui/
4
+ *
5
+ *
6
+ * Released under the MIT license
7
+ * http://opensource.org/licenses/MIT
8
+ *
9
+ */
10
+
11
+ ;(function ($, window, document, undefined) {
12
+
13
+ 'use strict';
14
+
15
+ window = (typeof window != 'undefined' && window.Math == Math)
16
+ ? window
17
+ : (typeof self != 'undefined' && self.Math == Math)
18
+ ? self
19
+ : Function('return this')()
20
+ ;
21
+
22
+ $.fn.tab = function(parameters) {
23
+
24
+ var
25
+ // use window context if none specified
26
+ $allModules = $.isFunction(this)
27
+ ? $(window)
28
+ : $(this),
29
+
30
+ moduleSelector = $allModules.selector || '',
31
+ time = new Date().getTime(),
32
+ performance = [],
33
+
34
+ query = arguments[0],
35
+ methodInvoked = (typeof query == 'string'),
36
+ queryArguments = [].slice.call(arguments, 1),
37
+
38
+ initializedHistory = false,
39
+ returnedValue
40
+ ;
41
+
42
+ $allModules
43
+ .each(function() {
44
+ var
45
+
46
+ settings = ( $.isPlainObject(parameters) )
47
+ ? $.extend(true, {}, $.fn.tab.settings, parameters)
48
+ : $.extend({}, $.fn.tab.settings),
49
+
50
+ className = settings.className,
51
+ metadata = settings.metadata,
52
+ selector = settings.selector,
53
+ error = settings.error,
54
+
55
+ eventNamespace = '.' + settings.namespace,
56
+ moduleNamespace = 'module-' + settings.namespace,
57
+
58
+ $module = $(this),
59
+ $context,
60
+ $tabs,
61
+
62
+ cache = {},
63
+ firstLoad = true,
64
+ recursionDepth = 0,
65
+ element = this,
66
+ instance = $module.data(moduleNamespace),
67
+
68
+ activeTabPath,
69
+ parameterArray,
70
+ module,
71
+
72
+ historyEvent
73
+
74
+ ;
75
+
76
+ module = {
77
+
78
+ initialize: function() {
79
+ module.debug('Initializing tab menu item', $module);
80
+ module.fix.callbacks();
81
+ module.determineTabs();
82
+
83
+ module.debug('Determining tabs', settings.context, $tabs);
84
+ // set up automatic routing
85
+ if(settings.auto) {
86
+ module.set.auto();
87
+ }
88
+ module.bind.events();
89
+
90
+ if(settings.history && !initializedHistory) {
91
+ module.initializeHistory();
92
+ initializedHistory = true;
93
+ }
94
+
95
+ module.instantiate();
96
+ },
97
+
98
+ instantiate: function () {
99
+ module.verbose('Storing instance of module', module);
100
+ instance = module;
101
+ $module
102
+ .data(moduleNamespace, module)
103
+ ;
104
+ },
105
+
106
+ destroy: function() {
107
+ module.debug('Destroying tabs', $module);
108
+ $module
109
+ .removeData(moduleNamespace)
110
+ .off(eventNamespace)
111
+ ;
112
+ },
113
+
114
+ bind: {
115
+ events: function() {
116
+ // if using $.tab don't add events
117
+ if( !$.isWindow( element ) ) {
118
+ module.debug('Attaching tab activation events to element', $module);
119
+ $module
120
+ .on('click' + eventNamespace, module.event.click)
121
+ ;
122
+ }
123
+ }
124
+ },
125
+
126
+ determineTabs: function() {
127
+ var
128
+ $reference
129
+ ;
130
+
131
+ // determine tab context
132
+ if(settings.context === 'parent') {
133
+ if($module.closest(selector.ui).length > 0) {
134
+ $reference = $module.closest(selector.ui);
135
+ module.verbose('Using closest UI element as parent', $reference);
136
+ }
137
+ else {
138
+ $reference = $module;
139
+ }
140
+ $context = $reference.parent();
141
+ module.verbose('Determined parent element for creating context', $context);
142
+ }
143
+ else if(settings.context) {
144
+ $context = $(settings.context);
145
+ module.verbose('Using selector for tab context', settings.context, $context);
146
+ }
147
+ else {
148
+ $context = $('body');
149
+ }
150
+ // find tabs
151
+ if(settings.childrenOnly) {
152
+ $tabs = $context.children(selector.tabs);
153
+ module.debug('Searching tab context children for tabs', $context, $tabs);
154
+ }
155
+ else {
156
+ $tabs = $context.find(selector.tabs);
157
+ module.debug('Searching tab context for tabs', $context, $tabs);
158
+ }
159
+ },
160
+
161
+ fix: {
162
+ callbacks: function() {
163
+ if( $.isPlainObject(parameters) && (parameters.onTabLoad || parameters.onTabInit) ) {
164
+ if(parameters.onTabLoad) {
165
+ parameters.onLoad = parameters.onTabLoad;
166
+ delete parameters.onTabLoad;
167
+ module.error(error.legacyLoad, parameters.onLoad);
168
+ }
169
+ if(parameters.onTabInit) {
170
+ parameters.onFirstLoad = parameters.onTabInit;
171
+ delete parameters.onTabInit;
172
+ module.error(error.legacyInit, parameters.onFirstLoad);
173
+ }
174
+ settings = $.extend(true, {}, $.fn.tab.settings, parameters);
175
+ }
176
+ }
177
+ },
178
+
179
+ initializeHistory: function() {
180
+ module.debug('Initializing page state');
181
+ if( $.address === undefined ) {
182
+ module.error(error.state);
183
+ return false;
184
+ }
185
+ else {
186
+ if(settings.historyType == 'state') {
187
+ module.debug('Using HTML5 to manage state');
188
+ if(settings.path !== false) {
189
+ $.address
190
+ .history(true)
191
+ .state(settings.path)
192
+ ;
193
+ }
194
+ else {
195
+ module.error(error.path);
196
+ return false;
197
+ }
198
+ }
199
+ $.address
200
+ .bind('change', module.event.history.change)
201
+ ;
202
+ }
203
+ },
204
+
205
+ event: {
206
+ click: function(event) {
207
+ var
208
+ tabPath = $(this).data(metadata.tab)
209
+ ;
210
+ if(tabPath !== undefined) {
211
+ if(settings.history) {
212
+ module.verbose('Updating page state', event);
213
+ $.address.value(tabPath);
214
+ }
215
+ else {
216
+ module.verbose('Changing tab', event);
217
+ module.changeTab(tabPath);
218
+ }
219
+ event.preventDefault();
220
+ }
221
+ else {
222
+ module.debug('No tab specified');
223
+ }
224
+ },
225
+ history: {
226
+ change: function(event) {
227
+ var
228
+ tabPath = event.pathNames.join('/') || module.get.initialPath(),
229
+ pageTitle = settings.templates.determineTitle(tabPath) || false
230
+ ;
231
+ module.performance.display();
232
+ module.debug('History change event', tabPath, event);
233
+ historyEvent = event;
234
+ if(tabPath !== undefined) {
235
+ module.changeTab(tabPath);
236
+ }
237
+ if(pageTitle) {
238
+ $.address.title(pageTitle);
239
+ }
240
+ }
241
+ }
242
+ },
243
+
244
+ refresh: function() {
245
+ if(activeTabPath) {
246
+ module.debug('Refreshing tab', activeTabPath);
247
+ module.changeTab(activeTabPath);
248
+ }
249
+ },
250
+
251
+ cache: {
252
+
253
+ read: function(cacheKey) {
254
+ return (cacheKey !== undefined)
255
+ ? cache[cacheKey]
256
+ : false
257
+ ;
258
+ },
259
+ add: function(cacheKey, content) {
260
+ cacheKey = cacheKey || activeTabPath;
261
+ module.debug('Adding cached content for', cacheKey);
262
+ cache[cacheKey] = content;
263
+ },
264
+ remove: function(cacheKey) {
265
+ cacheKey = cacheKey || activeTabPath;
266
+ module.debug('Removing cached content for', cacheKey);
267
+ delete cache[cacheKey];
268
+ }
269
+ },
270
+
271
+ set: {
272
+ auto: function() {
273
+ var
274
+ url = (typeof settings.path == 'string')
275
+ ? settings.path.replace(/\/$/, '') + '/{$tab}'
276
+ : '/{$tab}'
277
+ ;
278
+ module.verbose('Setting up automatic tab retrieval from server', url);
279
+ if($.isPlainObject(settings.apiSettings)) {
280
+ settings.apiSettings.url = url;
281
+ }
282
+ else {
283
+ settings.apiSettings = {
284
+ url: url
285
+ };
286
+ }
287
+ },
288
+ loading: function(tabPath) {
289
+ var
290
+ $tab = module.get.tabElement(tabPath),
291
+ isLoading = $tab.hasClass(className.loading)
292
+ ;
293
+ if(!isLoading) {
294
+ module.verbose('Setting loading state for', $tab);
295
+ $tab
296
+ .addClass(className.loading)
297
+ .siblings($tabs)
298
+ .removeClass(className.active + ' ' + className.loading)
299
+ ;
300
+ if($tab.length > 0) {
301
+ settings.onRequest.call($tab[0], tabPath);
302
+ }
303
+ }
304
+ },
305
+ state: function(state) {
306
+ $.address.value(state);
307
+ }
308
+ },
309
+
310
+ changeTab: function(tabPath) {
311
+ var
312
+ pushStateAvailable = (window.history && window.history.pushState),
313
+ shouldIgnoreLoad = (pushStateAvailable && settings.ignoreFirstLoad && firstLoad),
314
+ remoteContent = (settings.auto || $.isPlainObject(settings.apiSettings) ),
315
+ // only add default path if not remote content
316
+ pathArray = (remoteContent && !shouldIgnoreLoad)
317
+ ? module.utilities.pathToArray(tabPath)
318
+ : module.get.defaultPathArray(tabPath)
319
+ ;
320
+ tabPath = module.utilities.arrayToPath(pathArray);
321
+ $.each(pathArray, function(index, tab) {
322
+ var
323
+ currentPathArray = pathArray.slice(0, index + 1),
324
+ currentPath = module.utilities.arrayToPath(currentPathArray),
325
+
326
+ isTab = module.is.tab(currentPath),
327
+ isLastIndex = (index + 1 == pathArray.length),
328
+
329
+ $tab = module.get.tabElement(currentPath),
330
+ $anchor,
331
+ nextPathArray,
332
+ nextPath,
333
+ isLastTab
334
+ ;
335
+ module.verbose('Looking for tab', tab);
336
+ if(isTab) {
337
+ module.verbose('Tab was found', tab);
338
+ // scope up
339
+ activeTabPath = currentPath;
340
+ parameterArray = module.utilities.filterArray(pathArray, currentPathArray);
341
+
342
+ if(isLastIndex) {
343
+ isLastTab = true;
344
+ }
345
+ else {
346
+ nextPathArray = pathArray.slice(0, index + 2);
347
+ nextPath = module.utilities.arrayToPath(nextPathArray);
348
+ isLastTab = ( !module.is.tab(nextPath) );
349
+ if(isLastTab) {
350
+ module.verbose('Tab parameters found', nextPathArray);
351
+ }
352
+ }
353
+ if(isLastTab && remoteContent) {
354
+ if(!shouldIgnoreLoad) {
355
+ module.activate.navigation(currentPath);
356
+ module.fetch.content(currentPath, tabPath);
357
+ }
358
+ else {
359
+ module.debug('Ignoring remote content on first tab load', currentPath);
360
+ firstLoad = false;
361
+ module.cache.add(tabPath, $tab.html());
362
+ module.activate.all(currentPath);
363
+ settings.onFirstLoad.call($tab[0], currentPath, parameterArray, historyEvent);
364
+ settings.onLoad.call($tab[0], currentPath, parameterArray, historyEvent);
365
+ }
366
+ return false;
367
+ }
368
+ else {
369
+ module.debug('Opened local tab', currentPath);
370
+ module.activate.all(currentPath);
371
+ if( !module.cache.read(currentPath) ) {
372
+ module.cache.add(currentPath, true);
373
+ module.debug('First time tab loaded calling tab init');
374
+ settings.onFirstLoad.call($tab[0], currentPath, parameterArray, historyEvent);
375
+ }
376
+ settings.onLoad.call($tab[0], currentPath, parameterArray, historyEvent);
377
+ }
378
+
379
+ }
380
+ else if(tabPath.search('/') == -1 && tabPath !== '') {
381
+ // look for in page anchor
382
+ $anchor = $('#' + tabPath + ', a[name="' + tabPath + '"]');
383
+ currentPath = $anchor.closest('[data-tab]').data(metadata.tab);
384
+ $tab = module.get.tabElement(currentPath);
385
+ // if anchor exists use parent tab
386
+ if($anchor && $anchor.length > 0 && currentPath) {
387
+ module.debug('Anchor link used, opening parent tab', $tab, $anchor);
388
+ if( !$tab.hasClass(className.active) ) {
389
+ setTimeout(function() {
390
+ module.scrollTo($anchor);
391
+ }, 0);
392
+ }
393
+ module.activate.all(currentPath);
394
+ if( !module.cache.read(currentPath) ) {
395
+ module.cache.add(currentPath, true);
396
+ module.debug('First time tab loaded calling tab init');
397
+ settings.onFirstLoad.call($tab[0], currentPath, parameterArray, historyEvent);
398
+ }
399
+ settings.onLoad.call($tab[0], currentPath, parameterArray, historyEvent);
400
+ return false;
401
+ }
402
+ }
403
+ else {
404
+ module.error(error.missingTab, $module, $context, currentPath);
405
+ return false;
406
+ }
407
+ });
408
+ },
409
+
410
+ scrollTo: function($element) {
411
+ var
412
+ scrollOffset = ($element && $element.length > 0)
413
+ ? $element.offset().top
414
+ : false
415
+ ;
416
+ if(scrollOffset !== false) {
417
+ module.debug('Forcing scroll to an in-page link in a hidden tab', scrollOffset, $element);
418
+ $(document).scrollTop(scrollOffset);
419
+ }
420
+ },
421
+
422
+ update: {
423
+ content: function(tabPath, html, evaluateScripts) {
424
+ var
425
+ $tab = module.get.tabElement(tabPath),
426
+ tab = $tab[0]
427
+ ;
428
+ evaluateScripts = (evaluateScripts !== undefined)
429
+ ? evaluateScripts
430
+ : settings.evaluateScripts
431
+ ;
432
+ if(typeof settings.cacheType == 'string' && settings.cacheType.toLowerCase() == 'dom' && typeof html !== 'string') {
433
+ $tab
434
+ .empty()
435
+ .append($(html).clone(true))
436
+ ;
437
+ }
438
+ else {
439
+ if(evaluateScripts) {
440
+ module.debug('Updating HTML and evaluating inline scripts', tabPath, html);
441
+ $tab.html(html);
442
+ }
443
+ else {
444
+ module.debug('Updating HTML', tabPath, html);
445
+ tab.innerHTML = html;
446
+ }
447
+ }
448
+ }
449
+ },
450
+
451
+ fetch: {
452
+
453
+ content: function(tabPath, fullTabPath) {
454
+ var
455
+ $tab = module.get.tabElement(tabPath),
456
+ apiSettings = {
457
+ dataType : 'html',
458
+ encodeParameters : false,
459
+ on : 'now',
460
+ cache : settings.alwaysRefresh,
461
+ headers : {
462
+ 'X-Remote': true
463
+ },
464
+ onSuccess : function(response) {
465
+ if(settings.cacheType == 'response') {
466
+ module.cache.add(fullTabPath, response);
467
+ }
468
+ module.update.content(tabPath, response);
469
+ if(tabPath == activeTabPath) {
470
+ module.debug('Content loaded', tabPath);
471
+ module.activate.tab(tabPath);
472
+ }
473
+ else {
474
+ module.debug('Content loaded in background', tabPath);
475
+ }
476
+ settings.onFirstLoad.call($tab[0], tabPath, parameterArray, historyEvent);
477
+ settings.onLoad.call($tab[0], tabPath, parameterArray, historyEvent);
478
+
479
+ if(settings.loadOnce) {
480
+ module.cache.add(fullTabPath, true);
481
+ }
482
+ else if(typeof settings.cacheType == 'string' && settings.cacheType.toLowerCase() == 'dom' && $tab.children().length > 0) {
483
+ setTimeout(function() {
484
+ var
485
+ $clone = $tab.children().clone(true)
486
+ ;
487
+ $clone = $clone.not('script');
488
+ module.cache.add(fullTabPath, $clone);
489
+ }, 0);
490
+ }
491
+ else {
492
+ module.cache.add(fullTabPath, $tab.html());
493
+ }
494
+ },
495
+ urlData: {
496
+ tab: fullTabPath
497
+ }
498
+ },
499
+ request = $tab.api('get request') || false,
500
+ existingRequest = ( request && request.state() === 'pending' ),
501
+ requestSettings,
502
+ cachedContent
503
+ ;
504
+
505
+ fullTabPath = fullTabPath || tabPath;
506
+ cachedContent = module.cache.read(fullTabPath);
507
+
508
+
509
+ if(settings.cache && cachedContent) {
510
+ module.activate.tab(tabPath);
511
+ module.debug('Adding cached content', fullTabPath);
512
+ if(!settings.loadOnce) {
513
+ if(settings.evaluateScripts == 'once') {
514
+ module.update.content(tabPath, cachedContent, false);
515
+ }
516
+ else {
517
+ module.update.content(tabPath, cachedContent);
518
+ }
519
+ }
520
+ settings.onLoad.call($tab[0], tabPath, parameterArray, historyEvent);
521
+ }
522
+ else if(existingRequest) {
523
+ module.set.loading(tabPath);
524
+ module.debug('Content is already loading', fullTabPath);
525
+ }
526
+ else if($.api !== undefined) {
527
+ requestSettings = $.extend(true, {}, settings.apiSettings, apiSettings);
528
+ module.debug('Retrieving remote content', fullTabPath, requestSettings);
529
+ module.set.loading(tabPath);
530
+ $tab.api(requestSettings);
531
+ }
532
+ else {
533
+ module.error(error.api);
534
+ }
535
+ }
536
+ },
537
+
538
+ activate: {
539
+ all: function(tabPath) {
540
+ module.activate.tab(tabPath);
541
+ module.activate.navigation(tabPath);
542
+ },
543
+ tab: function(tabPath) {
544
+ var
545
+ $tab = module.get.tabElement(tabPath),
546
+ $deactiveTabs = (settings.deactivate == 'siblings')
547
+ ? $tab.siblings($tabs)
548
+ : $tabs.not($tab),
549
+ isActive = $tab.hasClass(className.active)
550
+ ;
551
+ module.verbose('Showing tab content for', $tab);
552
+ if(!isActive) {
553
+ $tab
554
+ .addClass(className.active)
555
+ ;
556
+ $deactiveTabs
557
+ .removeClass(className.active + ' ' + className.loading)
558
+ ;
559
+ if($tab.length > 0) {
560
+ settings.onVisible.call($tab[0], tabPath);
561
+ }
562
+ }
563
+ },
564
+ navigation: function(tabPath) {
565
+ var
566
+ $navigation = module.get.navElement(tabPath),
567
+ $deactiveNavigation = (settings.deactivate == 'siblings')
568
+ ? $navigation.siblings($allModules)
569
+ : $allModules.not($navigation),
570
+ isActive = $navigation.hasClass(className.active)
571
+ ;
572
+ module.verbose('Activating tab navigation for', $navigation, tabPath);
573
+ if(!isActive) {
574
+ $navigation
575
+ .addClass(className.active)
576
+ ;
577
+ $deactiveNavigation
578
+ .removeClass(className.active + ' ' + className.loading)
579
+ ;
580
+ }
581
+ }
582
+ },
583
+
584
+ deactivate: {
585
+ all: function() {
586
+ module.deactivate.navigation();
587
+ module.deactivate.tabs();
588
+ },
589
+ navigation: function() {
590
+ $allModules
591
+ .removeClass(className.active)
592
+ ;
593
+ },
594
+ tabs: function() {
595
+ $tabs
596
+ .removeClass(className.active + ' ' + className.loading)
597
+ ;
598
+ }
599
+ },
600
+
601
+ is: {
602
+ tab: function(tabName) {
603
+ return (tabName !== undefined)
604
+ ? ( module.get.tabElement(tabName).length > 0 )
605
+ : false
606
+ ;
607
+ }
608
+ },
609
+
610
+ get: {
611
+ initialPath: function() {
612
+ return $allModules.eq(0).data(metadata.tab) || $tabs.eq(0).data(metadata.tab);
613
+ },
614
+ path: function() {
615
+ return $.address.value();
616
+ },
617
+ // adds default tabs to tab path
618
+ defaultPathArray: function(tabPath) {
619
+ return module.utilities.pathToArray( module.get.defaultPath(tabPath) );
620
+ },
621
+ defaultPath: function(tabPath) {
622
+ var
623
+ $defaultNav = $allModules.filter('[data-' + metadata.tab + '^="' + tabPath + '/"]').eq(0),
624
+ defaultTab = $defaultNav.data(metadata.tab) || false
625
+ ;
626
+ if( defaultTab ) {
627
+ module.debug('Found default tab', defaultTab);
628
+ if(recursionDepth < settings.maxDepth) {
629
+ recursionDepth++;
630
+ return module.get.defaultPath(defaultTab);
631
+ }
632
+ module.error(error.recursion);
633
+ }
634
+ else {
635
+ module.debug('No default tabs found for', tabPath, $tabs);
636
+ }
637
+ recursionDepth = 0;
638
+ return tabPath;
639
+ },
640
+ navElement: function(tabPath) {
641
+ tabPath = tabPath || activeTabPath;
642
+ return $allModules.filter('[data-' + metadata.tab + '="' + tabPath + '"]');
643
+ },
644
+ tabElement: function(tabPath) {
645
+ var
646
+ $fullPathTab,
647
+ $simplePathTab,
648
+ tabPathArray,
649
+ lastTab
650
+ ;
651
+ tabPath = tabPath || activeTabPath;
652
+ tabPathArray = module.utilities.pathToArray(tabPath);
653
+ lastTab = module.utilities.last(tabPathArray);
654
+ $fullPathTab = $tabs.filter('[data-' + metadata.tab + '="' + tabPath + '"]');
655
+ $simplePathTab = $tabs.filter('[data-' + metadata.tab + '="' + lastTab + '"]');
656
+ return ($fullPathTab.length > 0)
657
+ ? $fullPathTab
658
+ : $simplePathTab
659
+ ;
660
+ },
661
+ tab: function() {
662
+ return activeTabPath;
663
+ }
664
+ },
665
+
666
+ utilities: {
667
+ filterArray: function(keepArray, removeArray) {
668
+ return $.grep(keepArray, function(keepValue) {
669
+ return ( $.inArray(keepValue, removeArray) == -1);
670
+ });
671
+ },
672
+ last: function(array) {
673
+ return $.isArray(array)
674
+ ? array[ array.length - 1]
675
+ : false
676
+ ;
677
+ },
678
+ pathToArray: function(pathName) {
679
+ if(pathName === undefined) {
680
+ pathName = activeTabPath;
681
+ }
682
+ return typeof pathName == 'string'
683
+ ? pathName.split('/')
684
+ : [pathName]
685
+ ;
686
+ },
687
+ arrayToPath: function(pathArray) {
688
+ return $.isArray(pathArray)
689
+ ? pathArray.join('/')
690
+ : false
691
+ ;
692
+ }
693
+ },
694
+
695
+ setting: function(name, value) {
696
+ module.debug('Changing setting', name, value);
697
+ if( $.isPlainObject(name) ) {
698
+ $.extend(true, settings, name);
699
+ }
700
+ else if(value !== undefined) {
701
+ if($.isPlainObject(settings[name])) {
702
+ $.extend(true, settings[name], value);
703
+ }
704
+ else {
705
+ settings[name] = value;
706
+ }
707
+ }
708
+ else {
709
+ return settings[name];
710
+ }
711
+ },
712
+ internal: function(name, value) {
713
+ if( $.isPlainObject(name) ) {
714
+ $.extend(true, module, name);
715
+ }
716
+ else if(value !== undefined) {
717
+ module[name] = value;
718
+ }
719
+ else {
720
+ return module[name];
721
+ }
722
+ },
723
+ debug: function() {
724
+ if(!settings.silent && settings.debug) {
725
+ if(settings.performance) {
726
+ module.performance.log(arguments);
727
+ }
728
+ else {
729
+ module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
730
+ module.debug.apply(console, arguments);
731
+ }
732
+ }
733
+ },
734
+ verbose: function() {
735
+ if(!settings.silent && settings.verbose && settings.debug) {
736
+ if(settings.performance) {
737
+ module.performance.log(arguments);
738
+ }
739
+ else {
740
+ module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
741
+ module.verbose.apply(console, arguments);
742
+ }
743
+ }
744
+ },
745
+ error: function() {
746
+ if(!settings.silent) {
747
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
748
+ module.error.apply(console, arguments);
749
+ }
750
+ },
751
+ performance: {
752
+ log: function(message) {
753
+ var
754
+ currentTime,
755
+ executionTime,
756
+ previousTime
757
+ ;
758
+ if(settings.performance) {
759
+ currentTime = new Date().getTime();
760
+ previousTime = time || currentTime;
761
+ executionTime = currentTime - previousTime;
762
+ time = currentTime;
763
+ performance.push({
764
+ 'Name' : message[0],
765
+ 'Arguments' : [].slice.call(message, 1) || '',
766
+ 'Element' : element,
767
+ 'Execution Time' : executionTime
768
+ });
769
+ }
770
+ clearTimeout(module.performance.timer);
771
+ module.performance.timer = setTimeout(module.performance.display, 500);
772
+ },
773
+ display: function() {
774
+ var
775
+ title = settings.name + ':',
776
+ totalTime = 0
777
+ ;
778
+ time = false;
779
+ clearTimeout(module.performance.timer);
780
+ $.each(performance, function(index, data) {
781
+ totalTime += data['Execution Time'];
782
+ });
783
+ title += ' ' + totalTime + 'ms';
784
+ if(moduleSelector) {
785
+ title += ' \'' + moduleSelector + '\'';
786
+ }
787
+ if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
788
+ console.groupCollapsed(title);
789
+ if(console.table) {
790
+ console.table(performance);
791
+ }
792
+ else {
793
+ $.each(performance, function(index, data) {
794
+ console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
795
+ });
796
+ }
797
+ console.groupEnd();
798
+ }
799
+ performance = [];
800
+ }
801
+ },
802
+ invoke: function(query, passedArguments, context) {
803
+ var
804
+ object = instance,
805
+ maxDepth,
806
+ found,
807
+ response
808
+ ;
809
+ passedArguments = passedArguments || queryArguments;
810
+ context = element || context;
811
+ if(typeof query == 'string' && object !== undefined) {
812
+ query = query.split(/[\. ]/);
813
+ maxDepth = query.length - 1;
814
+ $.each(query, function(depth, value) {
815
+ var camelCaseValue = (depth != maxDepth)
816
+ ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
817
+ : query
818
+ ;
819
+ if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
820
+ object = object[camelCaseValue];
821
+ }
822
+ else if( object[camelCaseValue] !== undefined ) {
823
+ found = object[camelCaseValue];
824
+ return false;
825
+ }
826
+ else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
827
+ object = object[value];
828
+ }
829
+ else if( object[value] !== undefined ) {
830
+ found = object[value];
831
+ return false;
832
+ }
833
+ else {
834
+ module.error(error.method, query);
835
+ return false;
836
+ }
837
+ });
838
+ }
839
+ if ( $.isFunction( found ) ) {
840
+ response = found.apply(context, passedArguments);
841
+ }
842
+ else if(found !== undefined) {
843
+ response = found;
844
+ }
845
+ if($.isArray(returnedValue)) {
846
+ returnedValue.push(response);
847
+ }
848
+ else if(returnedValue !== undefined) {
849
+ returnedValue = [returnedValue, response];
850
+ }
851
+ else if(response !== undefined) {
852
+ returnedValue = response;
853
+ }
854
+ return found;
855
+ }
856
+ };
857
+ if(methodInvoked) {
858
+ if(instance === undefined) {
859
+ module.initialize();
860
+ }
861
+ module.invoke(query);
862
+ }
863
+ else {
864
+ if(instance !== undefined) {
865
+ instance.invoke('destroy');
866
+ }
867
+ module.initialize();
868
+ }
869
+ })
870
+ ;
871
+ return (returnedValue !== undefined)
872
+ ? returnedValue
873
+ : this
874
+ ;
875
+
876
+ };
877
+
878
+ // shortcut for tabbed content with no defined navigation
879
+ $.tab = function() {
880
+ $(window).tab.apply(this, arguments);
881
+ };
882
+
883
+ $.fn.tab.settings = {
884
+
885
+ name : 'Tab',
886
+ namespace : 'tab',
887
+
888
+ silent : false,
889
+ debug : false,
890
+ verbose : false,
891
+ performance : true,
892
+
893
+ auto : false, // uses pjax style endpoints fetching content from same url with remote-content headers
894
+ history : false, // use browser history
895
+ historyType : 'hash', // #/ or html5 state
896
+ path : false, // base path of url
897
+
898
+ context : false, // specify a context that tabs must appear inside
899
+ childrenOnly : false, // use only tabs that are children of context
900
+ maxDepth : 25, // max depth a tab can be nested
901
+
902
+ deactivate : 'siblings', // whether tabs should deactivate sibling menu elements or all elements initialized together
903
+
904
+ alwaysRefresh : false, // load tab content new every tab click
905
+ cache : true, // cache the content requests to pull locally
906
+ loadOnce : false, // Whether tab data should only be loaded once when using remote content
907
+ cacheType : 'response', // Whether to cache exact response, or to html cache contents after scripts execute
908
+ ignoreFirstLoad : false, // don't load remote content on first load
909
+
910
+ apiSettings : false, // settings for api call
911
+ evaluateScripts : 'once', // whether inline scripts should be parsed (true/false/once). Once will not re-evaluate on cached content
912
+
913
+ onFirstLoad : function(tabPath, parameterArray, historyEvent) {}, // called first time loaded
914
+ onLoad : function(tabPath, parameterArray, historyEvent) {}, // called on every load
915
+ onVisible : function(tabPath, parameterArray, historyEvent) {}, // called every time tab visible
916
+ onRequest : function(tabPath, parameterArray, historyEvent) {}, // called ever time a tab beings loading remote content
917
+
918
+ templates : {
919
+ determineTitle: function(tabArray) {} // returns page title for path
920
+ },
921
+
922
+ error: {
923
+ api : 'You attempted to load content without API module',
924
+ method : 'The method you called is not defined',
925
+ missingTab : 'Activated tab cannot be found. Tabs are case-sensitive.',
926
+ noContent : 'The tab you specified is missing a content url.',
927
+ path : 'History enabled, but no path was specified',
928
+ recursion : 'Max recursive depth reached',
929
+ legacyInit : 'onTabInit has been renamed to onFirstLoad in 2.0, please adjust your code.',
930
+ legacyLoad : 'onTabLoad has been renamed to onLoad in 2.0. Please adjust your code',
931
+ state : 'History requires Asual\'s Address library <https://github.com/asual/jquery-address>'
932
+ },
933
+
934
+ metadata : {
935
+ tab : 'tab',
936
+ loaded : 'loaded',
937
+ promise: 'promise'
938
+ },
939
+
940
+ className : {
941
+ loading : 'loading',
942
+ active : 'active'
943
+ },
944
+
945
+ selector : {
946
+ tabs : '.ui.tab',
947
+ ui : '.ui'
948
+ }
949
+
950
+ };
951
+
952
+ })( jQuery, window, document );