functions.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. $(document).ready(function(){
  2. /* --------------------------------------------------------
  3. Template Settings
  4. -----------------------------------------------------------*/
  5. var settings = '<a id="settings" href="#changeSkin" data-toggle="modal">' +
  6. '<i class="fa fa-gear"></i> Change Skin' +
  7. '</a>' +
  8. '<div class="modal fade" id="changeSkin" tabindex="-1" role="dialog" aria-hidden="true">' +
  9. '<div class="modal-dialog modal-lg">' +
  10. '<div class="modal-content">' +
  11. '<div class="modal-header">' +
  12. '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>' +
  13. '<h4 class="modal-title">Change Template Skin</h4>' +
  14. '</div>' +
  15. '<div class="modal-body">' +
  16. '<div class="row template-skins">' +
  17. '<a data-skin="skin-blur-violate" class="col-sm-2 col-xs-4" href="">' +
  18. '<img src="img/skin-violate.jpg" alt="">' +
  19. '</a>' +
  20. '<a data-skin="skin-blur-lights" class="col-sm-2 col-xs-4" href="">' +
  21. '<img src="img/skin-lights.jpg" alt="">' +
  22. '</a>' +
  23. '<a data-skin="skin-blur-city" class="col-sm-2 col-xs-4" href="">' +
  24. '<img src="img/skin-city.jpg" alt="">' +
  25. '</a>' +
  26. '<a data-skin="skin-blur-greenish" class="col-sm-2 col-xs-4" href="">' +
  27. '<img src="img/skin-greenish.jpg" alt="">' +
  28. '</a>' +
  29. '<a data-skin="skin-blur-night" class="col-sm-2 col-xs-4" href="">' +
  30. '<img src="img/skin-night.jpg" alt="">' +
  31. '</a>' +
  32. '<a data-skin="skin-blur-blue" class="col-sm-2 col-xs-4" href="">' +
  33. '<img src="img/skin-blue.jpg" alt="">' +
  34. '</a>' +
  35. '<a data-skin="skin-blur-sunny" class="col-sm-2 col-xs-4" href="">' +
  36. '<img src="img/skin-sunny.jpg" alt="">' +
  37. '</a>' +
  38. '<a data-skin="skin-cloth" class="col-sm-2 col-xs-4" href="">' +
  39. '<img src="img/skin-cloth.jpg" alt="">' +
  40. '</a>' +
  41. '<a data-skin="skin-tectile" class="col-sm-2 col-xs-4" href="">' +
  42. '<img src="img/skin-tectile.jpg" alt="">' +
  43. '</a>' +
  44. '<a data-skin="skin-blur-chrome" class="col-sm-2 col-xs-4" href="">' +
  45. '<img src="img/skin-chrome.jpg" alt="">' +
  46. '</a>' +
  47. '<a data-skin="skin-blur-ocean" class="col-sm-2 col-xs-4" href="">' +
  48. '<img src="img/skin-ocean.jpg" alt="">' +
  49. '</a>' +
  50. '<a data-skin="skin-blur-sunset" class="col-sm-2 col-xs-4" href="">' +
  51. '<img src="img/skin-sunset.jpg" alt="">' +
  52. '</a>' +
  53. '<a data-skin="skin-blur-yellow" class="col-sm-2 col-xs-4" href="">' +
  54. '<img src="img/skin-yellow.jpg" alt="">' +
  55. '</a>' +
  56. '<a data-skin="skin-blur-kiwi"class="col-sm-2 col-xs-4" href="">' +
  57. '<img src="img/skin-kiwi.jpg" alt="">' +
  58. '</a>' +
  59. '</div>' +
  60. '</div>' +
  61. '</div>' +
  62. '</div>' +
  63. '</div>';
  64. $('#main').prepend(settings);
  65. $('body').on('click', '.template-skins > a', function(e){
  66. e.preventDefault();
  67. var skin = $(this).data('skin');
  68. $('body').attr('id', skin);
  69. $('#changeSkin').modal('hide');
  70. });
  71. /* --------------------------------------------------------
  72. Components
  73. -----------------------------------------------------------*/
  74. (function(){
  75. /* Textarea */
  76. if($('.auto-size')[0]) {
  77. $('.auto-size').autosize();
  78. }
  79. //Select
  80. if($('.select')[0]) {
  81. $('.select').selectpicker();
  82. }
  83. //Sortable
  84. if($('.sortable')[0]) {
  85. $('.sortable').sortable();
  86. }
  87. //Tag Select
  88. if($('.tag-select')[0]) {
  89. $('.tag-select').chosen();
  90. }
  91. /* Tab */
  92. if($('.tab')[0]) {
  93. $('.tab a').click(function(e) {
  94. e.preventDefault();
  95. $(this).tab('show');
  96. });
  97. }
  98. /* Collapse */
  99. if($('.collapse')[0]) {
  100. $('.collapse').collapse();
  101. }
  102. /* Accordion */
  103. $('.panel-collapse').on('shown.bs.collapse', function () {
  104. $(this).prev().find('.panel-title a').removeClass('active');
  105. });
  106. $('.panel-collapse').on('hidden.bs.collapse', function () {
  107. $(this).prev().find('.panel-title a').addClass('active');
  108. });
  109. //Popover
  110. if($('.pover')[0]) {
  111. $('.pover').popover();
  112. }
  113. })();
  114. /* --------------------------------------------------------
  115. Sidebar + Menu
  116. -----------------------------------------------------------*/
  117. (function(){
  118. /* Menu Toggle */
  119. $('body').on('click touchstart', '#menu-toggle', function(e){
  120. e.preventDefault();
  121. $('html').toggleClass('menu-active');
  122. $('#sidebar').toggleClass('toggled');
  123. //$('#content').toggleClass('m-0');
  124. });
  125. /* Active Menu */
  126. $('#sidebar .menu-item').hover(function(){
  127. $(this).closest('.dropdown').addClass('hovered');
  128. }, function(){
  129. $(this).closest('.dropdown').removeClass('hovered');
  130. });
  131. /* Prevent */
  132. $('.side-menu .dropdown > a').click(function(e){
  133. e.preventDefault();
  134. });
  135. })();
  136. /* --------------------------------------------------------
  137. Chart Info
  138. -----------------------------------------------------------*/
  139. (function(){
  140. $('body').on('click touchstart', '.tile .tile-info-toggle', function(e){
  141. e.preventDefault();
  142. $(this).closest('.tile').find('.chart-info').toggle();
  143. });
  144. })();
  145. /* --------------------------------------------------------
  146. Todo List
  147. -----------------------------------------------------------*/
  148. (function(){
  149. setTimeout(function(){
  150. //Add line-through for alreadt checked items
  151. $('.todo-list .media .checked').each(function(){
  152. $(this).closest('.media').find('.checkbox label').css('text-decoration', 'line-through')
  153. });
  154. //Add line-through when checking
  155. $('.todo-list .media input').on('ifChecked', function(){
  156. $(this).closest('.media').find('.checkbox label').css('text-decoration', 'line-through');
  157. });
  158. $('.todo-list .media input').on('ifUnchecked', function(){
  159. $(this).closest('.media').find('.checkbox label').removeAttr('style');
  160. });
  161. })
  162. })();
  163. /* --------------------------------------------------------
  164. Custom Scrollbar
  165. -----------------------------------------------------------*/
  166. (function() {
  167. if($('.overflow')[0]) {
  168. var overflowRegular, overflowInvisible = false;
  169. overflowRegular = $('.overflow').niceScroll();
  170. }
  171. })();
  172. /* --------------------------------------------------------
  173. Messages + Notifications
  174. -----------------------------------------------------------*/
  175. (function(){
  176. $('body').on('click touchstart', '.drawer-toggle', function(e){
  177. e.preventDefault();
  178. var drawer = $(this).attr('data-drawer');
  179. $('.drawer:not("#'+drawer+'")').removeClass('toggled');
  180. if ($('#'+drawer).hasClass('toggled')) {
  181. $('#'+drawer).removeClass('toggled');
  182. }
  183. else{
  184. $('#'+drawer).addClass('toggled');
  185. }
  186. });
  187. //Close when click outside
  188. $(document).on('mouseup touchstart', function (e) {
  189. var container = $('.drawer, .tm-icon');
  190. if (container.has(e.target).length === 0) {
  191. $('.drawer').removeClass('toggled');
  192. $('.drawer-toggle').removeClass('open');
  193. }
  194. });
  195. //Close
  196. $('body').on('click touchstart', '.drawer-close', function(){
  197. $(this).closest('.drawer').removeClass('toggled');
  198. $('.drawer-toggle').removeClass('open');
  199. });
  200. })();
  201. /* --------------------------------------------------------
  202. Calendar
  203. -----------------------------------------------------------*/
  204. (function(){
  205. //Sidebar
  206. if ($('#sidebar-calendar')[0]) {
  207. var date = new Date();
  208. var d = date.getDate();
  209. var m = date.getMonth();
  210. var y = date.getFullYear();
  211. $('#sidebar-calendar').fullCalendar({
  212. editable: false,
  213. events: [],
  214. header: {
  215. left: 'title'
  216. }
  217. });
  218. }
  219. //Content widget
  220. if ($('#calendar-widget')[0]) {
  221. $('#calendar-widget').fullCalendar({
  222. header: {
  223. left: 'title',
  224. right: 'prev, next',
  225. //right: 'month,basicWeek,basicDay'
  226. },
  227. editable: true,
  228. events: [
  229. {
  230. title: 'All Day Event',
  231. start: new Date(y, m, 1)
  232. },
  233. {
  234. title: 'Long Event',
  235. start: new Date(y, m, d-5),
  236. end: new Date(y, m, d-2)
  237. },
  238. {
  239. title: 'Repeat Event',
  240. start: new Date(y, m, 3),
  241. allDay: false
  242. },
  243. {
  244. title: 'Repeat Event',
  245. start: new Date(y, m, 4),
  246. allDay: false
  247. }
  248. ]
  249. });
  250. }
  251. })();
  252. /* --------------------------------------------------------
  253. RSS Feed widget
  254. -----------------------------------------------------------*/
  255. //(function(){
  256. //if($('#news-feed')[0]){
  257. // $('#news-feed').FeedEk({
  258. //FeedUrl: 'http://rss.cnn.com/rss/edition.rss',
  259. //MaxCount: 5,
  260. //ShowDesc: false,
  261. //ShowPubDate: true,
  262. //DescCharacterLimit: 0
  263. // });
  264. //}
  265. //})();
  266. /* --------------------------------------------------------
  267. Chat
  268. -----------------------------------------------------------*/
  269. $(function() {
  270. $('body').on('click touchstart', '.chat-list-toggle', function(){
  271. $(this).closest('.chat').find('.chat-list').toggleClass('toggled');
  272. });
  273. $('body').on('click touchstart', '.chat .chat-header .btn', function(e){
  274. e.preventDefault();
  275. $('.chat .chat-list').removeClass('toggled');
  276. $(this).closest('.chat').toggleClass('toggled');
  277. });
  278. $(document).on('mouseup touchstart', function (e) {
  279. var container = $('.chat, .chat .chat-list');
  280. if (container.has(e.target).length === 0) {
  281. container.removeClass('toggled');
  282. }
  283. });
  284. });
  285. /* --------------------------------------------------------
  286. Form Validation
  287. -----------------------------------------------------------*/
  288. (function(){
  289. if($("[class*='form-validation']")[0]) {
  290. $("[class*='form-validation']").validationEngine();
  291. //Clear Prompt
  292. $('body').on('click', '.validation-clear', function(e){
  293. e.preventDefault();
  294. $(this).closest('form').validationEngine('hide');
  295. });
  296. }
  297. })();
  298. /* --------------------------------------------------------
  299. `Color Picker
  300. -----------------------------------------------------------*/
  301. (function(){
  302. //Default - hex
  303. if($('.color-picker')[0]) {
  304. $('.color-picker').colorpicker();
  305. }
  306. //RGB
  307. if($('.color-picker-rgb')[0]) {
  308. $('.color-picker-rgb').colorpicker({
  309. format: 'rgb'
  310. });
  311. }
  312. //RGBA
  313. if($('.color-picker-rgba')[0]) {
  314. $('.color-picker-rgba').colorpicker({
  315. format: 'rgba'
  316. });
  317. }
  318. //Output Color
  319. if($('[class*="color-picker"]')[0]) {
  320. $('[class*="color-picker"]').colorpicker().on('changeColor', function(e){
  321. var colorThis = $(this).val();
  322. $(this).closest('.color-pick').find('.color-preview').css('background',e.color.toHex());
  323. });
  324. }
  325. })();
  326. /* --------------------------------------------------------
  327. Date Time Picker
  328. -----------------------------------------------------------*/
  329. (function(){
  330. //Date Only
  331. if($('.date-only')[0]) {
  332. $('.date-only').datetimepicker({
  333. pickTime: false
  334. });
  335. }
  336. //Time only
  337. if($('.time-only')[0]) {
  338. $('.time-only').datetimepicker({
  339. pickDate: false
  340. });
  341. }
  342. //12 Hour Time
  343. if($('.time-only-12')[0]) {
  344. $('.time-only-12').datetimepicker({
  345. pickDate: false,
  346. pick12HourFormat: true
  347. });
  348. }
  349. $('.datetime-pick input:text').on('click', function(){
  350. $(this).closest('.datetime-pick').find('.add-on i').click();
  351. });
  352. })();
  353. /* --------------------------------------------------------
  354. Input Slider
  355. -----------------------------------------------------------*/
  356. (function(){
  357. if($('.input-slider')[0]) {
  358. $('.input-slider').slider().on('slide', function(ev){
  359. $(this).closest('.slider-container').find('.slider-value').val(ev.value);
  360. });
  361. }
  362. })();
  363. /* --------------------------------------------------------
  364. WYSIWYE Editor + Markedown
  365. -----------------------------------------------------------*/
  366. (function(){
  367. //Markedown
  368. if($('.markdown-editor')[0]) {
  369. $('.markdown-editor').markdown({
  370. autofocus:false,
  371. savable:false
  372. });
  373. }
  374. //WYSIWYE Editor
  375. if($('.wysiwye-editor')[0]) {
  376. $('.wysiwye-editor').summernote({
  377. height: 200
  378. });
  379. }
  380. })();
  381. /* --------------------------------------------------------
  382. Media Player
  383. -----------------------------------------------------------*/
  384. (function(){
  385. if($('audio, video')[0]) {
  386. $('audio,video').mediaelementplayer({
  387. success: function(player, node) {
  388. $('#' + node.id + '-mode').html('mode: ' + player.pluginType);
  389. }
  390. });
  391. }
  392. })();
  393. /* ---------------------------
  394. Image Popup [Pirobox]
  395. --------------------------- */
  396. (function() {
  397. if($('.pirobox_gall')[0]) {
  398. //Fix IE
  399. jQuery.browser = {};
  400. (function () {
  401. jQuery.browser.msie = false;
  402. jQuery.browser.version = 0;
  403. if (navigator.userAgent.match(/MSIE ([0-9]+)\./)) {
  404. jQuery.browser.msie = true;
  405. jQuery.browser.version = RegExp.$1;
  406. }
  407. })();
  408. //Lightbox
  409. $().piroBox_ext({
  410. piro_speed : 700,
  411. bg_alpha : 0.5,
  412. piro_scroll : true // pirobox always positioned at the center of the page
  413. });
  414. }
  415. })();
  416. /* ---------------------------
  417. Vertical tab
  418. --------------------------- */
  419. (function(){
  420. $('.tab-vertical').each(function(){
  421. var tabHeight = $(this).outerHeight();
  422. var tabContentHeight = $(this).closest('.tab-container').find('.tab-content').outerHeight();
  423. if ((tabContentHeight) > (tabHeight)) {
  424. $(this).height(tabContentHeight);
  425. }
  426. })
  427. $('body').on('click touchstart', '.tab-vertical li', function(){
  428. var tabVertical = $(this).closest('.tab-vertical');
  429. tabVertical.height('auto');
  430. var tabHeight = tabVertical.outerHeight();
  431. var tabContentHeight = $(this).closest('.tab-container').find('.tab-content').outerHeight();
  432. if ((tabContentHeight) > (tabHeight)) {
  433. tabVertical.height(tabContentHeight);
  434. }
  435. });
  436. })();
  437. /* --------------------------------------------------------
  438. Login + Sign up
  439. -----------------------------------------------------------*/
  440. (function(){
  441. $('body').on('click touchstart', '.box-switcher', function(e){
  442. e.preventDefault();
  443. var box = $(this).attr('data-switch');
  444. $(this).closest('.box').toggleClass('active');
  445. $('#'+box).closest('.box').addClass('active');
  446. });
  447. })();
  448. /* --------------------------------------------------------
  449. Checkbox + Radio
  450. -----------------------------------------------------------*/
  451. if($('input:checkbox, input:radio')[0]) {
  452. //Checkbox + Radio skin
  453. $('input:checkbox:not([data-toggle="buttons"] input, .make-switch input), input:radio:not([data-toggle="buttons"] input)').iCheck({
  454. checkboxClass: 'icheckbox_minimal',
  455. radioClass: 'iradio_minimal',
  456. increaseArea: '20%' // optional
  457. });
  458. //Checkbox listing
  459. var parentCheck = $('.list-parent-check');
  460. var listCheck = $('.list-check');
  461. parentCheck.on('ifChecked', function(){
  462. $(this).closest('.list-container').find('.list-check').iCheck('check');
  463. });
  464. parentCheck.on('ifClicked', function(){
  465. $(this).closest('.list-container').find('.list-check').iCheck('uncheck');
  466. });
  467. listCheck.on('ifChecked', function(){
  468. var parent = $(this).closest('.list-container').find('.list-parent-check');
  469. var thisCheck = $(this).closest('.list-container').find('.list-check');
  470. var thisChecked = $(this).closest('.list-container').find('.list-check:checked');
  471. if(thisCheck.length == thisChecked.length) {
  472. parent.iCheck('check');
  473. }
  474. });
  475. listCheck.on('ifUnchecked', function(){
  476. var parent = $(this).closest('.list-container').find('.list-parent-check');
  477. parent.iCheck('uncheck');
  478. });
  479. listCheck.on('ifChanged', function(){
  480. var thisChecked = $(this).closest('.list-container').find('.list-check:checked');
  481. var showon = $(this).closest('.list-container').find('.show-on');
  482. if(thisChecked.length > 0 ) {
  483. showon.show();
  484. }
  485. else {
  486. showon.hide();
  487. }
  488. });
  489. }
  490. /* --------------------------------------------------------
  491. MAC Hack
  492. -----------------------------------------------------------*/
  493. (function(){
  494. //Mac only
  495. if(navigator.userAgent.indexOf('Mac') > 0) {
  496. $('body').addClass('mac-os');
  497. }
  498. })();
  499. });
  500. $(window).load(function(){
  501. /* --------------------------------------------------------
  502. Tooltips
  503. -----------------------------------------------------------*/
  504. (function(){
  505. if($('.tooltips')[0]) {
  506. $('.tooltips').tooltip();
  507. }
  508. })();
  509. /* --------------------------------------------------------
  510. Animate numbers
  511. -----------------------------------------------------------*/
  512. $('.quick-stats').each(function(){
  513. var target = $(this).find('h2');
  514. var toAnimate = $(this).find('h2').attr('data-value');
  515. // Animate the element's value from x to y:
  516. $({someValue: 0}).animate({someValue: toAnimate}, {
  517. duration: 1000,
  518. easing:'swing', // can be anything
  519. step: function() { // called on every step
  520. // Update the element's text with rounded-up value:
  521. target.text(commaSeparateNumber(Math.round(this.someValue)));
  522. }
  523. });
  524. function commaSeparateNumber(val){
  525. while (/(\d+)(\d{3})/.test(val.toString())){
  526. val = val.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
  527. }
  528. return val;
  529. }
  530. });
  531. });
  532. /* --------------------------------------------------------
  533. Date Time Widget
  534. -----------------------------------------------------------*/
  535. (function(){
  536. var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
  537. var dayNames= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
  538. // Create a newDate() object
  539. var newDate = new Date();
  540. // Extract the current date from Date object
  541. newDate.setDate(newDate.getDate());
  542. // Output the day, date, month and year
  543. $('#date').html(dayNames[newDate.getDay()] + " " + newDate.getDate() + ' ' + monthNames[newDate.getMonth()] + ' ' + newDate.getFullYear());
  544. setInterval( function() {
  545. // Create a newDate() object and extract the seconds of the current time on the visitor's
  546. var seconds = new Date().getSeconds();
  547. // Add a leading zero to seconds value
  548. $("#sec").html(( seconds < 10 ? "0":"" ) + seconds);
  549. },1000);
  550. setInterval( function() {
  551. // Create a newDate() object and extract the minutes of the current time on the visitor's
  552. var minutes = new Date().getMinutes();
  553. // Add a leading zero to the minutes value
  554. $("#min").html(( minutes < 10 ? "0":"" ) + minutes);
  555. },1000);
  556. setInterval( function() {
  557. // Create a newDate() object and extract the hours of the current time on the visitor's
  558. var hours = new Date().getHours();
  559. // Add a leading zero to the hours value
  560. $("#hours").html(( hours < 10 ? "0" : "" ) + hours);
  561. }, 1000);
  562. })();