App.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /*!
  2. * Author: Abdullah A Almsaeed
  3. * Date: 4 Jan 2014
  4. * Description:
  5. * This file should be included in all pages
  6. !**/
  7. /*!
  8. * Author: Hugo Briand
  9. * Date: 4 Apr 2014
  10. * Description:
  11. * Removed demo button from original AdmineLTE app.js file
  12. !**/
  13. $(function() {
  14. "use strict";
  15. //Enable sidebar toggle
  16. $("[data-toggle='offcanvas']").click(function(e) {
  17. e.preventDefault();
  18. //If window is small enough, enable sidebar push menu
  19. if ($(window).width() <= 992) {
  20. $('.row-offcanvas').toggleClass('active');
  21. $('.left-side').removeClass("collapse-left");
  22. $(".right-side").removeClass("strech");
  23. $('.row-offcanvas').toggleClass("relative");
  24. } else {
  25. //Else, enable content streching
  26. $('.left-side').toggleClass("collapse-left");
  27. $(".right-side").toggleClass("strech");
  28. }
  29. });
  30. //Add hover support for touch devices
  31. $('.btn').bind('touchstart', function() {
  32. $(this).addClass('hover');
  33. }).bind('touchend', function() {
  34. $(this).removeClass('hover');
  35. });
  36. //Activate tooltips
  37. $("[data-toggle='tooltip']").tooltip();
  38. /*
  39. * Add collapse and remove events to boxes
  40. */
  41. $("[data-widget='collapse']").click(function() {
  42. //Find the box parent
  43. var box = $(this).parents(".box").first();
  44. //Find the body and the footer
  45. var bf = box.find(".box-body, .box-footer");
  46. if (!box.hasClass("collapsed-box")) {
  47. box.addClass("collapsed-box");
  48. //Convert minus into plus
  49. $(this).children(".fa-minus").removeClass("fa-minus").addClass("fa-plus");
  50. bf.slideUp();
  51. } else {
  52. box.removeClass("collapsed-box");
  53. //Convert plus into minus
  54. $(this).children(".fa-plus").removeClass("fa-plus").addClass("fa-minus");
  55. bf.slideDown();
  56. }
  57. });
  58. /*
  59. * ADD SLIMSCROLL TO THE TOP NAV DROPDOWNS
  60. * ---------------------------------------
  61. */
  62. $(".navbar .menu").slimscroll({
  63. height: "200px",
  64. alwaysVisible: false,
  65. size: "3px"
  66. }).css("width", "100%");
  67. /*
  68. * INITIALIZE BUTTON TOGGLE
  69. * ------------------------
  70. */
  71. $('.btn-group[data-toggle="btn-toggle"]').each(function() {
  72. var group = $(this);
  73. $(this).find(".btn").click(function(e) {
  74. group.find(".btn.active").removeClass("active");
  75. $(this).addClass("active");
  76. e.preventDefault();
  77. });
  78. });
  79. $("[data-widget='remove']").click(function() {
  80. //Find the box parent
  81. var box = $(this).parents(".box").first();
  82. box.slideUp();
  83. });
  84. /* Sidebar tree view */
  85. $(".sidebar .treeview").tree();
  86. /*
  87. * Make sure that the sidebar is streched full height
  88. * ---------------------------------------------
  89. * We are gonna assign a min-height value every time the
  90. * wrapper gets resized and upon page load. We will use
  91. * Ben Alman's method for detecting the resize event.
  92. **/
  93. function _fix() {
  94. //Get window height and the wrapper height
  95. var height = $(window).height() - $("body > .header").height() - ($("body > .footer").outerHeight() || 0);
  96. $(".wrapper").css("min-height", height + "px");
  97. var content = $(".wrapper").height();
  98. //If the wrapper height is greater than the window
  99. if (content > height)
  100. //then set sidebar height to the wrapper
  101. $(".left-side, html, body").css("min-height", content + "px");
  102. else {
  103. //Otherwise, set the sidebar to the height of the window
  104. $(".left-side, html, body").css("min-height", height + "px");
  105. }
  106. }
  107. //Fire upon load
  108. _fix();
  109. //Fire when wrapper is resized
  110. $(".wrapper").resize(function() {
  111. _fix();
  112. fix_sidebar();
  113. });
  114. //Fix the fixed layout sidebar scroll bug
  115. fix_sidebar();
  116. });
  117. function fix_sidebar() {
  118. //Make sure the body tag has the .fixed class
  119. if (!$("body").hasClass("fixed")) {
  120. return;
  121. }
  122. //Add slimscroll
  123. $(".sidebar").slimscroll({
  124. height: ($(window).height() - $(".header").height()) + "px",
  125. color: "rgba(0,0,0,0.2)"
  126. });
  127. }
  128. /*
  129. * BOX REFRESH BUTTON
  130. * ------------------
  131. * This is a custom plugin to use with the compenet BOX. It allows you to add
  132. * a refresh button to the box. It converts the box's state to a loading state.
  133. *
  134. * USAGE:
  135. * $("#box-widget").boxRefresh( options );
  136. * */
  137. (function($) {
  138. "use strict";
  139. $.fn.boxRefresh = function(options) {
  140. // Render options
  141. var settings = $.extend({
  142. //Refressh button selector
  143. trigger: ".refresh-btn",
  144. //File source to be loaded (e.g: ajax/src.php)
  145. source: "",
  146. //Callbacks
  147. onLoadStart: function(box) {
  148. }, //Right after the button has been clicked
  149. onLoadDone: function(box) {
  150. } //When the source has been loaded
  151. }, options);
  152. //The overlay
  153. var overlay = $('<div class="overlay"></div><div class="loading-img"></div>');
  154. return this.each(function() {
  155. //if a source is specified
  156. if (settings.source === "") {
  157. if (console) {
  158. console.log("Please specify a source first - boxRefresh()");
  159. }
  160. return;
  161. }
  162. //the box
  163. var box = $(this);
  164. //the button
  165. var rBtn = box.find(settings.trigger).first();
  166. //On trigger click
  167. rBtn.click(function(e) {
  168. e.preventDefault();
  169. //Add loading overlay
  170. start(box);
  171. //Perform ajax call
  172. box.find(".box-body").load(settings.source, function() {
  173. done(box);
  174. });
  175. });
  176. });
  177. function start(box) {
  178. //Add overlay and loading img
  179. box.append(overlay);
  180. settings.onLoadStart.call(box);
  181. }
  182. function done(box) {
  183. //Remove overlay and loading img
  184. box.find(overlay).remove();
  185. settings.onLoadDone.call(box);
  186. }
  187. };
  188. })(jQuery);
  189. /*
  190. * SIDEBAR MENU
  191. * ------------
  192. * This is a custom plugin for the sidebar menu. It provides a tree view.
  193. *
  194. * Usage:
  195. * $(".sidebar).tree();
  196. *
  197. * Note: This plugin does not accept any options. Instead, it only requires a class
  198. * added to the element that contains a sub-menu.
  199. *
  200. * When used with the sidebar, for example, it would look something like this:
  201. * <ul class='sidebar-menu'>
  202. * <li class="treeview active">
  203. * <a href="#>Menu</a>
  204. * <ul class='treeview-menu'>
  205. * <li class='active'><a href=#>Level 1</a></li>
  206. * </ul>
  207. * </li>
  208. * </ul>
  209. *
  210. * Add .active class to <li> elements if you want the menu to be open automatically
  211. * on page load. See above for an example.
  212. */
  213. (function($) {
  214. "use strict";
  215. $.fn.tree = function() {
  216. return this.each(function() {
  217. var btn = $(this).children("a").first();
  218. var menu = $(this).children(".treeview-menu").first();
  219. var isActive = $(this).hasClass('active');
  220. //initialize already active menus
  221. if (isActive) {
  222. menu.show();
  223. btn.children(".fa-angle-left").first().removeClass("fa-angle-left").addClass("fa-angle-down");
  224. }
  225. //Slide open or close the menu on link click
  226. btn.click(function(e) {
  227. e.preventDefault();
  228. if (isActive) {
  229. //Slide up to close menu
  230. menu.slideUp();
  231. isActive = false;
  232. btn.children(".fa-angle-down").first().removeClass("fa-angle-down").addClass("fa-angle-left");
  233. btn.parent("li").removeClass("active");
  234. } else {
  235. //Slide down to open menu
  236. menu.slideDown();
  237. isActive = true;
  238. btn.children(".fa-angle-left").first().removeClass("fa-angle-left").addClass("fa-angle-down");
  239. btn.parent("li").addClass("active");
  240. }
  241. });
  242. /* Add margins to submenu elements to give it a tree look */
  243. menu.find("li > a").each(function() {
  244. var pad = parseInt($(this).css("margin-left")) + 10;
  245. $(this).css({"margin-left": pad + "px"});
  246. });
  247. });
  248. };
  249. }(jQuery));
  250. /*
  251. * TODO LIST CUSTOM PLUGIN
  252. * -----------------------
  253. * This plugin depends on iCheck plugin for checkbox and radio inputs
  254. */
  255. (function($) {
  256. "use strict";
  257. $.fn.todolist = function(options) {
  258. // Render options
  259. var settings = $.extend({
  260. //When the user checks the input
  261. onCheck: function(ele) {
  262. },
  263. //When the user unchecks the input
  264. onUncheck: function(ele) {
  265. }
  266. }, options);
  267. return this.each(function() {
  268. $('input', this).on('ifChecked', function(event) {
  269. var ele = $(this).parents("li").first();
  270. ele.toggleClass("done");
  271. settings.onCheck.call(ele);
  272. });
  273. $('input', this).on('ifUnchecked', function(event) {
  274. var ele = $(this).parents("li").first();
  275. ele.toggleClass("done");
  276. settings.onUncheck.call(ele);
  277. });
  278. });
  279. };
  280. }(jQuery));
  281. /* CENTER ELEMENTS */
  282. (function($) {
  283. "use strict";
  284. jQuery.fn.center = function(parent) {
  285. if (parent) {
  286. parent = this.parent();
  287. } else {
  288. parent = window;
  289. }
  290. this.css({
  291. "position": "absolute",
  292. "top": ((($(parent).height() - this.outerHeight()) / 2) + $(parent).scrollTop() + "px"),
  293. "left": ((($(parent).width() - this.outerWidth()) / 2) + $(parent).scrollLeft() + "px")
  294. });
  295. return this;
  296. }
  297. }(jQuery));
  298. /*
  299. * jQuery resize event - v1.1 - 3/14/2010
  300. * http://benalman.com/projects/jquery-resize-plugin/
  301. *
  302. * Copyright (c) 2010 "Cowboy" Ben Alman
  303. * Dual licensed under the MIT and GPL licenses.
  304. * http://benalman.com/about/license/
  305. */
  306. (function($, h, c) {
  307. var a = $([]), e = $.resize = $.extend($.resize, {}), i, k = "setTimeout", j = "resize", d = j + "-special-event", b = "delay", f = "throttleWindow";
  308. e[b] = 250;
  309. e[f] = true;
  310. $.event.special[j] = {setup: function() {
  311. if (!e[f] && this[k]) {
  312. return false;
  313. }
  314. var l = $(this);
  315. a = a.add(l);
  316. $.data(this, d, {w: l.width(), h: l.height()});
  317. if (a.length === 1) {
  318. g();
  319. }
  320. }, teardown: function() {
  321. if (!e[f] && this[k]) {
  322. return false
  323. }
  324. var l = $(this);
  325. a = a.not(l);
  326. l.removeData(d);
  327. if (!a.length) {
  328. clearTimeout(i);
  329. }
  330. }, add: function(l) {
  331. if (!e[f] && this[k]) {
  332. return false
  333. }
  334. var n;
  335. function m(s, o, p) {
  336. var q = $(this), r = $.data(this, d);
  337. r.w = o !== c ? o : q.width();
  338. r.h = p !== c ? p : q.height();
  339. n.apply(this, arguments)
  340. }
  341. if ($.isFunction(l)) {
  342. n = l;
  343. return m
  344. } else {
  345. n = l.handler;
  346. l.handler = m
  347. }
  348. }};
  349. function g() {
  350. i = h[k](function() {
  351. a.each(function() {
  352. var n = $(this), m = n.width(), l = n.height(), o = $.data(this, d);
  353. if (m !== o.w || l !== o.h) {
  354. n.trigger(j, [o.w = m, o.h = l])
  355. }
  356. });
  357. g()
  358. }, e[b])
  359. }}
  360. )(jQuery, this);
  361. /*!
  362. * SlimScroll https://github.com/rochal/jQuery-slimScroll
  363. * =======================================================
  364. *
  365. * Copyright (c) 2011 Piotr Rochala (http://rocha.la) Dual licensed under the MIT
  366. */
  367. (function(f) {
  368. jQuery.fn.extend({slimScroll: function(h) {
  369. var a = f.extend({width: "auto", height: "250px", size: "7px", color: "#000", position: "right", distance: "1px", start: "top", opacity: 0.4, alwaysVisible: !1, disableFadeOut: !1, railVisible: !1, railColor: "#333", railOpacity: 0.2, railDraggable: !0, railClass: "slimScrollRail", barClass: "slimScrollBar", wrapperClass: "slimScrollDiv", allowPageScroll: !1, wheelStep: 20, touchScrollStep: 200, borderRadius: "0px", railBorderRadius: "0px"}, h);
  370. this.each(function() {
  371. function r(d) {
  372. if (s) {
  373. d = d ||
  374. window.event;
  375. var c = 0;
  376. d.wheelDelta && (c = -d.wheelDelta / 120);
  377. d.detail && (c = d.detail / 3);
  378. f(d.target || d.srcTarget || d.srcElement).closest("." + a.wrapperClass).is(b.parent()) && m(c, !0);
  379. d.preventDefault && !k && d.preventDefault();
  380. k || (d.returnValue = !1)
  381. }
  382. }
  383. function m(d, f, h) {
  384. k = !1;
  385. var e = d, g = b.outerHeight() - c.outerHeight();
  386. f && (e = parseInt(c.css("top")) + d * parseInt(a.wheelStep) / 100 * c.outerHeight(), e = Math.min(Math.max(e, 0), g), e = 0 < d ? Math.ceil(e) : Math.floor(e), c.css({top: e + "px"}));
  387. l = parseInt(c.css("top")) / (b.outerHeight() - c.outerHeight());
  388. e = l * (b[0].scrollHeight - b.outerHeight());
  389. h && (e = d, d = e / b[0].scrollHeight * b.outerHeight(), d = Math.min(Math.max(d, 0), g), c.css({top: d + "px"}));
  390. b.scrollTop(e);
  391. b.trigger("slimscrolling", ~~e);
  392. v();
  393. p()
  394. }
  395. function C() {
  396. window.addEventListener ? (this.addEventListener("DOMMouseScroll", r, !1), this.addEventListener("mousewheel", r, !1), this.addEventListener("MozMousePixelScroll", r, !1)) : document.attachEvent("onmousewheel", r)
  397. }
  398. function w() {
  399. u = Math.max(b.outerHeight() / b[0].scrollHeight * b.outerHeight(), D);
  400. c.css({height: u + "px"});
  401. var a = u == b.outerHeight() ? "none" : "block";
  402. c.css({display: a})
  403. }
  404. function v() {
  405. w();
  406. clearTimeout(A);
  407. l == ~~l ? (k = a.allowPageScroll, B != l && b.trigger("slimscroll", 0 == ~~l ? "top" : "bottom")) : k = !1;
  408. B = l;
  409. u >= b.outerHeight() ? k = !0 : (c.stop(!0, !0).fadeIn("fast"), a.railVisible && g.stop(!0, !0).fadeIn("fast"))
  410. }
  411. function p() {
  412. a.alwaysVisible || (A = setTimeout(function() {
  413. a.disableFadeOut && s || (x || y) || (c.fadeOut("slow"), g.fadeOut("slow"))
  414. }, 1E3))
  415. }
  416. var s, x, y, A, z, u, l, B, D = 30, k = !1, b = f(this);
  417. if (b.parent().hasClass(a.wrapperClass)) {
  418. var n = b.scrollTop(),
  419. c = b.parent().find("." + a.barClass), g = b.parent().find("." + a.railClass);
  420. w();
  421. if (f.isPlainObject(h)) {
  422. if ("height"in h && "auto" == h.height) {
  423. b.parent().css("height", "auto");
  424. b.css("height", "auto");
  425. var q = b.parent().parent().height();
  426. b.parent().css("height", q);
  427. b.css("height", q)
  428. }
  429. if ("scrollTo"in h)
  430. n = parseInt(a.scrollTo);
  431. else if ("scrollBy"in h)
  432. n += parseInt(a.scrollBy);
  433. else if ("destroy"in h) {
  434. c.remove();
  435. g.remove();
  436. b.unwrap();
  437. return
  438. }
  439. m(n, !1, !0)
  440. }
  441. } else {
  442. a.height = "auto" == a.height ? b.parent().height() : a.height;
  443. n = f("<div></div>").addClass(a.wrapperClass).css({position: "relative",
  444. overflow: "hidden", width: a.width, height: a.height});
  445. b.css({overflow: "hidden", width: a.width, height: a.height});
  446. var g = f("<div></div>").addClass(a.railClass).css({width: a.size, height: "100%", position: "absolute", top: 0, display: a.alwaysVisible && a.railVisible ? "block" : "none", "border-radius": a.railBorderRadius, background: a.railColor, opacity: a.railOpacity, zIndex: 90}), c = f("<div></div>").addClass(a.barClass).css({background: a.color, width: a.size, position: "absolute", top: 0, opacity: a.opacity, display: a.alwaysVisible ?
  447. "block" : "none", "border-radius": a.borderRadius, BorderRadius: a.borderRadius, MozBorderRadius: a.borderRadius, WebkitBorderRadius: a.borderRadius, zIndex: 99}), q = "right" == a.position ? {right: a.distance} : {left: a.distance};
  448. g.css(q);
  449. c.css(q);
  450. b.wrap(n);
  451. b.parent().append(c);
  452. b.parent().append(g);
  453. a.railDraggable && c.bind("mousedown", function(a) {
  454. var b = f(document);
  455. y = !0;
  456. t = parseFloat(c.css("top"));
  457. pageY = a.pageY;
  458. b.bind("mousemove.slimscroll", function(a) {
  459. currTop = t + a.pageY - pageY;
  460. c.css("top", currTop);
  461. m(0, c.position().top, !1)
  462. });
  463. b.bind("mouseup.slimscroll", function(a) {
  464. y = !1;
  465. p();
  466. b.unbind(".slimscroll")
  467. });
  468. return!1
  469. }).bind("selectstart.slimscroll", function(a) {
  470. a.stopPropagation();
  471. a.preventDefault();
  472. return!1
  473. });
  474. g.hover(function() {
  475. v()
  476. }, function() {
  477. p()
  478. });
  479. c.hover(function() {
  480. x = !0
  481. }, function() {
  482. x = !1
  483. });
  484. b.hover(function() {
  485. s = !0;
  486. v();
  487. p()
  488. }, function() {
  489. s = !1;
  490. p()
  491. });
  492. b.bind("touchstart", function(a, b) {
  493. a.originalEvent.touches.length && (z = a.originalEvent.touches[0].pageY)
  494. });
  495. b.bind("touchmove", function(b) {
  496. k || b.originalEvent.preventDefault();
  497. b.originalEvent.touches.length &&
  498. (m((z - b.originalEvent.touches[0].pageY) / a.touchScrollStep, !0), z = b.originalEvent.touches[0].pageY)
  499. });
  500. w();
  501. "bottom" === a.start ? (c.css({top: b.outerHeight() - c.outerHeight()}), m(0, !0)) : "top" !== a.start && (m(f(a.start).position().top, null, !0), a.alwaysVisible || c.hide());
  502. C()
  503. }
  504. });
  505. return this
  506. }});
  507. jQuery.fn.extend({slimscroll: jQuery.fn.slimScroll})
  508. })(jQuery);
  509. /*! iCheck v1.0.1 by Damir Sultanov, http://git.io/arlzeA, MIT Licensed */
  510. (function(h) {
  511. function F(a, b, d) {
  512. var c = a[0], e = /er/.test(d) ? m : /bl/.test(d) ? s : l, f = d == H ? {checked: c[l], disabled: c[s], indeterminate: "true" == a.attr(m) || "false" == a.attr(w)} : c[e];
  513. if (/^(ch|di|in)/.test(d) && !f)
  514. D(a, e);
  515. else if (/^(un|en|de)/.test(d) && f)
  516. t(a, e);
  517. else if (d == H)
  518. for (e in f)
  519. f[e] ? D(a, e, !0) : t(a, e, !0);
  520. else if (!b || "toggle" == d) {
  521. if (!b)
  522. a[p]("ifClicked");
  523. f ? c[n] !== u && t(a, e) : D(a, e)
  524. }
  525. }
  526. function D(a, b, d) {
  527. var c = a[0], e = a.parent(), f = b == l, A = b == m, B = b == s, K = A ? w : f ? E : "enabled", p = k(a, K + x(c[n])), N = k(a, b + x(c[n]));
  528. if (!0 !== c[b]) {
  529. if (!d &&
  530. b == l && c[n] == u && c.name) {
  531. var C = a.closest("form"), r = 'input[name="' + c.name + '"]', r = C.length ? C.find(r) : h(r);
  532. r.each(function() {
  533. this !== c && h(this).data(q) && t(h(this), b)
  534. })
  535. }
  536. A ? (c[b] = !0, c[l] && t(a, l, "force")) : (d || (c[b] = !0), f && c[m] && t(a, m, !1));
  537. L(a, f, b, d)
  538. }
  539. c[s] && k(a, y, !0) && e.find("." + I).css(y, "default");
  540. e[v](N || k(a, b) || "");
  541. B ? e.attr("aria-disabled", "true") : e.attr("aria-checked", A ? "mixed" : "true");
  542. e[z](p || k(a, K) || "")
  543. }
  544. function t(a, b, d) {
  545. var c = a[0], e = a.parent(), f = b == l, h = b == m, q = b == s, p = h ? w : f ? E : "enabled", t = k(a, p + x(c[n])),
  546. u = k(a, b + x(c[n]));
  547. if (!1 !== c[b]) {
  548. if (h || !d || "force" == d)
  549. c[b] = !1;
  550. L(a, f, p, d)
  551. }
  552. !c[s] && k(a, y, !0) && e.find("." + I).css(y, "pointer");
  553. e[z](u || k(a, b) || "");
  554. q ? e.attr("aria-disabled", "false") : e.attr("aria-checked", "false");
  555. e[v](t || k(a, p) || "")
  556. }
  557. function M(a, b) {
  558. if (a.data(q)) {
  559. a.parent().html(a.attr("style", a.data(q).s || ""));
  560. if (b)
  561. a[p](b);
  562. a.off(".i").unwrap();
  563. h(G + '[for="' + a[0].id + '"]').add(a.closest(G)).off(".i")
  564. }
  565. }
  566. function k(a, b, d) {
  567. if (a.data(q))
  568. return a.data(q).o[b + (d ? "" : "Class")]
  569. }
  570. function x(a) {
  571. return a.charAt(0).toUpperCase() +
  572. a.slice(1)
  573. }
  574. function L(a, b, d, c) {
  575. if (!c) {
  576. if (b)
  577. a[p]("ifToggled");
  578. a[p]("ifChanged")[p]("if" + x(d))
  579. }
  580. }
  581. var q = "iCheck", I = q + "-helper", u = "radio", l = "checked", E = "un" + l, s = "disabled", w = "determinate", m = "in" + w, H = "update", n = "type", v = "addClass", z = "removeClass", p = "trigger", G = "label", y = "cursor", J = /ipad|iphone|ipod|android|blackberry|windows phone|opera mini|silk/i.test(navigator.userAgent);
  582. h.fn[q] = function(a, b) {
  583. var d = 'input[type="checkbox"], input[type="' + u + '"]', c = h(), e = function(a) {
  584. a.each(function() {
  585. var a = h(this);
  586. c = a.is(d) ?
  587. c.add(a) : c.add(a.find(d))
  588. })
  589. };
  590. if (/^(check|uncheck|toggle|indeterminate|determinate|disable|enable|update|destroy)$/i.test(a))
  591. return a = a.toLowerCase(), e(this), c.each(function() {
  592. var c = h(this);
  593. "destroy" == a ? M(c, "ifDestroyed") : F(c, !0, a);
  594. h.isFunction(b) && b()
  595. });
  596. if ("object" != typeof a && a)
  597. return this;
  598. var f = h.extend({checkedClass: l, disabledClass: s, indeterminateClass: m, labelHover: !0, aria: !1}, a), k = f.handle, B = f.hoverClass || "hover", x = f.focusClass || "focus", w = f.activeClass || "active", y = !!f.labelHover, C = f.labelHoverClass ||
  599. "hover", r = ("" + f.increaseArea).replace("%", "") | 0;
  600. if ("checkbox" == k || k == u)
  601. d = 'input[type="' + k + '"]';
  602. -50 > r && (r = -50);
  603. e(this);
  604. return c.each(function() {
  605. var a = h(this);
  606. M(a);
  607. var c = this, b = c.id, e = -r + "%", d = 100 + 2 * r + "%", d = {position: "absolute", top: e, left: e, display: "block", width: d, height: d, margin: 0, padding: 0, background: "#fff", border: 0, opacity: 0}, e = J ? {position: "absolute", visibility: "hidden"} : r ? d : {position: "absolute", opacity: 0}, k = "checkbox" == c[n] ? f.checkboxClass || "icheckbox" : f.radioClass || "i" + u, m = h(G + '[for="' + b + '"]').add(a.closest(G)),
  608. A = !!f.aria, E = q + "-" + Math.random().toString(36).replace("0.", ""), g = '<div class="' + k + '" ' + (A ? 'role="' + c[n] + '" ' : "");
  609. m.length && A && m.each(function() {
  610. g += 'aria-labelledby="';
  611. this.id ? g += this.id : (this.id = E, g += E);
  612. g += '"'
  613. });
  614. g = a.wrap(g + "/>")[p]("ifCreated").parent().append(f.insert);
  615. d = h('<ins class="' + I + '"/>').css(d).appendTo(g);
  616. a.data(q, {o: f, s: a.attr("style")}).css(e);
  617. f.inheritClass && g[v](c.className || "");
  618. f.inheritID && b && g.attr("id", q + "-" + b);
  619. "static" == g.css("position") && g.css("position", "relative");
  620. F(a, !0, H);
  621. if (m.length)
  622. m.on("click.i mouseover.i mouseout.i touchbegin.i touchend.i", function(b) {
  623. var d = b[n], e = h(this);
  624. if (!c[s]) {
  625. if ("click" == d) {
  626. if (h(b.target).is("a"))
  627. return;
  628. F(a, !1, !0)
  629. } else
  630. y && (/ut|nd/.test(d) ? (g[z](B), e[z](C)) : (g[v](B), e[v](C)));
  631. if (J)
  632. b.stopPropagation();
  633. else
  634. return!1
  635. }
  636. });
  637. a.on("click.i focus.i blur.i keyup.i keydown.i keypress.i", function(b) {
  638. var d = b[n];
  639. b = b.keyCode;
  640. if ("click" == d)
  641. return!1;
  642. if ("keydown" == d && 32 == b)
  643. return c[n] == u && c[l] || (c[l] ? t(a, l) : D(a, l)), !1;
  644. if ("keyup" == d && c[n] == u)
  645. !c[l] && D(a, l);
  646. else if (/us|ur/.test(d))
  647. g["blur" ==
  648. d ? z : v](x)
  649. });
  650. d.on("click mousedown mouseup mouseover mouseout touchbegin.i touchend.i", function(b) {
  651. var d = b[n], e = /wn|up/.test(d) ? w : B;
  652. if (!c[s]) {
  653. if ("click" == d)
  654. F(a, !1, !0);
  655. else {
  656. if (/wn|er|in/.test(d))
  657. g[v](e);
  658. else
  659. g[z](e + " " + w);
  660. if (m.length && y && e == B)
  661. m[/ut|nd/.test(d) ? z : v](C)
  662. }
  663. if (J)
  664. b.stopPropagation();
  665. else
  666. return!1
  667. }
  668. })
  669. })
  670. }
  671. })(window.jQuery || window.Zepto);