jqueryui_components.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # jQuery UI Widgets
  4. *
  5. * Demo JS code for jqueryui_components.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var JqueryUiComponents = function() {
  11. //
  12. // Setup module components
  13. //
  14. // Button
  15. var _componentUiButton = function() {
  16. if (!$().button) {
  17. console.warn('Warning - jQuery UI components are not loaded.');
  18. return;
  19. }
  20. // Basic button
  21. $('.jui-button').button();
  22. //
  23. // With icons
  24. //
  25. // Left icon
  26. $('.jui-button-icon-left').button({
  27. icon: 'icon-twitter'
  28. });
  29. // Right icon
  30. $('.jui-button-icon-right').button({
  31. icon: 'icon-dribbble3',
  32. iconPosition: 'end'
  33. });
  34. // Single icon only
  35. $('.jui-button-icon-only').button({
  36. icon: 'icon-vimeo',
  37. showLabel: false
  38. });
  39. };
  40. // Button set
  41. var _componentUiButtonset = function() {
  42. if (!$().buttonset) {
  43. console.warn('Warning - jQuery UI components are not loaded.');
  44. return;
  45. }
  46. // Basic button set
  47. $('.jui-button-set').buttonset();
  48. };
  49. // Control group
  50. var _componentUiControlgroup = function() {
  51. if (!$().controlgroup || !$().selectmenu) {
  52. console.warn('Warning - jQuery UI components are not loaded.');
  53. return;
  54. }
  55. // Basic example
  56. $('.jui-controlgroup').controlgroup();
  57. // Split button
  58. $('.jui-combo').selectmenu({
  59. classes: {
  60. 'ui-selectmenu-button': 'ui-button-icon-only'
  61. },
  62. position: {
  63. my: 'right top',
  64. at: 'right bottom',
  65. collision: 'none'
  66. }
  67. });
  68. };
  69. // Progress bar
  70. var _componentUiProgress = function() {
  71. if (!$().progressbar) {
  72. console.warn('Warning - jQuery UI components are not loaded.');
  73. return;
  74. }
  75. // Basic example
  76. $('.jui-progressbar').progressbar({
  77. value: 60
  78. });
  79. // Maximum value
  80. $('.jui-progressbar-max').progressbar({
  81. max: 1000,
  82. value: 400
  83. });
  84. // Indeterminate progress bar
  85. $('.jui-progressbar-indeterminate').progressbar({
  86. value: false
  87. }).on('create', function (event) {
  88. var target = $(event.target),
  89. progressbar = $('.jui-progressbar-indeterminate'),
  90. progressbarValue = progressbar.find('.ui-progressbar-value');
  91. progressbar.progressbar('option', 'value', false);
  92. });
  93. //
  94. // Custom label
  95. //
  96. // Define elements
  97. var progressbar = $( '.jui-progressbar-custom' ),
  98. progressLabel = $('.ui-progress-label');
  99. // Initialize progress bar
  100. progressbar.progressbar({
  101. value: false,
  102. change: function() {
  103. progressLabel.text(progressbar.progressbar('value') + '%');
  104. },
  105. complete: function() {
  106. progressLabel.text('Complete!');
  107. }
  108. });
  109. // Custom progress function
  110. function progress() {
  111. var val = progressbar.progressbar('value') || 0;
  112. progressbar.progressbar('value', val + 2);
  113. if (val < 99) {
  114. setTimeout(progress, 80);
  115. }
  116. }
  117. // Update progress after 2000ms
  118. setTimeout(progress, 2000);
  119. };
  120. // Dialog
  121. var _componentUiDialog = function() {
  122. if (!$().dialog) {
  123. console.warn('Warning - jQuery UI components are not loaded.');
  124. return;
  125. }
  126. // Basic example
  127. $('#jui-dialog-basic').dialog({
  128. autoOpen: false,
  129. width: 400
  130. });
  131. // With overlay
  132. $('#jui-dialog-overlay').dialog({
  133. autoOpen: false,
  134. modal: true,
  135. width: 400
  136. });
  137. // Animated
  138. $('#jui-dialog-animated').dialog({
  139. autoOpen: false,
  140. modal: true,
  141. width: 400,
  142. show: {
  143. effect: 'fade',
  144. duration: 500
  145. },
  146. hide: {
  147. effect: 'fade',
  148. duration: 500
  149. }
  150. });
  151. // With buttons
  152. $('#jui-dialog-buttons').dialog({
  153. autoOpen: false,
  154. modal: true,
  155. width: 400,
  156. buttons: {
  157. Save: function() {
  158. $(this).dialog('close');
  159. },
  160. Cancel: function() {
  161. $(this).dialog('close');
  162. }
  163. }
  164. });
  165. // Buttons with icons
  166. $('#jui-dialog-buttons-icons').dialog({
  167. autoOpen: false,
  168. modal: true,
  169. width: 400,
  170. buttons: [
  171. {
  172. text: 'Submit',
  173. icons: {
  174. primary: 'icon-checkmark5'
  175. },
  176. click: function() {
  177. $(this).dialog('close');
  178. }
  179. },
  180. {
  181. text: 'Cancel',
  182. icons: {
  183. primary: 'icon-cross3'
  184. },
  185. click: function() {
  186. $(this).dialog('close');
  187. }
  188. }
  189. ]
  190. });
  191. // Disable resize
  192. $('#jui-dialog-resize').dialog({
  193. autoOpen: false,
  194. modal: true,
  195. width: 400,
  196. resizable: false
  197. });
  198. // Disable close on escape
  199. $('#jui-dialog-close-escape').dialog({
  200. autoOpen: false,
  201. modal: true,
  202. width: 400,
  203. closeOnEscape: false
  204. });
  205. // Disable drag
  206. $('#jui-dialog-drag-disabled').dialog({
  207. autoOpen: false,
  208. modal: true,
  209. width: 400,
  210. draggable: false
  211. });
  212. // Append to element
  213. $('#jui-dialog-append').dialog({
  214. appendTo: '#modal-append-target',
  215. autoOpen: false,
  216. modal: true,
  217. width: 400
  218. });
  219. //
  220. // With forms
  221. //
  222. // Vertical form dialog
  223. $('#jui-dialog-form-vertical').dialog({
  224. autoOpen: false,
  225. modal: true,
  226. width: 500,
  227. buttons: {
  228. Submit: function() {
  229. $(this).dialog('close');
  230. },
  231. Cancel: function() {
  232. $(this).dialog('close');
  233. }
  234. }
  235. });
  236. // Horizontal form dialog
  237. $('#jui-dialog-form-horizontal').dialog({
  238. autoOpen: false,
  239. modal: true,
  240. width: 500,
  241. buttons: {
  242. Submit: function() {
  243. $(this).dialog('close');
  244. },
  245. Cancel: function() {
  246. $(this).dialog('close');
  247. }
  248. }
  249. });
  250. // Inline form dialog
  251. $('#jui-dialog-form-inline').dialog({
  252. autoOpen: false,
  253. modal: true,
  254. width: 555,
  255. buttons: {
  256. Submit: function() {
  257. $(this).dialog('close');
  258. },
  259. Cancel: function() {
  260. $(this).dialog('close');
  261. }
  262. }
  263. });
  264. //
  265. // Optional widths
  266. //
  267. // Default width
  268. $('#jui-dialog-width-default').dialog({
  269. autoOpen: false,
  270. modal: true
  271. });
  272. // Pixel width
  273. $('#jui-dialog-width-pixel').dialog({
  274. autoOpen: false,
  275. modal: true,
  276. width: 400
  277. });
  278. // Percentage width
  279. $('#jui-dialog-width-percentage').dialog({
  280. autoOpen: false,
  281. modal: true,
  282. width: '50%'
  283. });
  284. // Full width
  285. $('#jui-dialog-width-full').dialog({
  286. autoOpen: false,
  287. modal: true,
  288. width: '96%'
  289. });
  290. //
  291. // Dialog openers
  292. //
  293. $('#jui-dialog-basic-opener').on('click', function() {
  294. $('#jui-dialog-basic').dialog('open');
  295. });
  296. $('#jui-dialog-overlay-opener').on('click', function() {
  297. $('#jui-dialog-overlay').dialog('open');
  298. });
  299. $('#jui-dialog-animated-opener').on('click', function() {
  300. $('#jui-dialog-animated').dialog('open');
  301. });
  302. $('#jui-dialog-buttons-opener').on('click', function() {
  303. $('#jui-dialog-buttons').dialog('open');
  304. });
  305. $('#jui-dialog-buttons-icons-opener').on('click', function() {
  306. $('#jui-dialog-buttons-icons').dialog('open');
  307. });
  308. $('#jui-dialog-resize-opener').on('click', function() {
  309. $('#jui-dialog-resize').dialog('open');
  310. });
  311. $('#jui-dialog-close-escape-opener').on('click', function() {
  312. $('#jui-dialog-close-escape').dialog('open');
  313. });
  314. $('#jui-dialog-drag-disabled-opener').on('click', function() {
  315. $('#jui-dialog-drag-disabled').dialog('open');
  316. });
  317. $('#jui-dialog-append-opener').on('click', function() {
  318. $('#jui-dialog-append').dialog('open');
  319. });
  320. $('#jui-dialog-form-vertical-opener').on('click', function() {
  321. $('#jui-dialog-form-vertical').dialog('open');
  322. });
  323. $('#jui-dialog-form-horizontal-opener').on('click', function() {
  324. $('#jui-dialog-form-horizontal').dialog('open');
  325. });
  326. $('#jui-dialog-form-inline-opener').on('click', function() {
  327. $('#jui-dialog-form-inline').dialog('open');
  328. });
  329. $('#jui-dialog-width-default-opener').on('click', function() {
  330. $('#jui-dialog-width-default').dialog('open');
  331. });
  332. $('#jui-dialog-width-pixel-opener').on('click', function() {
  333. $('#jui-dialog-width-pixel').dialog('open');
  334. });
  335. $('#jui-dialog-width-percentage-opener').on('click', function() {
  336. $('#jui-dialog-width-percentage').dialog('open');
  337. });
  338. $('#jui-dialog-width-full-opener').on('click', function() {
  339. $('#jui-dialog-width-full').dialog('open');
  340. });
  341. };
  342. //
  343. // Return objects assigned to module
  344. //
  345. return {
  346. init: function() {
  347. _componentUiButton();
  348. _componentUiButtonset();
  349. _componentUiControlgroup();
  350. _componentUiProgress();
  351. _componentUiDialog();
  352. }
  353. }
  354. }();
  355. // Initialize module
  356. // ------------------------------
  357. document.addEventListener('DOMContentLoaded', function() {
  358. JqueryUiComponents.init();
  359. });