app.plugin.js 5.0 KB

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