form-advanced-demo.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. $(document).ready(function () {
  2. var $image = $(".image-crop > img")
  3. $($image).cropper({
  4. aspectRatio: 1.618,
  5. preview: ".img-preview",
  6. done: function (data) {
  7. // 输出结果
  8. }
  9. });
  10. var $inputImage = $("#inputImage");
  11. if (window.FileReader) {
  12. $inputImage.change(function () {
  13. var fileReader = new FileReader(),
  14. files = this.files,
  15. file;
  16. if (!files.length) {
  17. return;
  18. }
  19. file = files[0];
  20. if (/^image\/\w+$/.test(file.type)) {
  21. fileReader.readAsDataURL(file);
  22. fileReader.onload = function () {
  23. $inputImage.val("");
  24. $image.cropper("reset", true).cropper("replace", this.result);
  25. };
  26. } else {
  27. showMessage("请选择图片文件");
  28. }
  29. });
  30. } else {
  31. $inputImage.addClass("hide");
  32. }
  33. $("#download").click(function () {
  34. window.open($image.cropper("getDataURL"));
  35. });
  36. $("#zoomIn").click(function () {
  37. $image.cropper("zoom", 0.1);
  38. });
  39. $("#zoomOut").click(function () {
  40. $image.cropper("zoom", -0.1);
  41. });
  42. $("#rotateLeft").click(function () {
  43. $image.cropper("rotate", 45);
  44. });
  45. $("#rotateRight").click(function () {
  46. $image.cropper("rotate", -45);
  47. });
  48. $("#setDrag").click(function () {
  49. $image.cropper("setDragMode", "crop");
  50. });
  51. $('#data_1 .input-group.date').datepicker({
  52. todayBtn: "linked",
  53. keyboardNavigation: false,
  54. forceParse: false,
  55. calendarWeeks: true,
  56. autoclose: true
  57. });
  58. $('#data_2 .input-group.date').datepicker({
  59. startView: 1,
  60. todayBtn: "linked",
  61. keyboardNavigation: false,
  62. forceParse: false,
  63. autoclose: true,
  64. format: "yyyy-mm-dd"
  65. });
  66. $('#data_3 .input-group.date').datepicker({
  67. startView: 2,
  68. todayBtn: "linked",
  69. keyboardNavigation: false,
  70. forceParse: false,
  71. autoclose: true
  72. });
  73. $('#data_4 .input-group.date').datepicker({
  74. minViewMode: 1,
  75. keyboardNavigation: false,
  76. forceParse: false,
  77. autoclose: true,
  78. todayHighlight: true
  79. });
  80. $('#data_5 .input-daterange').datepicker({
  81. keyboardNavigation: false,
  82. forceParse: false,
  83. autoclose: true
  84. });
  85. var elem = document.querySelector('.js-switch');
  86. var switchery = new Switchery(elem, {
  87. color: '#1AB394'
  88. });
  89. var elem_2 = document.querySelector('.js-switch_2');
  90. var switchery_2 = new Switchery(elem_2, {
  91. color: '#ED5565'
  92. });
  93. var elem_3 = document.querySelector('.js-switch_3');
  94. var switchery_3 = new Switchery(elem_3, {
  95. color: '#1AB394'
  96. });
  97. $('.i-checks').iCheck({
  98. checkboxClass: 'icheckbox_square-green',
  99. radioClass: 'iradio_square-green'
  100. });
  101. $('.colorpicker-demo1').colorpicker();
  102. $('.colorpicker-demo2').colorpicker();
  103. $('.colorpicker-demo3').colorpicker();
  104. // Code for demos
  105. function createColorpickers() {
  106. // Api demo
  107. var bodyStyle = $('body')[0].style;
  108. $('#demo_apidemo').colorpicker({
  109. color: bodyStyle.backgroundColor
  110. }).on('changeColor', function (ev) {
  111. bodyStyle.backgroundColor = ev.color.toHex();
  112. });
  113. // Horizontal mode
  114. $('#demo_forceformat').colorpicker({
  115. format: 'rgba', // force this format
  116. horizontal: true
  117. });
  118. $('.demo-auto').colorpicker();
  119. // Disabled / enabled triggers
  120. $(".disable-button").click(function (e) {
  121. e.preventDefault();
  122. $("#demo_endis").colorpicker('disable');
  123. });
  124. $(".enable-button").click(function (e) {
  125. e.preventDefault();
  126. $("#demo_endis").colorpicker('enable');
  127. });
  128. }
  129. createColorpickers();
  130. // Create / destroy instances
  131. $('.demo-destroy').click(function (e) {
  132. e.preventDefault();
  133. $('.demo').colorpicker('destroy');
  134. $(".disable-button, .enable-button").off('click');
  135. });
  136. $('.demo-create').click(function (e) {
  137. e.preventDefault();
  138. createColorpickers();
  139. });
  140. var divStyle = $('.back-change')[0].style;
  141. $('#demo_apidemo').colorpicker({
  142. color: divStyle.backgroundColor
  143. }).on('changeColor', function (ev) {
  144. divStyle.backgroundColor = ev.color.toHex();
  145. });
  146. $('.clockpicker').clockpicker();
  147. $( '#file-pretty input[type="file"]' ).prettyFile();
  148. });
  149. var config = {
  150. '.chosen-select': {},
  151. '.chosen-select-deselect': {
  152. allow_single_deselect: true
  153. },
  154. '.chosen-select-no-single': {
  155. disable_search_threshold: 10
  156. },
  157. '.chosen-select-no-results': {
  158. no_results_text: 'Oops, nothing found!'
  159. },
  160. '.chosen-select-width': {
  161. width: "95%"
  162. }
  163. }
  164. for (var selector in config) {
  165. $(selector).chosen(config[selector]);
  166. }
  167. $("#ionrange_1").ionRangeSlider({
  168. min: 0,
  169. max: 5000,
  170. type: 'double',
  171. prefix: "¥",
  172. maxPostfix: "+",
  173. prettify: false,
  174. hasGrid: true
  175. });
  176. $("#ionrange_2").ionRangeSlider({
  177. min: 0,
  178. max: 10,
  179. type: 'single',
  180. step: 0.1,
  181. postfix: " 克",
  182. prettify: false,
  183. hasGrid: true
  184. });
  185. $("#ionrange_3").ionRangeSlider({
  186. min: -50,
  187. max: 50,
  188. from: 0,
  189. postfix: "°",
  190. prettify: false,
  191. hasGrid: true
  192. });
  193. $("#ionrange_4").ionRangeSlider({
  194. values: [
  195. "一月", "二月", "三月",
  196. "四月", "五月", "六月",
  197. "七月", "八月", "九月",
  198. "十月", "十一月", "十二月"
  199. ],
  200. type: 'single',
  201. hasGrid: true
  202. });
  203. $("#ionrange_5").ionRangeSlider({
  204. min: 10000,
  205. max: 100000,
  206. step: 100,
  207. postfix: " km",
  208. from: 55000,
  209. hideMinMax: true,
  210. hideFromTo: false
  211. });
  212. $(".dial").knob();
  213. $("#basic_slider").noUiSlider({
  214. start: 40,
  215. behaviour: 'tap',
  216. connect: 'upper',
  217. range: {
  218. 'min': 20,
  219. 'max': 80
  220. }
  221. });
  222. $("#range_slider").noUiSlider({
  223. start: [40, 60],
  224. behaviour: 'drag',
  225. connect: true,
  226. range: {
  227. 'min': 20,
  228. 'max': 80
  229. }
  230. });
  231. $("#drag-fixed").noUiSlider({
  232. start: [40, 60],
  233. behaviour: 'drag-fixed',
  234. connect: true,
  235. range: {
  236. 'min': 20,
  237. 'max': 80
  238. }
  239. });