@pageboard/html 0.14.19 → 0.14.20

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.
Files changed (109) hide show
  1. package/elements/accordion.js +1 -1
  2. package/elements/fieldsets.js +1 -1
  3. package/elements/form.js +2 -2
  4. package/elements/grid.js +1 -1
  5. package/elements/image.js +1 -1
  6. package/elements/input-file.js +2 -2
  7. package/elements/input-property.js +1 -1
  8. package/elements/inputs.js +5 -5
  9. package/elements/layout.js +1 -1
  10. package/elements/link.js +2 -2
  11. package/elements/menu.js +2 -2
  12. package/elements/navigation.js +1 -1
  13. package/elements/page.js +1 -1
  14. package/elements/paragraph.js +2 -2
  15. package/elements/query-tags.js +1 -1
  16. package/elements/tab.js +1 -1
  17. package/elements/table.js +1 -1
  18. package/elements/template.js +1 -1
  19. package/package.json +3 -8
  20. package/ui/card.css +3 -3
  21. package/ui/components/accordion.css +241 -0
  22. package/ui/components/accordion.js +613 -0
  23. package/ui/components/ad.css +275 -0
  24. package/ui/components/api.js +1167 -0
  25. package/ui/components/breadcrumb.css +122 -0
  26. package/ui/components/button.css +3525 -0
  27. package/ui/components/card.css +939 -0
  28. package/ui/components/checkbox.css +604 -0
  29. package/ui/components/checkbox.js +831 -0
  30. package/ui/components/colorize.js +274 -0
  31. package/ui/components/comment.css +268 -0
  32. package/ui/components/container.css +149 -0
  33. package/ui/components/dimmer.css +224 -0
  34. package/ui/components/dimmer.js +733 -0
  35. package/ui/components/divider.css +253 -0
  36. package/ui/components/dropdown.css +1448 -0
  37. package/ui/components/dropdown.js +3955 -0
  38. package/ui/components/embed.css +160 -0
  39. package/ui/components/embed.js +706 -0
  40. package/ui/components/feed.css +281 -0
  41. package/ui/components/flag.css +1035 -0
  42. package/ui/components/form.css +1011 -0
  43. package/ui/components/form.js +1706 -0
  44. package/ui/components/grid.css +1941 -0
  45. package/ui/components/header.css +719 -0
  46. package/ui/components/icon.css +4777 -0
  47. package/ui/components/image.css +310 -0
  48. package/ui/components/input.css +469 -0
  49. package/ui/components/item.css +464 -0
  50. package/ui/components/label.css +1281 -0
  51. package/ui/components/list.css +943 -0
  52. package/ui/components/loader.css +339 -0
  53. package/ui/components/menu.css +1940 -0
  54. package/ui/components/message.css +468 -0
  55. package/ui/components/modal.css +617 -0
  56. package/ui/components/modal.js +1034 -0
  57. package/ui/components/nag.css +145 -0
  58. package/ui/components/nag.js +507 -0
  59. package/ui/components/placeholder.css +229 -0
  60. package/ui/components/popup.css +640 -0
  61. package/ui/components/popup.js +1532 -0
  62. package/ui/components/progress.css +502 -0
  63. package/ui/components/progress.js +931 -0
  64. package/ui/components/rail.css +152 -0
  65. package/ui/components/rating.css +257 -0
  66. package/ui/components/rating.js +508 -0
  67. package/ui/components/reset.css +476 -0
  68. package/ui/components/reveal.css +260 -0
  69. package/ui/components/search.css +431 -0
  70. package/ui/components/search.js +1505 -0
  71. package/ui/components/segment.css +824 -0
  72. package/ui/components/shape.css +143 -0
  73. package/ui/components/shape.js +921 -0
  74. package/ui/components/sidebar.css +537 -0
  75. package/ui/components/sidebar.js +1033 -0
  76. package/ui/components/site.css +184 -0
  77. package/ui/components/site.js +487 -0
  78. package/ui/components/state.js +708 -0
  79. package/ui/components/statistic.css +534 -0
  80. package/ui/components/step.css +566 -0
  81. package/ui/components/sticky.css +73 -0
  82. package/ui/components/sticky.js +959 -0
  83. package/ui/components/tab.css +89 -0
  84. package/ui/components/tab.js +952 -0
  85. package/ui/components/table.css +1108 -0
  86. package/ui/components/transition.css +1792 -0
  87. package/ui/components/transition.js +1095 -0
  88. package/ui/components/video.css +121 -0
  89. package/ui/components/video.js +532 -0
  90. package/ui/components/visibility.js +1311 -0
  91. package/ui/components/visit.js +517 -0
  92. package/ui/item.css +2 -2
  93. package/ui/themes/default/assets/fonts/brand-icons.eot +0 -0
  94. package/ui/themes/default/assets/fonts/brand-icons.svg +1008 -0
  95. package/ui/themes/default/assets/fonts/brand-icons.ttf +0 -0
  96. package/ui/themes/default/assets/fonts/brand-icons.woff +0 -0
  97. package/ui/themes/default/assets/fonts/brand-icons.woff2 +0 -0
  98. package/ui/themes/default/assets/fonts/icons.eot +0 -0
  99. package/ui/themes/default/assets/fonts/icons.otf +0 -0
  100. package/ui/themes/default/assets/fonts/icons.svg +1518 -0
  101. package/ui/themes/default/assets/fonts/icons.ttf +0 -0
  102. package/ui/themes/default/assets/fonts/icons.woff +0 -0
  103. package/ui/themes/default/assets/fonts/icons.woff2 +0 -0
  104. package/ui/themes/default/assets/fonts/outline-icons.eot +0 -0
  105. package/ui/themes/default/assets/fonts/outline-icons.svg +366 -0
  106. package/ui/themes/default/assets/fonts/outline-icons.ttf +0 -0
  107. package/ui/themes/default/assets/fonts/outline-icons.woff +0 -0
  108. package/ui/themes/default/assets/fonts/outline-icons.woff2 +0 -0
  109. package/ui/themes/default/assets/images/flags.png +0 -0
@@ -0,0 +1,952 @@
1
+ /*!
2
+ * # Semantic UI 2.4.1 - 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 );