Advertisement
Guest User

js

a guest
Feb 25th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.63 KB | None | 0 0
  1. $(function() {
  2.  
  3. var formElements = function(){
  4. // Bootstrap datepicker
  5. var feDatepicker = function(){
  6. if($(".datepicker1").length > 0){
  7. $(".datepicker1").datepicker({format: 'yyyy-mm-dd'}); // Sample
  8. }
  9.  
  10. }// END Bootstrap datepicker
  11.  
  12. //Bootstrap timepicker
  13. var feTimepicker = function(){
  14. // Default timepicker
  15. if($(".timepicker").length > 0)
  16. $('.timepicker').timepicker();
  17.  
  18. // 24 hours mode timepicker
  19. if($(".timepicker24").length > 0)
  20. $(".timepicker24").timepicker({minuteStep: 5,showSeconds: true,showMeridian: false});
  21.  
  22. }// END Bootstrap timepicker
  23.  
  24. //Daterangepicker
  25. var feDaterangepicker = function(){
  26. if($(".daterange").length > 0)
  27. $(".daterange").daterangepicker({format: 'YYYY-MM-DD',startDate: '2013-01-01',endDate: '2013-12-31'});
  28. }
  29. // END Daterangepicker
  30.  
  31. //Bootstrap colopicker
  32. var feColorpicker = function(){
  33. // Default colorpicker hex
  34. if($(".colorpicker").length > 0)
  35. $(".colorpicker").colorpicker({format: 'hex'});
  36.  
  37. // RGBA mode
  38. if($(".colorpicker_rgba").length > 0)
  39. $(".colorpicker_rgba").colorpicker({format: 'rgba'});
  40.  
  41. // Sample
  42. if($("#colorpicker").length > 0)
  43. $("#colorpicker").colorpicker();
  44.  
  45. }// END Bootstrap colorpicker
  46.  
  47. //Bootstrap select
  48. var feSelect = function(){
  49. if($(".select").length > 0){
  50. $(".select").selectpicker();
  51.  
  52. $(".select").on("change", function(){
  53. if($(this).val() == "" || null === $(this).val()){
  54. if(!$(this).attr("multiple"))
  55. $(this).val("").find("option").removeAttr("selected").prop("selected",false);
  56. }else{
  57. $(this).find("option[value="+$(this).val()+"]").attr("selected",true);
  58. }
  59. });
  60. }
  61. }//END Bootstrap select
  62.  
  63.  
  64. //Validation Engine
  65. var feValidation = function(){
  66. if($("form[id^='validate']").length > 0){
  67.  
  68. // Validation prefix for custom form elements
  69. var prefix = "valPref_";
  70.  
  71. //Add prefix to Bootstrap select plugin
  72. $("form[id^='validate'] .select").each(function(){
  73. $(this).next("div.bootstrap-select").attr("id", prefix + $(this).attr("id")).removeClass("validate[required]");
  74. });
  75.  
  76. // Validation Engine init
  77. $("form[id^='validate']").validationEngine('attach', {promptPosition : "bottomLeft", scroll: false,
  78. onValidationComplete: function(form, status){
  79. form.validationEngine("updatePromptsPosition");
  80. },
  81. prettySelect : true,
  82. usePrefix: prefix
  83. });
  84. }
  85. }//END Validation Engine
  86.  
  87. //Masked Inputs
  88. var feMasked = function(){
  89. if($("input[class^='mask_']").length > 0){
  90. $("input.mask_tin").mask('99-9999999');
  91. $("input.mask_ssn").mask('999-99-9999');
  92. $("input.mask_date").mask('9999-99-99');
  93. $("input.mask_product").mask('a*-999-a999');
  94. $("input.mask_phone").mask('99 (999) 999-99-99');
  95. $("input.mask_phone_ext").mask('99 (999) 999-9999? x99999');
  96. $("input.mask_credit").mask('9999-9999-9999-9999');
  97. $("input.mask_percent").mask('99%');
  98. }
  99. }//END Masked Inputs
  100.  
  101. //Bootstrap tooltip
  102. var feTooltips = function(){
  103. $("body").tooltip({selector:'[data-toggle="tooltip"]',container:"body"});
  104. }//END Bootstrap tooltip
  105.  
  106. //Bootstrap Popover
  107. var fePopover = function(){
  108. $("[data-toggle=popover]").popover();
  109. $(".popover-dismiss").popover({trigger: 'focus'});
  110. }//END Bootstrap Popover
  111.  
  112. //Tagsinput
  113. var feTagsinput = function(){
  114. if($(".tagsinput").length > 0){
  115.  
  116. $(".tagsinput").each(function(){
  117.  
  118. if($(this).data("placeholder") != ''){
  119. var dt = $(this).data("placeholder");
  120. }else
  121. var dt = 'add a tag';
  122.  
  123. $(this).tagsInput({width: '100%',height:'auto',defaultText: dt});
  124. });
  125.  
  126. }
  127. }// END Tagsinput
  128.  
  129. //iCheckbox and iRadion - custom elements
  130. var feiCheckbox = function(){
  131. if($(".icheckbox").length > 0){
  132. $(".icheckbox,.iradio").iCheck({checkboxClass: 'icheckbox_minimal-grey',radioClass: 'iradio_minimal-grey'});
  133. }
  134. }
  135. // END iCheckbox
  136.  
  137. //Bootstrap file input
  138. var feBsFileInput = function(){
  139.  
  140. if($("input.fileinput").length > 0)
  141. $("input.fileinput").bootstrapFileInput();
  142.  
  143. }
  144. //END Bootstrap file input
  145.  
  146. return {// Init all form element features
  147. init: function(){
  148. feDatepicker();
  149. feTimepicker();
  150. feColorpicker();
  151. feSelect();
  152. feValidation();
  153. feMasked();
  154. feTooltips();
  155. fePopover();
  156. feTagsinput();
  157. feiCheckbox();
  158. feBsFileInput();
  159. feDaterangepicker();
  160. }
  161. }
  162. }();
  163.  
  164. var uiElements = function(){
  165.  
  166. //Datatables
  167. var uiDatatable = function(){
  168. if($(".datatable").length > 0){
  169. $(".datatable").dataTable();
  170. $(".datatable").on('page.dt',function () {
  171. onresize(100);
  172. });
  173. }
  174.  
  175. if($(".datatable_simple").length > 0){
  176. $(".datatable_simple").dataTable({"ordering": false, "info": false, "lengthChange": false,"searching": false});
  177. $(".datatable_simple").on('page.dt',function () {
  178. onresize(100);
  179. });
  180. }
  181. }//END Datatable
  182.  
  183. //RangeSlider // This function can be removed or cleared.
  184. var uiRangeSlider = function(){
  185.  
  186. //Default Slider with start value
  187. if($(".defaultSlider").length > 0){
  188. $(".defaultSlider").each(function(){
  189. var rsMin = $(this).data("min");
  190. var rsMax = $(this).data("max");
  191.  
  192. $(this).rangeSlider({
  193. bounds: {min: 1, max: 200},
  194. defaultValues: {min: rsMin, max: rsMax}
  195. });
  196. });
  197. }//End Default
  198.  
  199. //Date range slider
  200. if($(".dateSlider").length > 0){
  201. $(".dateSlider").each(function(){
  202. $(this).dateRangeSlider({
  203. bounds: {min: new Date(2012, 1, 1), max: new Date(2015, 12, 31)},
  204. defaultValues:{min: new Date(2012, 10, 15),max: new Date(2014, 12, 15)}
  205. });
  206. });
  207. }//End date range slider
  208.  
  209. //Range slider with predefinde range
  210. if($(".rangeSlider").length > 0){
  211. $(".rangeSlider").each(function(){
  212. var rsMin = $(this).data("min");
  213. var rsMax = $(this).data("max");
  214.  
  215. $(this).rangeSlider({
  216. bounds: {min: 1, max: 200},
  217. range: {min: 20, max: 40},
  218. defaultValues: {min: rsMin, max: rsMax}
  219. });
  220. });
  221. }//End
  222.  
  223. //Range Slider with custom step
  224. if($(".stepSlider").length > 0){
  225. $(".stepSlider").each(function(){
  226. var rsMin = $(this).data("min");
  227. var rsMax = $(this).data("max");
  228.  
  229. $(this).rangeSlider({
  230. bounds: {min: 1, max: 200},
  231. defaultValues: {min: rsMin, max: rsMax},
  232. step: 10
  233. });
  234. });
  235. }//End
  236.  
  237. }//END RangeSlider
  238.  
  239. //Start Knob Plugin
  240. var uiKnob = function(){
  241.  
  242. if($(".knob").length > 0){
  243. $(".knob").knob();
  244. }
  245.  
  246. }//End Knob
  247.  
  248. // Start Smart Wizard
  249. var uiSmartWizard = function(){
  250.  
  251. if($(".wizard").length > 0){
  252.  
  253. //Check count of steps in each wizard
  254. $(".wizard > ul").each(function(){
  255. $(this).addClass("steps_"+$(this).children("li").length);
  256. });//end
  257.  
  258. // This par of code used for example
  259. if($("#wizard-validation").length > 0){
  260.  
  261. var validator = $("#wizard-validation").validate({
  262. rules: {
  263. login: {
  264. required: true,
  265. minlength: 2,
  266. maxlength: 8
  267. },
  268. password: {
  269. required: true,
  270. minlength: 5,
  271. maxlength: 10
  272. },
  273. repassword: {
  274. required: true,
  275. minlength: 5,
  276. maxlength: 10,
  277. equalTo: "#password"
  278. },
  279. email: {
  280. required: true,
  281. email: true
  282. },
  283. name: {
  284. required: true,
  285. maxlength: 10
  286. },
  287. adress: {
  288. required: true
  289. }
  290. }
  291. });
  292.  
  293. }// End of example
  294.  
  295. $(".wizard").smartWizard({
  296. // This part of code can be removed FROM
  297. onLeaveStep: function(obj){
  298. var wizard = obj.parents(".wizard");
  299.  
  300. if(wizard.hasClass("wizard-validation")){
  301.  
  302. var valid = true;
  303.  
  304. $('input,textarea',$(obj.attr("href"))).each(function(i,v){
  305. valid = validator.element(v) && valid;
  306. });
  307.  
  308. if(!valid){
  309. wizard.find(".stepContainer").removeAttr("style");
  310. validator.focusInvalid();
  311. return false;
  312. }
  313.  
  314. }
  315.  
  316. return true;
  317. },// <-- TO
  318.  
  319. //This is important part of wizard init
  320. onShowStep: function(obj){
  321. var wizard = obj.parents(".wizard");
  322.  
  323. if(wizard.hasClass("show-submit")){
  324.  
  325. var step_num = obj.attr('rel');
  326. var step_max = obj.parents(".anchor").find("li").length;
  327.  
  328. if(step_num == step_max){
  329. obj.parents(".wizard").find(".actionBar .btn-primary").css("display","block");
  330. }
  331. }
  332. return true;
  333. }//End
  334. });
  335. }
  336.  
  337. }// End Smart Wizard
  338.  
  339. //OWL Carousel
  340. var uiOwlCarousel = function(){
  341.  
  342. if($(".owl-carousel").length > 0){
  343. $(".owl-carousel").owlCarousel({mouseDrag: false, touchDrag: true, slideSpeed: 300, paginationSpeed: 400, singleItem: true, navigation: false,autoPlay: true});
  344. }
  345.  
  346. }//End OWL Carousel
  347.  
  348. // Summernote
  349. var uiSummernote = function(){
  350. /* Extended summernote editor */
  351. if($(".summernote").length > 0){
  352. $(".summernote").summernote({height: 250,
  353. codemirror: {
  354. mode: 'text/html',
  355. htmlMode: true,
  356. lineNumbers: true,
  357. theme: 'default'
  358. }
  359. });
  360. }
  361. /* END Extended summernote editor */
  362.  
  363. /* Lite summernote editor */
  364. if($(".summernote_lite").length > 0){
  365.  
  366. $(".summernote_lite").on("focus",function(){
  367.  
  368. $(".summernote_lite").summernote({height: 100, focus: true,
  369. toolbar: [
  370. ["style", ["bold", "italic", "underline", "clear"]],
  371. ["insert",["link","picture","video"]]
  372. ]
  373. });
  374. });
  375. }
  376. /* END Lite summernote editor */
  377.  
  378. /* Email summernote editor */
  379. if($(".summernote_email").length > 0){
  380.  
  381. $(".summernote_email").summernote({height: 400, focus: true,
  382. toolbar: [
  383. ['style', ['bold', 'italic', 'underline', 'clear']],
  384. ['font', ['strikethrough']],
  385. ['fontsize', ['fontsize']],
  386. ['color', ['color']],
  387. ['para', ['ul', 'ol', 'paragraph']],
  388. ['height', ['height']]
  389. ]
  390. });
  391.  
  392. }
  393. /* END Email summernote editor */
  394.  
  395. }// END Summernote
  396.  
  397. // Custom Content Scroller
  398. var uiScroller = function(){
  399.  
  400. if($(".scroll").length > 0){
  401. $(".scroll").mCustomScrollbar({axis:"y", autoHideScrollbar: true, scrollInertia: 20, advanced: {autoScrollOnFocus: false}});
  402. }
  403.  
  404. }// END Custom Content Scroller
  405.  
  406. // Sparkline
  407. var uiSparkline = function(){
  408.  
  409. if($(".sparkline").length > 0)
  410. $(".sparkline").sparkline('html', { enableTagOptions: true,disableHiddenCheck: true});
  411.  
  412. }// End sparkline
  413.  
  414. $(window).resize(function(){
  415. if($(".owl-carousel").length > 0){
  416. $(".owl-carousel").data('owlCarousel').destroy();
  417. uiOwlCarousel();
  418. }
  419. });
  420.  
  421. return {
  422. init: function(){
  423. uiDatatable();
  424. uiRangeSlider();
  425. uiKnob();
  426. uiSmartWizard();
  427. uiOwlCarousel();
  428. uiSummernote();
  429. uiScroller();
  430. uiSparkline();
  431. }
  432. }
  433.  
  434. }();
  435.  
  436. var templatePlugins = function(){
  437.  
  438. var tp_clock = function(){
  439.  
  440. function tp_clock_time(){
  441. var now = new Date();
  442. var hour = now.getHours();
  443. var minutes = now.getMinutes();
  444.  
  445. hour = hour < 10 ? '0'+hour : hour;
  446. minutes = minutes < 10 ? '0'+minutes : minutes;
  447.  
  448. $(".plugin-clock").html(hour+"<span>:</span>"+minutes);
  449. }
  450. if($(".plugin-clock").length > 0){
  451.  
  452. tp_clock_time();
  453.  
  454. window.setInterval(function(){
  455. tp_clock_time();
  456. },10000);
  457.  
  458. }
  459. }
  460.  
  461. var tp_date = function(){
  462.  
  463. if($(".plugin-date").length > 0){
  464.  
  465. var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
  466. var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
  467.  
  468. var now = new Date();
  469. var day = days[now.getDay()];
  470. var date = now.getDate();
  471. var month = months[now.getMonth()];
  472. var year = now.getFullYear();
  473.  
  474. $(".plugin-date").html(day+", "+month+" "+date+", "+year);
  475. }
  476.  
  477. }
  478.  
  479. return {
  480. init: function(){
  481. tp_clock();
  482. tp_date();
  483. }
  484. }
  485. }();
  486.  
  487. var fullCalendar = function(){
  488.  
  489. var calendar = function(){
  490.  
  491. if($("#calendar").length > 0){
  492.  
  493. function prepare_external_list(){
  494.  
  495. $('#external-events .external-event').each(function() {
  496. var eventObject = {title: $.trim($(this).text())};
  497.  
  498. $(this).data('eventObject', eventObject);
  499. $(this).draggable({
  500. zIndex: 999,
  501. revert: true,
  502. revertDuration: 0
  503. });
  504. });
  505.  
  506. }
  507.  
  508.  
  509. var date = new Date();
  510. var d = date.getDate();
  511. var m = date.getMonth();
  512. var y = date.getFullYear();
  513.  
  514. prepare_external_list();
  515.  
  516. var calendar = $('#calendar').fullCalendar({
  517. header: {
  518. left: 'prev,next today',
  519. center: 'title',
  520. right: 'month,agendaWeek,agendaDay'
  521. },
  522. editable: true,
  523. eventSources: {url: "assets/ajax_fullcalendar.php"},
  524. droppable: true,
  525. selectable: true,
  526. selectHelper: true,
  527. select: function(start, end, allDay) {
  528. var title = prompt('Event Title:');
  529. if (title) {
  530. calendar.fullCalendar('renderEvent',
  531. {
  532. title: title,
  533. start: start,
  534. end: end,
  535. allDay: allDay
  536. },
  537. true
  538. );
  539. }
  540. calendar.fullCalendar('unselect');
  541. },
  542. drop: function(date, allDay) {
  543.  
  544. var originalEventObject = $(this).data('eventObject');
  545.  
  546. var copiedEventObject = $.extend({}, originalEventObject);
  547.  
  548. copiedEventObject.start = date;
  549. copiedEventObject.allDay = allDay;
  550.  
  551. $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
  552.  
  553.  
  554. if ($('#drop-remove').is(':checked')) {
  555. $(this).remove();
  556. }
  557.  
  558. }
  559. });
  560.  
  561. $("#new-event").on("click",function(){
  562. var et = $("#new-event-text").val();
  563. if(et != ''){
  564. $("#external-events").prepend('<a class="list-group-item external-event">'+et+'</a>');
  565. prepare_external_list();
  566. }
  567. });
  568.  
  569. }
  570. }
  571.  
  572. return {
  573. init: function(){
  574. calendar();
  575. }
  576. }
  577. }();
  578.  
  579. formElements.init();
  580. uiElements.init();
  581. templatePlugins.init();
  582.  
  583. fullCalendar.init();
  584.  
  585. /* My Custom Progressbar */
  586. $.mpb = function(action,options){
  587.  
  588. var settings = $.extend({
  589. state: '',
  590. value: [0,0],
  591. position: '',
  592. speed: 20,
  593. complete: null
  594. },options);
  595.  
  596. if(action == 'show' || action == 'update'){
  597.  
  598. if(action == 'show'){
  599. $(".mpb").remove();
  600. var mpb = '<div class="mpb '+settings.position+'">\n\
  601. <div class="mpb-progress'+(settings.state != '' ? ' mpb-'+settings.state: '')+'" style="width:'+settings.value[0]+'%;"></div>\n\
  602. </div>';
  603. $('body').append(mpb);
  604. }
  605.  
  606. var i = $.isArray(settings.value) ? settings.value[0] : $(".mpb .mpb-progress").width();
  607. var to = $.isArray(settings.value) ? settings.value[1] : settings.value;
  608.  
  609. var timer = setInterval(function(){
  610. $(".mpb .mpb-progress").css('width',i+'%'); i++;
  611.  
  612. if(i > to){
  613. clearInterval(timer);
  614. if($.isFunction(settings.complete)){
  615. settings.complete.call(this);
  616. }
  617. }
  618. }, settings.speed);
  619.  
  620. }
  621.  
  622. if(action == 'destroy'){
  623. $(".mpb").remove();
  624. }
  625.  
  626. }
  627. /* Eof My Custom Progressbar */
  628.  
  629.  
  630. // New selector case insensivity
  631. $.expr[':'].containsi = function(a, i, m) {
  632. return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0;
  633. };
  634. });
  635.  
  636. Object.size = function(obj) {
  637. var size = 0, key;
  638. for (key in obj) {
  639. if (obj.hasOwnProperty(key)) size++;
  640. }
  641. return size;
  642. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement