github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/public/js/app.plugin.js (about) 1 + function($) { 2 "use strict"; 3 4 $(function() { 5 6 // sparkline 7 var sr, sparkline = function($re) { 8 $(".sparkline").each(function() { 9 var $data = $(this).data(); 10 if ($re && !$data.resize) return; 11 ($data.type == 'pie') && $data.sliceColors && ($data.sliceColors = eval($data.sliceColors)); 12 ($data.type == 'bar') && $data.stackedBarColor && ($data.stackedBarColor = eval($data.stackedBarColor)); 13 $data.valueSpots = { 14 '0:': $data.spotColor 15 }; 16 $(this).sparkline('html', $data); 17 }); 18 }; 19 $(window).resize(function(e) { 20 clearTimeout(sr); 21 sr = setTimeout(function() { 22 sparkline(true) 23 }, 500); 24 }); 25 sparkline(false); 26 27 // easypie 28 var easypie = function() { 29 $('.easypiechart').each(function() { 30 var $this = $(this), 31 $data = $this.data(), 32 $step = $this.find('.step'), 33 $target_value = parseInt($($data.target).text()), 34 $value = 0; 35 $data.barColor || ($data.barColor = function($percent) { 36 $percent /= 100; 37 return "rgb(" + Math.round(200 * $percent) + ", 200, " + Math.round(200 * (1 - $percent)) + ")"; 38 }); 39 $data.onStep = function(value) { 40 $value = value; 41 $step.text(parseInt(value)); 42 $data.target && $($data.target).text(parseInt(value) + $target_value); 43 } 44 $data.onStop = function() { 45 $target_value = parseInt($($data.target).text()); 46 $data.update && setTimeout(function() { 47 $this.data('easyPieChart').update(100 - $value); 48 }, $data.update); 49 } 50 $(this).easyPieChart($data); 51 }); 52 }; 53 easypie(); 54 55 // datepicker 56 $(".datepicker-input").each(function() { 57 $(this).datepicker(); 58 }); 59 60 // dropfile 61 $('.dropfile').each(function() { 62 var $dropbox = $(this); 63 if (typeof window.FileReader === 'undefined') { 64 $('small', this).html('File API & FileReader API not supported').addClass('text-danger'); 65 return; 66 } 67 68 this.ondragover = function() { 69 $dropbox.addClass('hover'); 70 return false; 71 }; 72 this.ondragend = function() { 73 $dropbox.removeClass('hover'); 74 return false; 75 }; 76 this.ondrop = function(e) { 77 e.preventDefault(); 78 $dropbox.removeClass('hover').html(''); 79 var file = e.dataTransfer.files[0], 80 reader = new FileReader(); 81 reader.onload = function(event) { 82 $dropbox.append($('<img>').attr('src', event.target.result)); 83 }; 84 reader.readAsDataURL(file); 85 return false; 86 }; 87 }); 88 89 // slider 90 $('.slider').each(function() { 91 $(this).slider(); 92 }); 93 94 // sortable 95 if ($.fn.sortable) { 96 $('.sortable').sortable(); 97 } 98 99 // slim-scroll 100 $('.no-touch .slim-scroll').each(function() { 101 var $self = $(this), 102 $data = $self.data(), 103 $slimResize; 104 $self.slimScroll($data); 105 $(window).resize(function(e) { 106 clearTimeout($slimResize); 107 $slimResize = setTimeout(function() { 108 $self.slimScroll($data); 109 }, 500); 110 }); 111 $(document).on('updateNav', function() { 112 $self.slimScroll($data); 113 }); 114 }); 115 116 // portlet 117 $('.portlet').each(function() { 118 $(".portlet").sortable({ 119 connectWith: '.portlet', 120 iframeFix: false, 121 items: '.portlet-item', 122 opacity: 0.8, 123 helper: 'original', 124 revert: true, 125 forceHelperSize: true, 126 placeholder: 'sortable-box-placeholder round-all', 127 forcePlaceholderSize: true, 128 tolerance: 'pointer' 129 }); 130 }); 131 132 // docs 133 $('#docs pre code').each(function() { 134 var $this = $(this); 135 var t = $this.html(); 136 $this.html(t.replace(/</g, '<').replace(/>/g, '>')); 137 }); 138 139 // table select/deselect all 140 $(document).on('change', 'table thead [type="checkbox"]', function(e) { 141 e && e.preventDefault(); 142 var $table = $(e.target).closest('table'), 143 $checked = $(e.target).is(':checked'); 144 $('tbody [type="checkbox"]', $table).prop('checked', $checked); 145 }); 146 147 // random progress 148 $(document).on('click', '[data-toggle^="progress"]', function(e) { 149 e && e.preventDefault(); 150 151 var $el = $(e.target), 152 $target = $($el.data('target')); 153 $('.progress', $target).each( 154 function() { 155 var $max = 50, 156 $data, $ps = $('.progress-bar', this).last(); 157 ($(this).hasClass('progress-xs') || $(this).hasClass('progress-sm')) && ($max = 100); 158 $data = Math.floor(Math.random() * $max) + '%'; 159 $ps.css('width', $data).attr('data-original-title', $data); 160 } 161 ); 162 }); 163 164 // add notes 165 function addMsg($msg) { 166 var $el = $('.nav-user'), 167 $n = $('.count:first', $el), 168 $v = parseInt($n.text()); 169 $('.count', $el).fadeOut().fadeIn().text($v + 1); 170 $($msg).hide().prependTo($el.find('.list-group')).slideDown().css('display', 'block'); 171 } 172 var $msg = '<a href="#" class="media list-group-item">' + 173 '<span class="pull-left thumb-sm text-center">' + 174 '<i class="fa fa-envelope-o fa-2x text-success"></i>' + 175 '</span>' + 176 '<span class="media-body block m-b-none">' + 177 'Sophi sent you a email<br>' + 178 '<small class="text-muted">1 minutes ago</small>' + 179 '</span>' + 180 '</a>'; 181 setTimeout(function() { 182 addMsg($msg); 183 }, 1500); 184 185 //chosen 186 $(".chosen-select").length && $(".chosen-select").chosen(); 187 188 }); 189 }(window.jQuery);