Nessuna descrizione

um-admin-scripts.js 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. function um_admin_init_datetimepicker() {
  2. jQuery('.um-datepicker:not(.picker__input)').each(function(){
  3. elem = jQuery(this);
  4. if ( typeof elem.attr('data-disabled_weekdays') != 'undefined' && elem.attr('data-disabled_weekdays') != '' ) {
  5. var disable = JSON.parse( elem.attr('data-disabled_weekdays') );
  6. } else {
  7. var disable = false;
  8. }
  9. var years_n = null;
  10. if ( typeof elem.attr('data-years') != 'undefined' ) {
  11. years_n = elem.attr('data-years');
  12. }
  13. var minRange = elem.attr('data-date_min');
  14. var maxRange = elem.attr('data-date_max');
  15. var minSplit = [], maxSplit = [];
  16. if ( typeof minRange != 'undefined' ) {
  17. minSplit = minRange.split(",");
  18. }
  19. if ( typeof maxRange != 'undefined' ) {
  20. maxSplit = maxRange.split(",");
  21. }
  22. var min = minSplit.length ? new Date(minSplit) : null;
  23. var max = minSplit.length ? new Date(maxSplit) : null;
  24. // fix min date for safari
  25. if ( min && min.toString() == 'Invalid Date' && minSplit.length == 3 ) {
  26. var minDateString = minSplit[1] + '/' + minSplit[2] + '/' + minSplit[0];
  27. min = new Date(Date.parse(minDateString));
  28. }
  29. // fix max date for safari
  30. if ( max && max.toString() == 'Invalid Date' && maxSplit.length == 3 ) {
  31. var maxDateString = maxSplit[1] + '/' + maxSplit[2] + '/' + maxSplit[0];
  32. max = new Date(Date.parse(maxDateString));
  33. }
  34. var data = {
  35. disable: disable,
  36. format: elem.attr( 'data-format' ),
  37. formatSubmit: 'yyyy/mm/dd',
  38. hiddenName: true,
  39. onOpen: function() { elem.blur(); },
  40. onClose: function() { elem.blur(); }
  41. };
  42. if ( years_n !== null ) {
  43. data.selectYears = years_n;
  44. }
  45. if ( min !== null ) {
  46. data.min = min;
  47. }
  48. if ( max !== null ) {
  49. data.max = max;
  50. }
  51. elem.pickadate( data );
  52. });
  53. jQuery('.um-timepicker:not(.picker__input)').each(function(){
  54. elem = jQuery(this);
  55. elem.pickatime({
  56. format: elem.attr('data-format'),
  57. interval: parseInt( elem.attr('data-intervals') ),
  58. formatSubmit: 'HH:i',
  59. hiddenName: true,
  60. onOpen: function() { elem.blur(); },
  61. onClose: function() { elem.blur(); }
  62. });
  63. });
  64. }
  65. function um_init_tooltips() {
  66. if ( jQuery( '.um_tooltip' ).length > 0 ) {
  67. jQuery( '.um_tooltip' ).tooltip({
  68. tooltipClass: "um_tooltip",
  69. content: function () {
  70. return jQuery( this ).attr( 'title' );
  71. }
  72. });
  73. }
  74. }
  75. jQuery(document).ready(function() {
  76. /**
  77. clone a field dropdown
  78. **/
  79. jQuery(document.body).on('click', '.um-admin-clone', function(e){
  80. e.preventDefault();
  81. var container = jQuery(this).parents('.um-admin-field');
  82. var parent = jQuery(this).parents('p').find('.um-admin-field:last-child');
  83. container.find('select').select2('destroy');
  84. var cloned = container.clone();
  85. cloned.find('.um-admin-clone').replaceWith('<a href="#" class="um-admin-clone-remove button um-admin-tipsy-n" title="Remove Field"><i class="um-icon-close" style="margin-right:0!important"></i></a>');
  86. cloned.insertAfter( parent );
  87. cloned.find('select').val('');
  88. jQuery('.um-admin-field select').select2({
  89. allowClear: true,
  90. minimumResultsForSearch: 10
  91. });
  92. return false;
  93. });
  94. /**
  95. remove a field dropdown
  96. **/
  97. jQuery(document.body).on('click', '.um-admin-clone-remove', function(e){
  98. e.preventDefault();
  99. var container = jQuery(this).parents('.um-admin-field');
  100. jQuery('.tipsy').remove();
  101. container.remove();
  102. jQuery('.um-admin-field select').select2({
  103. allowClear: true,
  104. minimumResultsForSearch: 10
  105. });
  106. return false;
  107. });
  108. /**
  109. Ajax link
  110. **/
  111. jQuery('.um-admin-ajaxlink').on('click', function(e){
  112. e.preventDefault();
  113. return false;
  114. });
  115. /**
  116. On/Off Buttons
  117. **/
  118. jQuery(document.body).on('click', '.um-admin-yesno span.btn', function(){
  119. if (!jQuery(this).parents('p').hasClass('disabled-on-off')){
  120. if ( jQuery(this).parent().find('input[type=hidden]').val() == 0 ){
  121. update_val = 1;
  122. jQuery(this).animate({'left': '48px'}, 200);
  123. jQuery(this).parent().find('input[type=hidden]').val( update_val ).trigger('change');
  124. } else {
  125. update_val = 0;
  126. jQuery(this).animate({'left': '0'}, 200);
  127. jQuery(this).parent().find('input[type=hidden]').val( update_val ).trigger('change');
  128. }
  129. }
  130. });
  131. /**
  132. WP Color Picker
  133. **/
  134. if ( jQuery('.um-admin-colorpicker').length ) {
  135. jQuery('.um-admin-colorpicker').wpColorPicker();
  136. }
  137. /**
  138. Tooltips
  139. **/
  140. um_init_tooltips();
  141. if( typeof tipsy !== 'undefined' ){
  142. jQuery('.um-admin-tipsy-n').tipsy({gravity: 'n', opacity: 1, live: 'a.live' });
  143. jQuery('.um-admin-tipsy-w').tipsy({gravity: 'w', opacity: 1, live: 'a.live' });
  144. jQuery('.um-admin-tipsy-e').tipsy({gravity: 'e', opacity: 1, live: 'a.live' });
  145. jQuery('.um-admin-tipsy-s').tipsy({gravity: 's', opacity: 1, live: 'a.live' });
  146. }
  147. /**
  148. Conditional fields
  149. **/
  150. jQuery( document.body ).on('change', '.um-adm-conditional', function(){
  151. var value;
  152. if ( jQuery(this).attr("type") == 'checkbox' ) {
  153. value = jQuery(this).is(':checked') ? 1 : 0;
  154. } else {
  155. value = jQuery(this).val();
  156. }
  157. if ( jQuery(this).data('cond1') ) {
  158. if ( value == jQuery(this).data('cond1') ) {
  159. jQuery('.' + jQuery(this).data('cond1-show') ).show();
  160. jQuery('.' + jQuery(this).data('cond1-hide') ).hide();
  161. if ( jQuery(this).data('cond1-show') == '_roles' ) {
  162. return false;
  163. }
  164. } else {
  165. jQuery('.' + jQuery(this).data('cond1-show') ).hide();
  166. jQuery('.' + jQuery(this).data('cond1-hide') ).show();
  167. }
  168. }
  169. if ( jQuery(this).data('cond2') ) {
  170. if ( value == jQuery(this).data('cond2') ) {
  171. jQuery('.' + jQuery(this).data('cond2-show') ).show();
  172. jQuery('.' + jQuery(this).data('cond2-hide') ).hide();
  173. if ( jQuery(this).data('cond2-show') == '_roles' ) {
  174. return false;
  175. }
  176. } else {
  177. jQuery('.' + jQuery(this).data('cond2-show') ).hide();
  178. jQuery('.' + jQuery(this).data('cond2-hide') ).show();
  179. }
  180. }
  181. if ( jQuery(this).data('cond3') ) {
  182. if ( value == jQuery(this).data('cond3') ) {
  183. jQuery('.' + jQuery(this).data('cond3-show') ).show();
  184. jQuery('.' + jQuery(this).data('cond3-hide') ).hide();
  185. } else {
  186. jQuery('.' + jQuery(this).data('cond3-show') ).hide();
  187. jQuery('.' + jQuery(this).data('cond3-hide') ).show();
  188. }
  189. }
  190. });jQuery('.um-adm-conditional').each(function(){jQuery(this).trigger('change');});
  191. /**
  192. Conditional fields for
  193. Radio Group
  194. **/
  195. jQuery('.um-conditional-radio-group input[type=radio]').on('click', function(){
  196. var holder = jQuery('.um-conditional-radio-group');
  197. var val = jQuery(this).val();
  198. var cond1 = holder.data('cond1');
  199. var show1 = holder.data('cond1-show');
  200. if ( val == cond1 ) { // condition met
  201. jQuery('.' + show1).show();
  202. } else {
  203. jQuery('.' + show1).hide();
  204. }
  205. var val2 = jQuery(this).val();
  206. var cond2 = holder.data('cond2');
  207. var show2 = holder.data('cond2-show');
  208. if ( val2 == cond2 ) { // condition met
  209. jQuery('.' + show2).show();
  210. } else {
  211. jQuery('.' + show2).hide();
  212. }
  213. });jQuery('.um-conditional-radio-group input[type=radio]:checked').each(function(){jQuery(this).trigger('click');});
  214. /**
  215. Conditional fields for
  216. nav-menu editor options
  217. **/
  218. jQuery('.um-nav-mode').each( function() {
  219. if ( jQuery(this).find('select').val() == 2 ) {
  220. jQuery(this).parents('.um-nav-edit').find('.um-nav-roles').show();
  221. } else {
  222. jQuery(this).parents('.um-nav-edit').find('.um-nav-roles').hide();
  223. }
  224. });
  225. jQuery( document.body ).on('change', '.um-nav-mode select', function(){
  226. if ( jQuery(this).val() == 2 ) {
  227. jQuery(this).parents('.um-nav-edit').find('.um-nav-roles').show();
  228. } else {
  229. jQuery(this).parents('.um-nav-edit').find('.um-nav-roles').hide();
  230. }
  231. });
  232. });