1if (typeof RSFormPro === 'undefined') { 2 RSFormPro = {}; 3} 4 5RSFormPro.AdvancedFormFields = { 6 elements: [], 7 datepickers: {}, 8 initiate: function () { 9 var $formplate = jQuery('.formplate'); 10 11 if ($formplate.length) { 12 jQuery('body').formplate(); 13 } 14 jQuery.each(RSFormPro.AdvancedFormFields.elements, function () { 15 var $self = jQuery(document.getElementById(this)); 16 var type = $self.data('rsfp-type'); 17 var options; 18 var that = this; 19 20 switch (type) { 21 case 'datepicker': 22 // init the options with the submit format (used only in the picker javascript) and unfocus the field when the picker is closed 23 var picker_options = { 24 formatSubmit: 'yyyy/mm/dd', 25 hiddenPrefix: 'rsignore_', 26 onClose: function(){ 27 jQuery('#' + $self.attr('id') + '_container').hide(); 28 }, 29 onOpen: function(){ 30 jQuery('#' + $self.attr('id') + '_container').show(); 31 } 32 }; 33 var picker_exception = []; 34 35 var years_range = $self.data('rsfp-select-years-range'); 36 37 jQuery.each($self.data(), function(index, value){ 38 if (index.indexOf('rsfp') > -1 && index != 'rsfpType' && index != 'rsfpOffset') { 39 // remove the prefix 40 var new_index = index.replace('rsfp', ''); 41 42 // first letter should be lower case 43 new_index = new_index.charAt(0).toLowerCase() + new_index.slice(1); 44 45 // if there is no value make it false 46 if (value.length == 0) { 47 value = false; 48 } 49 // some exceptions 50 var skip = value === false; 51 switch(new_index) { 52 case 'min': 53 case 'max': 54 if (value) { 55 value = RSFormPro.AdvancedFormFields.getDateArray(value); 56 } 57 break; 58 case 'disableall': 59 if (value) { 60 new_index = 'disable'; 61 value = [true] 62 } 63 break; 64 case 'selectMonths': 65 case 'selectYears': 66 value = value == 1; 67 if (value && typeof years_range !== 'undefined') 68 { 69 value = years_range; 70 } 71 break; 72 73 case 'daysdisabled': 74 // the value must always be string 75 value = value.toString(); 76 77 var days = value.split(','); 78 var new_values = []; 79 jQuery.each(days, function(i, val) { 80 val = val.trim(); 81 val = parseInt(val); 82 if (new_values.indexOf(val) < 0 && val != 0) { 83 new_values.push(val); 84 } 85 }); 86 87 if (new_values.length > 0) { 88 value = new_values; 89 new_index = 'disable'; 90 } 91 break; 92 93 case 'exceptions': 94 // the value must always be string 95 value = value.toString(); 96 97 var value_data = value.split(','); 98 99 jQuery.each(value_data, function(i, val) { 100 if (!isNaN(val)) { 101 val = parseInt(val); 102 103 if (picker_exception.indexOf(val) < 0 && val != 0) { 104 picker_exception.push(val); 105 } 106 107 } else { 108 if (val.indexOf('|') > -1) { 109 var dates = val.split('|'); 110 picker_exception.push({from:RSFormPro.AdvancedFormFields.getDateArray(dates[0]), to:RSFormPro.AdvancedFormFields.getDateArray(dates[1])}); 111 } else { 112 picker_exception.push(RSFormPro.AdvancedFormFields.getDateArray(val)); 113 } 114 } 115 }); 116 117 // will skip this because we will process these exceptions later 118 skip = true; 119 break; 120 121 case 'next': 122 new_index = 'onSet'; 123 var other_calendar_id = value; 124 var offset = typeof $self.data('rsfp-offset') === 'undefined' ? 0 : $self.data('rsfp-offset'); 125 126 value = function(context) { 127 // set this only when a selection is made (set in this case) 128 if (typeof context.select !== 'undefined') { 129 RSFormPro.AdvancedFormFields.setMin(other_calendar_id, context, offset); 130 } 131 }; 132 break; 133 134 case 'previous': 135 new_index = 'onSet'; 136 var other_calendar_id = value; 137 var offset = typeof $self.data('rsfp-offset') === 'undefined' ? 0 : $self.data('rsfp-offset'); 138 139 value = function(context) { 140 // set this only when a selection is made (set in this case) 141 if (typeof context.select !== 'undefined') { 142 RSFormPro.AdvancedFormFields.setMax(other_calendar_id, context, offset); 143 } 144 }; 145 146 break; 147 } 148 149 if (!skip) { 150 picker_options[new_index] = value; 151 } 152 } 153 });
154 155 // handle the found exceptions 156 if (picker_exception.length && typeof picker_options.disable !== 'undefined') { 157 158 // if daysdisabled is used we must remove integers and use the inverted parameter 159 if (picker_options.disable[0] !== true) { 160 var allowweekdays = []; 161 var allowdates = []; 162 163 jQuery.each(picker_exception, function(index, value){ 164 if (typeof value === 'number') { 165 allowweekdays.push(value); 166 } else { 167 if (Array.isArray(value)){ 168 // add inverted 169 value.push('inverted'); 170 } else { 171 value.inverted = true; 172 } 173 // add to the dates array 174 allowdates.push(value); 175 } 176 }); 177 178 var diffweekdays = jQuery(picker_options.disable).not(allowweekdays).get(); 179 picker_options.disable = diffweekdays.concat(allowdates); 180 181 } else { 182 picker_options.disable = picker_options.disable.concat(picker_exception); 183 } 184 } 185 186 RSFormPro.AdvancedFormFields.datepickers[that] = $self.pickadate(picker_options); 187 188 $self[0].rsfpOnChange = function(func) { 189 $self.pickadate('picker').on('set', function() { 190 if (typeof func === 'function') { 191 func(); 192 } 193 }); 194 }; 195 196 $self[0].rsfpGetValue = function() { 197 var object = $self.pickadate('picker').get('select'); 198 199 if (object && object.hasOwnProperty('pick')) 200 { 201 return (object.pick / 1000).toString(); 202 } 203 204 return '0'; 205 }; 206 break; 207 208 case 'colorpicker': 209 $self.spectrum({ 210 allowEmpty: true, 211 chooseText: Joomla.JText._('RSFP_RSFA_COLOR_PICKER_CHOOSE'), 212 cancelText: Joomla.JText._('RSFP_RSFA_COLOR_PICKER_CANCEL'), 213 preferredFormat: 'hex', 214 showInput: $self.data('rsfp-showinput'), 215 change: function() { RSFormPro.triggerEvent(this, 'input'); } 216 }); 217 break; 218 219 case 'selectize': 220 options = { 221 searchField : 'text', 222 allowEmptyOption: true, 223 plugins: ['remove_button'] 224 }; 225 226 if (parseInt($self.data('rsfp-multiple')) === 1 && parseInt($self.data('rsfp-nritems')) > 0) { 227 options['maxItems'] = parseInt($self.data('rsfp-nritems')); 228 } 229 230 options['onChange'] = function(value) { 231 RSFormPro.triggerEvent($self[0], 'change'); 232 }; 233 234 $self.selectize(options); 235 break; 236 237 case 'advtextarea': 238 $self.fseditor({ 239 placeholder: $self.attr('placeholder'), 240 transition : 'fade', 241 overlay : true, 242 maxWidth : $self.data('rsfp-max-width'), 243 maxHeight : $self.data('rsfp-max-height') 244 }); 245 break; 246 247 case 'rating': 248 //set defaults 249 options = { 250 rating : $self.data('rsfp-rating'), 251 numStars : $self.data('rsfp-nrstars'), 252 starWidth : "40px", 253 normalFill: $self.data('rsfp-basecolor') 254 }; 255 256 options['maxValue'] = options['numStars']; 257 258 if ($self.data('rsfp-halfstar')) 259 { 260 options['halfStar'] = true; 261 } 262 else 263 { 264 options['fullStar'] = true; 265 } 266 267 if ($self.data('rsfp-ratingtype') === 'multicolor') 268 { 269 options['multiColor'] = { 270 "startColor": $self.data('rsfp-startcolor'), 271 "endColor" : $self.data('rsfp-endcolor') 272 }; 273 } 274 else 275 { 276 options['ratedFill'] = $self.data('rsfp-fillcolor'); 277 } 278 $self.rateYo(options); 279 $self.on('rateyo.set', function (e, data) { 280 var input = document.getElementById($self.attr('id') + '-value'); 281 input.value = data.rating; 282 RSFormPro.triggerEvent(input, 'change'); 283 }); 284 break; 285 286 case 'datedropper': 287 //set defaults 288 options = { 289 dropPrimaryColor : $self.data('rsfp-primary-color'), 290 dropTextColor : $self.data('rsfp-text-color'),
291 dropBackgroundColor: $self.data('rsfp-background-color'), 292 dropBorder : $self.data('rsfp-border'), 293 dropBorderRadius : $self.data('rsfp-border-radius'), 294 dropShadow : $self.data('rsfp-dropshadow'), 295 dropWidth : $self.data('rsfp-dropwidth'), 296 dropTextWidth : 500, 297 animate : true, 298 init_animation : $self.data('rsfp-init-animation'), 299 format : $self.data('rsfp-format'), 300 lang : $self.data('rsfp-lang'), 301 lock : $self.data('rsfp-lock'), 302 minYear : $self.data('rsfp-minyear'), 303 maxYear : !isNaN(parseInt($self.data('rsfp-maxyear'))) ? $self.data('rsfp-maxyear') : new Date().getFullYear(), 304 yearsRange : $self.data('rsfp-yearsrange') 305 }; 306 307 $self.dateDropper(options); 308 309 $self[0].rsfpGetValue = function() { 310 if ($self[0].getAttribute('data-rsfp-unixtimestamp')) 311 { 312 return $self[0].getAttribute('data-rsfp-unixtimestamp').toString(); 313 } 314 315 return '0'; 316 }; 317 break; 318 319 case 'timedropper': 320 //set defaults 321 options = { 322 primaryColor : $self.data('rsfp-primary-color'), 323 textColor : $self.data('rsfp-text-color'), 324 backgroundColor: $self.data('rsfp-background-color'), 325 borderColor : $self.data('rsfp-border-color'), 326 init_animation : $self.data('rsfp-init-animation'), 327 format : $self.data('rsfp-format'), 328 meridians : $self.data('rsfp-meridians'), 329 setCurrentTime : $self.data('rsfp-setcurrenttime') 330 }; 331 332 $self.timeDropper(options); 333 334 $self[0].rsfpGetValue = function() { 335 if ($self[0].getAttribute('data-rsfp-unixtimestamp')) 336 { 337 return $self[0].getAttribute('data-rsfp-unixtimestamp').toString(); 338 } 339 340 return '0'; 341 }; 342 break; 343 } 344 }); 345 346 // if calendar exists check if thy have date modifiers set (next and previous attributes) 347 RSFormPro.AdvancedFormFields.checkPickers(); 348 }, 349 350 setMin: function (other_calendar_id, selected_date, offset) { 351 if (typeof RSFormPro.AdvancedFormFields.datepickers[other_calendar_id] !== 'undefined') { 352 var other_calendar = RSFormPro.AdvancedFormFields.datepickers[other_calendar_id].pickadate('picker'); 353 354 // transform the offset in milliseconds 355 offset = 86400000 * offset; 356 var selectedDate = selected_date; 357 if (typeof selectedDate === 'object') 358 { 359 if (typeof selectedDate.select === 'object') 360 { 361 selectedDate = selectedDate.select.pick; 362 } 363 else if (typeof selectedDate.select === 'number') 364 { 365 selectedDate = selectedDate.select; 366 } 367 } 368 var min_seconds = selectedDate + offset; 369 370 // verify that the other calendar doesn't have a min date bigger than the result one 371 var other_calendar_min = RSFormPro.AdvancedFormFields.datepickers[other_calendar_id].data('rsfp-min'); 372 other_calendar_min = other_calendar_min.length == 0 ? false : new Date(other_calendar_min); 373 374 if (other_calendar_min) { 375 other_calendar_min = other_calendar_min.getTime(); 376 } 377 378 var ref_min = false; 379 var selected = other_calendar.get('select'); 380 if (!other_calendar_min || min_seconds >= other_calendar_min) { 381 other_calendar.set('min', new Date(min_seconds)); 382 ref_min = min_seconds; 383 } else if (other_calendar_min) { 384 other_calendar.set('min', new Date(other_calendar_min)); 385 ref_min = other_calendar_min; 386 } 387 388 if (ref_min && selected) { 389 if (new Date(ref_min).setHours(0) > new Date(selected.pick).setHours(0)) { 390 other_calendar.clear(); 391 } 392 } 393 } 394 }, 395 396 setMax: function (other_calendar_id, selected_date, offset) { 397 if (typeof RSFormPro.AdvancedFormFields.datepickers[other_calendar_id] !== 'undefined') { 398 var other_calendar = RSFormPro.AdvancedFormFields.datepickers[other_calendar_id].pickadate('picker'); 399 400 // transform the offset in milliseconds 401 offset = 86400000 * offset; 402 var selectedDate = selected_date; 403 if (typeof selectedDate === 'object') 404 { 405 if (typeof selectedDate.select === 'object') 406 { 407 selectedDate = selectedDate.select.pick; 408 } 409 else if (typeof selectedDate.select === 'number') 410 { 411 selectedDate = selectedDate.select; 412 } 413 } 414 var max_seconds = selectedDate + offset; 415 416 // verify that the other calendar doesn't have a max date smaller than the result one 417 var other_calendar_max = RSFormPro.AdvancedFormFields.datepickers[other_calendar_id].data('rsfp-max'); 418 other_calendar_max = other_calendar_max.length == 0 ? false : new Date(other_calendar_max); 419 420 if (other_calendar_max) { 421 other_calendar_max = other_calendar_max.getTime(); 422 } 423 424 var ref_max = false; 425 var selected = other_calendar.get('select');
426 if (!other_calendar_max || max_seconds <= other_calendar_max) { 427 other_calendar.set('max', new Date(max_seconds)); 428 ref_max = max_seconds; 429 } else if (other_calendar_max) { 430 other_calendar.set('max', new Date(other_calendar_max)); 431 ref_max = other_calendar_max; 432 } 433 434 if (ref_max && selected) { 435 if (new Date(ref_max).setHours(0) < new Date(selected.pick).setHours(0)) { 436 other_calendar.clear(); 437 } 438 } 439 } 440 }, 441 442 getDateArray: function(date) { 443 date = date.split('-'); 444 445 var year = parseInt(date[0]); 446 var month = parseInt(date[1]) - 1; 447 var day = parseInt(date[2]); 448 449 return [year, month, day]; 450 }, 451 452 limitSelections: function(formId, field, max) { 453 RSFormProUtils.addEvent(window, 'load', function() { 454 var fields = RSFormPro.getFieldsByName(formId, field); 455 var objects = []; 456 var i; 457 var tagName; 458 459 if (!fields || !fields.length) { 460 return; 461 } 462 463 for (i = 0; i < fields.length; i++) { 464 tagName = fields[i].tagName || fields[i].nodeName; 465 tagName = tagName.toUpperCase(); 466 467 if (tagName === 'INPUT' && fields[i].type && fields[i].type.toUpperCase() === 'CHECKBOX' && !fields[i].disabled) { 468 objects.push(fields[i]); 469 } 470 } 471 472 if (!objects.length) { 473 return; 474 } 475 476 function limitSelections() { 477 var values = RSFormProUtils.getChecked(objects); 478 479 // Remove disabled attribute 480 RSFormProUtils.remAttr(objects, 'disabled'); 481 482 // Remove disabled class 483 for (var j = 0; j < objects.length; j++) { 484 if (RSFormProUtils.hasClass(objects[j].parentNode, 'fp-checkbox')) { 485 RSFormProUtils.removeClass(objects[j].parentNode, 'disabled'); 486 } 487 } 488 489 if (values && values.length > 0 && values.length >= max) { 490 var unchecked = RSFormProUtils.getUnchecked(objects); 491 RSFormProUtils.setAttr(unchecked, 'disabled', true); 492 493 // Add disabled class 494 for (var k = 0; k < unchecked.length; k++) { 495 if (RSFormProUtils.hasClass(unchecked[k].parentNode, 'fp-checkbox')) { 496 RSFormProUtils.addClass(unchecked[k].parentNode, 'disabled'); 497 } 498 } 499 } 500 } 501 502 for (i = 0; i < objects.length; i++) { 503 RSFormProUtils.addEvent(objects[i], 'change', limitSelections); 504 } 505 506 limitSelections(); 507 }); 508 }, 509 isChecked: function(formId, name, value) { 510 var form = RSFormPro.getForm(formId); 511 var i, element, tagName; 512 513 if (typeof form != 'undefined') 514 { 515 for (i = 0; i < form.elements.length; i++) 516 { 517 element = form.elements[i]; 518 tagName = element.tagName || element.nodeName; 519 tagName = tagName.toUpperCase(); 520 521 if (tagName === 'INPUT' && RSFormProUtils.hasClass(element, 'rsform-switcher-box')) 522 { 523 if (!element.name || element.name !== 'form[' + name + '][]') 524 { 525 continue; 526 } 527 if ((value === '1' && element.checked) || (value === '0' && !element.checked)) 528 { 529 return true; 530 } 531 else 532 { 533 return false; 534 } 535 } 536 } 537 } 538 539 return RSFormPro.AdvancedFormFields.isCheckedBackup(formId, name, value); 540 }, 541 542 checkPickers: function() { 543 jQuery.each(RSFormPro.AdvancedFormFields.datepickers,function(calendar_id){ 544 // detect if the calendar has a data value 545 var current_calendar = jQuery('#'+calendar_id); 546 // use the data value, as this one is the standard format 547 var current_date = current_calendar.data('value'); 548 549 if (typeof current_date !== 'undefined') { 550 // convert the current_date in milliseconds 551 current_date = new Date(current_date); 552 current_date = current_date.getTime(); 553 554 var offset = typeof current_calendar.data('rsfp-offset') === 'undefined' ? 0 :current_calendar.data('rsfp-offset'); 555 556 var other_calendar_id_next = current_calendar.data('rsfp-next'); 557 var other_calendar_id_previous = current_calendar.data('rsfp-previous'); 558 559 // check if the calendar has a next defined 560 if (typeof other_calendar_id_next !== 'undefined') {
561 RSFormPro.AdvancedFormFields.setMin(other_calendar_id_next, current_date, offset); 562 } 563 564 // check if the calendar has a previous defined 565 if (typeof other_calendar_id_previous !== 'undefined') { 566 RSFormPro.AdvancedFormFields.setMax(other_calendar_id_previous, current_date, offset); 567 } 568 } 569 }); 570 } 571}; 572 573if ( typeof jQuery !== 'undefined' ){ 574 RSFormProUtils.addEvent(window, 'load', RSFormPro.AdvancedFormFields.initiate); 575}
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.