app.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. /*! http://mths.be/placeholder v2.0.7 by @mathias */
  2. ;(function (h, j, e) {
  3. var a = "placeholder" in j.createElement("input");
  4. var f = "placeholder" in j.createElement("textarea");
  5. var k = e.fn;
  6. var d = e.valHooks;
  7. var b = e.propHooks;
  8. var m;
  9. var l;
  10. if (a && f) {
  11. l = k.placeholder = function () {return this;};
  12. l.input = l.textarea = true;
  13. } else {
  14. l = k.placeholder = function () {
  15. var n = this;
  16. n.filter((a ? "textarea" : ":input") + "[placeholder]").not(".placeholder").bind({ "focus.placeholder": c, "blur.placeholder": g }).data("placeholder-enabled", true).trigger("blur.placeholder");
  17. return n;
  18. };
  19. l.input = a;
  20. l.textarea = f;
  21. m = {
  22. get: function (o) {
  23. var n = e(o);
  24. var p = n.data("placeholder-password");
  25. if (p) {return p[0].value;}
  26. return n.data("placeholder-enabled") && n.hasClass("placeholder") ? "" : o.value;
  27. }, set: function (o, q) {
  28. var n = e(o);
  29. var p = n.data("placeholder-password");
  30. if (p) {return p[0].value = q;}
  31. if (!n.data("placeholder-enabled")) {return o.value = q;}
  32. if (q == "") {
  33. o.value = q;
  34. if (o != j.activeElement) {g.call(o);}
  35. } else {if (n.hasClass("placeholder")) {c.call(o, true, q) || (o.value = q);} else {o.value = q;}}
  36. return n;
  37. }
  38. };
  39. if (!a) {
  40. d.input = m;
  41. b.value = m;
  42. }
  43. if (!f) {
  44. d.textarea = m;
  45. b.value = m;
  46. }
  47. e(function () {
  48. e(j).delegate("form", "submit.placeholder", function () {
  49. var n = e(".placeholder", this).each(c);
  50. setTimeout(function () {n.each(g);}, 10);
  51. });
  52. });
  53. e(h).bind("beforeunload.placeholder", function () {e(".placeholder").each(function () {this.value = "";});});
  54. }
  55. function i(o) {
  56. var n = {};
  57. var p = /^jQuery\d+$/;
  58. e.each(o.attributes, function (r, q) {if (q.specified && !p.test(q.name)) {n[q.name] = q.value;}});
  59. return n;
  60. }
  61. function c(o, p) {
  62. var n = this;
  63. var q = e(n);
  64. if (n.value == q.attr("placeholder") && q.hasClass("placeholder")) {
  65. if (q.data("placeholder-password")) {
  66. q = q.hide().next().show().attr("id", q.removeAttr("id").data("placeholder-id"));
  67. if (o === true) {return q[0].value = p;}
  68. q.focus();
  69. } else {
  70. n.value = "";
  71. q.removeClass("placeholder");
  72. n == j.activeElement && n.select();
  73. }
  74. }
  75. }
  76. function g() {
  77. var r;
  78. var n = this;
  79. var q = e(n);
  80. var p = this.id;
  81. if (n.value == "") {
  82. if (n.type == "password") {
  83. if (!q.data("placeholder-textinput")) {
  84. try {r = q.clone().attr({ type: "text" });} catch (o) {r = e("<input>").attr(e.extend(i(this), { type: "text" }));}
  85. r.removeAttr("name").data({ "placeholder-password": q, "placeholder-id": p }).bind("focus.placeholder", c);
  86. q.data({ "placeholder-textinput": r, "placeholder-id": p }).before(r);
  87. }
  88. q = q.removeAttr("id").hide().prev().attr("id", p).show();
  89. }
  90. q.addClass("placeholder");
  91. q[0].value = q.attr("placeholder");
  92. } else {q.removeClass("placeholder");}
  93. }
  94. }(this, document, jQuery));
  95. /* Modernizr 2.6.2 (Custom Build) | MIT & BSD
  96. * Build: http://modernizr.com/download/#-touch-cssclasses-teststyles-prefixes
  97. */
  98. ;window.Modernizr = function (a, b, c) {
  99. function w(a) {j.cssText = a;}
  100. function x(a, b) {return w(m.join(a + ";") + (b || ""));}
  101. function y(a, b) {return typeof a === b;}
  102. function z(a, b) {return !!~("" + a).indexOf(b);}
  103. function A(a, b, d) {
  104. for (var e in a) {
  105. var f = b[a[e]];
  106. if (f !== c) return d === !1 ? a[e] : y(f, "function") ? f.bind(d || b) : f;
  107. }
  108. return !1;
  109. }
  110. var d = "2.6.2", e = {}, f = !0, g = b.documentElement, h = "modernizr", i = b.createElement(h), j = i.style, k, l = {}.toString, m = " -webkit- -moz- -o- -ms- ".split(" "), n = {}, o = {}, p = {}, q = [], r = q.slice, s, t = function (a, c, d, e) {
  111. var f, i, j, k, l = b.createElement("div"), m = b.body, n = m || b.createElement("body");
  112. if (parseInt(d, 10)) while (d--) j = b.createElement("div"), j.id = e ? e[d] : h + (d + 1), l.appendChild(j);
  113. return f = ["&#173;", '<style id="s', h, '">', a, "</style>"].join(""), l.id = h, (m ? l : n).innerHTML += f, n.appendChild(l), m || (n.style.background = "", n.style.overflow = "hidden", k = g.style.overflow, g.style.overflow = "hidden", g.appendChild(n)), i = c(l, a), m ? l.parentNode.removeChild(l) : (n.parentNode.removeChild(n), g.style.overflow = k), !!i;
  114. }, u = {}.hasOwnProperty, v;
  115. !y(u, "undefined") && !y(u.call, "undefined") ? v = function (a, b) {return u.call(a, b);} : v = function (a, b) {return b in a && y(a.constructor.prototype[b], "undefined");}, Function.prototype.bind || (Function.prototype.bind = function (b) {
  116. var c = this;
  117. if (typeof c != "function") throw new TypeError;
  118. var d = r.call(arguments, 1), e = function () {
  119. if (this instanceof e) {
  120. var a = function () {};
  121. a.prototype = c.prototype;
  122. var f = new a, g = c.apply(f, d.concat(r.call(arguments)));
  123. return Object(g) === g ? g : f;
  124. }
  125. return c.apply(b, d.concat(r.call(arguments)));
  126. };
  127. return e;
  128. }), n.touch = function () {
  129. var c;
  130. return "ontouchstart" in a || a.DocumentTouch && b instanceof DocumentTouch ? c = !0 : t(["@media (", m.join("touch-enabled),("), h, ")", "{#modernizr{top:9px;position:absolute}}"].join(""), function (a) {c = a.offsetTop === 9;}), c;
  131. };
  132. for (var B in n) v(n, B) && (s = B.toLowerCase(), e[s] = n[B](), q.push((e[s] ? "" : "no-") + s));
  133. return e.addTest = function (a, b) {
  134. if (typeof a == "object") for (var d in a) v(a, d) && e.addTest(d, a[d]); else {
  135. a = a.toLowerCase();
  136. if (e[a] !== c) return e;
  137. b = typeof b == "function" ? b() : b, typeof f != "undefined" && f && (g.className += " " + (b ? "" : "no-") + a), e[a] = b;
  138. }
  139. return e;
  140. }, w(""), i = k = null, e._version = d, e._prefixes = m, e.testStyles = t, g.className = g.className.replace(/(^|\s)no-js(\s|$)/, "$1$2") + (f ? " js " + q.join(" ") : ""), e;
  141. }(this, this.document);
  142. Modernizr.addTest('android', function () {return !!navigator.userAgent.match(/Android/i);});
  143. Modernizr.addTest('chrome', function () {return !!navigator.userAgent.match(/Chrome/i);});
  144. Modernizr.addTest('firefox', function () {return !!navigator.userAgent.match(/Firefox/i);});
  145. Modernizr.addTest('iemobile', function () {return !!navigator.userAgent.match(/IEMobile/i);});
  146. Modernizr.addTest('ie', function () {return !!navigator.userAgent.match(/MSIE/i);});
  147. Modernizr.addTest('ie8', function () {return !!navigator.userAgent.match(/MSIE 8/i);});
  148. Modernizr.addTest('ie10', function () {return !!navigator.userAgent.match(/MSIE 10/i);});
  149. Modernizr.addTest('ie11', function () {return !!navigator.userAgent.match(/Trident.*rv:11\./);});
  150. Modernizr.addTest('ios', function () {return !!navigator.userAgent.match(/iPhone|iPad|iPod/i);});
  151. Modernizr.addTest('ios7 ipad', function () {return !!navigator.userAgent.match(/iPad;.*CPU.*OS 7_\d/i);});
  152. /*!
  153. * screenfull
  154. * v1.0.4 - 2013-05-26
  155. * https://github.com/sindresorhus/screenfull.js
  156. * (c) Sindre Sorhus; MIT License
  157. */
  158. (function (a, b) {
  159. "use strict";
  160. var c = "undefined" != typeof Element && "ALLOW_KEYBOARD_INPUT" in Element, d = function () {
  161. for (var a, c, d = [["requestFullscreen", "exitFullscreen", "fullscreenElement", "fullscreenEnabled", "fullscreenchange", "fullscreenerror"], ["webkitRequestFullscreen", "webkitExitFullscreen", "webkitFullscreenElement", "webkitFullscreenEnabled", "webkitfullscreenchange", "webkitfullscreenerror"], ["webkitRequestFullScreen", "webkitCancelFullScreen", "webkitCurrentFullScreenElement", "webkitCancelFullScreen", "webkitfullscreenchange", "webkitfullscreenerror"], ["mozRequestFullScreen", "mozCancelFullScreen", "mozFullScreenElement", "mozFullScreenEnabled", "mozfullscreenchange", "mozfullscreenerror"]], e = 0, f = d.length, g = {}; f > e; e++) if (a = d[e], a && a[1] in b) {
  162. for (e = 0, c = a.length; c > e; e++) g[d[0][e]] = a[e];
  163. return g;
  164. }
  165. return !1;
  166. }(), e = {
  167. request: function (a) {
  168. var e = d.requestFullscreen;
  169. a = a || b.documentElement, /5\.1[\.\d]* Safari/.test(navigator.userAgent) ? a[e]() : a[e](c && Element.ALLOW_KEYBOARD_INPUT);
  170. }, exit: function () {b[d.exitFullscreen]();}, toggle: function (a) {this.isFullscreen ? this.exit() : this.request(a);}, onchange: function () {}, onerror: function () {}, raw: d
  171. };
  172. return d ? (Object.defineProperties(e, {
  173. isFullscreen: { get: function () {return !!b[d.fullscreenElement];} },
  174. element: { enumerable: !0, get: function () {return b[d.fullscreenElement];} },
  175. enabled: { enumerable: !0, get: function () {return !!b[d.fullscreenEnabled];} }
  176. }), b.addEventListener(d.fullscreenchange, function (a) {e.onchange.call(e, a);}), b.addEventListener(d.fullscreenerror, function (a) {e.onerror.call(e, a);}), a.screenfull = e, void 0) : a.screenfull = !1;
  177. })(window, document);
  178. function numts(value) {
  179. if (isNaN(value) || value === undefined || value == '-') {
  180. return '-';
  181. }
  182. var theTime = parseInt(value);// 秒
  183. if (isNaN(theTime)) {
  184. return '-';
  185. }
  186. if (value < 0) {
  187. return '超时!';
  188. }
  189. var theTime1 = 0;// 分
  190. var theTime2 = 0;// 小时
  191. // alert(theTime);
  192. if (theTime > 60) {
  193. theTime1 = parseInt(theTime / 60);
  194. theTime = parseInt(theTime % 60);
  195. // alert(theTime1+"-"+theTime);
  196. if (theTime1 > 60) {
  197. theTime2 = parseInt(theTime1 / 60);
  198. theTime1 = parseInt(theTime1 % 60);
  199. }
  200. }
  201. var result = padZero(parseInt(theTime));
  202. if (theTime1 > 0) {
  203. result = padZero(parseInt(theTime1)) + ":" + result;
  204. } else {
  205. result = "00:" + result;
  206. }
  207. if (theTime2 > 0) {
  208. result = padZero(parseInt(theTime2)) + ":" + result;
  209. }
  210. return result;
  211. }
  212. function padZero(num) {
  213. if (!isNaN(num)) {
  214. if (num.toString().length < 2) {
  215. return "0" + num;
  216. } else {
  217. return num;
  218. }
  219. }
  220. return "00";
  221. }
  222. function numt(num) {
  223. if (num === undefined || isNaN(num)) {
  224. return '-';
  225. }
  226. return (num + '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
  227. }
  228. function nump(v) {
  229. if (v == '-' || v === undefined || isNaN(v)) {
  230. return '-';
  231. }
  232. return v + "%";
  233. }
  234. function numdateZ(javaTimestamp) {
  235. var timestamp = moment(new Date(parseInt(javaTimestamp))).subtract(8, 'hours');
  236. return timestamp.format("YYYY-MM-DD HH:mm:ss");
  237. }
  238. function numdate(javaTimestamp) {
  239. var timestamp = moment(new Date(parseInt(javaTimestamp)));
  240. return timestamp.format("YYYY-MM-DD HH:mm:ss");
  241. }
  242. function convertCardId(original) {
  243. return original;
  244. }
  245. function initDateRangePick(control) {
  246. control.daterangepicker({
  247. autoUpdateInput: false,
  248. ranges: {
  249. '今日': [moment().startOf('day'), moment()],
  250. '昨日': [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')],
  251. '最近7日': [moment().subtract(6, 'days'), moment()],
  252. '最近30日': [moment().subtract(29, 'days'), moment()]
  253. },
  254. locale: {
  255. 'format': "YYYY-MM-DD",
  256. 'separator': ' 至 ',
  257. 'applyLabel': '确定',
  258. 'cancelLabel': '清除',
  259. 'fromLabel': '起始时间',
  260. 'toLabel': '结束时间',
  261. 'customRangeLabel': '自定义',
  262. 'daysOfWeek': ['日', '一', '二', '三', '四', '五', '六'],
  263. 'monthNames': ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
  264. 'firstDay': 1
  265. }
  266. });
  267. control.on('apply.daterangepicker', function (ev, picker) {
  268. $(this).val(picker.startDate.format('YYYY-MM-DD') + ' 至 ' + picker.endDate.format('YYYY-MM-DD'));
  269. });
  270. control.on('cancel.daterangepicker', function (ev, picker) {
  271. control.val('');
  272. });
  273. }
  274. (function ($) {
  275. $.fn.extend({
  276. serializeObject: function () {
  277. var o = {};
  278. var a = this.serializeArray();
  279. $.each(a, function () {
  280. if (o[this.name] !== undefined) {
  281. if (!o[this.name].push) {
  282. o[this.name] = [o[this.name]];
  283. }
  284. o[this.name].push(this.value || '');
  285. } else {
  286. o[this.name] = this.value || '';
  287. }
  288. });
  289. return o;
  290. },
  291. formGet: function () {
  292. var jq = this;
  293. if (jq.length <= 0) {
  294. return {};
  295. }
  296. var vra = [];
  297. var m = [];
  298. jq.each(function (index, ele) {
  299. if (ele.tagName === 'FORM') {
  300. var $form = $(this);
  301. m.push({
  302. id: '',
  303. obj: $form.serializeObject()
  304. });
  305. }
  306. });
  307. jq.find('form').each(function (index, form) {
  308. var $form = $(form);
  309. if ($form.attr('name')) {
  310. m.push({
  311. id: $form.attr('name'),
  312. obj: $form.serializeObject()
  313. });
  314. } else {
  315. m.push({
  316. id: '',
  317. obj: $form.serializeObject()
  318. });
  319. }
  320. });
  321. var r = {};
  322. for (var i = 0; i < m.length; i++) {
  323. if (m[i].id) {
  324. if (r.hasOwnProperty(m[i].id)) {
  325. $.extend(r[m[i].id], m[i].obj);
  326. } else {
  327. r[m[i].id] = m[i].obj;
  328. }
  329. } else {
  330. $.extend(r, m[i].obj);
  331. }
  332. }
  333. return r;
  334. },
  335. formSet: function (data) {
  336. var jq = this;
  337. for (var p in data) {
  338. if (!data.hasOwnProperty(p)) continue;
  339. jq.find(":input[name='" + p + "']").val(data[p]);
  340. }
  341. },
  342. formClear: function () {
  343. var jq = this;
  344. jq.find(":input").val('');
  345. },
  346. });
  347. })(jQuery);
  348. // data-shift api
  349. +function ($) {
  350. "use strict";
  351. /* SHIFT CLASS DEFINITION
  352. * ====================== */
  353. var Shift = function (element) {
  354. this.$element = $(element);
  355. this.$prev = this.$element.prev();
  356. !this.$prev.length && (this.$parent = this.$element.parent());
  357. };
  358. Shift.prototype = {
  359. constructor: Shift
  360. , init: function () {
  361. var $el = this.$element
  362. , method = $el.data()['toggle'].split(':')[1]
  363. , $target = $el.data('target');
  364. $el.hasClass('in') || $el[method]($target).addClass('in');
  365. }
  366. , reset: function () {
  367. this.$parent && this.$parent['prepend'](this.$element);
  368. !this.$parent && this.$element['insertAfter'](this.$prev);
  369. this.$element.removeClass('in');
  370. }
  371. };
  372. /* SHIFT PLUGIN DEFINITION
  373. * ======================= */
  374. $.fn.shift = function (option) {
  375. return this.each(function () {
  376. var $this = $(this)
  377. , data = $this.data('shift');
  378. if (!data) $this.data('shift', (data = new Shift(this)));
  379. if (typeof option == 'string') data[option]();
  380. });
  381. };
  382. $.fn.shift.Constructor = Shift;
  383. }(jQuery);
  384. /*
  385. // data-bjax api
  386. +function ($) { "use strict";
  387. var Bjax = function (element, options) {
  388. this.options = options
  389. this.$element = $( this.options.target || 'html' );
  390. this.start()
  391. }
  392. Bjax.DEFAULTS = {
  393. backdrop: true
  394. , url: ''
  395. }
  396. Bjax.prototype.start = function () {
  397. var that = this;
  398. this.backdrop();
  399. $.ajax(this.options.url).done(function(r){
  400. that.$content = r;
  401. that.complete();
  402. });
  403. }
  404. Bjax.prototype.complete = function (){
  405. var that = this;
  406. if( this.$element.is('html') || (this.options.replace) ){
  407. try{
  408. window.history.pushState({}, '', this.options.url);
  409. }catch(e){
  410. window.location.replace(this.options.url)
  411. }
  412. }
  413. this.updateBar(100);
  414. }
  415. Bjax.prototype.backdrop = function(){
  416. this.$element.css('position','relative')
  417. this.$backdrop = $('<div class="backdrop fade bg-white"></div>')
  418. .appendTo(this.$element);
  419. if(!this.options.backdrop) this.$backdrop.css('height', '2');
  420. this.$backdrop[0].offsetWidth; // force reflow
  421. this.$backdrop.addClass('in');
  422. this.$bar = $('<div class="bar b-t b-2x b-info"></div>')
  423. .width(0)
  424. .appendTo(this.$backdrop);
  425. }
  426. Bjax.prototype.update = function (){
  427. this.$element.css('position','');
  428. if( !this.$element.is('html') ){
  429. if(this.options.el){
  430. this.$content = $(this.$content).find(this.options.el);
  431. }
  432. this.$element.html(this.$content);
  433. }
  434. if( this.$element.is('html') ) {
  435. if( $('.ie').length ){
  436. location.reload();
  437. return;
  438. }
  439. document.open();
  440. document.write(this.$content);
  441. document.close();
  442. }
  443. }
  444. Bjax.prototype.updateBar = function (per){
  445. var that = this;
  446. this.$bar.stop().animate({
  447. width: per + '%'
  448. }, 500, 'linear', function(){
  449. if(per == 100) that.update();
  450. });
  451. }
  452. Bjax.prototype.enable = function (e){
  453. var link = e.currentTarget;
  454. if ( location.protocol !== link.protocol || location.hostname !== link.hostname )
  455. return false
  456. if (link.hash && link.href.replace(link.hash, '') ===
  457. location.href.replace(location.hash, ''))
  458. return false
  459. if (link.href === location.href + '#' || link.href === location.href)
  460. return false
  461. if(link.protocol.indexOf('http') ==-1)
  462. return false
  463. return true;
  464. }
  465. $.fn.bjax = function (option) {
  466. return this.each(function () {
  467. var $this = $(this);
  468. var data = $this.data('app.bjax');
  469. var options = $.extend({}, Bjax.DEFAULTS, $this.data(), typeof option == 'object' && option)
  470. if (!data) $this.data('app.bjax', (data = new Bjax(this, options)))
  471. if (data) data['start']()
  472. if (typeof option == 'string') data[option]()
  473. })
  474. }
  475. $.fn.bjax.Constructor = Bjax
  476. $(window).on("popstate", function(e) {
  477. if (e.originalEvent.state !== null) {
  478. window.location.reload(true);
  479. }
  480. e.preventDefault();
  481. });
  482. $(document).on('click.app.bjax.data-api', '[data-bjax], .nav-primary a', function (e) {
  483. if(!Bjax.prototype.enable(e)) return;
  484. $(this).bjax({url: $(this).attr('href') || $(this).attr('data-url') });
  485. e.preventDefault();
  486. })
  487. }(jQuery);
  488. */
  489. Date.now = Date.now || function () { return +new Date; };
  490. +function ($) {
  491. $(function () {
  492. // toogle fullscreen
  493. $(document).on('click', "[data-toggle=fullscreen]", function (e) {
  494. e.preventDefault();
  495. if (screenfull.enabled) {
  496. screenfull.request();
  497. }
  498. });
  499. // placeholder
  500. $('input[placeholder], textarea[placeholder]').placeholder();
  501. // popover
  502. $("[data-toggle=popover]").popover();
  503. $(document).on('click', '.popover-title .close', function (e) {
  504. var $target = $(e.target), $popover = $target.closest('.popover').prev();
  505. $popover && $popover.popover('hide');
  506. });
  507. // ajax modal
  508. $(document).on('click', '[data-toggle="ajaxModal"]',
  509. function (e) {
  510. $('#ajaxModal').remove();
  511. e.preventDefault();
  512. var $this = $(this)
  513. , $remote = $this.data('remote') || $this.attr('href')
  514. , $modal = $('<div class="modal fade" id="ajaxModal"><div class="modal-body"></div></div>');
  515. $('body').append($modal);
  516. $modal.modal();
  517. $modal.load($remote);
  518. }
  519. );
  520. // dropdown menu
  521. $.fn.dropdown.Constructor.prototype.change = function (e) {
  522. e.preventDefault();
  523. var $item = $(e.target), $select, $checked = false, $menu, $label;
  524. !$item.is('a') && ($item = $item.closest('a'));
  525. $menu = $item.closest('.dropdown-menu');
  526. $label = $menu.parent().find('.dropdown-label');
  527. $labelHolder = $label.text();
  528. $select = $item.parent().find('input');
  529. $checked = $select.is(':checked');
  530. if ($select.is(':disabled')) return;
  531. if ($select.attr('type') == 'radio' && $checked) return;
  532. if ($select.attr('type') == 'radio') $menu.find('li').removeClass('active');
  533. $item.parent().removeClass('active');
  534. !$checked && $item.parent().addClass('active');
  535. $select.prop("checked", !$select.prop("checked"));
  536. $items = $menu.find('li > input:checked');
  537. if ($items.length) {
  538. $text = [];
  539. $items.each(function () {
  540. var $str = $(this).parent().text();
  541. $str && $text.push($.trim($str));
  542. });
  543. $text = $text.length < 4 ? $text.join(', ') : $text.length + ' selected';
  544. $label.html($text);
  545. } else {
  546. $label.html($label.data('placeholder'));
  547. }
  548. };
  549. $(document).on('click.dropdown-menu', '.dropdown-select > li > a', $.fn.dropdown.Constructor.prototype.change);
  550. // tooltip
  551. $("[data-toggle=tooltip]").tooltip();
  552. // class
  553. $(document).on('click', '[data-toggle^="class"]', function (e) {
  554. e && e.preventDefault();
  555. var $this = $(e.target), $class, $target, $tmp, $classes, $targets;
  556. !$this.data('toggle') && ($this = $this.closest('[data-toggle^="class"]'));
  557. $class = $this.data()['toggle'];
  558. $target = $this.data('target') || $this.attr('href');
  559. $class && ($tmp = $class.split(':')[1]) && ($classes = $tmp.split(','));
  560. $target && ($targets = $target.split(','));
  561. $classes && $classes.length && $.each($targets, function (index, value) {
  562. if ($classes[index].indexOf('*') !== -1) {
  563. var patt = new RegExp('\\s' +
  564. $classes[index].replace(/\*/g, '[A-Za-z0-9-_]+').split(' ').join('\\s|\\s') +
  565. '\\s', 'g');
  566. $($this).each(function (i, it) {
  567. var cn = ' ' + it.className + ' ';
  568. while (patt.test(cn)) {
  569. cn = cn.replace(patt, ' ');
  570. }
  571. it.className = $.trim(cn);
  572. });
  573. }
  574. ($targets[index] != '#') && $($targets[index]).toggleClass($classes[index]) || $this.toggleClass($classes[index]);
  575. });
  576. $this.toggleClass('active');
  577. });
  578. // panel toggle
  579. $(document).on('click', '.panel-toggle', function (e) {
  580. e && e.preventDefault();
  581. var $this = $(e.target), $class = 'collapse', $target;
  582. if (!$this.is('a')) $this = $this.closest('a');
  583. $target = $this.closest('.panel');
  584. $target.find('.panel-body').toggleClass($class);
  585. $this.toggleClass('active');
  586. });
  587. // carousel
  588. $('.carousel.auto').carousel();
  589. // button loading
  590. $(document).on('click.button.data-api', '[data-loading-text]', function (e) {
  591. var $this = $(e.target);
  592. $this.is('i') && ($this = $this.parent());
  593. $this.button('loading');
  594. });
  595. var $window = $(window);
  596. // mobile
  597. var mobile = function (option) {
  598. if (option == 'reset') {
  599. $('[data-toggle^="shift"]').shift('reset');
  600. return true;
  601. }
  602. $('[data-toggle^="shift"]').shift('init');
  603. return true;
  604. };
  605. // unmobile
  606. $window.width() < 768 && mobile();
  607. // resize
  608. var $resize, $width = $window.width();
  609. $window.resize(function () {
  610. if ($width !== $window.width()) {
  611. clearTimeout($resize);
  612. $resize = setTimeout(function () {
  613. setHeight();
  614. $window.width() < 768 && mobile();
  615. $window.width() >= 768 && mobile('reset') && fixVbox();
  616. $width = $window.width();
  617. }, 500);
  618. }
  619. });
  620. // fluid layout
  621. var setHeight = function () {
  622. $('.app-fluid #nav > *').css('min-height', $(window).height() - 60);
  623. return true;
  624. };
  625. setHeight();
  626. // fix vbox
  627. var fixVbox = function () {
  628. $('.ie11 .vbox').each(function () {
  629. $(this).height($(this).parent().height());
  630. });
  631. return true;
  632. };
  633. fixVbox();
  634. // collapse nav
  635. $(document).on('click', '[data-ride="collapse"] a', function (e) {
  636. var $this = $(e.target), $active;
  637. $this.is('a') || ($this = $this.closest('a'));
  638. $active = $this.parent().siblings(".active");
  639. $active && $active.toggleClass('active').find('> ul:visible').slideUp(200);
  640. ($this.parent().hasClass('active') && $this.next().slideUp(200)) || $this.next().slideDown(200);
  641. $this.parent().toggleClass('active');
  642. $this.next().is('ul') && e.preventDefault();
  643. setTimeout(function () { $(document).trigger('updateNav'); }, 300);
  644. });
  645. // dropdown still
  646. $(document).on('click.bs.dropdown.data-api', '.dropdown .on, .dropup .on, .open .on', function (e) { e.stopPropagation(); });
  647. });
  648. }(jQuery);
  649. (function ($) {
  650. jQuery.fn.setfocus = function () {
  651. return this.each(function () {
  652. var dom = this;
  653. setTimeout(function () {
  654. try { dom.focus(); } catch (e) { }
  655. }, 0);
  656. });
  657. };
  658. })(jQuery);