1jQuery(document).ready(function($) { 2 3 var weFormsFrontReport = { 4 init: function () { 5 var form_id = [], 6 frontend_report = []; 7 $(".wpuf-form-add :input[name=form_id]").each(function(){ 8 form_id.push( $(this).val() ); 9 }); 10 $(".wpuf-form-add :input[name=weforms-front-report]").each(function(){ 11 frontend_report.push( $(this).val() ); 12 }); 13 14 var idx, 15 form_selector = ''; 16 17 for ( idx = 0; idx < form_id.length; idx++ ) { 18 form_selector = '.weforms-' + form_id[idx]; 19 if ( frontend_report[idx] === 'yes' ) { 20 $(form_selector).off(); 21 $(form_selector).on('submit', this.frontReportFormSubmit); 22 } 23 } 24 }, 25 26 frontReportFormSubmit: function (e) { 27 e.preventDefault(); 28 29 var form = $(this), 30 submitButton = form.find('input[type=submit]'), 31 form_data = weFormsFrontReport.weFormsValidateForm(form); 32 33 if (form_data) { 34 35 // send the request 36 form.find('li.wpuf-submit').append('<span class="wpuf-loading"></span>'); 37 submitButton.attr('disabled', 'disabled').addClass('button-primary-disabled'); 38 39 $.post( wpuf_frontend.ajaxurl, form_data, function ( res ) { 40 e.preventDefault(); 41 // var res = $.parseJSON(res); 42 43 if ( res.show_chart === true ) { 44 45 form.find('ul').remove(); 46 form.before('<div class="wpuf-success">' + res.message + '</div>'); 47 form.addClass('weforms-chart-container'); 48 $('.weforms-chart-container').css({ 49 "width": "350px", 50 "height": "auto", 51 }); 52 53 this.report_data_parsed = JSON.parse(res.report_data); 54 var id_num = 1; 55 56 for (var index = 0; index < this.report_data_parsed.length; index++) { 57 var ex_template = this.report_data_parsed[index].template; 58 59 if (ex_template === 'file_upload' || ex_template === 'image_upload' || ex_template === 'address_field' || 60 ex_template === 'repeat_field' || ex_template === 'google_map' || ex_template === 'step_start' || 61 ex_template === 'shortcode' || ex_template === 'action_hook' || ex_template === 'toc' || 62 ex_template === 'custom_hidden_field' || ex_template === 'image_upload' || ex_template === 'section_break' || 63 ex_template === 'custom_html' || ex_template === 'recaptcha') { 64 continue; 65 } 66 67 var chart_data = this.report_data_parsed[index]; 68 var chart_title = chart_data.field_label; 69 var data_set = []; 70 var chart_dataset = [ 71 { 72 label: chart_data.field_label, 73 backgroundColor: chart_data.bg_color, 74 data: chart_data.data, 75 } 76 ]; 77 var tooltip_var = { 78 callbacks: { 79 title: function() { 80 return ''; 81 }, 82 label: function(item,data) { 83 return item.xLabel + ': ' + item.yLabel; 84 } 85 } 86 }; 87 88 if (chart_data.template === 'checkbox_grid' || chart_data.template === 'multiple_choice_grid') { 89 var count = 0; 90 for (var idx in chart_data.data) { 91 var new_data = chart_data.data[idx]; 92 if (!Array.isArray(new_data)) { 93 new_data = [new_data]; 94 } 95 data_set.push({ 96 label: idx, 97 backgroundColor: chart_data.bg_color[count++], 98 data: new_data, 99 }); 100 } 101 chart_dataset = data_set; 102 tooltip_var = {}; 103 } 104 105 id_name = 'weforms-chart-' + chart_data.template + id_num; 106 form.append('<div class="' + id_name + '" style="width: 100%; height: auto">
106<canvas id="' + id_name + '" width="100" height="100"></canvas></div>'); 107 108 new Chart(document.getElementById(id_name), { 109 responsive: true, 110 type: 'bar', 111 data: { 112 labels: chart_data.label, 113 datasets: chart_dataset 114 }, 115 options: { 116 legend: { 117 display: true, 118 position: 'top', 119 labels: { 120 fontColor: '#333' 121 } 122 }, 123 title: { 124 display: true, 125 text: chart_title 126 }, 127 scales: { 128 yAxes: [{ 129 ticks: { 130 min: 0, 131 beginAtZero: true, 132 stepSize: 1, 133 } 134 }] 135 }, 136 tooltips: tooltip_var, 137 } 138 }); 139 id_num = id_num + 1; 140 } 141 } else { 142 form.before( '<div class="wpuf-success">' + res.message + '</div>'); 143 form.slideUp( 'fast', function() { 144 form.remove(); 145 }); 146 } 147 148 submitButton.removeClass('button-primary-disabled'); 149 form.find('span.wpuf-loading').remove(); 150 }); 151 } 152 }, 153 154 weFormsValidateForm: function (self) { 155 156 var temp, 157 temp_val = '', 158 error = false, 159 error_items = []; 160 error_type = ''; 161 162 // ===== Validate: Text and Textarea ======== 163 var required = self.find('[data-required="yes"]:visible'); 164 165 required.each(function (i, item) { 166 // temp_val = $.trim($(item).val()); 167 168 // console.log( $(item).data('type') ); 169 var data_type = $(item).data('type'); 170 val = ''; 171 172 switch (data_type) { 173 case 'rich': 174 var name = $(item).data('id'); 175 val = $.trim(tinyMCE.get(name).getContent()); 176 177 if (val === '') { 178 error = true; 179 180 // make it warn collor 181 weFormsFrontReport.weFormsFrontMarkError(item); 182 } 183 break; 184 185 case 'textarea': 186 case 'text': 187 188 val = $.trim($(item).val()); 189 190 if (val === '') { 191 error = true; 192 error_type = 'required'; 193 194 // make it warn collor 195 weFormsFrontReport.weFormsFrontMarkError(item, error_type); 196 } 197 break; 198 199 case 'password': 200 case 'confirm_password': 201 var hasRepeat = $(item).data('repeat'); 202 203 val = $.trim($(item).val()); 204 205 if (val === '') { 206 error = true; 207 error_type = 'required'; 208 209 // make it warn collor 210 weFormsFrontReport.weFormsFrontMarkError(item, error_type); 211 } 212 213 if (hasRepeat) { 214 var repeatItem = $('[data-type="confirm_password"]').eq(0); 215 216 if (repeatItem.val() !== val) { 217 error = true; 218 error_type = 'mismatch'; 219 220 weFormsFrontReport.weFormsFrontMarkError(repeatItem, error_type); 221 } 222 } 223 224 break; 225 226 case 'select': 227 val = $(item).val(); 228 229 // console.log(val); 230 if (!val || val === '-1') { 231 error = true; 232 error_type = 'required'; 233 234 // make it warn collor 235 weFormsFrontReport.weFormsFrontMarkError(item, error_type); 236 } 237 break; 238 239 case 'multiselect': 240 val = $(item).val(); 241 242 if (val === null || val.length === 0) { 243 error = true; 244 error_type = 'required'; 245 246 // make it warn collor 247 weFormsFrontReport.weFormsFrontMarkError(item, error_type); 248 } 249 break; 250 251 case 'tax-checkbox': 252 var length = $(item).children().find('input
252:checked').length; 253 254 if (!length) { 255 error = true; 256 error_type = 'required'; 257 258 // make it warn collor 259 weFormsFrontReport.weFormsFrontMarkError(item, error_type); 260 } 261 break; 262 263 case 'radio': 264 var length = $(item).find('input:checked').length; 265 266 if (!length) { 267 error = true; 268 error_type = 'required'; 269 270 // make it warn collor 271 weFormsFrontReport.weFormsFrontMarkError(item, error_type); 272 } 273 break; 274 275 case 'file': 276 var length = $(item).find('ul').children().length; 277 278 if (!length) { 279 error = true; 280 error_type = 'required'; 281 282 // make it warn collor 283 weFormsFrontReport.weFormsFrontMarkError(item, error_type); 284 } 285 break; 286 287 case 'email': 288 var val = $(item).val(); 289 290 if (val !== '') { 291 //run the validation 292 if (!weFormsFrontReport.isValidEmail(val)) { 293 error = true; 294 error_type = 'validation'; 295 296 weFormsFrontReport.weFormsFrontMarkError(item, error_type); 297 } 298 } else if (val === '') { 299 error = true; 300 error_type = 'required'; 301 302 weFormsFrontReport.weFormsFrontMarkError(item, error_type); 303 } 304 break; 305 306 307 case 'url': 308 var val = $(item).val(); 309 310 if (val !== '') { 311 //run the validation 312 if (!weFormsFrontReport.isValidURL(val)) { 313 error = true; 314 error_type = 'validation'; 315 316 weFormsFrontReport.weFormsFrontMarkError(item, error_type); 317 } 318 } 319 break; 320 } 321 322 }); 323 324 // if already some error found, bail out 325 if (error) { 326 // add error notice 327 weFormsFrontReport.addErrorNotice(self, 'end'); 328 329 return false; 330 } 331 332 var form_data = self.serialize(), 333 rich_texts = []; 334 335 // grab rich texts from tinyMCE 336 $('.wpuf-rich-validation', self).each(function (index, item) { 337 var item = $(item); 338 var editor_id = item.data('id'); 339 var item_name = item.data('name'); 340 var val = $.trim(tinyMCE.get(editor_id).getContent()); 341 342 rich_texts.push(item_name + '=' + encodeURIComponent(val)); 343 }); 344 345 // append them to the form var 346 form_data = form_data + '&' + rich_texts.join('&'); 347 return form_data; 348 }, 349 350 weFormsFrontMarkError: function(item, error_type) { 351 352 var error_string = ''; 353 $(item).closest('li').addClass('has-error'); 354 355 if ( error_type ) { 356 error_string = $(item).closest('li').data('label'); 357 switch ( error_type ) { 358 case 'required' : 359 error_string = error_string + ' ' + error_str_obj[error_type]; 360 break; 361 case 'mismatch' : 362 error_string = error_string + ' ' +error_str_obj[error_type]; 363 break; 364 case 'validation' : 365 error_string = error_string + ' ' + error_str_obj[error_type]; 366 break; 367 } 368 $(item).siblings('.wpuf-error-msg').remove(); 369 $(item).after('<div class="wpuf-error-msg">'+ error_string +'</div>'); 370 } 371 372 $(item).focus(); 373 }, 374 375 isValidEmail: function( email ) { 376 var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i); 377 return pattern.test(email); 378 }, 379 380 isValidURL: function(url) { 381 var urlregex = new RegExp("^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|http:\/\/|https:\/\/){1}([0-9A-Za-z]+\.)"); 382 return urlregex.test(url); 383 }, 384 385 }; 386 387 weFormsFrontReport.init(); 388});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.