ccj_admin-url_rules.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. if (!String.prototype.trim) {(function() {
  2. var r = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
  3. String.prototype.trim = function() {
  4. return this.replace(r, '');
  5. };
  6. })();};
  7. if (!String.prototype.esc_html) {(function() {
  8. var r = /[&<>"'\/]/g;
  9. var entity_map = {'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;', '/': '&#x2F;'};
  10. String.prototype.esc_html = function() {
  11. return this.replace(r, function from_entity_map(s) {
  12. return entity_map[s];
  13. });
  14. };
  15. })();};
  16. if (!String.prototype.capitalize) {
  17. String.prototype.capitalize = function() {
  18. return this.charAt(0).toUpperCase() + this.slice(1);
  19. }
  20. };
  21. ;jQuery(document).ready(function($) {
  22. var elist_index = {};
  23. function elist_arrange(names) {
  24. var rq = /\%quot\%/g;
  25. var n, name, field, editable, f;
  26. var filters = {
  27. 'contains' : 'Contains',
  28. 'not-contains' : 'Not contains',
  29. 'equal-to' : 'Is equal to',
  30. 'not-equal-to' : 'Not equal to',
  31. 'begins-with' : 'Starts with',
  32. 'ends-by' : 'Ends by',
  33. 'all' : 'All Website',
  34. 'first-page' : 'Homepage'
  35. };
  36. for (n in names) {
  37. name = names[n];
  38. field = $('#wplnst-scan-' + name).val();
  39. field = ('' === field)? [] : JSON.parse(field);
  40. if (!(field instanceof Array) || 0 == field.length)
  41. continue;
  42. elist_index[name] = field.length;
  43. editable = ('true' == $('#wplnst-elist-' + name).attr('data-editable'));
  44. if ('anchor-filters' == name) {
  45. for (f in field)
  46. elist_add_row(name, elist_get_row(name, {'value' : field[f]['value'].esc_html().replace(rq, '&quot;'), 'type' : filters[ field[f]['type']].esc_html().replace('-', ' ')}, editable), field[f]['index']);
  47. }
  48. }
  49. }
  50. function elist_add(name, value, inputs, row) {
  51. var field = $('#wplnst-scan-' + name).val();
  52. field = ('' === field)? [] : JSON.parse(field);
  53. if (!(field instanceof Array) || field.length > 25)
  54. return;
  55. var max_index = 1;
  56. $('.wplnst-elist-close-link').each(function() {
  57. if ( $(this).data('index') > max_index ) {
  58. max_index = $(this).data('index');
  59. }
  60. });
  61. (name in elist_index)? elist_index[name]++ : elist_index[name] = 0;
  62. // value['index'] = elist_index[name] + 1;
  63. value['index'] = max_index + 1;
  64. field.push(value);
  65. $('#wplnst-scan-' + name).val(JSON.stringify(field));
  66. for (var i = 0; i < inputs.length; i++)
  67. $('#' + inputs[i]).val('');
  68. elist_add_row(name, row, value['index']);
  69. }
  70. function elist_add_row(name, row, index) {
  71. row = row.replace(/\%class\-index\%/g, 'wplnst-' + name + '-' + index);
  72. row = row.replace('%close%', '<a href="#" class="wplnst-elist-close-link" data-name = "' + name + '" data-index="' + index + '">&nbsp;</a>');
  73. $('#' + 'wplnst-elist-' + name).append(row);
  74. $('#' + 'wplnst-elist-' + name).show();
  75. }
  76. function elist_get_row(name, args, editable) {
  77. if ('anchor-filters' == name)
  78. return '<tr class="%class-index%"><td class="wplnst-elist-type wplnst-afs-type">' + $('#wplnst-elist-anchor-filters').attr('data-label') + '&nbsp; <strong>' + args['type'] + '</strong></td><td class="wplnst-elist-val wplnst-afs-val">' + args['value'] + '</td><td class="wplnst-elist-close wplnst-afs-close">' + (editable? '%close%' : '') + '</td></tr><tr class="%class-index%"><td colspan="3" class="wplnst-elist-split"></td></tr>';
  79. return false;
  80. }
  81. $('.wplnst-elist').on('click', '.wplnst-elist-close-link', function() {
  82. var name = $(this).attr('data-name');
  83. var index = $(this).attr('data-index');
  84. var field = $('#wplnst-scan-' + name).val();
  85. if ('' !== field) {
  86. field = JSON.parse(field);
  87. if (field instanceof Array) {
  88. var field_new = [];
  89. for (var i = 0; i < field.length; i++) {
  90. if (index != field[i]['index'])
  91. field_new.push(field[i]);
  92. }
  93. $('#wplnst-scan-' + name).val(JSON.stringify(field_new));
  94. $('.wplnst-' + name + '-' + index).remove();
  95. if (0 === field_new.length)
  96. $('#' + 'wplnst-elist-' + name).hide();
  97. }
  98. }
  99. return false;
  100. });
  101. $('.wplnst-status-level').click(function() {
  102. var level = $(this).attr('id').replace('ck-status-level-', '');
  103. $('.wplnst-code-level-' + level).prop('checked', false);
  104. });
  105. $('.wplnst-code-level').click(function() {
  106. var level = $(this).attr('id').replace('ck-status-code-', '').charAt(0);
  107. $('#ck-status-level-' + level).prop('checked', false);
  108. });
  109. $('#wplnst-save-and-run').click(function() {
  110. $('#wplnst-scan-run').val('1');
  111. $('#wplnst-form').submit();
  112. });
  113. $('#wplnst-cf-new-add').click(function() {
  114. var name = $('#wplnst-cf-new').val().trim();
  115. if ('' === name)
  116. return;
  117. elist_add('custom-fields', {'name' : name, 'type': $('#wplnst-cf-new-type').val()}, ['wplnst-cf-new'], elist_get_row('custom-fields', {'name' : name.esc_html(), 'type' : $('#wplnst-cf-new-type option:selected').text().esc_html()}, true));
  118. });
  119. $('#wplnst-cf-new').bind('keypress', function(e) {
  120. if (e.keyCode == 13) {
  121. $('#wplnst-cf-new-add').click();
  122. return false;
  123. }
  124. });
  125. $('#wplnst-af-new-add').click(function() {
  126. var value = $('#wplnst-af-new').val().trim();
  127. var type = $('#wplnst-af-new-type').val();
  128. if ( type === 'empty' || type === 'all' || type === 'first-page' ) {
  129. value = '';
  130. } else if ( value === '' ) {
  131. return;
  132. }
  133. elist_add('anchor-filters', {'value' : value, 'type': type}, ['wplnst-af-new'], elist_get_row('anchor-filters', {'type' : $('#wplnst-af-new-type option:selected').text().esc_html(), 'value' : value.esc_html() }, true));
  134. });
  135. $('#wplnst-af-new').bind('keypress', function(e) {
  136. if (e.keyCode == 13) {
  137. $('#wplnst-af-new-add').click();
  138. return false;
  139. }
  140. });
  141. $('#wplnst-af-new-type').change(function() {
  142. var disabled = ('empty' == $(this).val());
  143. $('#wplnst-af-new').attr('disabled', disabled);
  144. });
  145. $('#wplnst-ius-new-add').click(function() {
  146. var value = $('#wplnst-ius-new').val().trim();
  147. if ('' === value)
  148. return;
  149. elist_add('include-urls', {'value' : value, 'type': $('#wplnst-ius-new-type').val()}, ['wplnst-ius-new'], elist_get_row('include-urls', {'value' : value.esc_html(), 'type' : $('#wplnst-ius-new-type option:selected').text().esc_html()}, true));
  150. });
  151. $('#wplnst-ius-new').bind('keypress', function(e) {
  152. if (e.keyCode == 13) {
  153. $('#wplnst-ius-new-add').click();
  154. return false;
  155. }
  156. });
  157. $('#wplnst-eus-new-add').click(function() {
  158. var value = $('#wplnst-eus-new').val().trim();
  159. if ('' === value)
  160. return;
  161. elist_add('exclude-urls', {'value' : value, 'type': $('#wplnst-eus-new-type').val()}, ['wplnst-eus-new'], elist_get_row('exclude-urls', {'value' : value.esc_html(), 'type' : $('#wplnst-eus-new-type option:selected').text().esc_html()}, true));
  162. });
  163. $('#wplnst-eus-new').bind('keypress', function(e) {
  164. if (e.keyCode == 13) {
  165. $('#wplnst-eus-new-add').click();
  166. return false;
  167. }
  168. });
  169. $('#wplnst-hes-new-add').click(function() {
  170. var att = $('#wplnst-hes-new-att').val().trim();
  171. if ('' === att)
  172. return;
  173. var element = $('#wplnst-hes-new').val();
  174. var having = $('#wplnst-hes-new-have').val();
  175. var op = op_text = value = '';
  176. if ('have' == having) {
  177. var op = $('#wplnst-hes-new-op').val();
  178. var op_text = $('#wplnst-hes-new-op option:selected').text().toLowerCase();
  179. var value = '' + $('#wplnst-hes-new-val').val().trim();
  180. if ('not-empty' == op || 'empty' == op) {
  181. value = '';
  182. } else if ('' === value) {
  183. return;
  184. }
  185. }
  186. elist_add(
  187. 'html-attributes',
  188. {'att' : att, 'element' : element, 'having' : having, 'op' : op, 'value' : value},
  189. ['wplnst-hes-new-att', 'wplnst-hes-new-val'],
  190. elist_get_row('html-attributes', {'element' : element.esc_html(), 'having' : $('#wplnst-hes-new-have option:selected').text().toLowerCase().esc_html(), 'att' : att.esc_html(), 'op' : op_text.esc_html(), 'value' : value.esc_html()}, true)
  191. );
  192. });
  193. $('#wplnst-hes-new-att').bind('keypress', function(e) {
  194. if (e.keyCode == 13) {
  195. $('#wplnst-hes-new-add').click();
  196. return false;
  197. }
  198. });
  199. $('#wplnst-hes-new-val').bind('keypress', function(e) {
  200. if (e.keyCode == 13) {
  201. $('#wplnst-hes-new-add').click();
  202. return false;
  203. }
  204. });
  205. $('#wplnst-hes-new-have').change(function() {
  206. var disabled = ('have' != $(this).val());
  207. $('#wplnst-hes-new-op').attr('disabled', disabled);
  208. $('#wplnst-hes-new-val').attr('disabled', disabled);
  209. });
  210. $('#wplnst-hes-new-op').change(function() {
  211. $('#wplnst-hes-new-val').attr('disabled', ('empty' == $(this).val() || 'not-empty' == $(this).val()));
  212. });
  213. elist_arrange(['anchor-filters']);
  214. });