PageRenderTime 45ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/contact-form-7/admin/taggenerator.js

https://gitlab.com/endomorphosis/reservationtelco
JavaScript | 262 lines | 218 code | 44 blank | 0 comment | 22 complexity | b15564759571c55f1619d4639aafadfd MD5 | raw file
  1. (function($) {
  2. $.fn.tagGenerator = function(title, options) {
  3. var menu = $('<div class="tag-generator"></div>');
  4. var selector = $('<span>' + title + '</span>');
  5. selector.css({
  6. border: '1px solid #ddd',
  7. padding: '2px 4px',
  8. background: '#fff url( ../wp-admin/images/fade-butt.png ) repeat-x 0 0',
  9. '-moz-border-radius': '3px',
  10. '-khtml-border-radius': '3px',
  11. '-webkit-border-radius': '3px',
  12. 'border-radius': '3px'
  13. });
  14. selector.mouseover(function() {
  15. $(this).css({ 'border-color': '#bbb' });
  16. });
  17. selector.mouseout(function() {
  18. $(this).css({ 'border-color': '#ddd' });
  19. });
  20. selector.mousedown(function() {
  21. $(this).css({ background: '#ddd' });
  22. });
  23. selector.mouseup(function() {
  24. $(this).css({
  25. background: '#fff url( ../wp-admin/images/fade-butt.png ) repeat-x 0 0'
  26. });
  27. });
  28. selector.click(function() {
  29. dropdown.slideDown('fast');
  30. return false;
  31. });
  32. $('body').click(function() {
  33. dropdown.hide();
  34. });
  35. if (options.dropdownIconUrl) {
  36. var dropdown_icon = $('<img src="' + options.dropdownIconUrl + '" />');
  37. dropdown_icon.css({ 'vertical-align': 'bottom' });
  38. selector.append(dropdown_icon);
  39. }
  40. menu.append(selector);
  41. var pane = $('<div class="tg-pane"></div>');
  42. pane.hide();
  43. menu.append(pane);
  44. var dropdown = $('<div class="tg-dropdown"></div>');
  45. dropdown.hide();
  46. menu.append(dropdown);
  47. $.each($.tgPanes, function(i, n) {
  48. var submenu = $('<div>' + $.tgPanes[i].title + '</div>');
  49. submenu.css({
  50. margin: 0,
  51. padding: '0 4px',
  52. 'line-height': '180%',
  53. background: '#fff'
  54. });
  55. submenu.mouseover(function() {
  56. $(this).css({ background: '#d4f2f2' });
  57. });
  58. submenu.mouseout(function() {
  59. $(this).css({ background: '#fff' });
  60. });
  61. submenu.click(function() {
  62. dropdown.hide();
  63. pane.hide();
  64. pane.empty();
  65. $.tgPane(pane, i);
  66. pane.slideDown('fast');
  67. return false;
  68. });
  69. dropdown.append(submenu);
  70. });
  71. this.append(menu);
  72. };
  73. $.tgPane = function(pane, tagType) {
  74. var closeButtonDiv = $('<div></div>');
  75. closeButtonDiv.css({ float: 'right' });
  76. var closeButton = $('<span class="tg-closebutton">&#215;</span>');
  77. closeButton.click(function() {
  78. pane.slideUp('fast').empty();
  79. });
  80. closeButtonDiv.append(closeButton);
  81. pane.append(closeButtonDiv);
  82. var paneTitle = $('<div class="tg-panetitle">' + $.tgPanes[tagType].title + '</div>');
  83. pane.append(paneTitle);
  84. pane.append($('#' + $.tgPanes[tagType].content).clone().contents());
  85. pane.find(':checkbox.exclusive').change(function() {
  86. if ($(this).is(':checked'))
  87. $(this).siblings(':checkbox.exclusive').removeAttr('checked');
  88. });
  89. if ($.isFunction($.tgPanes[tagType].change))
  90. $.tgPanes[tagType].change(pane, tagType);
  91. else
  92. $.tgCreateTag(pane, tagType);
  93. pane.find(':input').change(function() {
  94. if ($.isFunction($.tgPanes[tagType].change))
  95. $.tgPanes[tagType].change(pane, tagType);
  96. else
  97. $.tgCreateTag(pane, tagType);
  98. });
  99. }
  100. $.tgCreateTag = function(pane, tagType) {
  101. pane.find('input[name="name"]').each(function(i) {
  102. var val = $(this).val();
  103. val = val.replace(/[^0-9a-zA-Z:._-]/g, '').replace(/^[^a-zA-Z]+/, '');
  104. if ('' == val) {
  105. var rand = Math.floor(Math.random() * 1000);
  106. val = tagType + '-' + rand;
  107. }
  108. $(this).val(val);
  109. });
  110. pane.find(':input.numeric').each(function(i) {
  111. var val = $(this).val();
  112. val = val.replace(/[^0-9]/g, '');
  113. $(this).val(val);
  114. });
  115. pane.find(':input.idvalue').each(function(i) {
  116. var val = $(this).val();
  117. val = val.replace(/[^-0-9a-zA-Z_]/g, '');
  118. $(this).val(val);
  119. });
  120. pane.find(':input.classvalue').each(function(i) {
  121. var val = $(this).val();
  122. val = $.map(val.split(' '), function(n) {
  123. return n.replace(/[^-0-9a-zA-Z_]/g, '');
  124. }).join(' ');
  125. val = $.trim(val.replace(/\s+/g, ' '));
  126. $(this).val(val);
  127. });
  128. pane.find(':input.color').each(function(i) {
  129. var val = $(this).val();
  130. val = val.replace(/[^0-9a-fA-F]/g, '');
  131. $(this).val(val);
  132. });
  133. pane.find(':input.filesize').each(function(i) {
  134. var val = $(this).val();
  135. val = val.replace(/[^0-9kKmMbB]/g, '');
  136. $(this).val(val);
  137. });
  138. pane.find(':input.filetype').each(function(i) {
  139. var val = $(this).val();
  140. val = val.replace(/[^0-9a-zA-Z.\s]/g, '');
  141. $(this).val(val);
  142. });
  143. pane.find(':input.date').each(function(i) {
  144. var val = $(this).val();
  145. if (! val.match(/^\d{4}-\d{1,2}-\d{1,2}$/)) // 'yyyy-mm-dd' ISO 8601 format
  146. $(this).val('');
  147. });
  148. pane.find(':input[name="values"]').each(function(i) {
  149. var val = $(this).val();
  150. val = $.trim(val);
  151. $(this).val(val);
  152. });
  153. pane.find('input.tag').each(function(i) {
  154. var type = $(this).attr('name');
  155. var scope = pane.find('.scope.' + type);
  156. if (! scope.length)
  157. scope = pane;
  158. if (pane.find(':input[name="required"]').is(':checked'))
  159. type += '*';
  160. var name = pane.find(':input[name="name"]').val();
  161. var options = [];
  162. var size = scope.find(':input[name="size"]').val();
  163. var maxlength = scope.find(':input[name="maxlength"]').val();
  164. if (size || maxlength)
  165. options.push(size + '/' + maxlength);
  166. var cols = scope.find(':input[name="cols"]').val();
  167. var rows = scope.find(':input[name="rows"]').val();
  168. if (cols || rows)
  169. options.push(cols + 'x' + rows);
  170. scope.find('input:text.option').each(function(i) {
  171. if (-1 < $.inArray($(this).attr('name'), ['size', 'maxlength', 'cols', 'rows']))
  172. return;
  173. var val = $(this).val();
  174. if (! val)
  175. return;
  176. if ($(this).hasClass('filetype'))
  177. val = val.split(' ').join('|');
  178. if ($(this).hasClass('color'))
  179. val = '#' + val;
  180. if ('class' == $(this).attr('name')) {
  181. $.each(val.split(' '), function(i, n) { options.push('class:' + n) });
  182. } else {
  183. options.push($(this).attr('name') + ':' + val);
  184. }
  185. });
  186. scope.find('input:checkbox.option').each(function(i) {
  187. if ($(this).is(':checked'))
  188. options.push($(this).attr('name'));
  189. });
  190. options = (options.length > 0) ? ' ' + options.join(' ') : '';
  191. var value = '';
  192. if (scope.find(':input[name="values"]').val()) {
  193. $.each(scope.find(':input[name="values"]').val().split("\n"), function(i, n) {
  194. value += ' "' + n.replace(/["]/g, '&quot;') + '"';
  195. });
  196. }
  197. if ($.tgPanes[tagType].nameless)
  198. var tag = '[' + type + options + value + ']';
  199. else
  200. var tag = name ? '[' + type + ' ' + name + options + value + ']' : '';
  201. $(this).val(tag);
  202. });
  203. pane.find('input.mail-tag').each(function(i) {
  204. var name = pane.find(':input[name="name"]').val();
  205. var tag = name ? '[' + name + ']' : '';
  206. $(this).val(tag);
  207. });
  208. }
  209. $.tgPanes = {};
  210. })(jQuery);