jquery.tabs.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /* ========================================================
  2. * bootstrap-tab.js v2.0.4
  3. * http://twitter.github.com/bootstrap/javascript.html#tabs
  4. * ========================================================
  5. * Copyright 2012 Twitter, Inc.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * ======================================================== */
  19. define([
  20. "jquery"
  21. ], function(jQuery){
  22. !function ($) {
  23. "use strict"; // jshint ;_;
  24. /* TAB CLASS DEFINITION
  25. * ==================== */
  26. var Tab = function ( element ) {
  27. this.element = $(element)
  28. };
  29. Tab.prototype = {
  30. constructor: Tab
  31. , show: function () {
  32. var $this = this.element
  33. , $ul = $this.closest('ul:not(.dropdown-menu)')
  34. , selector = $this.attr('data-target')
  35. , previous
  36. , $target
  37. , e;
  38. if (!selector) {
  39. selector = $this.attr('href');
  40. selector = selector && selector.replace(/.*(?=#[^\s]*$)/, ''); //strip for ie7
  41. }
  42. if ( $this.parent('li').hasClass('active') ) return;
  43. previous = $ul.find('.active a').last()[0];
  44. e = $.Event('show', {
  45. relatedTarget: previous
  46. });
  47. $this.trigger(e);
  48. if (e.isDefaultPrevented()) return;
  49. $target = $(selector);
  50. this.activate($this.parent('li'), $ul);
  51. this.activate($target, $target.parent(), function () {
  52. $this.trigger({
  53. type: 'shown'
  54. , relatedTarget: previous
  55. })
  56. })
  57. }
  58. , activate: function ( element, container, callback) {
  59. var $active = container.find('> .active')
  60. , transition = callback
  61. && $.support.transition
  62. && $active.hasClass('fade');
  63. function next() {
  64. $active
  65. .removeClass('active')
  66. .find('> .dropdown-menu > .active')
  67. .removeClass('active');
  68. element.addClass('active');
  69. if (transition) {
  70. element[0].offsetWidth; // reflow for transition
  71. element.addClass('in');
  72. } else {
  73. element.removeClass('fade')
  74. }
  75. if ( element.parent('.dropdown-menu') ) {
  76. element.closest('li.dropdown').addClass('active')
  77. }
  78. callback && callback()
  79. }
  80. transition ?
  81. $active.one($.support.transition.end, next) :
  82. next();
  83. $active.removeClass('in')
  84. }
  85. };
  86. /* TAB PLUGIN DEFINITION
  87. * ===================== */
  88. $.fn.tab = function ( option ) {
  89. return this.each(function () {
  90. var $this = $(this)
  91. , data = $this.data('tab');
  92. if (!data) $this.data('tab', (data = new Tab(this)));
  93. if (typeof option == 'string') data[option]()
  94. })
  95. };
  96. $.fn.tab.Constructor = Tab;
  97. /* TAB DATA-API
  98. * ============ */
  99. $(function () {
  100. $('body').on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
  101. e.preventDefault();
  102. $(this).tab('show')
  103. })
  104. })
  105. }(jQuery);
  106. /* =============================================================
  107. * bootstrap-collapse.js v2.0.4
  108. * http://twitter.github.com/bootstrap/javascript.html#collapse
  109. * =============================================================
  110. * Copyright 2012 Twitter, Inc.
  111. *
  112. * Licensed under the Apache License, Version 2.0 (the "License");
  113. * you may not use this file except in compliance with the License.
  114. * You may obtain a copy of the License at
  115. *
  116. * http://www.apache.org/licenses/LICENSE-2.0
  117. *
  118. * Unless required by applicable law or agreed to in writing, software
  119. * distributed under the License is distributed on an "AS IS" BASIS,
  120. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  121. * See the License for the specific language governing permissions and
  122. * limitations under the License.
  123. * ============================================================ */
  124. !function ($) {
  125. "use strict"; // jshint ;_;
  126. /* COLLAPSE PUBLIC CLASS DEFINITION
  127. * ================================ */
  128. var Collapse = function (element, options) {
  129. this.$element = $(element);
  130. this.options = $.extend({}, $.fn.collapse.defaults, options);
  131. if (this.options.parent) {
  132. this.$parent = $(this.options.parent)
  133. }
  134. this.options.toggle && this.toggle()
  135. };
  136. Collapse.prototype = {
  137. constructor: Collapse
  138. , dimension: function () {
  139. var hasWidth = this.$element.hasClass('width');
  140. return hasWidth ? 'width' : 'height'
  141. }
  142. , show: function () {
  143. var dimension
  144. , scroll
  145. , actives
  146. , hasData;
  147. if (this.transitioning) return;
  148. dimension = this.dimension();
  149. scroll = $.camelCase(['scroll', dimension].join('-'));
  150. actives = this.$parent && this.$parent.find('> .accordion-group > .in');
  151. if (actives && actives.length) {
  152. hasData = actives.data('collapse');
  153. if (hasData && hasData.transitioning) return;
  154. actives.collapse('hide');
  155. hasData || actives.data('collapse', null)
  156. }
  157. this.$element[dimension](0);
  158. this.transition('addClass', $.Event('show'), 'shown');
  159. this.$element[dimension](this.$element[0][scroll]);
  160. }
  161. , hide: function () {
  162. var dimension;
  163. if (this.transitioning) return;
  164. dimension = this.dimension();
  165. this.reset(this.$element[dimension]());
  166. this.transition('removeClass', $.Event('hide'), 'hidden');
  167. this.$element[dimension](0)
  168. }
  169. , reset: function (size) {
  170. var dimension = this.dimension();
  171. this.$element
  172. .removeClass('collapse')
  173. [dimension](size || 'auto')
  174. [0].offsetWidth;
  175. this.$element[size !== null ? 'addClass' : 'removeClass']('collapse');
  176. return this
  177. }
  178. , transition: function (method, startEvent, completeEvent) {
  179. var that = this
  180. , complete = function () {
  181. if (startEvent.type == 'show') that.reset();
  182. that.transitioning = 0;
  183. that.$element.trigger(completeEvent)
  184. };
  185. this.$element.trigger(startEvent);
  186. if (startEvent.isDefaultPrevented()) return;
  187. this.transitioning = 1;
  188. this.$element[method]('in');
  189. $.support.transition && this.$element.hasClass('collapse') ?
  190. this.$element.one($.support.transition.end, complete) :
  191. complete()
  192. }
  193. , toggle: function () {
  194. this[this.$element.hasClass('in') ? 'hide' : 'show']();
  195. }
  196. };
  197. /* COLLAPSIBLE PLUGIN DEFINITION
  198. * ============================== */
  199. $.fn.collapse = function (option) {
  200. return this.each(function () {
  201. var $this = $(this)
  202. , data = $this.data('collapse')
  203. , options = typeof option == 'object' && option;
  204. if (!data) $this.data('collapse', (data = new Collapse(this, options)));
  205. if (typeof option == 'string') data[option]()
  206. })
  207. };
  208. $.fn.collapse.defaults = {
  209. toggle: true
  210. };
  211. $.fn.collapse.Constructor = Collapse;
  212. /* COLLAPSIBLE DATA-API
  213. * ==================== */
  214. $(function () {
  215. $('body').on('click.collapse.data-api', '[data-toggle=collapse]', function ( e ) {
  216. var $this = $(this), href
  217. , target = $this.attr('data-target')
  218. || e.preventDefault()
  219. || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
  220. , option = $(target).data('collapse') ? 'toggle' : $this.data();
  221. $(target).collapse(option);
  222. $(this).toggleClass('active');
  223. })
  224. })
  225. }(jQuery);
  226. });