| @@ -6,18 +6,16 @@ | ||
| 6 | 6 | * Event 'cf7sg-form-change' fired on #contact-form-editor element when codemirror changes occur |
| 7 | 7 | */ |
| 8 | 8 | const offsets = ['offset-one','offset-two', 'offset-three', 'offset-four', 'offset-five', 'offset-six', 'offset-seven', 'offset-eight', 'offset-nine', 'offset-ten', 'offset-eleven'], |
| 9 | 9 | columnsizes = ['one', 'two', 'one-fourth', 'one-third', 'five', 'one-half', 'seven', 'two-thirds', 'nine', 'ten', 'eleven', 'full']; |
| 10 | - const cf7FieldRgxp = '^([^\\s=\"\':]+)([\\s]+(([^\"]+\\s)+)?(\\"source:([^\\s\":]+)?(:[^\\s]*)?\\")?\\s?(\\"slug:([^\\s\":]+)(:[^\\s]*)?\\")?(?:.*)?)?$'; | |
| 11 | - let cf7TagRgxp, $wpcf7Editor, $grid, $rowControl = null; | |
| 12 | - | |
| 13 | - //graphics UI template pattern, @since 4.11.7 fix classes on cell element. | |
| 14 | - let $pattern = $('<div>').html(cf7grid.preHTML.replace(/class="([\w\s]*)"/,'class="$1[\\s_a-zA-Z0-9-]*"') + '\\s*(\\[.*\\s*\\].*\\s*){0,}\\s*'+cf7grid.postHTML), | |
| 10 | + let $wpcf7Editor,$grid,$rowControl = null; | |
| 11 | + //graphics UI template pattern | |
| 12 | + const $pattern = $('<div>').html(cf7grid.preHTML+'\\s*(\\[.*\\s*\\].*\\s*){0,}\\s*'+cf7grid.postHTML), | |
| 15 | 13 | required = cf7grid.requiredHTML.replace('*', '\\*'); |
| 16 | 14 | // console.log('r:'+required); |
| 17 | 15 | $pattern.find('label').html('((\\s*.*)('+required+'){1}|(\\s*.*))'); |
| 18 | 16 | $pattern.find('.info-tip').text('(.*\\s*)'); |
| 19 | - // console.log('p:'+$pattern.html().replace('><','>\\s?<')); | |
| 17 | + //console.log('p:'+$pattern.html()); | |
| 20 | 18 | const templateRegex = new RegExp($pattern.html().replace('><','>\\s?<'), 'ig'); |
| 21 | 19 | let seekTemplate = false, cssTemplate = 'div.field', |
| 22 | 20 | $template = $('<div id="cf7sg-dummy">').append(cf7grid.preHTML+cf7grid.postHTML); |
| 23 | 21 | $template = $template.children(); |
| @@ -27,24 +25,10 @@ | ||
| 27 | 25 | if($template.prop('class').length>0){ |
| 28 | 26 | cssTemplate += '.'+$template.attr('class').split(' ').join('.'); |
| 29 | 27 | } |
| 30 | 28 | } |
| 31 | - let wpcf7Value = '', | |
| 32 | - $fieldTags = $('#form-panel .cf7-tag-generators'); //tag buttons | |
| 33 | - /** @since 4.11 notify usage of tags in grid UI. */ | |
| 34 | - $fieldTags.click('a',function(e){ | |
| 35 | - let $t = $(e.target); | |
| 36 | - if($t.is('.click-disabled *') || $t.is('.click-disabled')){ | |
| 37 | - if(cf7sg_pointers.helpers.ui_editor_tags){ | |
| 38 | - $('#grid-form .cf7-field-type .content').first().pointer({ | |
| 39 | - content: cf7sg_pointers.helpers.ui_editor_tags, | |
| 40 | - pointerClass: 'wp-pointer cf7sg-pointer cf7sg-pointer-ui_editor_tags', | |
| 41 | - position:{edge: 'left', align: 'center'}, | |
| 42 | - pointerWidth: 350, | |
| 43 | - }).pointer('open'); | |
| 44 | - } | |
| 45 | - } | |
| 46 | - }) | |
| 29 | + let wpcf7Value = ''; | |
| 30 | + | |
| 47 | 31 | $(document).ready( function(){ |
| 48 | 32 | //change the form id to mimic cf7 plugin custom admin page. |
| 49 | 33 | /** @since 2.11.0 full screen button*/ |
| 50 | 34 | let $editor = $('#cf7sg-editor') ; |
| @@ -58,15 +42,9 @@ | ||
| 58 | 42 | }); |
| 59 | 43 | $wpcf7Editor = $('textarea#wpcf7-form-hidden'); |
| 60 | 44 | $grid = $('#grid-form'); |
| 61 | 45 | $rowControl = $('#top-grid-controls'); |
| 62 | - /** @since v5.0 improved cf7 tag regex pattern. */ | |
| 63 | - cf7TagRgxp = ['hidden']; //by default no hidden button. | |
| 64 | - $('form.tag-generator-panel .insert-box input.tag').each((i,el)=>{ | |
| 65 | - cf7TagRgxp.push(el.name); | |
| 66 | - }); | |
| 67 | - cf7TagRgxp = cf7TagRgxp.join('|'); | |
| 68 | - cf7TagRgxp = '\\[(('+cf7TagRgxp+')\\*?)(?:[\\s](.*?))?(?:[\\s](\\/))?\\]'; | |
| 46 | + | |
| 69 | 47 | /* |
| 70 | 48 | Build grid from existing form------------------------- BUILD UI FORM |
| 71 | 49 | */ |
| 72 | 50 | function buildGridForm(){ |
| @@ -73,9 +51,9 @@ | ||
| 73 | 51 | let formhtml = $wpcf7Editor.text(); |
| 74 | 52 | if(0===formhtml.length){ |
| 75 | 53 | formhtml = '<div class="container"><div class="row"><div class="columns full"></div></div></div>'; |
| 76 | 54 | } |
| 77 | - let $form = $('<div>').append( formhtml ); | |
| 55 | + const $form = $('<div>').append( formhtml ); | |
| 78 | 56 | let isGrid = true; //return value. |
| 79 | 57 | $grid.html(''); //empty the grid. |
| 80 | 58 | if(0===$form.children('.container').length){ |
| 81 | 59 | isGrid = false; |
| @@ -81,14 +59,12 @@ | ||
| 81 | 59 | isGrid = false; |
| 82 | 60 | } |
| 83 | 61 | //remove the external forms |
| 84 | 62 | $('.cf7sg-external-form .cf7sg-external-form-content', $form).remove(); |
| 85 | - //seek collapsibles for slider/accordion. | |
| 86 | - let $collapsibles = $('.columns .cf7sg-collapsible:not(.with-toggle):first-child', $form); | |
| 87 | 63 | //replace columns content with textareas |
| 88 | 64 | /*--------------------------------------------------- convert columns */ |
| 89 | 65 | $('div.columns', $form).each(function(){ |
| 90 | - let $this = $(this), $area = $($('#grid-col').html()); | |
| 66 | + const $this = $(this), $area = $($('#grid-col').html()); | |
| 91 | 67 | if($this.children().is('.container')){ |
| 92 | 68 | $('textarea.grid-input', $area).remove(); |
| 93 | 69 | $('div.cf7-field-inner', $area).remove(); |
| 94 | 70 | }else{ |
| @@ -104,9 +80,9 @@ | ||
| 104 | 80 | $(this).append( $('#grid-row .row-controls').clone() ); |
| 105 | 81 | }); |
| 106 | 82 | /*--------------------------------------------------- convert collapsible sections */ |
| 107 | 83 | $('div.container.cf7sg-collapsible', $form).each(function(){ |
| 108 | - let $this = $(this); | |
| 84 | + const $this = $(this); | |
| 109 | 85 | let id = $this.attr('id'); |
| 110 | 86 | if(typeof id == 'undefined'){ |
| 111 | 87 | id = randString(6); |
| 112 | 88 | $this.attr('id', id); //assign a random id |
| @@ -118,18 +94,17 @@ | ||
| 118 | 94 | let $toggle = $('.toggle', $this.children('.cf7sg-collapsible-title')); |
| 119 | 95 | if($toggle.length>0){ |
| 120 | 96 | $toggle = $toggle.clone(); |
| 121 | 97 | } |
| 122 | - //swap out HTML title element for UI title elemen with input fields. | |
| 123 | - let $title = $this.children('.cf7sg-collapsible-title'); | |
| 124 | - $title.children().remove(); | |
| 125 | - $title.prepend( $('.cf7sg-collapsible-title',$('#grid-collapsible')).html()); | |
| 126 | - $('input', $title).not('[type="checkbox"]').val(text); | |
| 98 | + | |
| 99 | + $this.children('.cf7sg-collapsible-title').remove(); | |
| 100 | + $this.prepend( $('#grid-collapsible').html()); | |
| 101 | + $('input', $this.children('.cf7sg-collapsible-title')).not('[type="checkbox"]').val(text); | |
| 127 | 102 | if($toggle.length>0){ |
| 128 | - $title.append($toggle); | |
| 129 | - $('input[type="checkbox"]', $title ).prop('checked', true); | |
| 103 | + $this.children('.cf7sg-collapsible-title').append($toggle); | |
| 104 | + $('input[type="checkbox"]', $this.children('.cf7sg-collapsible-title') ).prop('checked', true); | |
| 130 | 105 | } |
| 131 | - let $ctrl = $this.children('.row').children('.row-controls').find('.collapsible-row-label'); | |
| 106 | + const $ctrl = $this.children('.row').children('.row-controls').find('.collapsible-row-label'); | |
| 132 | 107 | $('input', $ctrl).prop('checked', true); |
| 133 | 108 | //toggle disable the sibling input |
| 134 | 109 | $('input', $ctrl.siblings('.unique-mod')).prop('disabled', function(i,v){return !v;}); |
| 135 | 110 | }); |
| @@ -134,9 +109,9 @@ | ||
| 134 | 109 | $('input', $ctrl.siblings('.unique-mod')).prop('disabled', function(i,v){return !v;}); |
| 135 | 110 | }); |
| 136 | 111 | /*--------------------------------------------------- convert tables */ |
| 137 | 112 | $('div.container.cf7-sg-table', $form).each(function(){ |
| 138 | - let $this = $(this); | |
| 113 | + const $this = $(this); | |
| 139 | 114 | let id = $this.attr('id'); |
| 140 | 115 | if(typeof id == 'undefined'){ |
| 141 | 116 | id = 'cf7-sg-table-'+(new Date).getTime(); |
| 142 | 117 | $this.attr('id', id); |
| @@ -152,9 +127,9 @@ | ||
| 152 | 127 | $ctrl.next('.table-row-button').children('input').val(text); |
| 153 | 128 | //toggle disable the sibling input |
| 154 | 129 | $('input', $ctrl.siblings('.unique-mod')).prop('disabled', function(i,v){return !v;}); |
| 155 | 130 | //toggle footer row |
| 156 | - let $footer = $this.next(); | |
| 131 | + const $footer = $this.next(); | |
| 157 | 132 | if($footer.is('.cf7-sg-table-footer')){ |
| 158 | 133 | $ctrl = $footer.children('.row').first().find('.row-controls .footer-row-label'); |
| 159 | 134 | $('input.footer-row', $ctrl).prop('checked', true); |
| 160 | 135 | $('input', $ctrl.siblings('.unique-mod')).prop('disabled', function(i,v){return !v;}); |
| @@ -162,21 +137,21 @@ | ||
| 162 | 137 | }); |
| 163 | 138 | //tabs |
| 164 | 139 | /*--------------------------------------------------- convert tabs */ |
| 165 | 140 | $('ul.cf7-sg-tabs-list li', $form).each(function(){ |
| 166 | - let $this = $(this); | |
| 141 | + const $this = $(this); | |
| 167 | 142 | let text = $this.children('a').text(); |
| 168 | 143 | $this.append($('#grid-tabs ul li label').clone()); |
| 169 | 144 | $('label input', $this).val(text); |
| 170 | 145 | //setup checkbox |
| 171 | 146 | let $ctrl = $this.parent().siblings('.cf7-sg-tabs-panel'); |
| 172 | - $ctrl = $ctrl.children('.row').children('.row-controls' ).find('.tabs-row-label'); | |
| 147 | + $ctrl = $ctrl.children('.row').find('.row-controls' ).first().find('.tabs-row-label'); | |
| 173 | 148 | $('input.tabs-row', $ctrl).prop('checked', true); |
| 174 | - $('input', $ctrl.siblings('.unique-mod')).prop('disabled', function(i,v){return !v}); | |
| 149 | + $('input', $ctrl.siblings('.unique-mod')).prop('disabled', function(i,v){return !v;}); | |
| 175 | 150 | }); |
| 176 | 151 | //reinsert the external forms |
| 177 | 152 | $('.cf7sg-external-form', $form).each(function(){ |
| 178 | - let $extform = $(this); | |
| 153 | + const $extform = $(this); | |
| 179 | 154 | $extform.append($( $('#grid-cf7-forms .cf7sg-external-form').html() ) ); |
| 180 | 155 | let id = $extform.data('form'); |
| 181 | 156 | if($('#grid-cf7-forms .form-select option[value="'+id+'"]' ).length > 0 ){ |
| 182 | 157 | //add controls |
| @@ -182,9 +157,9 @@ | ||
| 182 | 157 | //add controls |
| 183 | 158 | //$extform.append($('#grid-cf7-forms .form-controls').clone()); |
| 184 | 159 | $('.form-controls .form-select', $extform).val(id); |
| 185 | 160 | //check for form update. |
| 186 | - let data = { | |
| 161 | + const data = { | |
| 187 | 162 | 'action' : 'get_cf7_content', |
| 188 | 163 | 'id': $('#post_ID').val(), |
| 189 | 164 | 'nonce' : $('#_wpcf7nonce').val(), |
| 190 | 165 | 'cf7_key' : id, |
| @@ -201,26 +176,18 @@ | ||
| 201 | 176 | /** @since 3.4 enable groupings of collapsible rows */ |
| 202 | 177 | $('.cf7sg-accordion-rows.columns, .cf7sg-slider-section.columns', $form).each(function(){ |
| 203 | 178 | let $col = $(this), |
| 204 | 179 | $control = $col.children('.grid-column').addClass('enable-grouping'); //enable checkboxes. |
| 205 | - /** @since 4.13.0 display auto scroll helper code */ | |
| 206 | - $('.php-icon',$control).show().attr('data-search', 'li.cf7sg-slider'); | |
| 207 | 180 | if($col.is('.cf7sg-accordion-rows')){ |
| 208 | 181 | $('.accordion-rows:input', $control).prop('checked', true); |
| 209 | 182 | }else{ //is .cf7sg-slider-section |
| 210 | 183 | $('.slider-rows:input', $control).prop('checked', true); |
| 211 | - //check if next container is a slider control. | |
| 212 | - let $ctrl = $col.closest('.container').next(); | |
| 213 | - if($ctrl.is('.container.cf7sg-slider-controls')){ | |
| 214 | - $control = $ctrl.children('.row').children('.row-controls'); | |
| 215 | - $('.slider-control:input', $control).prop('checked', true); | |
| 216 | - } | |
| 217 | 184 | } |
| 218 | 185 | //remove toggle checkbox. |
| 219 | 186 | $('input[type="checkbox"]', $col.children('.cf7sg-collapsible').children('.cf7sg-collapsible-title') ).hide().next('span').hide(); |
| 220 | 187 | }); |
| 221 | 188 | //check if any columns have more than 2 collapsible sections. |
| 222 | - $collapsibles.each(function(){ | |
| 189 | + $('.row .cf7sg-collapsible:first-child', $form).each(function(){ | |
| 223 | 190 | $(this).siblings('.cf7sg-collapsible').closest('.columns').children('.grid-column').addClass('enable-grouping'); |
| 224 | 191 | }); |
| 225 | 192 | //add the form to the grid |
| 226 | 193 | if($form.children('.container').length >0 || $form.children('.cf7sg-external-form').length>0){ |
| @@ -229,9 +196,9 @@ | ||
| 229 | 196 | $grid.html($form.html()); |
| 230 | 197 | } |
| 231 | 198 | //set the value of each textarea as inner text |
| 232 | 199 | $('textarea', $grid).each(function(){ |
| 233 | - let $this = $(this); | |
| 200 | + const $this = $(this); | |
| 234 | 201 | $this.html($this.val()); |
| 235 | 202 | }); |
| 236 | 203 | /*--------------------------------------------------- if ui mode, then convert to gui template */ |
| 237 | 204 | let $textareaSelected=''; |
| @@ -236,9 +203,9 @@ | ||
| 236 | 203 | /*--------------------------------------------------- if ui mode, then convert to gui template */ |
| 237 | 204 | let $textareaSelected=''; |
| 238 | 205 | if(cf7grid.ui){ |
| 239 | 206 | $('div.columns', $grid).each(function(){ |
| 240 | - let $this = $(this); | |
| 207 | + const $this = $(this); | |
| 241 | 208 | if($this.children().is('.container')) return true; |
| 242 | 209 | $this.html2gui(); |
| 243 | 210 | }); |
| 244 | 211 | }else{ |
| @@ -248,9 +215,9 @@ | ||
| 248 | 215 | $textareaSelected.attr('id', 'wpcf7-form'); |
| 249 | 216 | } |
| 250 | 217 | //change this to whichever is live |
| 251 | 218 | $('textarea', $grid).on('focus', function(){ |
| 252 | - let $this = $(this); | |
| 219 | + const $this = $(this); | |
| 253 | 220 | if($textareaSelected.length>0 && $textareaSelected.is('#wpcf7-form')){ |
| 254 | 221 | $textareaSelected.attr('id',''); |
| 255 | 222 | $textareaSelected.html($textareaSelected.val()); //set its inner html |
| 256 | 223 | } |
| @@ -287,9 +254,9 @@ | ||
| 287 | 254 | }); |
| 288 | 255 | //offset/size change using event delegation |
| 289 | 256 | /*---------------------------------------------------------------------------- ui menus */ |
| 290 | 257 | $grid.on('change', function(event){ |
| 291 | - let $target = $(event.target); | |
| 258 | + const $target = $(event.target); | |
| 292 | 259 | if($target.is('.column-setting')){ //----------- column size/offset settings |
| 293 | 260 | let validation = ['dummy']; |
| 294 | 261 | if( $target.is('.column-offset') ){ |
| 295 | 262 | validation = offsets; |
| @@ -297,9 +264,9 @@ | ||
| 297 | 264 | validation = columnsizes; |
| 298 | 265 | }else{ |
| 299 | 266 | return false; |
| 300 | 267 | } |
| 301 | - let $column = $target.closest('.columns'), classList = $column.attr('class').split(/\s+/); | |
| 268 | + const $column = $target.closest('.columns'), classList = $column.attr('class').split(/\s+/); | |
| 302 | 269 | for(let idx=0; idx<classList.length; idx++){ |
| 303 | 270 | if($.inArray(classList[idx], validation) > -1){ |
| 304 | 271 | $column.removeClass(classList[idx]); |
| 305 | 272 | } |
| @@ -307,11 +274,11 @@ | ||
| 307 | 274 | $column.addClass($target.val()); |
| 308 | 275 | //filter the options |
| 309 | 276 | $target.closest('.grid-controls').filterColumnControls(); |
| 310 | 277 | }else if($target.is('.form-select')){ //-------------- external form selection |
| 311 | - let $container = $target.closest('.cf7sg-external-form'); | |
| 278 | + const $container = $target.closest('.cf7sg-external-form'); | |
| 312 | 279 | $container.attr('data-form', $target.val()); |
| 313 | - let data = { | |
| 280 | + const data = { | |
| 314 | 281 | 'action' : 'get_cf7_content', |
| 315 | 282 | 'id': $('#post_ID').val(), |
| 316 | 283 | 'nonce' : $('#_wpcf7nonce').val(), |
| 317 | 284 | 'cf7_key' : $target.val() |
| @@ -325,9 +292,9 @@ | ||
| 325 | 292 | */ |
| 326 | 293 | if($target.is('.cf7sg-collapsible-title label input[type="text"]')){ //------- Collapsible title |
| 327 | 294 | $target.siblings('input[type="hidden"]').val($target.val()); |
| 328 | 295 | }else if( $target.is('.cf7sg-collapsible-title label input[type="checkbox"]')){ //------- Collapsible title toggled |
| 329 | - let $title = $target.closest('.cf7sg-collapsible-title'); | |
| 296 | + const $title = $target.closest('.cf7sg-collapsible-title'); | |
| 330 | 297 | if($target.is(':checked')){ |
| 331 | 298 | $title.append($('#grid-collapsible-with-toggle').html()); |
| 332 | 299 | $title.closest('.container.cf7sg-collapsible').addClass('with-toggle').attr('data-group','').attr('data-open','false'); |
| 333 | 300 | }else{ |
| @@ -341,9 +308,8 @@ | ||
| 341 | 308 | } |
| 342 | 309 | if(cf7grid.ui){ |
| 343 | 310 | if($target.is('.cf7-field-inner textarea')){ |
| 344 | 311 | let label = $target.scanCF7Tag(); |
| 345 | - $grid.trigger('cf7sg-cf7tag-update'); | |
| 346 | 312 | $target.siblings('p.content').html(label);//.show(); |
| 347 | 313 | $target.parent().siblings('textarea.grid-input').updateGridForm(); |
| 348 | 314 | }else if($target.is('.cf7-field-inner input')){ |
| 349 | 315 | $target.siblings('p.content').html($target.val()); |
| @@ -353,9 +319,9 @@ | ||
| 353 | 319 | }); //end $grid.on('change'); |
| 354 | 320 | |
| 355 | 321 | //grid click event delegation |
| 356 | 322 | $grid.on('click', function(event){ |
| 357 | - let $target = $(event.target); | |
| 323 | + const $target = $(event.target); | |
| 358 | 324 | switch(true){ |
| 359 | 325 | case $target.is('input[type="text"]:visible'): |
| 360 | 326 | case $target.is('textarea:visible'): //click on a field. |
| 361 | 327 | case $target.is('select:visible'): |
| @@ -399,9 +365,9 @@ | ||
| 399 | 365 | */ |
| 400 | 366 | }else if( $target.is('.dashicons-no-alt.row-control') ) { //----------------hide controls |
| 401 | 367 | //take care by closeAllControls |
| 402 | 368 | }else if($target.is('input.collapsible-row')){ //-------------checkbox collapsible row |
| 403 | - let $container = $target.closest('.container'); | |
| 369 | + const $container = $target.closest('.container'); | |
| 404 | 370 | if($target.is(':checked')){ |
| 405 | 371 | $container.addClass('cf7sg-collapsible'); |
| 406 | 372 | let id = $container.attr('id'); |
| 407 | 373 | if(typeof id == 'undefined'){ |
| @@ -427,9 +393,9 @@ | ||
| 427 | 393 | } |
| 428 | 394 | //toggle disable the sibling input |
| 429 | 395 | $target.parent().siblings('label.unique-mod').children('input').prop('disabled', function(i,v){return !v;}); |
| 430 | 396 | }else if($target.is('input.tabs-row')){ //-------------checkbox tabbed row |
| 431 | - let $panel = $target.closest('.container'); | |
| 397 | + const $panel = $target.closest('.container'); | |
| 432 | 398 | if($target.is(':checked')){ |
| 433 | 399 | let id = 'cf7-sg-tab-'+(new Date).getTime(); |
| 434 | 400 | $panel.addClass('cf7-sg-tabs-panel').attr('id',id); |
| 435 | 401 | $panel.before($('#grid-tabs').html()); |
| @@ -444,9 +410,9 @@ | ||
| 444 | 410 | } |
| 445 | 411 | //toggle disable the sibling input |
| 446 | 412 | $target.parent().siblings('label.unique-mod').children('input').prop('disabled', function(i,v){return !v;}); |
| 447 | 413 | }else if($target.is('input.footer-row')){ //-------------checkbox footer row |
| 448 | - let $table = $target.closest('.container').prev(); | |
| 414 | + const $table = $target.closest('.container').prev(); | |
| 449 | 415 | if($table.is('.container.cf7-sg-table')){ |
| 450 | 416 | if($target.is(':checked')){ |
| 451 | 417 | $target.closest('.container').addClass('cf7-sg-table-footer').fireGridUpdate('add','footer-row'); |
| 452 | 418 | }else{ |
| @@ -464,9 +430,9 @@ | ||
| 464 | 430 | $parentRow = $target.closest('.row'); |
| 465 | 431 | if($parentRow && $parentRow.children('.columns').length>1){ |
| 466 | 432 | //is row table/tab |
| 467 | 433 | $parentContainer = $parentRow.closest('.container'); |
| 468 | - let $content = $parentRow.children('.columns'); | |
| 434 | + const $content = $parentRow.children('.columns'); | |
| 469 | 435 | $content.wrapAll('<div class="columns full"></div>'); |
| 470 | 436 | $parentColumn = $content.parent('.columns'); |
| 471 | 437 | $parentColumn.prepend( $( $('#grid-col').html() ) ); |
| 472 | 438 | //remove single cell UI content |
| @@ -474,21 +440,8 @@ | ||
| 474 | 440 | $parentColumn.children('.grid-column').children('div.cf7-field-inner').remove(); |
| 475 | 441 | //finally insert a new row with the content moved to the new row. |
| 476 | 442 | $parentColumn.insertNewRow($content.remove()); |
| 477 | 443 | } |
| 478 | - }else if($target.is('input.slider-control')){ | |
| 479 | - $parentContainer = $target.closest('.container'); | |
| 480 | - $parentRow = $target.closest('.row'); | |
| 481 | - if($target.is(':checked')){ | |
| 482 | - $parentContainer.addClass('cf7sg-slider-controls').fireGridUpdate('add','slider-control'); | |
| 483 | - $parentRow.addClass('cf7sg-submit-controls'); | |
| 484 | - $parentRow.before('<span class="button slider-control slider-prev">Prev</span>'); | |
| 485 | - $parentRow.after('<span class="button slider-control slider-next">Next</span>'); | |
| 486 | - }else{ | |
| 487 | - $parentContainer.removeClass('cf7sg-slider-controls').fireGridUpdate('remove','slider-control'); | |
| 488 | - $('.button.slider-control',$parentContainer).remove(); | |
| 489 | - $parentRow.removeClass('cf7sg-submit-controls'); | |
| 490 | - } | |
| 491 | 444 | } |
| 492 | 445 | |
| 493 | 446 | |
| 494 | 447 | /* |
| @@ -566,9 +519,9 @@ | ||
| 566 | 519 | $helper.click('a.helper, .dashicons-no-alt', function(e){ |
| 567 | 520 | $(this).remove(); |
| 568 | 521 | }); |
| 569 | 522 | }else if($target.is('.icon-code.column-control') ){ |
| 570 | - let $focus = $target.closest('.columns'); | |
| 523 | + const $focus = $target.closest('.columns'); | |
| 571 | 524 | //toggle cf7sgfocus class on inner field to focus on. |
| 572 | 525 | if($focus.is('.cf7sgfocus')){ |
| 573 | 526 | $focus.removeClass('cf7sgfocus'); |
| 574 | 527 | }else{ |
| @@ -672,10 +625,9 @@ | ||
| 672 | 625 | $newColumn.changeColumnSize('',columnsizes[newSize]); |
| 673 | 626 | $parentColumn.after($newColumn); |
| 674 | 627 | }else if( $target.is('.accordion-rows.column-control') ){ /** @since 3.4.0 enable accordion */ |
| 675 | 628 | if($target.is(':checked')){ |
| 676 | - $parentColumn.addClass('cf7sg-accordion-rows').removeClass('cf7sg-slider-section').removeAttr("data-next data-prev data-submit data-dots"); | |
| 677 | - $parentColumn.closest('.container').removeClass('cf7sg-slider'); | |
| 629 | + $parentColumn.addClass('cf7sg-accordion-rows').removeClass('cf7sg-slider-section').removeAttr("data-next data-prev data-submit"); | |
| 678 | 630 | $target.parent('label').siblings('.grouping-option').children(':input').prop('checked', false); |
| 679 | 631 | $target.fireGridUpdate('add','accordion-rows'); |
| 680 | 632 | //hide toggle checkbox. |
| 681 | 633 | $('input[type="checkbox"]', $parentColumn.children('.cf7sg-collapsible').children('.cf7sg-collapsible-title') ).hide().next('span').hide(); |
| @@ -686,26 +638,19 @@ | ||
| 686 | 638 | $('input[type="checkbox"]', $parentColumn.children('.cf7sg-collapsible').children('.cf7sg-collapsible-title') ).show().next('span').show(); |
| 687 | 639 | } |
| 688 | 640 | }else if( $target.is('.slider-rows.column-control') ) { /** @since 3.4.0 enable slider */ |
| 689 | 641 | if($target.is(':checked')){ |
| 690 | - /** @since 4.7.2 enable dots on sliders */ | |
| 691 | - let attrs = { "data-next":"", "data-prev":"", "data-submit":"", "data-dots":"false"}; | |
| 642 | + let attrs = { "data-next":"", "data-prev":"", "data-submit":""}; | |
| 692 | 643 | $target.closest('.columns').addClass('cf7sg-slider-section').attr(attrs).removeClass('cf7sg-accordion-rows'); |
| 693 | - $target.closest('.container').addClass('cf7sg-slider'); | |
| 694 | 644 | $target.parent('label').siblings('.grouping-option').children(':input').prop('checked', false); |
| 695 | 645 | $target.fireGridUpdate('add','slider-section'); |
| 696 | 646 | //hide toggle checkbox. |
| 697 | 647 | $('input[type="checkbox"]', $parentColumn.children('.cf7sg-collapsible').children('.cf7sg-collapsible-title') ).hide().next('span').hide(); |
| 698 | - /** @since 4.13.0 display auto scroll helper code */ | |
| 699 | - $target.closest('.grid-controls').siblings('.php-icon').show().attr('data-search', 'li.cf7sg-slider'); | |
| 700 | 648 | }else{ |
| 701 | - $target.closest('.columns').removeClass('cf7sg-slider-section').removeAttr("data-next data-prev data-submit data-dots"); | |
| 702 | - $target.closest('.container').removeClass('cf7sg-slider'); | |
| 649 | + $target.closest('.columns').removeClass('cf7sg-slider-section').removeAttr("data-next data-prev data-submit"); | |
| 703 | 650 | $target.fireGridUpdate('remove','slider-section'); |
| 704 | 651 | //show toggle checkbox. |
| 705 | 652 | $('input[type="checkbox"]', $parentColumn.children('.cf7sg-collapsible').children('.cf7sg-collapsible-title') ).show().next('span').show(); |
| 706 | - /** @since 4.13.0 display auto scroll helper code */ | |
| 707 | - $target.closest('.grid-controls').siblings('.php-icon').hide().attr('data-search', ''); | |
| 708 | 653 | } |
| 709 | 654 | } |
| 710 | 655 | /* |
| 711 | 656 | Column UI fields |
| @@ -745,9 +690,9 @@ | ||
| 745 | 690 | |
| 746 | 691 | } |
| 747 | 692 | //general inputs into the textareas will trigger form change event |
| 748 | 693 | $grid.on('input selectionchange propertychange', 'textarea', function(event){ |
| 749 | - let $target = $(event.target); | |
| 694 | + const $target = $(event.target); | |
| 750 | 695 | if($target.is('.cf7-field-type textarea')){ |
| 751 | 696 | return false; //form change trigger will happen after this |
| 752 | 697 | }else if($target.is('textarea')){ |
| 753 | 698 | $target.html($target.val()+'\n'); //ensure changes are capture in the codemirror editor |
| @@ -765,9 +710,9 @@ | ||
| 765 | 710 | $grid.trigger('cf7grid-form-ready'); //codemirror initialisation |
| 766 | 711 | }); |
| 767 | 712 | changeTextarea(true); |
| 768 | 713 | }else{ |
| 769 | - let $txta = $('textarea#wpcf7-form'); | |
| 714 | + const $txta = $('textarea#wpcf7-form'); | |
| 770 | 715 | $txta.html($txta.val()+'\n'); |
| 771 | 716 | $grid.trigger('cf7grid-form-ready'); //codemirror initialisation |
| 772 | 717 | } |
| 773 | 718 | }); |
| @@ -777,11 +722,11 @@ | ||
| 777 | 722 | $grid.on('build-grid', function(){ |
| 778 | 723 | if( !buildGridForm() ){ |
| 779 | 724 | $('#form-editor-tabs').tabs('option',{ active:1, disabled:true}); |
| 780 | 725 | }else{ |
| 781 | - let $focus = $('.cf7sgfocus', $grid); | |
| 726 | + const $focus = $('.cf7sgfocus', $grid); | |
| 782 | 727 | if($focus.length>0){ |
| 783 | - let scrollPos = $focus.offset().top - $(window).height()/2 + $focus.height()/2; | |
| 728 | + const scrollPos = $focus.offset().top - $(window).height()/2 + $focus.height()/2; | |
| 784 | 729 | //console.log(scrollPos); |
| 785 | 730 | $(window).scrollTop(scrollPos); |
| 786 | 731 | $focus.removeClass('cf7sgfocus'); |
| 787 | 732 | } |
| @@ -808,9 +753,9 @@ | ||
| 808 | 753 | if(!n){ |
| 809 | 754 | n = 5; |
| 810 | 755 | } |
| 811 | 756 | let text = ''; |
| 812 | - let possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; | |
| 757 | + const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; | |
| 813 | 758 | for(let i=0; i < n; i++){ |
| 814 | 759 | text += possible.charAt(Math.floor(Math.random() * possible.length)); |
| 815 | 760 | } |
| 816 | 761 | return text; |
| @@ -819,14 +764,13 @@ | ||
| 819 | 764 | function closeAlluiFields(){ |
| 820 | 765 | $('.cf7-field-inner :input:visible').each(function(){ |
| 821 | 766 | $(this).closeUIfield(); |
| 822 | 767 | }); |
| 823 | - // $fieldTags.addClass('click-disabled'); | |
| 824 | 768 | } |
| 825 | 769 | //close controls row/column |
| 826 | 770 | function closeAllControls(){ |
| 827 | 771 | $('.grid-controls:visible', $grid).each(function(){ |
| 828 | - let $this = $(this); | |
| 772 | + const $this = $(this); | |
| 829 | 773 | $this.hide(); |
| 830 | 774 | $this.siblings('.dashicons-no-alt').hide(); |
| 831 | 775 | $this.siblings('.dashicons-edit').show(); |
| 832 | 776 | }); |
| @@ -835,9 +779,9 @@ | ||
| 835 | 779 | } |
| 836 | 780 | //trigger a change on the textarea#wpcf7-form field if its value has changed |
| 837 | 781 | function changeTextarea(finalise = false){ |
| 838 | 782 | if(cf7grid.ui){ |
| 839 | - let $lastTA = $('#wpcf7-form'); | |
| 783 | + const $lastTA = $('#wpcf7-form'); | |
| 840 | 784 | if($lastTA.length >0 && wpcf7Value !== $lastTA.val()){ |
| 841 | 785 | wpcf7Value = ''; |
| 842 | 786 | $lastTA.trigger('change'); |
| 843 | 787 | }else if(finalise){ |
| @@ -842,9 +786,8 @@ | ||
| 842 | 786 | $lastTA.trigger('change'); |
| 843 | 787 | }else if(finalise){ |
| 844 | 788 | $grid.trigger('cf7grid-form-ready'); //codemirror initialisation |
| 845 | 789 | } |
| 846 | - $fieldTags.addClass('click-disabled'); | |
| 847 | 790 | } |
| 848 | 791 | } |
| 849 | 792 | function sortableRows( $newRow='' ){ |
| 850 | 793 | if($newRow.lenght>0){ |
| @@ -860,14 +803,14 @@ | ||
| 860 | 803 | receive: function( event, ui ) { |
| 861 | 804 | //ui.item validate column size relative to new row columns. |
| 862 | 805 | //ui.sender original row. cnacel if column does not fit in new row. |
| 863 | 806 | //$targetRow has more than 12 columns then cancel. |
| 864 | - let $targetRow = $(event.target);//receiving row | |
| 807 | + const $targetRow = $(event.target);//receiving row | |
| 865 | 808 | let row = $targetRow.getRowSize(); |
| 866 | 809 | |
| 867 | 810 | if( row.length > 12){ |
| 868 | 811 | ui.sender.sortable('cancel'); |
| 869 | - let $warning = $('<span class="cf7sg-warning">Not enough space in this row to add column</span>'); | |
| 812 | + const $warning = $('<span class="cf7sg-warning">Not enough space in this row to add column</span>'); | |
| 870 | 813 | $targetRow.after($warning); |
| 871 | 814 | $warning.delay(2000).fadeOut('slow', function(){ |
| 872 | 815 | $(this).remove(); |
| 873 | 816 | }); |
| @@ -872,9 +815,9 @@ | ||
| 872 | 815 | $(this).remove(); |
| 873 | 816 | }); |
| 874 | 817 | }else{ |
| 875 | 818 | //make sure the row controls is at the end. |
| 876 | - let control = $targetRow.children('.row-controls').remove(); | |
| 819 | + const control = $targetRow.children('.row-controls').remove(); | |
| 877 | 820 | $targetRow.append(control); |
| 878 | 821 | } |
| 879 | 822 | } |
| 880 | 823 | }); |
| @@ -883,9 +826,9 @@ | ||
| 883 | 826 | $.fn.closeUIfield = function(){ |
| 884 | 827 | let obj = this; |
| 885 | 828 | if(!Array.isArray(this)) obj=[this]; |
| 886 | 829 | $.each(obj,function(idx, item){ |
| 887 | - let $this = $(item); | |
| 830 | + const $this = $(item); | |
| 888 | 831 | if(!$this.is('.cf7-field-inner :input:visible')){ |
| 889 | 832 | return $this; |
| 890 | 833 | } |
| 891 | 834 | if($this.parent().is('.cf7-field-type')) changeTextarea(); |
| @@ -895,22 +838,20 @@ | ||
| 895 | 838 | }); |
| 896 | 839 | return true; |
| 897 | 840 | } |
| 898 | 841 | $.fn.showUIfield = function(){ |
| 899 | - let $this = $(this); | |
| 842 | + const $this = $(this); | |
| 900 | 843 | if(!$this.is('.cf7-field-inner')){ |
| 901 | 844 | return $this; |
| 902 | 845 | } |
| 903 | 846 | $this.find('p.content').hide(); |
| 904 | 847 | $this.find('span.dashicons').show(); |
| 905 | - let $input = $(':input', $this).show(); | |
| 848 | + const $input = $(':input', $this).show(); | |
| 906 | 849 | $input.focus(); |
| 907 | 850 | if($input.is('textarea')){ |
| 908 | 851 | $('textarea#wpcf7-form').attr('id',''); |
| 909 | 852 | $input.attr('id', 'wpcf7-form'); |
| 910 | 853 | wpcf7Value = $input.val(); |
| 911 | - /** @since 4.11 enable tag buttons when a field is being edited */ | |
| 912 | - $fieldTags.removeClass('click-disabled'); | |
| 913 | 854 | }else{ |
| 914 | 855 | changeTextarea(); |
| 915 | 856 | } |
| 916 | 857 | return $this; |
| @@ -915,9 +856,9 @@ | ||
| 915 | 856 | } |
| 916 | 857 | return $this; |
| 917 | 858 | } |
| 918 | 859 | $.fn.html2gui = function(html){ |
| 919 | - let $this = $(this); | |
| 860 | + const $this = $(this); | |
| 920 | 861 | if(typeof html === 'undefined') html =''; |
| 921 | 862 | if(html.length === 0){ |
| 922 | 863 | //get the fields from the textarea |
| 923 | 864 | html = $('textarea.grid-input', $this).text(); |
| @@ -929,14 +870,14 @@ | ||
| 929 | 870 | let singleField = true; |
| 930 | 871 | let search = $('<div>').append(html); |
| 931 | 872 | |
| 932 | 873 | if(seekTemplate && 1==search.children(cssTemplate).length){ |
| 933 | - let lines = html.split(/\r\n|\r|\n/g); | |
| 874 | + const lines = html.split(/\r\n|\r|\n/g); | |
| 934 | 875 | search = ''; |
| 935 | 876 | for(let i=0; i<lines.length; i++){ |
| 936 | 877 | search += lines[i].trim(); |
| 937 | 878 | } |
| 938 | - let match = templateRegex.exec(search); | |
| 879 | + const match = templateRegex.exec(search); | |
| 939 | 880 | if(null !== match){ |
| 940 | 881 | //populate the fields |
| 941 | 882 | let $field = $('div.cf7-field-label', $this); |
| 942 | 883 | $('input', $field).val(match[1]); |
| @@ -941,9 +882,9 @@ | ||
| 941 | 882 | let $field = $('div.cf7-field-label', $this); |
| 942 | 883 | $('input', $field).val(match[1]); |
| 943 | 884 | $('p.content', $field).html(match[1]); |
| 944 | 885 | $field = $('div.cf7-field-type', $this); |
| 945 | - let tag = $('textarea', $field).val(match[5]).scanCF7Tag(); | |
| 886 | + const tag = $('textarea', $field).val(match[5]).scanCF7Tag(); | |
| 946 | 887 | $('p.content', $field).html(tag); |
| 947 | 888 | $field = $('div.cf7-field-tip', $this); |
| 948 | 889 | $('input', $field).val(match[6]); |
| 949 | 890 | $('p.content', $field).html(match[6]); |
| @@ -985,13 +926,13 @@ | ||
| 985 | 926 | $(this).removeAttr('data-field').removeAttr('data-tag').removeAttr('data-search'); |
| 986 | 927 | }); |
| 987 | 928 | //reset jshelper. |
| 988 | 929 | $jshelper = $parent.siblings('.js-icon'); |
| 989 | - // | |
| 990 | - //kitchen-facilities limit class:cf7sg-hybriddd "slug:category:tree" | |
| 991 | - let search = $this.val(), fMatch, match, | |
| 930 | + | |
| 931 | + let cf7TagRegexp = /\[(.[^\s]*)\s*(.[^\s\]]*)[\s\[]*(.[^\[]*\"source:([^\s]*)\"[\s^\[]*|[.^\[]*(?!\"source:)[^\[]*)\]/img, | |
| 932 | + search = $this.val(), | |
| 933 | + match = cf7TagRegexp.exec(search), | |
| 992 | 934 | label='', |
| 993 | - tagRegex = new RegExp(cf7TagRgxp, 'igm'), | |
| 994 | 935 | isRequired = false, |
| 995 | 936 | type = [], |
| 996 | 937 | fields = [], |
| 997 | 938 | hooks = [],jshooks=[], |
| @@ -998,76 +939,86 @@ | ||
| 998 | 939 | tag='', |
| 999 | 940 | isSubmit = false, hasHidden = false, |
| 1000 | 941 | count =0, counth = 0, |
| 1001 | 942 | field = '', |
| 1002 | - stopSearch = false, isField = false, | |
| 943 | + stopSearch = false, isField =true, | |
| 1003 | 944 | classes = $('#grid-col div.cf7-field-type').attr('class'); |
| 1004 | 945 | |
| 1005 | - while ( (match = tagRegex.exec(search)) !== null) { | |
| 1006 | - isRequired = (match[2]+'*' === match[1]); | |
| 946 | + while (match != null && !stopSearch) { | |
| 1007 | 947 | count++; |
| 1008 | - tag = match[2]; | |
| 1009 | - field=''; | |
| 1010 | - if(match.length>3){ | |
| 1011 | - fMatch = (new RegExp(cf7FieldRgxp)).exec(match[3]); | |
| 1012 | - if(fMatch && fMatch[1]){ | |
| 1013 | - field = fMatch[1]; | |
| 1014 | - isField = true; | |
| 1015 | - } | |
| 1016 | - } | |
| 948 | + label+='['+match[1]+' '+match[2]+']'; | |
| 949 | + tag = match[1].replace('*',''); | |
| 950 | + field = match[2]; | |
| 1017 | 951 | let helpers = ['cf7sg-tag-all'], jsHelpers = ['cf7sg-tag-all']; |
| 1018 | 952 | helpers[helpers.length] = 'cf7sg-tag-'+tag; |
| 1019 | 953 | jsHelpers[jsHelpers.length] = 'cf7sg-tag-'+tag; |
| 1020 | - switch(true){ | |
| 1021 | - case 'submit'==tag: | |
| 1022 | - case 'save'==tag: | |
| 954 | + switch(tag){ | |
| 955 | + case 'submit': | |
| 956 | + case 'save': | |
| 1023 | 957 | tag +='-button'; |
| 1024 | 958 | isSubmit = true; |
| 1025 | 959 | break; |
| 1026 | - case 'textarea'==tag: | |
| 960 | + case 'textarea': | |
| 1027 | 961 | if( match[0].search(/\s[0-9]{0,3}x[0-9]{1,3}\s?/ig) <0){ |
| 1028 | - let cf7sc = match[0].replace(match[3],match[3]+' x5'); //textarea prefill. | |
| 962 | + let cf7sc = match[0].replace(']',' x5]'); | |
| 1029 | 963 | cf7sc = search.replace(match[0], cf7sc); |
| 1030 | 964 | $this.val(cf7sc); |
| 1031 | 965 | } |
| 1032 | 966 | break; |
| 1033 | - case 'hidden'==tag: /** @since 3.2.1 fix hidden field class */ | |
| 967 | + case 'acceptance': //special case with closing tag. | |
| 968 | + stopSearch = true; | |
| 969 | + break; | |
| 970 | + case 'recaptch': | |
| 971 | + case 'recaptcha': //special case with closing tag. | |
| 972 | + label='[recaptcha]'; | |
| 973 | + stopSearch = true; | |
| 974 | + break; | |
| 975 | + case 'dynamic_select': | |
| 976 | + let source =''; | |
| 977 | + switch(true){ | |
| 978 | + case ( match.length > 4 && 'undefined' !== typeof match[4] ) : //match[4] exists. | |
| 979 | + source = match[4].split(':'); | |
| 980 | + source = source[0]; | |
| 981 | + helpers[helpers.length] = 'cf7sg-tag-dynamic_select-'+source; | |
| 982 | + case match.length > 3: //lets deal with match[3] | |
| 983 | + if(0=== source.length){ | |
| 984 | + source="filter"; | |
| 985 | + switch(true){ | |
| 986 | + case match[3].indexOf("source:post")>0: | |
| 987 | + source="post"; | |
| 988 | + break; | |
| 989 | + case match[3].indexOf("slug:")>0: | |
| 990 | + source="taxonomy"; | |
| 991 | + break; | |
| 992 | + } | |
| 993 | + } | |
| 994 | + helpers[helpers.length] = 'cf7sg-tag-dynamic_select-'+source; | |
| 995 | + | |
| 996 | + if(match[3].indexOf('class:tags')>-1){ | |
| 997 | + helpers[helpers.length] = 'cf7sg-tag-dynamic_select-tags'; | |
| 998 | + if(source.length>0){ | |
| 999 | + helpers[helpers.length] = 'cf7sg-tag-dynamic_select-'+source+'-tags'; | |
| 1000 | + } | |
| 1001 | + } | |
| 1002 | + break; | |
| 1003 | + } | |
| 1004 | + break; | |
| 1005 | + case 'hidden': /** @since 3.2.1 fix hidden field class */ | |
| 1034 | 1006 | tag+='-input'; |
| 1035 | 1007 | counth++; |
| 1036 | 1008 | break; |
| 1037 | - case 'group'==tag: /** @since 4.4.3 fix conditional groups within */ | |
| 1009 | + case 'group': /** @since 4.4.3 fix conditional groups within */ | |
| 1038 | 1010 | isField = false; |
| 1039 | 1011 | classes += " conditional-group"; |
| 1040 | - counth++; //don't count as field. | |
| 1041 | 1012 | break; |
| 1042 | - case cf7grid.dynamicTags.indexOf(tag)>=0: | |
| 1043 | -/* | |
| 1044 | -kitchen-facilities limit class:cf7sg-hybriddd "slug:category:tree" | |
| 1045 | -ddcb limit class:cf7sg-hybriddd "slug:category" "data-maxcheck:1" | |
| 1046 | -posts-dd multiple permalinks class:select2 "source:post:post" "taxonomy:category:paris" | |
| 1047 | - | |
| 1048 | -ddcb-filter limit id:test class:some-class class:cf7sg-imagehdd "source:filter" | |
| 1049 | -ddcb-tax limit id:test class:some-class class:cf7sg-imagehdd "slug:category:tree" | |
| 1050 | -*/ | |
| 1051 | - let source =''; | |
| 1052 | - if(fMatch[5]) source = fMatch[6]; | |
| 1053 | - else if(fMatch[8]) source = 'taxonomy'; | |
| 1054 | - | |
| 1055 | - if(match[3].indexOf('class:tags')>-1){ | |
| 1056 | - helpers[helpers.length] = 'cf7sg-tag-dynamic_select-tags'; | |
| 1057 | - if(source.length>0){ | |
| 1058 | - helpers[helpers.length] = 'cf7sg-tag-dynamic_select-'+source+'-tags'; | |
| 1059 | - } | |
| 1060 | - } | |
| 1061 | - | |
| 1062 | - helpers[helpers.length] = 'cf7sg-tag-dynamic_list'; | |
| 1063 | - helpers[helpers.length] = 'cf7sg-tag-dynamic_list-'+source; | |
| 1013 | + case '/grou': | |
| 1014 | + isField = false; | |
| 1015 | + stopSearch = true; | |
| 1064 | 1016 | break; |
| 1065 | - default: //tags with no field names nor irrelevant fields. | |
| 1066 | - classes += ` ${tag}`; | |
| 1017 | + default: | |
| 1067 | 1018 | break; |
| 1068 | 1019 | } |
| 1069 | - /** @since 3.3.0 add extension classes & include 3rd party plugins helper codes */ | |
| 1020 | + /** @since 3.3.0 add extension classes */ | |
| 1070 | 1021 | if(undefined !== cf7sgCustomHelperModule[tag]){ |
| 1071 | 1022 | let ch = cf7sgCustomHelperModule[tag](search); |
| 1072 | 1023 | if(Array.isArray(ch.php) && ch.php.length>0) helpers = helpers.concat(ch.php); |
| 1073 | 1024 | if(Array.isArray(ch.js) && ch.js.length>0) jsHelpers = jsHelpers.concat(ch.js); |
| @@ -1072,19 +1023,23 @@ | ||
| 1072 | 1023 | if(Array.isArray(ch.php) && ch.php.length>0) helpers = helpers.concat(ch.php); |
| 1073 | 1024 | if(Array.isArray(ch.js) && ch.js.length>0) jsHelpers = jsHelpers.concat(ch.js); |
| 1074 | 1025 | } |
| 1075 | 1026 | if(isField){ |
| 1076 | - type.push(tag); | |
| 1077 | - fields.push(field); | |
| 1078 | - hooks.push(helpers); | |
| 1079 | - jshooks.push(jsHelpers); | |
| 1027 | + type[type.length] = tag; | |
| 1028 | + fields[fields.length] = field; | |
| 1029 | + hooks[hooks.length] = helpers; | |
| 1030 | + jshooks[jshooks.length] = jsHelpers; | |
| 1080 | 1031 | } |
| 1081 | - | |
| 1082 | - label+='['+tag+ (isRequired?'*':'') + (isField?' '+field:match[3])+']'; //disolay label. | |
| 1032 | + if('*' === match[1][match[1].length -1]){ | |
| 1033 | + isRequired = true; | |
| 1034 | + } | |
| 1035 | + if(!stopSearch) match = cf7TagRegexp.exec(search); //get the next match. | |
| 1083 | 1036 | } |
| 1084 | - classes += " "+ type.join(' ') + (isRequired ? ' required':''); | |
| 1037 | + classes += " "+ type.join(' '); | |
| 1085 | 1038 | field = fields.join(' '); |
| 1086 | - let $parentColumn = $parent.closest('.columns'); | |
| 1039 | + // $parent.removeClass('required'); | |
| 1040 | + if(isRequired) classes += ' required';//$parent.addClass('required'). | |
| 1041 | + const $parentColumn = $parent.closest('.columns'); | |
| 1087 | 1042 | if($parentColumn.is('[class*="cf7-tags-"]')){ |
| 1088 | 1043 | $parentColumn.removeClass(function (index, className) { |
| 1089 | 1044 | return (className.match (/(^|\s)cf7-tags-\S+/g) || []).join(' '); |
| 1090 | 1045 | }); |
| @@ -1099,9 +1054,8 @@ | ||
| 1099 | 1054 | */ |
| 1100 | 1055 | //for each tag get corresponding set of filters. |
| 1101 | 1056 | let helperUsed = false, jsHelperUsed=false,len = type.length, jlen=0; |
| 1102 | 1057 | search = ''; |
| 1103 | - // console.log(hooks); | |
| 1104 | 1058 | for (let i = 0; i < len; i++) { |
| 1105 | 1059 | for (let j=0, jlen = hooks[i].length; j<jlen; j++){ |
| 1106 | 1060 | search += 'li.'+hooks[i][j]+','; |
| 1107 | 1061 | } |
| @@ -1108,9 +1062,9 @@ | ||
| 1108 | 1062 | search = search.slice(0,-1); //remove last ',' |
| 1109 | 1063 | if($( search ,$('#fieldhelperdiv')).length>0){ |
| 1110 | 1064 | //this tag has some filters. |
| 1111 | 1065 | if(helperUsed){ |
| 1112 | - let $clone = $helper.clone(); | |
| 1066 | + const $clone = $helper.clone(); | |
| 1113 | 1067 | $helper.after($clone); |
| 1114 | 1068 | $helper = $clone; |
| 1115 | 1069 | } |
| 1116 | 1070 | helperUsed = true; |
| @@ -1127,9 +1081,9 @@ | ||
| 1127 | 1081 | search = search.slice(0,-1); //remove last ',' |
| 1128 | 1082 | if($( search ,$('#fieldhelperjs')).length>0){ |
| 1129 | 1083 | //this tag has some filters. |
| 1130 | 1084 | if(jsHelperUsed){ |
| 1131 | - let $clone = $jshelper.clone(); | |
| 1085 | + const $clone = $jshelper.clone(); | |
| 1132 | 1086 | $jshelper.after($clone); |
| 1133 | 1087 | $jshelper = $clone; |
| 1134 | 1088 | } |
| 1135 | 1089 | jsHelperUsed = true; |
| @@ -1145,19 +1099,18 @@ | ||
| 1145 | 1099 | |
| 1146 | 1100 | return label; |
| 1147 | 1101 | } |
| 1148 | 1102 | $.fn.updateGridForm = function(){ |
| 1149 | - let $this = $(this); | |
| 1103 | + const $this = $(this); | |
| 1150 | 1104 | if(!$this.is('textarea.grid-input')){ |
| 1151 | 1105 | return $this; |
| 1152 | 1106 | } |
| 1153 | - //extract field components to contruct html markup. | |
| 1154 | - let $label = $this.siblings('div.cf7-field-label').find(':input'), | |
| 1155 | - label = $label.val(), //label | |
| 1156 | - field = $this.siblings('div.cf7-field-type'), | |
| 1157 | - classes = field.attr('class').replace('cf7-field-type','').replace('cf7-field-inner', '').trim(), | |
| 1158 | - idx = 0; | |
| 1159 | - field = field.find('textarea.field-entry').val(); //field | |
| 1107 | + //label | |
| 1108 | + const $label = $this.siblings('div.cf7-field-label').find(':input'); | |
| 1109 | + let label = $label.val(); | |
| 1110 | + //field | |
| 1111 | + const field = $this.siblings('div.cf7-field-type').find('textarea.field-entry').val(); | |
| 1112 | + let idx = 0; | |
| 1160 | 1113 | if(cf7grid.requiredHTML.length>0) idx=label.indexOf(cf7grid.requiredHTML) |
| 1161 | 1114 | if($this.siblings('div.cf7-field-type').is('.required')){ |
| 1162 | 1115 | /** @since 2.10.4 fix for custom manual labels, allow replacement with empty span*/ |
| 1163 | 1116 | if(idx<0) idx = label.search(/<span>[\w\W]*<\/span>/g); |
| @@ -1173,13 +1126,12 @@ | ||
| 1173 | 1126 | $label.siblings('p.content').html(label); |
| 1174 | 1127 | } |
| 1175 | 1128 | } |
| 1176 | 1129 | //tip |
| 1177 | - let tip = $this.siblings('div.cf7-field-tip').find(':input').val(), | |
| 1130 | + const tip = $this.siblings('div.cf7-field-tip').find(':input').val(), | |
| 1178 | 1131 | $cell = $('<div>').append( cf7grid.preHTML + field + cf7grid.postHTML ); |
| 1179 | 1132 | $('label', $cell).html(label); |
| 1180 | 1133 | $('.info-tip', $cell).html(tip); |
| 1181 | - $('.field',$cell).addClass(classes); | |
| 1182 | 1134 | //update grid input and trigger change to udpate form |
| 1183 | 1135 | if(cf7grid.ui) $this.html($cell.html()+'\n').trigger('change'); |
| 1184 | 1136 | else $this.val($cell.html()).trigger('change'); |
| 1185 | 1137 | return $this; |
| @@ -1185,14 +1137,14 @@ | ||
| 1185 | 1137 | return $this; |
| 1186 | 1138 | }; |
| 1187 | 1139 | |
| 1188 | 1140 | $.fn.toggleSiblingUIFields = function(){ |
| 1189 | - let $this = $(this); | |
| 1141 | + const $this = $(this); | |
| 1190 | 1142 | if(!$this.is('div.cf7-field-inner')){ |
| 1191 | 1143 | return $this; |
| 1192 | 1144 | } |
| 1193 | 1145 | $this.siblings('div.cf7-field-inner').each(function(){ |
| 1194 | - let $this = $(this); | |
| 1146 | + const $this = $(this); | |
| 1195 | 1147 | $('p.content', $this).show(); |
| 1196 | 1148 | $(':input', $this).hide().attr('id',''); |
| 1197 | 1149 | $('span.dashicons', $this).hide(); |
| 1198 | 1150 | }); |
| @@ -1198,9 +1150,9 @@ | ||
| 1198 | 1150 | }); |
| 1199 | 1151 | } |
| 1200 | 1152 | $.fn.getRowSize = function(){ |
| 1201 | 1153 | let size, off, idx, foundSize, classList,total = 0; |
| 1202 | - let sizes = [0]; | |
| 1154 | + const sizes = [0]; | |
| 1203 | 1155 | $(this).children('.columns').each(function(index){ |
| 1204 | 1156 | classList = $(this).attr('class').split(/\s+/); |
| 1205 | 1157 | foundSize = false; |
| 1206 | 1158 | for(idx=0;idx<classList.length; idx++){ |
| @@ -1220,14 +1172,14 @@ | ||
| 1220 | 1172 | }); |
| 1221 | 1173 | return {'length':total, 'cols':sizes}; |
| 1222 | 1174 | } |
| 1223 | 1175 | $.fn.getColumnTotalSize = function(){ |
| 1224 | - let $this = $(this); | |
| 1176 | + const $this = $(this); | |
| 1225 | 1177 | if(! $this.is('.columns')){ |
| 1226 | 1178 | return 0; |
| 1227 | 1179 | } |
| 1228 | 1180 | let off, foundSize, size = 0,total = 0, classList = $this.attr('class').split(/\s+/); |
| 1229 | - let $sizes = $this.find('.grid-column select.column-size'), $offsets = $this.find('.grid-column select.column-offset'); | |
| 1181 | + const $sizes = $this.find('.grid-column select.column-size'), $offsets = $this.find('.grid-column select.column-offset'); | |
| 1230 | 1182 | $offsets.val(''); |
| 1231 | 1183 | $sizes.val('one'); |
| 1232 | 1184 | foundSize = false; |
| 1233 | 1185 | for(let idx=0;idx<classList.length; idx++){ |
| @@ -1253,11 +1205,11 @@ | ||
| 1253 | 1205 | return {'length':total, 'size':size}; |
| 1254 | 1206 | } |
| 1255 | 1207 | //add new rows |
| 1256 | 1208 | $.fn.insertNewRow = function(areaCode){ |
| 1257 | - let $this = $(this); | |
| 1209 | + const $this = $(this); | |
| 1258 | 1210 | if(typeof areaCode === 'undefined') areaCode =''; |
| 1259 | - let $newRow = $( $('#grid-row').html() ); | |
| 1211 | + const $newRow = $( $('#grid-row').html() ); | |
| 1260 | 1212 | //append the column controls and textarea |
| 1261 | 1213 | $('.columns', $newRow).append( $($('#grid-col').html()) ); |
| 1262 | 1214 | |
| 1263 | 1215 | switch(true){ |
| @@ -1296,9 +1248,9 @@ | ||
| 1296 | 1248 | return $this; |
| 1297 | 1249 | } |
| 1298 | 1250 | //refresh controls select |
| 1299 | 1251 | $.fn.changeColumnSize = function(oldSize, newSize){ |
| 1300 | - let $this = $(this); | |
| 1252 | + const $this = $(this); | |
| 1301 | 1253 | if(oldSize.length > 0) $this.removeClass(oldSize); |
| 1302 | 1254 | $this.addClass(newSize); |
| 1303 | 1255 | $('.column-size option[value="'+newSize+'"]', $this ).prop('selected', true); |
| 1304 | 1256 | } |
| @@ -1303,9 +1255,9 @@ | ||
| 1303 | 1255 | $('.column-size option[value="'+newSize+'"]', $this ).prop('selected', true); |
| 1304 | 1256 | } |
| 1305 | 1257 | //$target.closest('.grid-controls').filterColumnControls(); |
| 1306 | 1258 | $.fn.filterColumnControls = function(){ |
| 1307 | - let $this = $(this); | |
| 1259 | + const $this = $(this); | |
| 1308 | 1260 | if(!$this.is('.grid-controls')){ |
| 1309 | 1261 | return $this; |
| 1310 | 1262 | } |
| 1311 | 1263 | //enable all options |
| @@ -1310,10 +1262,10 @@ | ||
| 1310 | 1262 | } |
| 1311 | 1263 | //enable all options |
| 1312 | 1264 | $('.column-size option', $this ).prop('disabled', false); |
| 1313 | 1265 | $('.column-offset option', $this ).prop('disabled', false); |
| 1314 | - let $parentRow = $this.closest('.row'), $parentColumn = $this.closest('.columns'); | |
| 1315 | - let row = $parentRow.getRowSize(), col = $parentColumn.getColumnTotalSize(); | |
| 1266 | + const $parentRow = $this.closest('.row'), $parentColumn = $this.closest('.columns'); | |
| 1267 | + const row = $parentRow.getRowSize(), col = $parentColumn.getColumnTotalSize(); | |
| 1316 | 1268 | let idx, start, free = 0; |
| 1317 | 1269 | if(row.length < 12) free = (12 - row.length); |
| 1318 | 1270 | for(idx = start = col.size+1; idx < columnsizes.length; idx++){ |
| 1319 | 1271 | if( idx > (free + start - 1) ){ |