汇联通执法队后台管理系统
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

jquery.bootstrap.wizard.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*!
  2. * jQuery twitter bootstrap wizard plugin
  3. * Examples and documentation at: http://github.com/VinceG/twitter-bootstrap-wizard
  4. * version 1.3.1
  5. * Requires jQuery v1.3.2 or later
  6. * Supports Bootstrap 2.2.x, 2.3.x, 3.0
  7. * Dual licensed under the MIT and GPL licenses:
  8. * http://www.opensource.org/licenses/mit-license.php
  9. * http://www.gnu.org/licenses/gpl.html
  10. * Authors: Vadim Vincent Gabriel (http://vadimg.com), Jason Gill (www.gilluminate.com)
  11. */
  12. ;(function($) {
  13. var bootstrapWizardCreate = function(element, options) {
  14. var element = $(element);
  15. var obj = this;
  16. // selector skips any 'li' elements that do not contain a child with a tab data-toggle
  17. var baseItemSelector = 'li:has([data-toggle="tab"])';
  18. var historyStack = [];
  19. // Merge options with defaults
  20. var $settings = $.extend({}, $.fn.bootstrapWizard.defaults, options);
  21. var $activeTab = null;
  22. var $navigation = null;
  23. this.rebindClick = function(selector, fn)
  24. {
  25. selector.unbind('click', fn).bind('click', fn);
  26. }
  27. this.fixNavigationButtons = function() {
  28. // Get the current active tab
  29. if(!$activeTab.length) {
  30. // Select first one
  31. $navigation.find('a:first').tab('show');
  32. $activeTab = $navigation.find(baseItemSelector + ':first');
  33. }
  34. // See if we're currently in the first/last then disable the previous and last buttons
  35. $($settings.previousSelector, element).toggleClass('disabled', (obj.firstIndex() >= obj.currentIndex()));
  36. $($settings.nextSelector, element).toggleClass('disabled', (obj.currentIndex() >= obj.navigationLength()));
  37. $($settings.nextSelector, element).toggleClass('hidden', (obj.currentIndex() >= obj.navigationLength() && $($settings.finishSelector, element).length > 0));
  38. $($settings.lastSelector, element).toggleClass('hidden', (obj.currentIndex() >= obj.navigationLength() && $($settings.finishSelector, element).length > 0));
  39. $($settings.finishSelector, element).toggleClass('hidden', (obj.currentIndex() < obj.navigationLength()));
  40. $($settings.backSelector, element).toggleClass('disabled', (historyStack.length == 0));
  41. $($settings.backSelector, element).toggleClass('hidden', (obj.currentIndex() >= obj.navigationLength() && $($settings.finishSelector, element).length > 0));
  42. // We are unbinding and rebinding to ensure single firing and no double-click errors
  43. obj.rebindClick($($settings.nextSelector, element), obj.next);
  44. obj.rebindClick($($settings.previousSelector, element), obj.previous);
  45. obj.rebindClick($($settings.lastSelector, element), obj.last);
  46. obj.rebindClick($($settings.firstSelector, element), obj.first);
  47. obj.rebindClick($($settings.finishSelector, element), obj.finish);
  48. obj.rebindClick($($settings.backSelector, element), obj.back);
  49. if($settings.onTabShow && typeof $settings.onTabShow === 'function' && $settings.onTabShow($activeTab, $navigation, obj.currentIndex())===false){
  50. return false;
  51. }
  52. };
  53. this.next = function(e) {
  54. // If we clicked the last then dont activate this
  55. if(element.hasClass('last')) {
  56. return false;
  57. }
  58. if($settings.onNext && typeof $settings.onNext === 'function' && $settings.onNext($activeTab, $navigation, obj.nextIndex())===false){
  59. return false;
  60. }
  61. var formerIndex = obj.currentIndex();
  62. var $index = obj.nextIndex();
  63. // Did we click the last button
  64. if($index > obj.navigationLength()) {
  65. } else {
  66. historyStack.push(formerIndex);
  67. $navigation.find(baseItemSelector + ($settings.withVisible ? ':visible' : '') + ':eq(' + $index + ') a').tab('show');
  68. }
  69. };
  70. this.previous = function(e) {
  71. // If we clicked the first then dont activate this
  72. if(element.hasClass('first')) {
  73. return false;
  74. }
  75. if($settings.onPrevious && typeof $settings.onPrevious === 'function' && $settings.onPrevious($activeTab, $navigation, obj.previousIndex())===false){
  76. return false;
  77. }
  78. var formerIndex = obj.currentIndex();
  79. var $index = obj.previousIndex();
  80. if($index < 0) {
  81. } else {
  82. historyStack.push(formerIndex);
  83. $navigation.find(baseItemSelector + ($settings.withVisible ? ':visible' : '') + ':eq(' + $index + ') a').tab('show');
  84. }
  85. };
  86. this.first = function (e) {
  87. if($settings.onFirst && typeof $settings.onFirst === 'function' && $settings.onFirst($activeTab, $navigation, obj.firstIndex())===false){
  88. return false;
  89. }
  90. // If the element is disabled then we won't do anything
  91. if(element.hasClass('disabled')) {
  92. return false;
  93. }
  94. historyStack.push(obj.currentIndex());
  95. $navigation.find(baseItemSelector + ':eq(0) a').tab('show');
  96. };
  97. this.last = function(e) {
  98. if($settings.onLast && typeof $settings.onLast === 'function' && $settings.onLast($activeTab, $navigation, obj.lastIndex())===false){
  99. return false;
  100. }
  101. // If the element is disabled then we won't do anything
  102. if(element.hasClass('disabled')) {
  103. return false;
  104. }
  105. historyStack.push(obj.currentIndex());
  106. $navigation.find(baseItemSelector + ':eq(' + obj.navigationLength() + ') a').tab('show');
  107. };
  108. this.finish = function (e) {
  109. if ($settings.onFinish && typeof $settings.onFinish === 'function') {
  110. $settings.onFinish($activeTab, $navigation, obj.lastIndex());
  111. }
  112. };
  113. this.back = function () {
  114. if (historyStack.length == 0) {
  115. return null;
  116. }
  117. var formerIndex = historyStack.pop();
  118. if ($settings.onBack && typeof $settings.onBack === 'function' && $settings.onBack($activeTab, $navigation, formerIndex) === false) {
  119. historyStack.push(formerIndex);
  120. return false;
  121. }
  122. element.find(baseItemSelector + ':eq(' + formerIndex + ') a').tab('show');
  123. };
  124. this.currentIndex = function() {
  125. return $navigation.find(baseItemSelector).index($activeTab);
  126. };
  127. this.firstIndex = function() {
  128. return 0;
  129. };
  130. this.lastIndex = function() {
  131. return obj.navigationLength();
  132. };
  133. this.getIndex = function(e) {
  134. return $navigation.find(baseItemSelector).index(e);
  135. };
  136. this.nextIndex = function() {
  137. var nextIndexCandidate=this.currentIndex();
  138. var nextTabCandidate=null;
  139. do {
  140. nextIndexCandidate++;
  141. nextTabCandidate = $navigation.find(baseItemSelector + ":eq(" + nextIndexCandidate + ")");
  142. } while ((nextTabCandidate)&&(nextTabCandidate.hasClass("disabled")));
  143. return nextIndexCandidate;
  144. };
  145. this.previousIndex = function() {
  146. var prevIndexCandidate=this.currentIndex();
  147. var prevTabCandidate=null;
  148. do {
  149. prevIndexCandidate--;
  150. prevTabCandidate = $navigation.find(baseItemSelector + ":eq(" + prevIndexCandidate + ")");
  151. } while ((prevTabCandidate)&&(prevTabCandidate.hasClass("disabled")));
  152. return prevIndexCandidate;
  153. };
  154. this.navigationLength = function() {
  155. return $navigation.find(baseItemSelector).length - 1;
  156. };
  157. this.activeTab = function() {
  158. return $activeTab;
  159. };
  160. this.nextTab = function() {
  161. return $navigation.find(baseItemSelector + ':eq('+(obj.currentIndex()+1)+')').length ? $navigation.find(baseItemSelector + ':eq('+(obj.currentIndex()+1)+')') : null;
  162. };
  163. this.previousTab = function() {
  164. if(obj.currentIndex() <= 0) {
  165. return null;
  166. }
  167. return $navigation.find(baseItemSelector + ':eq('+parseInt(obj.currentIndex()-1)+')');
  168. };
  169. this.show = function(index) {
  170. var tabToShow = isNaN(index) ?
  171. element.find(baseItemSelector + ' a[href="#' + index + '"]') :
  172. element.find(baseItemSelector + ':eq(' + index + ') a');
  173. if (tabToShow.length > 0) {
  174. historyStack.push(obj.currentIndex());
  175. tabToShow.tab('show');
  176. }
  177. };
  178. this.disable = function (index) {
  179. $navigation.find(baseItemSelector + ':eq('+index+')').addClass('disabled');
  180. };
  181. this.enable = function(index) {
  182. $navigation.find(baseItemSelector + ':eq('+index+')').removeClass('disabled');
  183. };
  184. this.hide = function(index) {
  185. $navigation.find(baseItemSelector + ':eq('+index+')').hide();
  186. };
  187. this.display = function(index) {
  188. $navigation.find(baseItemSelector + ':eq('+index+')').show();
  189. };
  190. this.remove = function(args) {
  191. var $index = args[0];
  192. var $removeTabPane = typeof args[1] != 'undefined' ? args[1] : false;
  193. var $item = $navigation.find(baseItemSelector + ':eq('+$index+')');
  194. // Remove the tab pane first if needed
  195. if($removeTabPane) {
  196. var $href = $item.find('a').attr('href');
  197. $($href).remove();
  198. }
  199. // Remove menu item
  200. $item.remove();
  201. };
  202. var innerTabClick = function (e) {
  203. // Get the index of the clicked tab
  204. var $ul = $navigation.find(baseItemSelector);
  205. var clickedIndex = $ul.index($(e.currentTarget).parent(baseItemSelector));
  206. var $clickedTab = $( $ul[clickedIndex] );
  207. if($settings.onTabClick && typeof $settings.onTabClick === 'function' && $settings.onTabClick($activeTab, $navigation, obj.currentIndex(), clickedIndex, $clickedTab)===false){
  208. return false;
  209. }
  210. };
  211. var innerTabShown = function (e) {
  212. var $element = $(e.target).parent();
  213. var nextTab = $navigation.find(baseItemSelector).index($element);
  214. // If it's disabled then do not change
  215. if($element.hasClass('disabled')) {
  216. return false;
  217. }
  218. if($settings.onTabChange && typeof $settings.onTabChange === 'function' && $settings.onTabChange($activeTab, $navigation, obj.currentIndex(), nextTab)===false){
  219. return false;
  220. }
  221. $activeTab = $element; // activated tab
  222. obj.fixNavigationButtons();
  223. };
  224. this.resetWizard = function() {
  225. // remove the existing handlers
  226. $('a[data-toggle="tab"]', $navigation).off('click', innerTabClick);
  227. $('a[data-toggle="tab"]', $navigation).off('show show.bs.tab', innerTabShown);
  228. // reset elements based on current state of the DOM
  229. $navigation = element.find('ul:first', element);
  230. $activeTab = $navigation.find(baseItemSelector + '.active', element);
  231. // re-add handlers
  232. $('a[data-toggle="tab"]', $navigation).on('click', innerTabClick);
  233. $('a[data-toggle="tab"]', $navigation).on('show show.bs.tab', innerTabShown);
  234. obj.fixNavigationButtons();
  235. };
  236. $navigation = element.find('ul:first', element);
  237. $activeTab = $navigation.find(baseItemSelector + '.active', element);
  238. if(!$navigation.hasClass($settings.tabClass)) {
  239. $navigation.addClass($settings.tabClass);
  240. }
  241. // Load onInit
  242. if($settings.onInit && typeof $settings.onInit === 'function'){
  243. $settings.onInit($activeTab, $navigation, 0);
  244. }
  245. // Load onShow
  246. if($settings.onShow && typeof $settings.onShow === 'function'){
  247. $settings.onShow($activeTab, $navigation, obj.nextIndex());
  248. }
  249. $('a[data-toggle="tab"]', $navigation).on('click', innerTabClick);
  250. // attach to both show and show.bs.tab to support Bootstrap versions 2.3.2 and 3.0.0
  251. $('a[data-toggle="tab"]', $navigation).on('show show.bs.tab', innerTabShown);
  252. };
  253. $.fn.bootstrapWizard = function(options) {
  254. //expose methods
  255. if (typeof options == 'string') {
  256. var args = Array.prototype.slice.call(arguments, 1)
  257. if(args.length === 1) {
  258. args.toString();
  259. }
  260. return this.data('bootstrapWizard')[options](args);
  261. }
  262. return this.each(function(index){
  263. var element = $(this);
  264. // Return early if this element already has a plugin instance
  265. if (element.data('bootstrapWizard')) return;
  266. // pass options to plugin constructor
  267. var wizard = new bootstrapWizardCreate(element, options);
  268. // Store plugin object in this element's data
  269. element.data('bootstrapWizard', wizard);
  270. // and then trigger initial change
  271. wizard.fixNavigationButtons();
  272. });
  273. };
  274. // expose options
  275. $.fn.bootstrapWizard.defaults = {
  276. withVisible: true,
  277. tabClass: 'nav nav-pills',
  278. nextSelector: '.wizard li.next',
  279. previousSelector: '.wizard li.previous',
  280. firstSelector: '.wizard li.first',
  281. lastSelector: '.wizard li.last',
  282. finishSelector: '.wizard li.finish',
  283. backSelector: '.wizard li.back',
  284. onShow: null,
  285. onInit: null,
  286. onNext: null,
  287. onPrevious: null,
  288. onLast: null,
  289. onFirst: null,
  290. onFinish: null,
  291. onBack: null,
  292. onTabChange: null,
  293. onTabClick: null,
  294. onTabShow: null
  295. };
  296. })(jQuery);