PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/types/library/toolset/types/embedded/resources/js/custom-fields-form-filter.js

https://gitlab.com/Fraternal-Group/fraternal
JavaScript | 449 lines | 260 code | 25 blank | 164 comment | 74 complexity | 053a73ff648cda08622b8addce37a161 MD5 | raw file
  1. /*
  2. * Filter box on fields edit page.
  3. */
  4. jQuery(document).ready(function(){
  5. wpcfFieldsFormFiltersSummary();
  6. //jQuery('#wpfooter').css({'position':'relative'});
  7. });
  8. function wpcfFieldsFormFiltersSummary()
  9. {
  10. if ( 'undefined' == typeof wpcf_settings ) {
  11. return;
  12. }
  13. if (jQuery('#wpcf-fields-form-filters-association-form').find("input:checked").val() == 'all') {
  14. var string = wpcf_settings.wpcf_filters_association_and;
  15. } else {
  16. var string = wpcf_settings.wpcf_filters_association_or;
  17. }
  18. var pt = new Array();
  19. jQuery('#wpcf-form-fields-post_types').find("input:checked").each(function(){
  20. pt.push(jQuery(this).next().html());
  21. });
  22. var tx = new Array();
  23. jQuery('#wpcf-form-fields-taxonomies').find("input:checked").each(function(){
  24. tx.push(jQuery(this).next().html());
  25. });
  26. var vt = new Array();
  27. jQuery('#wpcf-form-fields-templates').find("input:checked").each(function(){
  28. vt.push(jQuery(this).next().html());
  29. });
  30. if (pt.length < 1) {
  31. pt.push(wpcf_settings.wpcf_filters_association_all_pages);
  32. }
  33. if (tx.length < 1) {
  34. tx.push(wpcf_settings.wpcf_filters_association_all_taxonomies);
  35. }
  36. if (vt.length < 1) {
  37. vt.push(wpcf_settings.wpcf_filters_association_all_templates);
  38. }
  39. string = string.replace('%pt%', pt.join(', '));
  40. string = string.replace('%tx%', tx.join(', '));
  41. string = string.replace('%vt%', vt.join(', '));
  42. jQuery('#wpcf-fields-form-filters-association-summary').html(string);
  43. }
  44. // Title func
  45. function _wpcfFilterTitle(e, title, title_not_empty, title_empty) {
  46. if (e == 'empty') {
  47. return title + ' ' + title_empty;
  48. } else {
  49. return title + ' ' + title_not_empty;
  50. }
  51. }
  52. /**
  53. * Autocomplete slugs
  54. */
  55. jQuery('input.wpcf-forms-field-slug').live('blur focus click', function(){
  56. var slug = jQuery(this).val();
  57. if ( '' == slug ){
  58. // jQuery(this).val(wpcf_slugize(jQuery(this).parent().find('input.wpcf-forms-field-name').val()));
  59. }
  60. });
  61. var CSSLayoutEditor = '';
  62. var HTMMLLayoutEditor = '';
  63. // Edit Button
  64. //
  65. //
  66. //
  67. function wpcfFilterEditClick(object, edit, title, title_not_empty, title_empty) {
  68. var parent = object.parents('.wpcf-filter-wrap');
  69. var toggle = parent.next();
  70. /*
  71. *
  72. * Built-in filters
  73. *
  74. *
  75. * Custom types
  76. */
  77. if (edit == 'custom_post_types') {
  78. /*
  79. *
  80. * Take a snapshot
  81. */
  82. window.wpcfPostTypesText = new Array();
  83. window.wpcfFormGroupsSupportPostTypesState = new Array();
  84. toggle.slideToggle().find('.checkbox').each(function(index){
  85. if (jQuery(this).is(':checked')) {
  86. window.wpcfPostTypesText.push(jQuery(this).next().html());
  87. window.wpcfFormGroupsSupportPostTypesState.push(jQuery(this).attr('id'));
  88. }
  89. });
  90. /*
  91. *
  92. *
  93. *
  94. *
  95. *
  96. *
  97. * Do taxonomies
  98. */
  99. } else if (edit == 'custom_taxonomies') {
  100. /*
  101. *
  102. * Take a snapshot
  103. */
  104. window.wpcfTaxText = new Array();
  105. window.wpcfFormGroupsSupportTaxState = new Array();
  106. toggle.slideToggle().find('.checkbox').each(function(index){
  107. if (jQuery(this).is(':checked')) {
  108. window.wpcfTaxText.push(jQuery(this).next().html());
  109. window.wpcfFormGroupsSupportTaxState.push(jQuery(this).attr('id'));
  110. }
  111. });
  112. } else if (edit == 'templates') {
  113. window.wpcfTemplatesText = new Array();
  114. window.wpcfFormGroupsTemplatesState = new Array();
  115. toggle.slideToggle().find('.checkbox').each(function(index){
  116. if (jQuery(this).is(':checked')) {
  117. window.wpcfTemplatesText.push(jQuery(this).next().html());
  118. window.wpcfFormGroupsTemplatesState.push(jQuery(this).attr('id'));
  119. }
  120. });
  121. jQuery(this).css('visibility', 'hidden');
  122. }
  123. else if (edit == 'admin_styles') {
  124. toggle.slideToggle();
  125. //.CodeMirror-scroll{
  126. //width:713px;
  127. //}
  128. jQuery("#wpcf-admin-styles-box").css({width:'700px','border-color':'#808080','box-shadow':'5px 5px 10px #888888','z-index':'10000'});
  129. if (CSSLayoutEditor == ''){
  130. jQuery("#wpcf-update-preview-div").resizable({});
  131. document.getElementById("wpcf-form-groups-admin-html-preview").innerHTML = typesBase64.decode( wpcfEditMode );
  132. CSSLayoutEditor = CodeMirror.fromTextArea(document.getElementById("wpcf-form-groups-css-fields-editor"), {mode: "css", tabMode: "indent",
  133. lineWrapping: true, lineNumbers: true});
  134. HTMMLLayoutEditor = CodeMirror.fromTextArea(document.getElementById("wpcf-form-groups-admin-html-preview"), {mode: "text/html", tabMode: "indent",
  135. readOnly:true, lineWrapping: true, lineNumbers: true});
  136. wpcfPreviewHtml();
  137. jQuery(".CodeMirror-scroll").css({width:'675px'});
  138. jQuery(".CodeMirror").resizable({
  139. stop: function() { CSSLayoutEditor.refresh(); HTMMLLayoutEditor.refresh(); },
  140. resize: function() {
  141. jQuery(this).find(".CodeMirror-scroll").height(jQuery(this).height());
  142. jQuery(this).find(".CodeMirror-scroll").width(jQuery(this).width());
  143. CSSLayoutEditor.refresh();HTMMLLayoutEditor.refresh();
  144. }
  145. });
  146. }
  147. }
  148. // Hide until OK or Cancel
  149. object.css('visibility', 'hidden');
  150. /**
  151. * remove functionality from links in preview mode
  152. */
  153. jQuery('#wpcf-update-preview-div a').on('click', function() {
  154. alert(wpcfFormAlertOnlyPreview);
  155. return false;
  156. });
  157. }
  158. function changePreviewHtml(mode){
  159. if (mode == 'readonly'){
  160. HTMMLLayoutEditor.setValue( typesBase64.decode( wpcfReadOnly) );
  161. }
  162. else{
  163. HTMMLLayoutEditor.setValue( typesBase64.decode( wpcfEditMode ) );
  164. }
  165. HTMMLLayoutEditor.refresh();
  166. wpcfPreviewHtml();
  167. }
  168. function wpcfPreviewHtml(){
  169. jQuery("#wpcf-update-preview-div").resizable( "destroy" );
  170. jQuery("<style type='text/css'> "+ CSSLayoutEditor.getValue() +" </style>").appendTo("head");
  171. document.getElementById("wpcf-update-preview-div").innerHTML = HTMMLLayoutEditor.getValue();
  172. jQuery("#wpcf-update-preview-div").resizable({});
  173. }
  174. // OK Button
  175. //
  176. //
  177. //
  178. //
  179. function wpcfFilterOkClick(object, edit, title, title_not_empty, title_empty) {
  180. var toggle = object.parent();
  181. var parent = toggle.prev('.wpcf-filter-wrap');
  182. /*
  183. *
  184. * Built-in filters
  185. *
  186. *
  187. *
  188. *
  189. * Do post types
  190. */
  191. if (edit == 'custom_post_types') {
  192. /*
  193. *
  194. * Take a snapshot of current state
  195. */
  196. window.wpcfPostTypesText = new Array();
  197. window.wpcfFormGroupsSupportPostTypesState = new Array();
  198. toggle.slideUp().find('.checkbox').each(function(index){
  199. if (jQuery(this).is(':checked')) {
  200. window.wpcfPostTypesText.push(jQuery(this).next().html());
  201. window.wpcfFormGroupsSupportPostTypesState.push(jQuery(this).attr('id'));
  202. }
  203. });
  204. /*
  205. *
  206. *
  207. * Set TEXT
  208. */
  209. if (window.wpcfPostTypesText.length < 1) {
  210. parent.find('.wpcf-filter-ajax-response').html(
  211. _wpcfFilterTitle('empty', title, title_not_empty, title_empty)
  212. );
  213. } else {
  214. var title_not_empty = wpcfPostTypesText.join(', ');
  215. parent.find('.wpcf-filter-ajax-response').html(
  216. _wpcfFilterTitle('has', title, title_not_empty, title_empty)
  217. );
  218. };
  219. /*
  220. *
  221. *
  222. *
  223. *
  224. *
  225. *
  226. *
  227. *
  228. *
  229. * Now do taxonomies
  230. */
  231. } else if (edit == 'custom_taxonomies') {
  232. /*
  233. *
  234. * Take a snapshot of current state
  235. */
  236. window.wpcfTaxText = new Array();
  237. window.wpcfFormGroupsSupportTaxState = new Array();
  238. toggle.slideToggle().find('.checkbox').each(function(index){
  239. if (jQuery(this).is(':checked')) {
  240. window.wpcfTaxText.push(jQuery(this).next().html());
  241. window.wpcfFormGroupsSupportTaxState.push(jQuery(this).attr('id'));
  242. }
  243. });
  244. /*
  245. *
  246. * Set TEXT
  247. */
  248. if (window.wpcfTaxText.length < 1) {
  249. parent.find('.wpcf-filter-ajax-response').html(
  250. _wpcfFilterTitle('empty', title, title_not_empty, title_empty)
  251. );
  252. } else {
  253. title_not_empty = window.wpcfTaxText.join(', ');
  254. parent.find('.wpcf-filter-ajax-response').html(
  255. _wpcfFilterTitle('has', title, title_not_empty, title_empty)
  256. );
  257. }
  258. /*
  259. *
  260. *
  261. *
  262. *
  263. *
  264. *
  265. * Do templates
  266. */
  267. } else if (edit == 'templates') {
  268. /*
  269. *
  270. * Take snaphot
  271. */
  272. window.wpcfTemplatesText = new Array();
  273. window.wpcfFormGroupsTemplatesState = new Array();
  274. toggle.slideUp().find('.checkbox').each(function(index){
  275. if (jQuery(this).is(':checked')) {
  276. window.wpcfTemplatesText.push(jQuery(this).next().html());
  277. window.wpcfFormGroupsTemplatesState.push(jQuery(this).attr('id'));
  278. }
  279. });
  280. /*
  281. *
  282. *
  283. * Set title
  284. */
  285. if (window.wpcfTemplatesText.length < 1) {
  286. parent.find('.wpcf-filter-ajax-response').html(
  287. _wpcfFilterTitle('empty', title, title_not_empty, title_empty)
  288. );
  289. } else {
  290. title_not_empty = window.wpcfTemplatesText.join(', ');
  291. parent.find('.wpcf-filter-ajax-response').html(
  292. _wpcfFilterTitle('has', title, title_not_empty, title_empty)
  293. );
  294. }
  295. }
  296. else if (edit == 'admin_styles') {
  297. jQuery("#wpcf-admin-styles-box").css({width:'400px','border-color':'#dfdfdf','box-shadow':'none','z-index':'0'});
  298. //jQuery('html, body').animate({scrollTop:jQuery('#wpcf-admin-styles-box').position().top}, 'fast');
  299. toggle.slideUp();
  300. }
  301. parent.children('a').css('visibility', 'visible');
  302. }
  303. // CANCEL Button
  304. //
  305. //
  306. //
  307. //
  308. function wpcfFilterCancelClick(object, edit, title, title_not_empty, title_empty) {
  309. var toggle = object.parent();
  310. var parent = toggle.prev('.wpcf-filter-wrap');
  311. /*
  312. *
  313. * Built-in filters
  314. *
  315. *
  316. *
  317. *
  318. * Do post types
  319. */
  320. if (edit == 'custom_post_types') {
  321. /*
  322. *
  323. *
  324. * Take a snaphot
  325. */
  326. toggle.slideUp().find('input').removeAttr('checked');
  327. if (window.wpcfFormGroupsSupportPostTypesState.length > 0) {
  328. for (var element in window.wpcfFormGroupsSupportPostTypesState) {
  329. jQuery('#'+window.wpcfFormGroupsSupportPostTypesState[element])
  330. .attr('checked', 'checked');
  331. }
  332. }
  333. /*
  334. *
  335. *
  336. * Set title
  337. */
  338. if (window.wpcfPostTypesText.length > 0) {
  339. title_not_empty = window.wpcfPostTypesText.join(', ');
  340. parent.find('.wpcf-filter-ajax-response').html(
  341. _wpcfFilterTitle('has', title, title_not_empty, title_empty)
  342. );
  343. } else {
  344. parent.find('.wpcf-filter-ajax-response').html(
  345. _wpcfFilterTitle('empty', title, title_not_empty, title_empty)
  346. );
  347. }
  348. /*
  349. *
  350. *
  351. *
  352. *
  353. *
  354. *
  355. *
  356. *
  357. *
  358. *
  359. * Now do taxonomies
  360. */
  361. } else if (edit == 'custom_taxonomies') {
  362. /*
  363. *
  364. *
  365. * Take a snaphot
  366. */
  367. toggle.slideUp().find('input').removeAttr('checked');
  368. if (window.wpcfFormGroupsSupportTaxState.length > 0) {
  369. for (var element in window.wpcfFormGroupsSupportTaxState) {
  370. jQuery('#'+window.wpcfFormGroupsSupportTaxState[element])
  371. .attr('checked', 'checked');
  372. }
  373. }
  374. /*
  375. *
  376. *
  377. * Set title
  378. */
  379. if (window.wpcfTaxText.length > 0) {
  380. title_not_empty = window.wpcfTaxText.join(', ');
  381. parent.find('.wpcf-filter-ajax-response').html(
  382. _wpcfFilterTitle('has', title, title_not_empty, title_empty)
  383. );
  384. } else {
  385. parent.find('.wpcf-filter-ajax-response').html(
  386. _wpcfFilterTitle('empty', title, title_not_empty, title_empty)
  387. );
  388. }
  389. /*
  390. *
  391. *
  392. *
  393. *
  394. *
  395. *
  396. *
  397. * Do templates
  398. */
  399. } else if (edit == 'templates') {
  400. toggle.slideUp().find('input').removeAttr('checked');
  401. if (window.wpcfFormGroupsTemplatesState.length > 0) {
  402. for (var element in window.wpcfFormGroupsTemplatesState) {
  403. jQuery('#'+window.wpcfFormGroupsTemplatesState[element])
  404. .attr('checked', 'checked');
  405. }
  406. }
  407. if (window.wpcfTemplatesText.length > 0) {
  408. title_not_empty = window.wpcfTemplatesText.join(', ');
  409. parent.find('.wpcf-filter-ajax-response')
  410. .html(_wpcfFilterTitle('has', title, title_not_empty, title_empty));
  411. } else {
  412. parent.find('.wpcf-filter-ajax-response')
  413. .html(_wpcfFilterTitle('empty', title, title_not_empty, title_empty));
  414. }
  415. }
  416. // Do admin styles
  417. else if (edit == 'admin_styles') {
  418. jQuery("#wpcf-admin-styles-box").css({width:'400px','border-color':'#dfdfdf','box-shadow':'none','z-index':'0'});
  419. jQuery('html, body').animate({scrollTop:jQuery('#wpcf-admin-styles-box').position().top}, 'fast');
  420. CSSLayoutEditor.setValue( typesBase64.decode(wpcfDefaultCss) );
  421. toggle.slideUp();
  422. }
  423. parent.children('a').css('visibility', 'visible');
  424. }