1/** 2 * JS utilities 3 * 4 * @package ThemeREX Addons 5 * @since v1.0 6 */ 7 8/* global jQuery, TRX_ADDONS_STORAGE */ 9 10(function() { 11 "use strict"; 12 13 var $window = jQuery( window ), 14 $document = jQuery( document ), 15 $html_dom = document.querySelector('html'), 16 $adminbar = jQuery( '#wpadminbar' ), 17 $body = jQuery( 'body' ); 18 19 20 /* Dev shorthands 21 ---------------------------------------------------------------- */ 22 23 window.dcl === undefined && ( window.dcl = function(s) { console.log(s); } ); 24 window.dcs === undefined && ( window.dcs = function() { console.trace(); } ); 25 window.dcts === undefined && ( window.dcts = function( name ) { console.time( name ? name : 'timer' ); } ); 26 window.dctl === undefined && ( window.dctl = function( name ) { console.timeLog( name ? name : 'timer' ); } ); 27 window.dcte === undefined && ( window.dcte = function( name ) { console.timeEnd( name ? name : 'timer' ); } ); 28 29 30 /* Cookies manipulations 31 ---------------------------------------------------------------- */ 32 33 window.trx_addons_get_cookie = function(name) { 34 var defa = arguments[1] !== undefined ? arguments[1] : null; 35 var start = document.cookie.indexOf(name + '='); 36 var len = start + name.length + 1; 37 if ((!start) && (name != document.cookie.substring(0, name.length))) { 38 return defa; 39 } 40 if (start == -1) { 41 return defa; 42 } 43 var end = document.cookie.indexOf(';', len); 44 if (end == -1) { 45 end = document.cookie.length; 46 } 47 return decodeURIComponent(document.cookie.substring(len, end)); 48 }; 49 50 51 window.trx_addons_set_cookie = function(name, value) { 52 var expires = arguments[2] !== undefined ? arguments[2] : 0; // In ms ( sec * 1000 ). If 0 (by default) - store the value for the current session only 53 var path = arguments[3] !== undefined ? arguments[3] : '/'; 54 var domain = arguments[4] !== undefined ? arguments[4] : ''; 55 var secure = arguments[5] !== undefined ? arguments[5] : ''; 56 var samesite = arguments[6] !== undefined ? arguments[6] : 'strict'; // strict | lax | none 57 var today = new Date(); 58 today.setTime(today.getTime()); 59 var expires_date = new Date(today.getTime() + (expires * 1)); 60 document.cookie = encodeURIComponent(name) + '=' 61 + encodeURIComponent(value) 62 + (expires ? ';expires=' + expires_date.toGMTString() : '') 63 + (path ? ';path=' + path : '') 64 + (domain ? ';domain=' + domain : '') 65 + (secure ? ';secure' : '') 66 + (samesite ? ';samesite=' + samesite : ''); 67 }; 68 69 70 window.trx_addons_del_cookie = function(name) { 71 var path = arguments[1] !== undefined ? arguments[1] : '/'; 72 var domain = arguments[2] !== undefined ? arguments[2] : ''; 73 var secure = arguments[3] !== undefined ? arguments[3] : ''; 74 var samesite = arguments[4] !== undefined ? arguments[4] : 'strict'; // strict | lax | none 75 if ( trx_addons_get_cookie(name) ) { 76 document.cookie = encodeURIComponent(name) + '=' 77 + ';expires=Thu, 01-Jan-1970 00:00:01 GMT' 78 + (path ? ';path=' + path : '') 79 + (domain ? ';domain=' + domain : '') 80 + (secure ? ';secure' : '') 81 + (samesite ? ';samesite=' + samesite : ''); 82 } 83 }; 84 85 86 /* Local storage manipulations 87 ---------------------------------------------------------------- */ 88 89 window.trx_addons_is_local_storage_exists = function() { 90 try { 91 return 'localStorage' in window && window['localStorage'] !== null; 92 } catch (e) { 93 return false; 94 } 95 }; 96 97 window.trx_addons_get_storage = function(name) { 98 var defa = arguments[1] !== undefined ? arguments[1] : null; 99 var val = null; 100 if (trx_addons_is_local_storage_exists()) { 101 val = window['localStorage'].getItem(name); 102 if (val === null) val = defa; 103 } else { 104 val = trx_addons_get_cookie(name, defa); 105 } 106 return val; 107 }; 108 109 window.trx_addons_set_storage = function(name, value) { 110 if (trx_addons_is_local_storage_exists()) 111 window['localStorage'].setItem(name, value); 112 else 113 trx_addons_set_cookie(name, value, 365 * 24 * 60 * 60 * 1000); // 1 year 114 }; 115 116 window.trx_addons_del_storage = function(name) { 117 if (trx_addons_is_local_storage_exists()) 118 window['localStorage'].removeItem(name); 119 else 120 trx_addons_del_cookie(name); 121 }; 122 123 window.trx_addons_clear_storage = function() { 124 if (trx_addons_is_local_storage_exists()) 125 window['localStorage'].clear(); 126 }; 127 128 129 130 /* Clipboard manipulations 131 ---------------------------------------------------------------- */ 132 133 window.trx_addons_copy_to_clipboard = function(str, strip_tags) { 134 var selected = document.getSelection().rangeCount > 0 // Check if there is any content selected previously 135 ? document.getSelection().getRangeAt(0) // Store selection if found 136 : false; // Mark as false to know no selection existed before 137 if ( typeof str == 'object' && str.length ) { 138 str = str.is( 'textarea' ) ? str.val() : str.html(); 139 } 140 if ( strip_tags ) { 141 str = str.replace(/<[^>]+>/g, ''); 142 } 143 var el = document.createElement('textarea'); // Create a <textarea> element 144 el.value = str; // Set its value to the string that you want copied 145 el.setAttribute('readonly', ''); // Make it readonly to be tamper-proof
146 el.style.position = 'absolute'; // Move outside the screen to make it invisible 147 el.style.left = '-9999px'; 148 document.body.appendChild(el); // Append the <textarea> element to the HTML document 149 el.select(); // Select the <textarea> content 150 document.execCommand('copy'); // Copy - only works as a result of a user action (e.g. click events) 151 document.body.removeChild(el); // Remove the <textarea> element 152 if (selected) { // If a selection existed before copying 153 document.getSelection().removeAllRanges(); // Unselect everything on the HTML document 154 document.getSelection().addRange(selected); // Restore the original selection 155 } 156 }; 157 158 159 160 /* ListBox and ComboBox manipulations 161 ---------------------------------------------------------------- */ 162 163 window.trx_addons_clear_listbox = function(box) { 164 for (var i=box.options.length-1; i >= 0; i--) 165 box.options[i] = null; 166 }; 167 168 window.trx_addons_add_listbox_item = function(box, val, text) { 169 var item = new Option(); 170 item.value = val; 171 item.text = text; 172 box.options.add(item); 173 }; 174 175 window.trx_addons_del_listbox_item_by_value = function(box, val) { 176 for (var i=0; i < box.options.length; i++) { 177 if (box.options[i].value == val) { 178 box.options[i] = null; 179 break; 180 } 181 } 182 }; 183 184 window.trx_addons_del_listbox_item_by_text = function(box, txt) { 185 for (var i=0; i < box.options.length; i++) { 186 if (box.options[i].text == txt) { 187 box.options[i] = null; 188 break; 189 } 190 } 191 }; 192 193 window.trx_addons_find_listbox_item_by_value = function(box, val) { 194 var idx = -1; 195 for (var i=0; i < box.options.length; i++) { 196 if (box.options[i].value == val) { 197 idx = i; 198 break; 199 } 200 } 201 return idx; 202 }; 203 204 window.trx_addons_find_listbox_item_by_text = function(box, txt) { 205 var idx = -1; 206 for (var i=0; i < box.options.length; i++) { 207 if (box.options[i].text == txt) { 208 idx = i; 209 break; 210 } 211 } 212 return idx; 213 }; 214 215 window.trx_addons_select_listbox_item_by_value = function(box, val) { 216 for (var i = 0; i < box.options.length; i++) { 217 box.options[i].selected = (val == box.options[i].value); 218 } 219 }; 220 221 window.trx_addons_select_listbox_item_by_text = function(box, txt) { 222 for (var i = 0; i < box.options.length; i++) { 223 box.options[i].selected = (txt == box.options[i].text); 224 } 225 }; 226 227 window.trx_addons_get_listbox_values = function(box) { 228 var delim = arguments[1] ? arguments[1] : ','; 229 var str = ''; 230 for (var i=0; i < box.options.length; i++) { 231 str += (str ? delim : '') + box.options[i].value; 232 } 233 return str; 234 }; 235 236 window.trx_addons_get_listbox_texts = function(box) { 237 var delim = arguments[1] ? arguments[1] : ','; 238 var str = ''; 239 for (var i=0; i < box.options.length; i++) { 240 str += (str ? delim : '') + box.options[i].text; 241 } 242 return str; 243 }; 244 245 window.trx_addons_sort_listbox = function(box) { 246 var temp_opts = new Array(); 247 var temp = new Option(); 248 for(var i=0; i<box.options.length; i++) { 249 temp_opts[i] = box.options[i].clone(); 250 } 251 for(var x=0; x<temp_opts.length-1; x++) { 252 for(var y=(x+1); y<temp_opts.length; y++) { 253 if (temp_opts[x].text > temp_opts[y].text) { 254 temp = temp_opts[x]; 255 temp_opts[x] = temp_opts[y]; 256 temp_opts[y] = temp; 257 } 258 } 259 } 260 for(i=0; i<box.options.length; i++) { 261 box.options[i] = temp_opts[i].clone(); 262 } 263 }; 264 265 window.trx_addons_get_listbox_selected_index = function(box) { 266 for (var i = 0; i < box.options.length; i++) { 267 if (box.options[i].selected) { 268 return i; 269 } 270 } 271 return -1; 272 }; 273 274 window.trx_addons_get_listbox_selected_value = function(box) { 275 for (var i = 0; i < box.options.length; i++) { 276 if (box.options[i].selected) { 277 return box.options[i].value; 278 } 279 } 280 return null; 281 }; 282 283 window.trx_addons_get_listbox_selected_text = function(box) { 284 for (var i = 0; i < box.options.length; i++) { 285 if (box.options[i].selected) { 286 return box.options[i].text; 287 } 288 } 289 return null; 290 }; 291 292 window.trx_addons_get_listbox_selected_option = function(box) { 293 for (var i = 0; i < box.options.length; i++) { 294 if (box.options[i].selected) { 295 return box.options[i]; 296 } 297 } 298 return null; 299 }; 300 301 302 303 /* Radio buttons manipulations 304 ---------------------------------------------------------------- */ 305 306 window.trx_addons_get_radio_value = function(radioGroupObj) { 307 for (var i=0; i < radioGroupObj.length; i++) { 308 if (radioGroupObj[i].checked) { 309 return radioGroupObj[i].value; 310 } 311 } 312 return null; 313 }; 314 315 window.trx_addons_set_radio_checked_by_num = function(radioGroupObj, num) { 316 for (var i=0; i < radioGroupObj.length; i++) { 317 if (radioGroupObj[i].checked && i!=num) { 318 radioGroupObj[i].checked=false; 319 } else if (i==num) { 320 radioGroupObj[i].checked=true; 321 } 322 } 323 }; 324 325 window.trx_addons_set_radio_checked_by_value = function(radioGroupObj, val) { 326 for (var i=0; i < radioGroupObj.length; i++) { 327 if (radioGroupObj[i].checked && radioGroupObj[i].value!=val) { 328 radioGroupObj[i].checked=false; 329 } else if (radioGroupObj[i].value==val) { 330 radioGroupObj[i].checked=true; 331 } 332 } 333 }; 334 335 336 337 /* Form validation 338 ---------------------------------------------------------------- */ 339 340 /* 341 // Usage example: 342 var error = trx_addons_form_validate(jQuery(form_selector), { // -------- Options --------- 343 error_message_show: true, // Display or not error message 344 error_message_time: 5000, // Time to display error message 345 success_message_class: 'trx_addons_message_box_success', // Should be removed from the error message block 346 error_message_class: 'trx_addons_message_box_error', // Class, appended to error message block 347 error_message_text: 'Global error text', // Global error message text (if not specify message in the checked field) 348 error_fields_class: 'trx_addons_field_error', // Class, appended to error fields 349 exit_after_first_error: false, // Cancel validation and exit after first error 350 rules: [ 351 { 352 field: 'author', // Checking field name 353 min_length: { value: 1, message: 'The author name can\'t be empty' }, // Min character count (0 - don't check), message - if error occurs 354 max_length: { value: 60, message: 'Too long author name'} // Max character count (0 - don't check), message - if error occurs 355 }, 356 { 357 field: 'email', 358 min_length: { value: 7, message: 'Too short (or empty) email address' }, 359 max_length: { value: 60, message: 'Too long email address'}, 360 mask: { value: '^([a-zA-Z0-9_\\-]+\\.)*[a-zA-Z0-9_\\-]+@[a-zA-Z0-9_\\-]+(\\.[a-zA-Z0-9_\\-]+)*\\.[a-zA-Z0-9]{2,6}$', message: 'Invalid email address'} 361 }, 362 { 363 field: 'comment', 364 min_length: { value: 1, message: 'The comment text can\'t be empty' }, 365 max_length: { value: 200, message: 'Too long comment'} 366 }, 367 { 368 field: 'pwd1', 369 min_length: { value: 5, message: 'The password can\'t be less then 5 characters' }, 370 max_length: { value: 20, message: 'Too long password'} 371 }, 372 { 373 field: 'pwd2', 374 equal_to: { value: 'pwd1', message: 'The passwords in both fields must be equals' } 375 } 376 ] 377 }); 378 */ 379 380 window.trx_addons_form_validate = function(form, opt) { 381 // Default options 382 if (typeof(opt.error_message_show)=='undefined') opt.error_message_show = true; 383 if (typeof(opt.error_message_time)=='undefined') opt.error_message_time = 5000; 384 if (typeof(opt.error_message_class)=='undefined') opt.error_message_class = 'trx_addons_message_box_error'; 385 if (typeof(opt.success_message_class)=='undefined') opt.success_message_class = 'trx_addons_message_box_success'; 386 if (typeof(opt.error_message_text)=='undefined') opt.error_message_text = 'Incorrect data in the fields!'; 387 if (typeof(opt.error_fields_class)=='undefined') opt.error_fields_class = 'trx_addons_field_error'; 388 if (typeof(opt.exit_after_first_error)=='undefined') opt.exit_after_first_error = false;
389 // Validate fields 390 var error_msg = ''; 391 form.find(":input").each(function() { 392 if (error_msg !== '' && opt.exit_after_first_error) return; 393 for (var i = 0; i < opt.rules.length; i++) { 394 if (jQuery(this).attr("name") == opt.rules[i].field) { 395 var val = jQuery(this).val(); 396 var error = false; 397 if (typeof(opt.rules[i].min_length) == 'object') { 398 if (opt.rules[i].min_length.value > 0 && val.length < opt.rules[i].min_length.value) { 399 if (error_msg === '') jQuery(this).get(0).focus(); 400 error_msg += '<p class="trx_addons_error_item">' + (typeof(opt.rules[i].min_length.message)!='undefined' ? opt.rules[i].min_length.message : opt.error_message_text ) + '</p>'; 401 error = true; 402 } 403 } 404 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].max_length) == 'object') { 405 if (opt.rules[i].max_length.value > 0 && val.length > opt.rules[i].max_length.value) { 406 if (error_msg === '') jQuery(this).get(0).focus(); 407 error_msg += '<p class="trx_addons_error_item">' + (typeof(opt.rules[i].max_length.message)!='undefined' ? opt.rules[i].max_length.message : opt.error_message_text ) + '</p>'; 408 error = true; 409 } 410 } 411 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].mask) == 'object') { 412 if (opt.rules[i].mask.value !== '') { 413 var regexp = new RegExp(opt.rules[i].mask.value); 414 if (!regexp.test(val)) { 415 if (error_msg === '') jQuery(this).get(0).focus(); 416 error_msg += '<p class="trx_addons_error_item">' + (typeof(opt.rules[i].mask.message)!='undefined' ? opt.rules[i].mask.message : opt.error_message_text ) + '</p>'; 417 error = true; 418 } 419 } 420 } 421 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].state) == 'object') { 422 if (opt.rules[i].state.value=='checked' && !jQuery(this).get(0).checked) { 423 if (error_msg === '') jQuery(this).get(0).focus(); 424 error_msg += '<p class="trx_addons_error_item">' + (typeof(opt.rules[i].state.message)!='undefined' ? opt.rules[i].state.message : opt.error_message_text ) + '</p>'; 425 error = true; 426 } 427 } 428 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].equal_to) == 'object') { 429 if (opt.rules[i].equal_to.value !== '' && val!=jQuery(jQuery(this).get(0).form[opt.rules[i].equal_to.value]).val()) { 430 if (error_msg === '') jQuery(this).get(0).focus(); 431 error_msg += '<p class="trx_addons_error_item">' + (typeof(opt.rules[i].equal_to.message)!='undefined' ? opt.rules[i].equal_to.message : opt.error_message_text ) + '</p>'; 432 error = true; 433 } 434 } 435 if (opt.error_fields_class !== '') jQuery(this).toggleClass(opt.error_fields_class, error); 436 } 437 438 } 439 }); 440 if (error_msg !== '' && opt.error_message_show) { 441 var error_message_box = form.find(".trx_addons_message_box"); 442 if (error_message_box.length === 0) error_message_box = form.parent().find(".trx_addons_message_box"); 443 if (error_message_box.length === 0) { 444 form.append('<div class="trx_addons_message_box"></div>'); 445 error_message_box = form.find(".trx_addons_message_box"); 446 } else 447 error_message_box.removeClass(opt.success_message_class); 448 if (opt.error_message_class) error_message_box.addClass(opt.error_message_class); 449 error_message_box.html(error_msg).fadeIn(); 450 setTimeout(function() { error_message_box.fadeOut(); }, opt.error_message_time); 451 } 452 return error_msg !== ''; 453 }; 454 455 456 457 // Fill (refresh) list in specified field when parent fields is changed 458 // ------------------------------------------------------------------------------------- 459 460 // Compare two lists with objects 'key': 'value' for equal length and equal keys and values 461 function trx_addons_compare_lists( list1, list2 ) { 462 var result = list1.length == list2.length; 463 if ( result ) { 464 for ( var i in list1 ) { 465 if ( ! list2.hasOwnProperty(i) || list1[i] != list2[i] ) { 466 result = false;
467 break; 468 } 469 } 470 } 471 return result; 472 } 473 474 var _trx_addons_refresh_list_cache = {}; 475 window.trx_addons_refresh_list = function( parent_type, parent_val, list_fld, list_lbl, list_not_selected, elementor_obj ) { 476 477 // Need '- Select ... -' 478 if ( list_not_selected === undefined ) { 479 list_not_selected = list_fld.data('not-selected') === true // field has data-not-selected="true" 480 || list_fld.parents('.vc_edit-form-tab').length > 0 // or field in the VC shortcodes form 481 || list_fld.parents('#elementor-controls').length > 0 // or field in the Elementor shortcodes form 482 || list_fld.parents('[class*="widget_field_type_"]').length > 0 // or field in the new SOW form 483 || list_fld.parents('.widget-liquid-right').length > 0 // or field in the Widgets panel 484 || list_fld.parents('.widgets-holder-wrap').length > 0 // or field in the Widgets panel 485 || list_fld.parents('.customize-control-widget_form').length > 0; // or field in the Widget in the Customizer 486 } 487 488 var list_val = elementor_obj && list_fld.data( 'setting' ) 489 ? elementor_obj.model.getSetting( list_fld.data( 'setting' ) ) 490 : list_fld.val(); 491 list_val = ',' + list_val + ','; // Add ',' to the start and end of the string to simplify search 492 if ( list_lbl.find('.trx_addons_refresh').length === 0 ) { 493 list_lbl.append('<span class="trx_addons_refresh trx_addons_icon-spin3 animate-spin"></span>'); 494 } 495 496 if ( parent_val ) { 497 // Check cache 498 var cache_key = ( typeof parent_val == 'object' ? JSON.stringify( parent_val ) : parent_val ) + '_' + parent_type; 499 if ( _trx_addons_refresh_list_cache[cache_key] !== undefined ) { 500 trx_addons_refresh_field_items( _trx_addons_refresh_list_cache[cache_key] ); 501 } else { 502 // Get data from server 503 var data = { 504 action: 'trx_addons_refresh_list', 505 nonce: TRX_ADDONS_STORAGE['ajax_nonce'], 506 parent_type: parent_type, 507 parent_value: parent_val, 508 list_not_selected: list_not_selected, 509 is_admin_request: 1 510 }; 511 512 jQuery.post( TRX_ADDONS_STORAGE['ajax_url'], data, function( response ) { 513 var rez = trx_addons_parse_ajax_response( response ); 514 if ( rez.error === '' ) { 515 _trx_addons_refresh_list_cache[cache_key] = rez.data; 516 trx_addons_refresh_field_items( rez.data ); 517 } 518 } ); 519 } 520 } else { 521 var args = []; 522 if ( list_not_selected ) { 523 var list_type = list_fld.prop('tagName').toLowerCase(); 524 if ( list_type == 'select' ) { 525 var opt = list_fld.find( 'option' ).eq(0); 526 if ( opt.length > 0 ) { 527 args[0] = { 528 key: opt.val(), 529 value: opt.text() 530 }; 531 } 532 } 533 } 534 trx_addons_refresh_field_items( args ); 535 } 536 537 function trx_addons_refresh_field_items( data ) { 538 var list = {}; 539 var opt_list = ''; 540 var list_type = list_fld.prop('tagName').toLowerCase(); 541 var list_name = list_type == 'select' 542 ? ( list_fld.attr('name') ? list_fld.attr('name') : list_fld.data('setting') ) 543 : list_fld.data('field_name'); 544 if ( data.length === 0 ) { 545 data = [ { key: 0, value: '' } ]; 546 } 547 for ( var i in data ) { 548 if ( list_type != 'select' && data[i]['key'] == 0 ) { 549 continue; 550 } 551 list[ data[i]['key'] ] = data[i]['value']; 552 opt_list += list_type == 'select' 553 ? '<option class="'+data[i]['key']+'"' 554 + ' value="'+data[i]['key']+'"' 555 + ( list_val.indexOf( ',' + ( '' + data[i]['key'] ).trim() + ',' ) >= 0 || list_val.indexOf( ',' + ( '' + data[i]['key'] ).trim() + ' ,' ) >= 0 556 ? ' selected="selected"' 557 : '' 558 ) 559 + '>' 560 + data[i]['value'] 561 + '</option>' 562 : '<label><input type="checkbox"' 563 + ' value="' + data[i]['key'] + '"' 564 + ' name="' + list_name + '"' 565 + '>' 566 + data[i]['value'] 567 + '</label>'; 568 } 569 // Update a list of the options 570 list_fld.html( opt_list ); 571 if ( list_type == 'select' && list_fld.find('option:selected').length === 0 && list_fld.find('option').length > 0 ) { 572 list_fld.find('option').get(0).selected = true; 573 } 574 // Update an options list for the Elementor controls 575 var need_refresh = true; 576 if ( elementor_obj ) { 577 need_refresh = ! trx_addons_compare_lists( elementor_obj.view.container.controls[ list_name ].options, list ); 578 if ( need_refresh ) { 579 //elementor_obj.model.attributes.settings.controls[ list_name ].options = list; 580 elementor_obj.view.container.controls[ list_name ].options = list; 581 } 582 } 583 // Remove a loading spinner 584 list_lbl.find('span.trx_addons_refresh').remove(); 585 // Remove placeholder from the field 'cat' 586 if ( list_fld.data( 'select2' ) ) { 587 setTimeout( function() { 588 list_fld.parent().find('input.select2-search__field[placeholder]').removeAttr( 'placeholder' ); 589 }, 1 ); 590 } 591 // Trigger change event 592 if ( need_refresh ) { 593 list_fld.trigger('change'); 594 } else { 595 list_fld.trigger('change.trx_addons_refresh_list'); 596 } 597 } 598 return false;
599 }; 600 601 602 603 /* Document manipulations 604 ---------------------------------------------------------------- */ 605 606 // Detect window width, height and scroll 607 var _window_width = $window.width(), 608 _window_height = $window.height(), 609 _window_scroll_top = $window.scrollTop(), 610 _window_scroll_left = $window.scrollLeft(); 611 $window.on( 'resize', function() { 612 _window_width = $window.width(); 613 _window_height = $window.height(); 614 _window_scroll_top = $window.scrollTop(); 615 _window_scroll_left = $window.scrollLeft(); 616 } ); 617 $window.on( 'scroll', function() { 618 _window_scroll_top = $window.scrollTop(); 619 _window_scroll_left = $window.scrollLeft(); 620 } ); 621 window.trx_addons_window_width = function( val ) { 622 if ( val ) _window_width = val; 623 return _window_width; 624 }; 625 window.trx_addons_window_height = function( val ) { 626 if ( val ) _window_height = val; 627 return _window_height; 628 }; 629 window.trx_addons_window_scroll_top = function() { 630 return _window_scroll_top; 631 }; 632 window.trx_addons_window_scroll_left = function() { 633 return _window_scroll_left; 634 }; 635 636 // Detect document height 637 var _document_height; 638 var _document_height_first_run = true; 639 var _update_document_height = function( e ) { 640 if ( _document_height_first_run && e && e.namespace == 'init_hidden_elements' ) { 641 _document_height_first_run = false; 642 return; 643 } 644 _document_height = $document.height(); 645 }; 646 $document.ready( _update_document_height ); 647 $document.on( 'action.init_hidden_elements action.got_ajax_response', // Maybe need for ' action.sc_layouts_row_fixed_on action.sc_layouts_row_fixed_off' 648 _update_document_height 649 ); 650 $window.on( 'resize', _update_document_height ); 651 window.trx_addons_document_height = function() { 652 return _document_height; 653 }; 654 655 // Detect adminbar height (if present and fixed) 656 var _adminbar_height = 0; 657 var _update_adminbar_height = function() { 658 _adminbar_height = trx_addons_adminbar_height_calc(); 659 }; 660 $document.ready( _update_adminbar_height ); 661 $window.on( 'resize', _update_adminbar_height ); 662 window.trx_addons_adminbar_height_calc = function() { 663 return trx_addons_apply_filters( 'trx_addons_filter_adminbar_height', 664 $adminbar.length === 0 665 || $adminbar.css( 'display' ) == 'none' 666 || $adminbar.css( 'position' ) == 'absolute' 667 ? 0 668 : $adminbar.height() 669 ); 670 }; 671 window.trx_addons_adminbar_height = function() { 672 return _adminbar_height; 673 }; 674 675 // Detect fixed rows height 676 var $fixed_rows = false, 677 _fixed_rows_height = 0; 678 var _update_fixed_rows = function() { 679 if ( $fixed_rows === false ) { 680 $fixed_rows = jQuery( '.sc_layouts_row_fixed'); 681 } 682 _fixed_rows_height = trx_addons_fixed_rows_height_calc(); 683 $html_dom.style.setProperty( '--fixed-rows-height', ( _fixed_rows_height + trx_addons_adminbar_height() ) + 'px' ); 684 }; 685 $document.ready( _update_fixed_rows ); 686 $document.on('action.ready_trx_addons action.sc_layouts_row_fixed_on action.sc_layouts_row_fixed_off', _update_fixed_rows ); 687 $window.on( 'resize', _update_fixed_rows ); 688 window.trx_addons_fixed_rows_height_calc = function() { 689 var oft = 0; 690 if ( $fixed_rows.length > 0 ) { 691 var $fixed_on = $fixed_rows.filter( '.sc_layouts_row_fixed_on' ); 692 if ( $fixed_on.length > 0 693 && ! $body.hasClass( 'hide_fixed_rows' ) 694// && ! $body.hasClass( 'hide_fixed_rows_enabled' ) 695// && ! $body.hasClass( 'header_position_over' ) 696 ) { 697 $fixed_on.each( function() { 698 var $row = jQuery( this ); 699 if ( $row.css( 'position' ) == 'fixed' && $row.css( 'display' ) != 'none' ) { 700// if ( ! $body.hasClass( 'header_position_over' ) && ! $body.hasClass( 'header_position_under' ) || $row.parents( TRX_ADDONS_STORAGE['header_wrap_class'] ).length === 0 ) { 701 oft += $row.outerHeight(); 702// } 703 } 704 } ); 705 } 706 } 707 return trx_addons_apply_filters( 'trx_addons_filter_fixed_rows_height', oft ); 708 }; 709 window.trx_addons_fixed_rows_height = function() { 710 var with_admin_bar = arguments.length > 0 ? arguments[0] : true, 711 with_fixed_rows = arguments.length > 1 ? arguments[1] : true; 712 return ( with_admin_bar ? trx_addons_adminbar_height() : 0 ) 713 + ( with_fixed_rows ? _fixed_rows_height : 0 ); 714 }; 715 716 // Animated scroll to selected id 717 window.trx_addons_document_animate_to_busy = false;
718 window.trx_addons_document_animate_to = function(id, callback) { 719 var split_animation = true; 720 var oft = !isNaN(id) ? Number(id) : 0, 721 oft2 = -1; 722 var obj = null; 723 if ( isNaN(id) ) { 724 if ( typeof id == 'object' ) { 725 if ( id.length > 0 ) { 726 obj = id; 727 } else { 728 return; 729 } 730 } else { 731 if ( id.substring(0, 1) != '#' && id.substring(0, 1) != '.' ) { 732 id = '#' + id; 733 } 734 obj = jQuery(id).eq(0); 735 if ( obj.length === 0 ) { 736 return; 737 } 738 } 739 oft = split_animation ? obj.offset().top : Math.max( 0, obj.offset().top - trx_addons_fixed_rows_height() ); 740 if ( split_animation ) { 741 oft2 = Math.max( 0, oft - trx_addons_fixed_rows_height() ); 742 } 743 } 744 var speed = Math.min(1000, Math.max(300, Math.round(Math.abs( (oft2 < 0 ? oft : oft2) - jQuery(window).scrollTop()) / jQuery(window).height() * 300))); 745 // Recalc offset always (after the half animation time) to detect change size of the fullheight rows 746 window.trx_addons_document_animate_to_busy = true; 747 if ( oft2 >= 0 ) { 748 setTimeout( function() { 749 if (isNaN(id)) oft = obj.offset().top; 750 oft2 = Math.max( 0, oft - trx_addons_fixed_rows_height() ); 751 jQuery('body,html').stop(true).animate( {scrollTop: oft2}, Math.floor(speed/2), 'linear', function() { 752 _window_scroll_top = $window.scrollTop(); 753 window.trx_addons_document_animate_to_busy = false; 754 if ( callback ) callback( id, speed ); 755 } ); 756 }, Math.floor(speed/2) ); 757 } else { 758 oft2 = oft; 759 } 760 if ( speed > 0 ) { 761 jQuery('body,html').stop(true).animate( {scrollTop: oft2}, speed, 'linear', function() { 762 _window_scroll_top = $window.scrollTop(); 763 window.trx_addons_document_animate_to_busy = false; 764 if ( callback ) callback( id, speed ); 765 } ); 766 } else { 767 jQuery( 'body,html' ).stop( true ).scrollTop( oft2 ); 768 _window_scroll_top = $window.scrollTop(); 769 window.trx_addons_document_animate_to_busy = false; 770 if ( callback ) callback( id, speed ); 771 } 772 }; 773 774 // Return a requestAnimationFrame function 775 window.trx_addons_request_animation_frame = function() { 776 return window.requestAnimationFrame 777 || window.webkitRequestAnimationFrame 778 || window.mozRequestAnimationFrame 779 || window.oRequestAnimationFrame 780 || window.msRequestAnimationFrame 781 || null; 782 }; 783 784 // Change browser address without reload page 785 window.trx_addons_document_set_location = function( curLoc, state ) { 786 if ( history.pushState === undefined || navigator.userAgent.match(/MSIE\s[6-9]/i) !== null ) { 787 return; 788 } 789 try { 790 history.pushState( state ? state : { url: curLoc }, null, curLoc ); 791 return; 792 } catch( e ) {} 793 location.href = curLoc; 794 }; 795 796 // Add/Change arguments to the url address 797 window.trx_addons_add_to_url = function(loc, prm) { 798 var ignore_empty = arguments[2] !== undefined ? arguments[2] : true, 799 q = loc.split('?'), 800 attr = q.length > 1 ? trx_addons_parse_query_string(q[1]) : {}, 801 i = 0; 802 for (var p in prm) { 803 attr[p] = prm[p]; 804 } 805 loc = q[0] + '?'; 806 i = 0; 807 for (p in attr) { 808 if (ignore_empty && attr[p] === '') continue; 809 loc += (i++ > 0 ? '&' : '') + encodeURIComponent(p) + '=' + encodeURIComponent(attr[p]); 810 } 811 return loc; 812 }; 813 814 // Add extra parameters to all links on page 815 window.trx_addons_add_extra_args_to_links = function( args, cont ) { 816 if ( ! cont ) { 817 cont = $body; 818 } 819 cont.find( 'a' ).each( function() { 820 var link = jQuery( this ), 821 href = link.attr( 'href' ); 822 if ( href && href != '#' && ! trx_addons_is_local_link( href ) && ! link.data( 'trx-addons-extra-args-added' ) ) { 823 var loc = window.location.href, 824 page_valid = true; 825 for ( var i = 0; i < args.length; i++ ) { 826 // Check a current page URL 827 page_valid = true; 828 if ( args[i].page ) { 829 page_valid = false; 830 if ( typeof args[i].page == 'object' ) { 831 for ( var pg in args[i].page ) { 832 page_valid = loc.indexOf( args[i].page[pg] ) >= 0; 833 if ( page_valid ) break; 834 } 835 } else { 836 page_valid = loc.indexOf( args[i].page ) >= 0; 837 } 838 } 839 // Check a href against mask 840 if ( page_valid 841 && ( ! args[i].mask || href.indexOf( args[i].mask ) >= 0 ) // If mask is not defined or href matches it 842 && ( ! args[i].link || href.indexOf( args[i].link ) < 0 ) // If link is not defined or href does not match it 843 ) { 844 // Prepare args to add to the URL 845 var add = false;
846 if ( typeof args[i].args == 'object' ) { 847 add = {}; 848 for ( var a in args[i].args ) { 849 // Skip empty args 850 if ( args[i].args[a] === '' ) { 851 continue; 852 } 853 // Replace an arguments starts with the '@' by the value of the specified field 854 if ( args[i].args[a] == '@href' ) { 855 add[a] = href; 856 } else if ( args[i].args[a] == '@location' || args[i].args[a] == '@loc' ) { 857 add[a] = loc; 858 } else if ( args[i].args[a] == '@title' ) { 859 add[a] = document.title; 860 } else { 861 add[a] = args[i].args[a]; 862 } 863 } 864 } 865 if ( typeof args[i].link != 'undefined' ) { 866 href = args[i].link; 867 } 868 if ( add !== false ) { 869 href = trx_addons_add_to_url( href, add ); 870 } 871 if ( typeof args[i].hash != 'undefined' && href.indexOf('#') < 0 ) { 872 href += '#' + args[i].hash; 873 } 874 link.attr( 'href', href ); 875 link.data( 'trx-addons-extra-args-added', 1 ); 876 break; 877 } 878 } 879 } 880 } ); 881 }; 882 883 // Return value of URL parameter 884 window.trx_addons_get_value_gp = function(prm) { 885 var urlParams = new URLSearchParams(window.location.search), 886 value = urlParams.get(prm); 887 return decodeURIComponent( value ? value : ''); 888 }; 889 890 // Parse the string with AJAX response from the server and return it as an object 891 window.trx_addons_parse_ajax_response = function( response, error_msg = '' ) { 892 var rez = {}; 893 if ( response == '' || response == 0 ) { 894 rez = { error: error_msg || TRX_ADDONS_STORAGE['msg_ajax_error'] }; 895 } else if ( typeof response == 'string' ) { 896 try { 897 rez = JSON.parse( response ); 898 } catch (e) { 899 rez = { error: error_msg || TRX_ADDONS_STORAGE['msg_ajax_error'] }; 900 console.log( response ); 901 } 902 } else { 903 rez = response; 904 } 905 return rez; 906 }; 907 908 // Parse query string 909 window.trx_addons_parse_query_string = function(qs) { 910 var query = {}, 911 pairs = ( qs.indexOf('?') >= 0 ? qs.substring( qs.indexOf('?') + 1 ) : qs).split('&'), 912 pair = []; 913 for (var i = 0; i < pairs.length; i++) { 914 pair = pairs[i].split('='); 915 query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || ''); 916 } 917 return query; 918 }; 919 920 // Check if url is page-inner (local) link 921 window.trx_addons_is_local_link = function(url) { 922 var rez = url!==undefined; 923 if (rez) { 924 var url_pos = url.indexOf('#'); 925 if (url_pos === 0 && url.length == 1) { 926 rez = false; 927 } else { 928 if (url_pos < 0) url_pos = url.length; 929 var loc = window.location.href; 930 var loc_pos = loc.indexOf('#'); 931 if (loc_pos > 0) loc = loc.substring(0, loc_pos); 932 rez = url_pos === 0; 933 if (!rez) rez = loc == url.substring(0, url_pos); 934 } 935 } 936 return rez; 937 }; 938 939 // Check if the specified path is url 940 window.trx_addons_is_url = function( url ) { 941 return url.indexOf( '//' ) === 0 || url.indexOf( '://' ) > 0; 942 }; 943 944 // Check if the specified url is local (from the current site) 945 window.trx_addons_is_local_url = function( url ) { 946 return url.indexOf( '//' ) < 0 || url.indexOf( window.location.hostname ) > 0; 947 }; 948 949 // Check if the specified url is external 950 window.trx_addons_is_external_url = function( url ) { 951 return ( url.indexOf( '//' ) === 0 || url.indexOf( '://' ) > 0 ) && url.indexOf( window.location.hostname ) === -1; 952 }; 953 954 // Get embed code from video URL 955 window.trx_addons_get_embed_from_url = function(url, autoplay, mute, loop ) { 956 if (autoplay === undefined) { 957 autoplay = true; 958 } 959 if (mute === undefined) { 960 mute = true; 961 } 962 if (loop === undefined) { 963 loop = true; 964 } 965 var embed = ''; 966 if ( url.indexOf( '.mp4' ) > 0 || trx_addons_is_local_link( url ) ) { 967 embed = '<video class="trx_addons_video_video" playsinline disablepictureinpicture' 968 + ( autoplay ? ' autoplay="autoplay"' : '' ) 969 + ( loop ? ' loop="loop"' : '' ) 970 + ( mute ? ' muted="muted"' : '' ) 971 + '>' 972 + '<source src="' + url + '" type="video/mp4" />' 973 + '</video>'; 974 } else { 975 url = url.replace('/watch?v=', '/embed/') 976 .replace('/youtu.be/', '/www.youtube.com/embed/') 977 //.replace('/vimeo.com/', '/player.vimeo.com/video/') 978 .replace(new RegExp(/\/vimeo\.com\/(\d+)(?:\/([a-z0-9]+))?/, 'i'), '/player.vimeo.com/video/$1?h=$2') 979 .replace('/dai.ly/', '/dailymotion.com/embed/video/') 980 .replace('/dailymotion.com/video/', '/dailymotion.com/embed/video/'); 981 if (autoplay) { 982 url += (url.indexOf('?') >
982 0 ? '&' : '?') + 'autoplay=1'; 983 } 984 if (mute) { 985 url += (url.indexOf('?') > 0 ? '&' : '?') + 'muted=1'; 986 } 987 embed = '<iframe src="'+url+'" border="0" width="1280" height="720"' + (autoplay ? ' allow="autoplay"' : '') + '></iframe>'; 988 } 989 return embed; 990 }; 991 992 // Turn on autoplay for videos in the container 993 window.trx_addons_set_autoplay = function(container, value) { 994 if (value === undefined) { 995 value = 1; 996 } 997 container.find('.video_frame > iframe, iframe').each(function () { 998 if (value) { 999 jQuery(this).attr('allow', 'autoplay'); 1000 } 1001 var src = jQuery(this).data('src'); 1002 if (src) { 1003 jQuery(this).attr('src', src); 1004 } else { 1005 src = jQuery(this).attr('src'); 1006 if (src === undefined) { 1007 src = ''; 1008 } 1009 if (src.indexOf('youtube')>=0 || src.indexOf('vimeo')>=0) { 1010 jQuery(this).attr('src', trx_addons_add_to_url(src, {'autoplay': value})); 1011 } 1012 } 1013 }); 1014 }; 1015 1016 // Insert an iframe with a video player after click on the preview image 1017 // If a video with autoplay and it hosted on Youtube - for iOS a Youtube API script is used instead an iframe 1018 window.trx_addons_insert_video_iframe = function( $cont, iframe_html ) { 1019 if ( $cont.length === 0 ) { 1020 return; 1021 } 1022 // If we are in iOS and the video from Youtube - try to create player and start the video 1023 if ( trx_addons_browser_is_ios() && iframe_html.indexOf( 'youtu' ) > 0 && iframe_html.indexOf( 'autoplay=1' ) > 0 && typeof YT != 'undefined' ) { 1024 var id = 'trx_addons_yt_player_' + trx_addons_get_unique_id(); 1025 $cont.html( iframe_html.replace( /<iframe[\s]+[\s\S]+<\/iframe>/, '<div class="trx_addons_yt_player" id="' + id + '"></div>' ) ); 1026 var src = iframe_html.split('?'); 1027 var video_id = src[0].substring( src[0].indexOf('/embed/') + 7 ); 1028 var player = new YT.Player( id, { 1029 videoId: video_id, 1030 suggestedQuality: 'hd720', 1031 //height: '390', 1032 //width: '640', 1033 playerVars: { 1034 autoplay: 1, 1035 autohide: 0, 1036 modestbranding: 1, 1037 rel: 0, 1038 showinfo: 0, 1039 controls: 1, 1040 disablekb: 1, 1041 enablejsapi: 1, 1042 iv_load_policy: 3, 1043 playsinline: 1, 1044 loop: 0 1045 }, 1046 events: { 1047 'onReady': function onReady(e) { 1048 player.playVideo(); 1049 } 1050 } 1051 } ); 1052 1053 // Otherwise insert the iframe with a video to the block .video_embed 1054 } else { 1055 $cont.html( iframe_html ); 1056 } 1057 }; 1058 1059 1060 /* Browsers detection 1061 ---------------------------------------------------------------- */ 1062 window.trx_addons_browser_is_support = function( prop, value ) { 1063 var prefixes = ' -webkit- -moz- -o- -ms- '.split(' '); 1064 var el = document.createElement('a'); 1065 var style = el.style; 1066 if ( prop.slice( -1 ) != ':' ) { 1067 prop += ':'; 1068 } 1069 style.cssText = prop + prefixes.join( value + ';' + prop ).slice( 0, - prop.length ); 1070 return style.position.indexOf( value ) !== -1; 1071 }; 1072 1073 window.trx_addons_browser_is_support_css_sticky = function() { 1074 return trx_addons_browser_is_support( 'position', 'sticky' ); 1075 }; 1076 1077 window.trx_addons_browser_is_touch = function() { 1078 return 'ontouchstart' in document.documentElement; 1079 }; 1080 1081 window.trx_addons_browser_is_pointer_events = function() { 1082 return !!window.PointerEvent && ('maxTouchPoints' in window.navigator) && window.navigator.maxTouchPoints >= 0; 1083 }; 1084 1085 window.trx_addons_browser_is_mobile = function() { 1086 var check = false; 1087 ( function(a) { 1088 if ( /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|
1088sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test( a.substr(0,4) ) ) { 1089 check = true; 1090 } 1091 } )( navigator.userAgent || navigator.vendor || window.opera ); 1092 return check; 1093 }; 1094 1095 window.trx_addons_browser_is_ios = function() { 1096 return navigator.userAgent.match(/iPad|iPhone|iPod/i) !== null 1097 ? true 1098 : false; 1099 }; 1100 1101 window.trx_addons_browser_is_iphone = function() { 1102 return navigator.userAgent.match(/iPhone/i) !== null 1103 ? true 1104 : false; 1105 }; 1106 1107 window.trx_addons_browser_is_ipad = function() { 1108 return navigator.userAgent.match(/iPad/i) !== null 1109 ? true 1110 : false; 1111 }; 1112 1113 window.trx_addons_browser_is_ipod = function() { 1114 return navigator.userAgent.match(/iPod/i) !== null 1115 ? true 1116 : false; 1117 }; 1118 1119 window.trx_addons_is_retina = function() { 1120 var mediaQuery = '(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)'; 1121 return (window.devicePixelRatio > 1) || (window.matchMedia && window.matchMedia(mediaQuery).matches); 1122 }; 1123 1124 window.trx_addons_browser_classes = function() { 1125 var userAgent = navigator.userAgent, 1126 matchUserAgent = function( ua ) { 1127 return userAgent.indexOf( ua ) >= 0; 1128 }, 1129 classes = { 1130 // Platform 1131 'mobile': trx_addons_browser_is_mobile(), 1132 'mac': matchUserAgent('Macintosh'), 1133 'ios': trx_addons_browser_is_ios(), 1134 'iphone': trx_addons_browser_is_iphone() || trx_addons_browser_is_ipad() || trx_addons_browser_is_ipod(), 1135 'touch': trx_addons_browser_is_touch(), 1136 'retina': trx_addons_is_retina(), 1137 // Browser 1138 'firefox': matchUserAgent( 'Firefox' ), // Firefox 1.0+ 1139 'opera': !!window.opr && !!opr.addons || !!window.opera || matchUserAgent(' OPR/'), // Opera 8.0+ 1140 'safari': /^((?!chrome|android).)*safari/i.test(userAgent) // Safari 3.0+ "[object HTMLElementConstructor]" 1141 || /constructor/i.test(window.HTMLElement) 1142 || (p => { return '[object SafariRemoteNotification]' === p.toString(); })(!window.safari || typeof safari !== 'undefined' && safari.pushNotification), 1143 'ie': /Trident|MSIE/.test(userAgent) && ( false || !!document.documentMode ), // Internet Explorer 6-11 1144 'blink': matchUserAgent('Chrome') && !!window.CSS, // Blink engine 1145 'webkit': matchUserAgent('AppleWebKit') 1146 }; 1147 classes['edge'] = ! classes['ie'] && !!window.StyleMedia || matchUserAgent('Edg'); // Edge 20+ 1148 classes['chrome'] = !!window.chrome && matchUserAgent('Chrome') && ! classes['edge'] && ! classes['opera'];// Google Chrome (Not accurate) 1149 classes['applewebkit'] = matchUserAgent('AppleWebKit') && ! classes['blink']; // Apple Webkit engine 1150 classes['gecko'] = matchUserAgent('Gecko') && classes['firefox']; // Gecko 1151 return classes; 1152 }; 1153 1154 1155 /* File functions 1156 ---------------------------------------------------------------- */ 1157 1158 window.trx_addons_get_file_name = function(path) { 1159 path = path.replace(/\\/g, '/'); 1160 if ( path.indexOf('?') > 0 ) { 1161 path = path.substr( 0, path.indexOf('?') ); 1162 } 1163 var pos = path.lastIndexOf('/'); 1164 if (pos >= 0) 1165 path = path.substr(pos+1); 1166 return path; 1167 }; 1168 1169 window.trx_addons_get_file_ext = function(path) { 1170 if ( path.indexOf('?') > 0 ) { 1171 path = path.substr( 0, path.indexOf('?') ); 1172 } 1173 var pos = path.lastIndexOf('.'); 1174 path = pos >= 0 ? path.substr(pos+1) : ''; 1175 return path; 1176 }; 1177 1178 window.trx_addons_get_basename = function(path) { 1179 return trx_addons_get_file_name(path).replace('.'+trx_addons_get_file_ext(path), ''); 1180 }; 1181 1182 1183 1184 /* Image functions 1185 ---------------------------------------------------------------- */ 1186 1187 // Return true, if all images in the specified container are loaded 1188 window.trx_addons_is_images_loaded = function(cont) { 1189 var complete = true; 1190 cont.find('img').each(function() { 1191 // If any of previous images is not loaded - skip rest 1192 if ( ! complete ) { 1193 return; 1194 } 1195 var img = jQuery(this).get(0); 1196 if (typeof img.complete == 'boolean') { 1197 // See if "complete" property is available 1198 complete = img.complete; 1199 }
1199 else if (typeof img.naturalWidth == 'number' && typeof img.naturalHeight == 'number') { 1200 // See if "naturalWidth" and "naturalHeight" properties are available 1201 complete = !(img.naturalWidth == 0 && img.naturalHeight == 0); 1202 } 1203 }); 1204 return complete; 1205 }; 1206 1207 // Call function when all images in the specified container are loaded 1208 window.trx_addons_when_images_loaded = function(cont, callback, max_delay) { 1209 if (max_delay === undefined) { 1210 max_delay = 3000; 1211 } 1212 if (max_delay <= 0 || trx_addons_is_images_loaded(cont)) { 1213 callback( cont ); 1214 } else { 1215 setTimeout(function(){ 1216 trx_addons_when_images_loaded(cont, callback, max_delay - 200); 1217 }, 200); 1218 } 1219 }; 1220 1221 // Fetch content from URL 1222 window.trx_addons_fetch_url = function( url, callback ) { 1223 // Set the protocol of url to https if the current page is loaded via https 1224 if ( window.location.protocol == 'https:' && url.indexOf( 'http:' ) == 0 ) { 1225 url = 'https:' + url.substr(5); 1226 } 1227 if ( typeof window.fetch == 'function' ) { 1228 fetch( url ) 1229 .then( function( response ) { 1230 return response.ok ? response.text() : ''; 1231 } ) 1232 .then( function( data ) { 1233 if ( callback ) { 1234 callback( data ); 1235 } 1236 } ); 1237 } else { 1238 jQuery.get( url ) 1239 .done( function( response ) { 1240 if ( typeof response == 'object' 1241 && typeof response.childElementCount != 'undefined' && response.childElementCount > 0 1242 && typeof response.children != 'undefined' && typeof response.children[0] != 'undefined' 1243 ) { 1244 response = response.children[0].outerHTML; 1245 } 1246 if ( callback ) { 1247 callback( response ); 1248 } 1249 } ) 1250 .fail( function() { 1251 if ( callback ) { 1252 callback( '' ); 1253 } 1254 } ); 1255 } 1256 }; 1257 1258 // Return cached SVG-file content or fetch a file if not in a cache 1259 var inline_svg = []; 1260 window.trx_addons_get_inline_svg = function( svg_url, view ) { 1261 var html = ''; 1262 for( var i = 0; i < inline_svg.length; i++ ) { 1263 if ( inline_svg[i].url == svg_url ) { 1264 html = inline_svg[i].html; 1265 break; 1266 } 1267 } 1268 if ( html === '' ) { 1269 if ( svg_url && trx_addons_get_file_ext( svg_url ) == 'svg' ) { 1270 trx_addons_fetch_url( svg_url, function( html ) { 1271 if ( html && html.indexOf( '<svg' ) >= 0 ) { 1272 // Sanitize the SVG content 1273 html = trx_addons_sanitize_svg( html ); 1274 // Add the SVG to the cache 1275 inline_svg.push( { 1276 url: svg_url, 1277 html: html 1278 } ); 1279 } 1280 if ( view ) { 1281 view.render( html ); 1282 } 1283 } ); 1284 } 1285 } else if ( view ) { 1286 view.render( html ); 1287 } 1288 return html; 1289 }; 1290 1291 // Legacy function to compatibility with the old themes 1292 if ( ! window.get_inline_svg ) { 1293 window.get_inline_svg = window.trx_addons_get_inline_svg; 1294 } 1295 1296 // Sanitize the SVG content from any potential security issues: 1297 // remove any script tags, foreignobject tags, and other potentially dangerous elements 1298 window.trx_addons_sanitize_svg = function( svg ) { 1299 if ( svg && typeof svg == 'string' ) { 1300 var disallowed_tags = [ 'script', 'foreignobject', 'object', 'iframe', 'applet', 'embed', 'form', 'input', 'textarea', 'select', 'button' ]; 1301 // Remove disallowed tags 1302 for ( var i = 0; i < disallowed_tags.length; i++ ) { 1303 var tag = disallowed_tags[i]; 1304 svg = svg.replace( new RegExp( '<' + tag + '[^>]*>.*?</' + tag + '>', 'gi' ), '' ); 1305 svg = svg.replace( new RegExp( '<' + tag + '[^>]*>', 'gi' ), '' ); 1306 svg = svg.replace( new RegExp( '</' + tag + '[^>]*>', 'gi' ), '' ); 1307 } 1308 // Remove any attributes that could be used for XSS attacks 1309 svg = svg.replace( / src='[^']*'/gi, '' ); // Remove src attributes 1310 svg = svg.replace( / on\w+="[^"]*"/gi, '' ); // Remove event handlers like onclick, onmouseover, etc. 1311 svg = svg.replace( / on\w+='[^']*'/gi, '' ); // Remove event handlers like onclick, onmouseover, etc. 1312 svg = svg.replace( /javascript:/gi, '' ); // Remove javascript: protocol 1313 svg = svg.replace( / xmlns="[^"]*"/gi, '' ); // Remove xmlns attributes 1314 svg = svg.replace( / xmlns='[^']*'/gi, '' ); // Remove xmlns attributes 1315 svg = svg.replace( / xmlns:xlink="[^"]*"/gi, '' ); // Remove xmlns:xlink attributes 1316 svg = svg.replace( / xmlns:xlink='[^']*'/gi, '' ); // Remove xmlns:xlink attributes 1317 } 1318 return svg; 1319 }; 1320 1321 1322 /* Date & Time functions 1323 ---------------------------------------------------------------- */ 1324 // Get a date in format 'YYYY-MM-DD' from the time 1325 window.trx_addons_get_sql_date = function( time, with_time ) { 1326 var date = new Date( time ); 1327 var year = date.getFullYear();
1328 var month = ( date.getMonth() + 1 ).toString().padStart( 2, '0' ); 1329 var day = date.getDate().toString().padStart( 2, '0' ); 1330 var output = year + '-' + month + '-' + day; 1331 if ( with_time ) { 1332 var hours = date.getHours().toString().padStart( 2, '0' ); 1333 var minutes = date.getMinutes().toString().padStart( 2, '0' ); 1334 var seconds = date.getSeconds().toString().padStart( 2, '0' ); 1335 output += ' ' + hours + ':' + minutes + ':' + seconds; 1336 } 1337 return output; 1338 }; 1339 1340 1341 /* Numbers functions 1342 ---------------------------------------------------------------- */ 1343 1344 // Round number to specified precision. 1345 // For example: num=1.12345, prec=2, rounded=1.12 1346 // num=12345, prec=-2, rounded=12300 1347 window.trx_addons_round_number = function(num) { 1348 var precision = arguments[1]!==undefined ? arguments[1] : 0; 1349 var p = Math.pow(10, precision); 1350 return Math.round(num*p)/p; 1351 }; 1352 1353 // Format money: 1354 // For example: (123456789.12345).formatMoney(2, '.', ','); 1355 Number.prototype.formatMoney = function(c, d, t) { 1356 var n = this, 1357 c = c == undefined ? 2 : (isNaN(c = Math.abs(c)) ? 2 : c), 1358 d = d == undefined ? "." : d, 1359 t = t == undefined ? "," : t, 1360 s = n < 0 ? "-" : "", 1361 i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))), 1362 j = (j = i.length) > 3 ? j % 3 : 0; 1363 return s 1364 + (j ? i.substring(0, j) + t : "") 1365 + i.substring(j).replace(/(\d{3})(?=\d)/g, "$1" + t) 1366 + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); 1367 }; 1368 1369 // Return random integer from a to b 1370 window.trx_addons_random = function(a, b) { 1371 return Math.floor( Math.random() * ( b - a ) ) + a; 1372 }; 1373 1374 1375 /* Strings 1376 ---------------------------------------------------------------- */ 1377 1378 // Make first letter of every word 1379 window.trx_addons_proper = function(str) { 1380 return str.replace(/(\b\w)/gi, function(m) { return m.toUpperCase(); }); 1381 }; 1382 1383 // Replicate string several times 1384 window.trx_addons_replicate = function(str, num) { 1385 var rez = ''; 1386 for (var i=0; i < num; i++) { 1387 rez += str; 1388 } 1389 return rez; 1390 }; 1391 1392 // Split a string by delimiter, but not split if delimiter inside quotes 1393 window.trx_addons_split = function(str, delimiter) { 1394 var rez = [], 1395 quotes = false, 1396 pos = 0; 1397 for ( var i = 0; i < str.length; i++ ) { 1398 if ( str[i] == delimiter && ! quotes ) { 1399 rez.push( str.substring( pos, i ) ); 1400 pos = i + 1; 1401 } else if ( str[ i ] == '"' ) { 1402 quotes = ! quotes; 1403 } 1404 } 1405 rez.push( str.substring( pos, i ) ); 1406 return rez; 1407 }; 1408 1409 // Parse a string with arguments to the object 1410 window.trx_addons_parse_atts = function(str, delimiter) { 1411 var obj = {}; 1412 if ( ! delimiter ) { 1413 delimiter = ' '; 1414 } 1415 if ( str !== undefined ) { 1416 if ( delimiter == '&' ) { 1417 str = str.replace(/&/g, '&'); 1418 } 1419 var pairs = trx_addons_split( str, delimiter ); 1420 for ( var i in pairs ) { 1421 if ( pairs[i].indexOf('=') != -1 ) { 1422 var pair = pairs[i].split('='); 1423 obj[ pair[0] ] = ('' + pair[1]).slice(0, 1) == '"' && ('' + pair[1]).slice(-1) == '"' 1424 || ( '' + pair[1]).slice(0, 1) == "'" && ('' + pair[1]).slice(-1) == "'" 1425 ? pair[1].slice( 1, -1 ) 1426 : pair[1]; 1427 } 1428 } 1429 } 1430 return obj; 1431 }; 1432 1433 // Replace: 1434 // {{..}} to the <i>..</i> 1435 // ((..)) to the <b>..</b> 1436 // || to the <br> 1437 // ^N to the <sup>N</sup> 1438 window.trx_addons_prepare_macros = function(str, args) { 1439 if ( ! str || typeof str != 'string' ) { 1440 return str; 1441 } 1442 if ( ! args ) { 1443 args = {}; 1444 } 1445 // Replace shortcodes 1446 if ( str.indexOf('[') >= 0 && str.indexOf(']') >= 0 ) { 1447 str = str.replace( 1448 /([\[])([\[\]\S]+?)[\s]+([^\[\]]+)?([\]])/g, 1449 function( match, p1, p2, p3, p4 ) { 1450 // Allowed CSS properties as attributes in format: 1451 // 'attribute': 'css_property' or 'attribute': { 'rule': 'css_property', 'default': 'default_value' } 1452 var allowed_css = trx_addons_apply_filters( 'trx_addons_filter_prepare_macros_allowed_css', { 1453 'valign': 'vertical-align', 1454 'color': 'color', 1455 'bgcolor': 'background-color', 1456 'bdcolor': 'border-color', 1457 'border': 'border-width', 1458 'radius': 'border-radius', 1459 'padding': 'padding', 1460 'margin': 'margin', 1461 'top': 'top', 1462 'left': 'left', 1463 'right': 'right', 1464 'bottom': 'bottom' 1465 }, 1466 'common' 1467 ), 1468 image_css = trx_addons_apply_filters( 'trx_addons_filter_prepare_macros_allowed_css', { 1469 'size': { 'rule': 'max-height', 'default': '1em' }, 1470 }, 1471 'image' 1472 ), 1473 icon_css = trx_addons_apply_filters( 'trx_addons_filter_prepare_macros_allowed_css', { 1474 'size': { 'rule': 'font-size', 'default': '1em' }, 1475 }, 1476 'icon' 1477 ), 1478 atts = false;
1479 if ( p2 == 'image' ) { 1480 atts = p3 ? trx_addons_parse_atts( p3 ) : {}; 1481 // Fetch an image url by id or replace it by default image 1482 if ( ! atts['url'] ) { 1483 // Default image 1484 atts['url'] = TRX_ADDONS_STORAGE['no_image']; 1485 // Get url with specified size 1486 var get_url_by_size = function( data, thumb_size ) { 1487 var url = ''; 1488 for ( var i in data['media_details']['sizes'] ) { 1489 if ( ('' + i).indexOf( thumb_size ) >= 0 ) { 1490 url = data['media_details']['sizes'][i]['source_url']; 1491 break; 1492 } 1493 } 1494 return url; 1495 }; 1496 // Fetch image by id 1497 if ( atts['id'] ) { 1498 if ( TRX_ADDONS_STORAGE['fetch_images' ] === undefined ) { 1499 TRX_ADDONS_STORAGE['fetch_images'] = {}; 1500 } 1501 if ( ! TRX_ADDONS_STORAGE['fetch_images'][ atts['id'] ] ) { 1502 args['class'] = ( args['class'] ? args['class'] + ' ' : '' ) + 'trx_addons_image_placeholder trx_addons_image_' + atts['id']; 1503 jQuery.get( TRX_ADDONS_STORAGE['rest_url'] + 'wp/v2/media/' + atts['id'] + '/', function( response ) { 1504 if ( response && response['media_details'] && response['media_details']['sizes'] ) { 1505 TRX_ADDONS_STORAGE['fetch_images'][ atts['id'] ] = response; 1506 jQuery('.trx_addons_image_' + atts['id'] ) 1507 .removeClass( 'trx_addons_image_placeholder' ) 1508 .attr( 'src', get_url_by_size( response, atts['thumb'] ? '-' + atts['thumb'] : '-tiny' ) ); 1509 } 1510 } ); 1511 } else { 1512 atts['url'] = get_url_by_size( TRX_ADDONS_STORAGE['fetch_images'][ atts['id'] ], atts['thumb'] ? '-' + atts['thumb'] : '-tiny' ); 1513 } 1514 } 1515 } 1516 return atts['url'] 1517 ? '<img src="' + atts['url'] + '"' 1518 + ( atts['id'] ? ' id="trx_addons_image_' + atts['id'] + '"' : '' ) 1519 + ( atts['alt'] ? ' alt="' + atts['alt'] + '"' : '' ) 1520 + ( args['class'] || atts['class'] ? ' class="' + ( args['class'] ? args['class'] + ' ' : '' ) + ( ( atts['class'] ? atts['class'] : '' ) ) + '"' : '' ) 1521 + ' style="' 1522 + trx_addons_get_css_from_atts( atts, trx_addons_object_merge( allowed_css, image_css ) ) 1523 + ( atts['css'] ? atts['css'] : '' ) 1524 + '"' 1525 + '>' 1526 : ''; 1527 } else if ( p2 == 'icon' ) { 1528 atts = p3 ? trx_addons_parse_atts( p3 ) : {}; 1529 if ( atts['name'] && atts['name'].slice( 0, 5 ) != 'icon-' ) { 1530 atts['name'] = 'icon-' + atts['name']; 1531 } 1532 return atts['name'] 1533 ? '<span class="' + atts['name'] + ( args['class'] ? ' ' + args['class'] : '' ) + ( atts['class'] ? ' ' + atts['class'] : '' ) + '"' 1534 + ' style="' 1535 + trx_addons_get_css_from_atts( atts, trx_addons_object_merge( allowed_css, icon_css ) ) 1536 + ( atts['css'] ? atts['css'] : '' ) 1537 + '"' 1538 + '></span>' 1539 : ''; 1540 } else if ( p2.slice( 0, 1 ) != '&' ) { 1541 return p1 + p2 + p4; 1542 } else { 1543 return match; 1544 } 1545 } 1546 ); 1547 } 1548 // Replace simple macros 1549 return str 1550 // Replace all shortcodes with its short variant - names only, without attributes 1551 // Commented because it's already done in the callback above 1552 //.replace(/([\[])([\[\]\S]+?)[\s]+([^\[\]]+)?([\]])/g, '$1$2$4') 1553 .replace(/\{\{/g, "<i>") 1554 .replace(/\}\}/g, "</i>") 1555 .replace(/\(\(/g, "<b>") 1556 .replace(/\)\)/g, "</b>") 1557 .replace(/\|\|/g, "<br>") 1558 .replace(/(\^(\d+))/g, "<sup>$2</sup>"); 1559 }; 1560 window.trx_addons_remove_macros = function(str) { 1561 return str 1562 .replace(/[^\[]([\[][^\[\]]+[\]])[^\]]/g, "") 1563 .replace(/\{\{/g, "") 1564 .replace(/\}\}/g, "") 1565 .replace(/\(\(/g, "") 1566 .replace(/\)\)/g, "") 1567 .replace(/\|\|/g, ""); 1568 }; 1569 1570 // Replace {{ and }} with < and > 1571 window.trx_addons_parse_codes = function(text, tag_start, tag_end) { 1572 if (tag_start === undefined) tag_start = '{{'; 1573 if (tag_end === undefined) tag_end = '}}'; 1574 var r1 = new RegExp(tag_start, 'g'); 1575 var r2 = new RegExp(tag_end, 'g'); 1576 return text.replace(r1, '<').replace(r2, '>'); 1577 }; 1578 1579 // Check value for "on" | "off" | "inherit" values 1580 window.trx_addons_is_on = function(prm) { 1581 return prm>0 || ['true', 'on', 'yes', 'show'].indexOf((''+prm).toLowerCase()) >= 0; 1582 }; 1583 window.trx_addons_is_off = function(prm) { 1584 return prm === undefined || prm === '' || prm === 0 || ['false', 'off', 'no', 'none', 'hide'].indexOf((''+prm).toLowerCase()) >= 0; 1585 }; 1586 window.trx_addons_is_inherit = function(prm) { 1587 return ['inherit'].indexOf((''+prm).toLowerCase()) >= 0; 1588 }; 1589 1590 // Check for an object is empty 1591 window.trx_addons_is_empty = function(prm) { 1592 return prm === undefined || prm === '' || prm === 0 || prm === false || ( typeof prm == 'object' && Object.keys( prm ).length === 0 ); 1593 }; 1594 1595 // Return class by prefix from classes string
1596 window.trx_addons_get_class_by_prefix = function(classes, prefix) { 1597 var rez = ''; 1598 if ( classes ) { 1599 classes = classes.split(' '); 1600 for (var i=0; i < classes.length; i++) { 1601 if (classes[i].indexOf(prefix) >= 0) { 1602 rez = classes[i].replace(/[\s]+/g, ''); // Remove \t\r\n and spaces from the new class 1603 break; 1604 } 1605 } 1606 } 1607 return rez; 1608 }; 1609 1610 // Replace class by prefix with new value 1611 window.trx_addons_chg_class_by_prefix = function(classes, prefix, new_value) { 1612 var chg = false; 1613 if ( ! classes ) classes = ''; 1614 classes = classes.replace(/[\s]+/g, ' ').split(' '); // Replace groups \t\r\n and spaces with the single space 1615 new_value = new_value.replace(/[\s]+/g, ''); // Remove \t\r\n and spaces from the new class 1616 if ( typeof prefix == 'string' ) { 1617 prefix = [prefix]; 1618 } 1619 for (var i=0; i < classes.length; i++) { 1620 for (var j = 0; j < prefix.length; j++ ) { 1621 if (classes[i].indexOf( prefix[j] ) >= 0) { 1622 classes[i] = new_value; 1623 chg = true; 1624 break; 1625 } 1626 } 1627 if ( chg ) break; 1628 } 1629 if ( ! chg && new_value ) { 1630 if (classes.length == 1 && classes[0] === '') 1631 classes[0] = new_value; 1632 else 1633 classes.push( new_value ); 1634 } 1635 return classes.join(' ').replace(/[\s]{2,}/g, ' '); 1636 }; 1637 1638 // Return icon class from classes string 1639 window.trx_addons_get_icon_class = function(classes) { 1640 if ( ! classes ) classes = ''; 1641 return trx_addons_get_class_by_prefix(classes, 'icon-'); 1642 }; 1643 1644 // Replace icon's class with new value 1645 window.trx_addons_chg_icon_class = function(classes, icon, prefix) { 1646 var chg = false, 1647 icon_parts = icon.split( '-' ); 1648 if ( prefix === undefined ) { 1649 prefix = ['none', 'icon-', 'image-']; 1650 } 1651 prefix.push( icon_parts[0] + '-' ); 1652 if ( ! classes ) classes = ''; 1653 classes = classes.split(' '); 1654 for (var i=0; i < classes.length; i++) { 1655 for (var j = 0; j < prefix.length; j++ ) { 1656 if (classes[i].indexOf( prefix[j] ) >= 0) { 1657 classes[i] = [ 'none', 'image-none' ].indexOf( icon ) != -1 ? '' : icon; 1658 chg = true; 1659 break; 1660 } 1661 } 1662 if ( chg ) break; 1663 } 1664 if ( ! chg && [ 'none', 'image-none' ].indexOf( icon ) == -1 ) { 1665 if ( classes.length == 1 && classes[0] === '' ) { 1666 classes[0] = icon; 1667 } else { 1668 classes.push( icon ); 1669 } 1670 } 1671 return classes.join(' '); 1672 }; 1673 1674 // Add a data-parameter attributes to the <audio> tag with icons for each control button 1675 window.trx_addons_mediaplayer_add_button_icons = function( view, settings ) { 1676 var buttons = [ 'icon_media_play', 'icon_media_pause', 'icon_media_volume', 'icon_media_mute', 'icon_media_fullscreen', 'icon_media_unfullscreen' ]; 1677 var output = '', icon = '', iconHTML = ''; 1678 for ( var i = 0; i < buttons.length; i++ ) { 1679 if ( settings[ buttons[ i ] ] ) { 1680 if ( typeof settings[ buttons[ i ] ] == 'object' && settings[ buttons[ i ] ]['value'] ) { 1681 iconHTML = elementor.helpers.renderIcon( view, settings.selected_icon, { 'aria-hidden': true }, 'span' , 'object' ); 1682 if ( typeof iconHTML == 'object' ) { 1683 icon = iconHTML.value || ''; 1684 } else if ( typeof iconHTML == 'string' ) { 1685 icon = iconHTML; 1686 } else { 1687 icon = settings[ buttons[ i ] ]['value']; 1688 } 1689 } else if ( typeof settings[ buttons[ i ] ] == 'string' ) { 1690 icon = '<span class="' + settings[ buttons[ i ] ] + '" aria-hidden="true"></span>'; 1691 } else { 1692 icon = ''; 1693 } 1694 if ( icon ) { 1695 output += ' data-' + buttons[ i ].replace( '_', '-' ) + '="' + trx_addons_esc_html( icon ) + '"'; 1696 } 1697 } 1698 } 1699 return output; 1700 }; 1701 1702 // Render icon for Elementor view 1703 window.trx_addons_elm_render_icon = function( view, icon_settings, defa ) { 1704 var args = Object.assign( {}, icon_settings ); 1705 if ( ! args.value && defa ) { 1706 args = { 1707 library: defa.indexOf( 'eicon-' ) === 0 ? 'eicons' : ( defa.indexOf( 'far-' ) >= 0 ? 'fa-regular' : 'fa-solid' ), 1708 value: defa, 1709 }; 1710 } 1711 if ( args.value ) { 1712 var output = elementor.helpers.renderIcon( view, args, { 'aria-hidden': true }, 'i' , 'value' ); 1713 if ( typeof output == 'object' ) { 1714 output = output.value || ''; 1715 } else if ( typeof output != 'string' || output === '' ) { 1716 output = '<i class="' + defa + '" aria-hidden="true"></i>'; 1717 } 1718 } else { 1719 output = ''; 1720 } 1721 return output; 1722 }; 1723 1724 1725 1726 // Return column class by number of columns
1727 window.trx_addons_get_column_class = function( num, all, all_tablet, all_mobile ) { 1728 var column_class_tpl = TRX_ADDONS_STORAGE['column_class_template']; 1729 var column_class = column_class_tpl.replace( '$1', num ).replace( '$2', all ); 1730 if ( all_tablet ) { 1731 column_class += ' ' + column_class_tpl.replace( '$1', num ).replace( '$2', all_tablet ) + '-tablet'; 1732 } 1733 if ( all_mobile ) { 1734 column_class += ' ' + column_class_tpl.replace( '$1', num ).replace( '$2', all_mobile ) + '-mobile'; 1735 } 1736 return column_class; 1737 }; 1738 1739 // Return a list of the responsive classes for the shortcode's attribute 1740 window.trx_addons_get_responsive_classes = function( prefix, atts, param, default_value ) { 1741 var list = []; 1742 // Push a general or default value 1743 if ( atts[ param ] ) { 1744 list.push( prefix + atts[ param ] ); 1745 } else if ( default_value ) { 1746 list.push( prefix + default_value ); 1747 } 1748 // Add responsive values (if present) 1749 if ( TRX_ADDONS_STORAGE['elementor_breakpoints'] ) { 1750 for ( var bp_name in TRX_ADDONS_STORAGE['elementor_breakpoints'] ) { 1751 if ( atts[ param + '_' + bp_name ] ) { 1752 list.push( prefix + atts[ param + '_' + bp_name ] + '_' + bp_name ); 1753 } 1754 } 1755 } 1756 // Apply filters to allow 3rd-party plugins modify the list of the responsive classes 1757 list = trx_addons_apply_filters( 'trx_addons_filter_responsive_classes', list, prefix, atts, param ); 1758 return list.length ? list.join( ' ' ) : ''; 1759 }; 1760 1761 // Return a name of the current breakpoint 1762 window.trx_addons_get_responsive_breakpoint = function() { 1763 var rez = 'desktop', ww = trx_addons_window_width(); 1764 if ( TRX_ADDONS_STORAGE['elementor_breakpoints'] ) { 1765 for ( var bp_name in TRX_ADDONS_STORAGE['elementor_breakpoints'] ) { 1766 if ( TRX_ADDONS_STORAGE['elementor_breakpoints'][bp_name] < ww ) { 1767 break; 1768 } 1769 rez = bp_name; 1770 } 1771 } 1772 return rez; 1773 }; 1774 1775 // Return a tag name if the token is an icon 1776 function trx_addons_is_icon_tag( token ) { 1777 var tag = ''; 1778 if ( token.slice(0, 3) == '<i ' || token.slice(0, 3) == '<i>' ) { 1779 tag = 'i'; 1780 } else if ( token.slice(0, 4) == '<svg' ) { 1781 tag = 'svg'; 1782 } else if ( token.slice(0, 6) == '<video' ) { 1783 tag = 'video'; 1784 } else if ( token.slice(0, 52) == '<span class="trx-addons-advanced-title-item-icon-svg' ) { 1785 tag = 'span'; 1786 } else if ( token.slice(0, 56) == '<span class="trx-addons-advanced-title-item-gallery-wrap' ) { 1787 tag = 'span'; 1788 } 1789 return tag; 1790 } 1791 1792 // Return a tag name if the token is an image 1793 function trx_addons_is_image_tag( token ) { 1794 var tag = ''; 1795 if ( token.slice(0, 4) == '<img' ) { 1796 tag = 'img'; 1797 } 1798 return tag; 1799 } 1800 1801 // Get a next token from the string (character or a tag) 1802 // If a tag is <i>...</i> - return it as a single token 1803 function trx_addons_get_next_token( str, pos ) { 1804 var token = '', tag = ''; 1805 if ( pos < str.length ) { 1806 if ( str[pos] == '<' ) { 1807 while ( pos < str.length && str[pos] != '>' ) { 1808 token += str[pos++]; 1809 } 1810 token += str[pos++]; 1811 tag = trx_addons_is_icon_tag( token ); 1812 if ( tag ) { 1813 while ( pos < str.length && token.indexOf('</' + tag + '>') == -1 ) { 1814 token += str[pos++]; 1815 } 1816 } 1817 } else { 1818 token = str[pos++]; 1819 } 1820 } 1821 return token; 1822 } 1823 1824 // Wrap each word to the specified tag 1825 window.trx_addons_wrap_words = function( txt, before, after ) { 1826 var rez = '', token = '', in_word = false, cnt = 0, is_icon = false, is_space = false; 1827 for ( var i = 0; i < txt.length; i++ ) { 1828 token = trx_addons_get_next_token( txt, i ); 1829 is_icon = trx_addons_is_icon_tag( token ) || trx_addons_is_image_tag( token ); 1830 is_space = token == ' ' || /^[\s]*$/.test(token); 1831 if ( in_word ) { 1832 if ( token.slice(0, 1) == '<' || is_space ) { 1833 rez += after; 1834 in_word = false; 1835 } 1836 } else { 1837 if ( ! is_space && ( token.slice(0, 1) != '<' || is_icon ) ) { 1838 rez += before.replace( '>', ' data-animation-index="' + cnt + '">' ); 1839 in_word = true; 1840 cnt++; 1841 } 1842 } 1843 rez += token; 1844 i += token.length - 1; 1845 if ( is_icon || ( in_word && i == txt.length - 1 ) ) { 1846 rez += after; 1847 in_word = false; 1848 } 1849 } 1850 return rez; 1851 }; 1852 1853 // Wrap each character to the specified tag 1854 window.trx_addons_wrap_chars = function( txt, before, after, before_word, after_word ) { 1855 var rez = '', token = '', in_word = false, cnt = 0, is_icon = false, is_space = false;
1856 if ( before_word === undefined ) before_word = ''; 1857 if ( after_word === undefined ) after_word = ''; 1858 for ( var i = 0; i < txt.length; i++ ) { 1859 token = trx_addons_get_next_token( txt, i ); 1860 is_icon = trx_addons_is_icon_tag( token ) || trx_addons_is_image_tag( token ); 1861 is_space = token == ' ' || /^[\s]*$/.test(token); 1862 if ( in_word ) { 1863 if ( token.slice(0, 1) == '<' || is_space ) { 1864 rez += after_word; 1865 in_word = false; 1866 } 1867 } else { 1868 if ( ! is_space && ( token.slice(0, 1) != '<' || is_icon ) ) { 1869 rez += before_word; 1870 in_word = true; 1871 } 1872 } 1873 rez += token.slice(0, 1) == '<' && ! is_icon 1874 ? token 1875 : ( is_space 1876 ? token 1877 : before.replace( '>', ' data-animation-index="' + cnt + '">' ) + token + after 1878 ); 1879 i += token.length - 1; 1880 if ( is_icon || ( in_word && i == txt.length - 1 ) ) { 1881 rez += after_word; 1882 in_word = false; 1883 } 1884 if ( token.slice(0, 1) != '<' || is_icon ) { 1885 cnt++; 1886 } 1887 } 1888 return rez; 1889 }; 1890 1891 // Function to clear string from tags 1892 window.trx_addons_clear_tags = function( str ) { 1893 return str.replace( /<\/?[^>]+>/g, '' ); 1894 }; 1895 1896 // Function to escape string for use it in HTML 1897 window.trx_addons_esc_html = function( str ) { 1898 // 1st case: use browser's built-in functionality to quickly and safely escape strings 1899 // var textarea = document.createElement( 'textarea' ); 1900 // textarea.textContent = str; 1901 // return textarea.innerHTML; 1902 1903 // 2nd case: use jQuery to escape strings 1904 // return jQuery('<div>').text(str).html(); 1905 1906 // 3rd case: use our own function to escape strings 1907 return ! str ? str : str 1908 .replace( /&/g, '&' ) 1909 .replace( /</g, '<' ) 1910 .replace( />/g, '>' ) 1911 .replace( /"/g, '"' ) 1912 .replace( /'/g, ''' ); 1913 }; 1914 1915 // Function to escape string for use it in HTML attributes 1916 window.trx_addons_esc_attr = function( str ) { 1917 return ! str ? str : str 1918 .replace( /"/g, '"' ) 1919 .replace( /'/g, ''' ); 1920 }; 1921 1922 // Return an unique ID 1923 window.trx_addons_get_unique_id = function() { 1924 return Math.random().toString(16).slice(2, 9); 1925 }; 1926 1927 1928 /* Colors functions 1929 ---------------------------------------------------------------- */ 1930 1931 window.trx_addons_hex2rgb = function(hex) { 1932 hex = hex.indexOf('#') > -1 ? hex.substring(1) : hex; 1933 if ( hex.length == 3 ) { 1934 hex = hex.slice(0,1).repeat(2) + hex.slice(1,2).repeat(2) + hex.slice(2,3).repeat(2); 1935 } 1936 var num = parseInt( hex, 16 ); 1937 if ( hex.length > 6 ) { 1938 return {r: ( num >> 24 ) + 256, g: (num & 0x00FF0000) >> 16, b: (num & 0x0000FF00) >> 8, a: (num & 0x000000FF)}; 1939 } else { 1940 return {r: num >> 16, g: (num & 0x00FF00) >> 8, b: (num & 0x0000FF)}; 1941 } 1942 }; 1943 1944 window.trx_addons_hex2rgba = function(hex, alpha) { 1945 var rgb = trx_addons_hex2rgb(hex); 1946 return 'rgba('+rgb.r+','+rgb.g+','+rgb.b+','+alpha+')'; 1947 }; 1948 1949 window.trx_addons_rgb2hex = function(color) { 1950 var aRGB; 1951 color = color.replace(/\s/g,"").toLowerCase(); 1952 if (color=='rgba(0,0,0,0)' || color=='rgba(0%,0%,0%,0%)') { 1953 color = 'transparent'; 1954 } 1955 if (color.indexOf('rgba(')==0) 1956 aRGB = color.match(/^rgba\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i); 1957 else 1958 aRGB = color.match(/^rgb\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i); 1959 1960 if(aRGB) { 1961 color = ''; 1962 for (var i=1; i <= 3; i++) 1963 color += Math.round((aRGB[i][aRGB[i].length-1]=="%"?2.55:1)*parseInt(aRGB[i])).toString(16).replace(/^(.)$/,'0$1'); 1964 } else { 1965 color = color.replace(/^#?([\da-f])([\da-f])([\da-f])$/i, '$1$1$2$2$3$3'); 1966 } 1967 return (color.substr(0,1)!='#' ? '#' : '') + color; 1968 }; 1969 1970 window.trx_addons_components2hex = function(r,g,b,a) { 1971 return '#'+ 1972 Number(r).toString(16).toUpperCase().replace(/^(.)$/,'0$1') + 1973 Number(g).toString(16).toUpperCase().replace(/^(.)$/,'0$1') + 1974 Number(b).toString(16).toUpperCase().replace(/^(.)$/,'0$1') + 1975 ( a || a === 0 1976 ? Number(a).toString(16).toUpperCase().replace(/^(.)$/,'0$1') 1977 : '' 1978 ); 1979 }; 1980 1981 window.trx_addons_rgb2components = function(color) { 1982 color = trx_addons_rgb2hex(color); 1983 var matches = color.match(/^#?([\dabcdef]{2})([\dabcdef]{2})([\dabcdef]{2})$/i); 1984 if (!matches) return false;
1985 for (var i=1, rgb = new Array(3); i <= 3; i++) { 1986 rgb[i-1] = parseInt(matches[i],16); 1987 } 1988 return rgb; 1989 }; 1990 1991 window.trx_addons_hex2hsb = function(hex) { 1992 var h = arguments[1]!==undefined ? arguments[1] : 0; 1993 var s = arguments[2]!==undefined ? arguments[2] : 0; 1994 var b = arguments[3]!==undefined ? arguments[3] : 0; 1995 var hsb = trx_addons_rgb2hsb(trx_addons_hex2rgb(hex)); 1996 hsb.h = Math.min(359, Math.max( 0, hsb.h + h)); 1997 hsb.s = Math.min(100, Math.max( 0, hsb.s + s)); 1998 hsb.b = Math.min(100, Math.max( 0, hsb.b + b)); 1999 return hsb; 2000 }; 2001 2002 window.trx_addons_hsb2hex = function(hsb) { 2003 var rgb = trx_addons_hsb2rgb(hsb); 2004 return trx_addons_components2hex(rgb.r, rgb.g, rgb.b); 2005 }; 2006 2007 window.trx_addons_rgb2hsb = function(rgb) { 2008 var hsb = {}; 2009 hsb.b = Math.max(Math.max(rgb.r,rgb.g),rgb.b); 2010 hsb.s = (hsb.b <= 0) ? 0 : Math.round(100*(hsb.b - Math.min(Math.min(rgb.r,rgb.g),rgb.b))/hsb.b); 2011 hsb.b = Math.round((hsb.b /255)*100); 2012 if ((rgb.r==rgb.g) && (rgb.g==rgb.b)) hsb.h = 0; 2013 else if (rgb.r>=rgb.g && rgb.g>=rgb.b) hsb.h = 60*(rgb.g-rgb.b)/(rgb.r-rgb.b); 2014 else if (rgb.g>=rgb.r && rgb.r>=rgb.b) hsb.h = 60 + 60*(rgb.g-rgb.r)/(rgb.g-rgb.b); 2015 else if (rgb.g>=rgb.b && rgb.b>=rgb.r) hsb.h = 120 + 60*(rgb.b-rgb.r)/(rgb.g-rgb.r); 2016 else if (rgb.b>=rgb.g && rgb.g>=rgb.r) hsb.h = 180 + 60*(rgb.b-rgb.g)/(rgb.b-rgb.r); 2017 else if (rgb.b>=rgb.r && rgb.r>=rgb.g) hsb.h = 240 + 60*(rgb.r-rgb.g)/(rgb.b-rgb.g); 2018 else if (rgb.r>=rgb.b && rgb.b>=rgb.g) hsb.h = 300 + 60*(rgb.r-rgb.b)/(rgb.r-rgb.g); 2019 else hsb.h = 0; 2020 hsb.h = Math.round(hsb.h); 2021 return hsb; 2022 }; 2023 2024 window.trx_addons_hsb2rgb = function(hsb) { 2025 var rgb = {}; 2026 var h = Math.round(hsb.h); 2027 var s = Math.round(hsb.s*255/100); 2028 var v = Math.round(hsb.b*255/100); 2029 if (s == 0) { 2030 rgb.r = rgb.g = rgb.b = v; 2031 } else { 2032 var t1 = v; 2033 var t2 = (255-s)*v/255; 2034 var t3 = (t1-t2)*(h%60)/60; 2035 if (h==360) h = 0; 2036 if (h<60) { rgb.r=t1; rgb.b=t2; rgb.g=t2+t3; } 2037 else if (h<120) { rgb.g=t1; rgb.b=t2; rgb.r=t1-t3; } 2038 else if (h<180) { rgb.g=t1; rgb.r=t2; rgb.b=t2+t3; } 2039 else if (h<240) { rgb.b=t1; rgb.r=t2; rgb.g=t1-t3; } 2040 else if (h<300) { rgb.b=t1; rgb.g=t2; rgb.r=t2+t3; } 2041 else if (h<360) { rgb.r=t1; rgb.g=t2; rgb.b=t1-t3; } 2042 else { rgb.r=0; rgb.g=0; rgb.b=0; } 2043 } 2044 return { r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b) }; 2045 }; 2046 2047 window.trx_addons_color_picker = function(){ 2048 var id = arguments[0] !== undefined ? arguments[0] : 'iColorPicker_' + trx_addons_get_unique_id(); 2049 var colors = arguments[1]!==undefined ? arguments[1] : 2050 '#f00,#ff0,#0f0,#0ff,#00f,#f0f,#fff,#ebebeb,#e1e1e1,#d7d7d7,#cccccc,#c2c2c2,#b7b7b7,#acacac,#a0a0a0,#959595,' 2051 +'#ee1d24,#fff100,#00a650,#00aeef,#2f3192,#ed008c,#898989,#7d7d7d,#707070,#626262,#555,#464646,#363636,#262626,#111,#000,' 2052 +'#f7977a,#fbad82,#fdc68c,#fff799,#c6df9c,#a4d49d,#81ca9d,#7bcdc9,#6ccff7,#7ca6d8,#8293ca,#8881be,#a286bd,#bc8cbf,#f49bc1,#f5999d,' 2053 +'#f16c4d,#f68e54,#fbaf5a,#fff467,#acd372,#7dc473,#39b778,#16bcb4,#00bff3,#438ccb,#5573b7,#5e5ca7,#855fa8,#a763a9,#ef6ea8,#f16d7e,' 2054 +'#ee1d24,#f16522,#f7941d,#fff100,#8fc63d,#37b44a,#00a650,#00a99e,#00aeef,#0072bc,#0054a5,#2f3192,#652c91,#91278f,#ed008c,#ee105a,' 2055 +'#9d0a0f,#a1410d,#a36209,#aba000,#588528,#197b30,#007236,#00736a,#0076a4,#004a80,#003370,#1d1363,#450e61,#62055f,#9e005c,#9d0039,' 2056 +'#790000,#7b3000,#7c4900,#827a00,#3e6617,#045f20,#005824,#005951,#005b7e,#003562,#002056,#0c004b,#30004a,#4b0048,#7a0045,#7a0026'; 2057 var colorsList = colors.split(','); 2058 var tbl = '<table class="colorPickerTable"><thead>'; 2059 for (var i=0; i < colorsList.length; i++) { 2060 if (i%16==0) tbl += (i>0 ? '</tr>' : '') + '<tr>'; 2061 tbl += '<td style="background-color:'+colorsList[i]+'"> </td>'; 2062 } 2063 tbl += '</tr></thead><tbody>' 2064 + '<tr style="height:60px;">' 2065 + '<td colspan="8" id="'+id+'_colorPreview" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">' 2066 + '<input style="width:55px;color:#000;border:1px solid rgb(0, 0, 0);padding:5px;background-color:#fff;font:11px Arial, Helvetica, sans-serif;" maxlength="7" />' 2067 + '<a href="#" id="'+id+'_moreColors" class="iColorPicker_moreColors"></a>' 2068 + '</td>' 2069 + '<td colspan="8" id="'+id+'_colorOriginal" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">' 2070 + '<input style="width:55px;color:#000;border:1px solid rgb(0, 0, 0);padding:5px;background-color:#fff;font:11px Arial, Helvetica, sans-serif;" readonly="readonly" />' 2071 + '</td>' 2072 + '</tr></tbody></table>'; 2073 2074 jQuery(document.createElement("div")) 2075 .attr("id", id) 2076 .css('display','none') 2077 .html(tbl) 2078 .appendTo("body") 2079 .addClass("iColorPickerTable") 2080 .on('mouseover', 'thead td', function(){ 2081 var aaa = trx_addons_rgb2hex(jQuery(this).css('background-color')); 2082 jQuery('#'+id+'_colorPreview').css('background',aaa); 2083 jQuery('#'+id+'_colorPreview input').val(aaa); 2084 }) 2085 .on('keypress', '#'+id+'_colorPreview input', function(key){ 2086 var aaa = jQuery(this).val(); 2087 if (key.which===13 && (aaa.length===4 || aaa.length===7)) { 2088 var fld = jQuery('#'+id).data('field'); 2089 var func = jQuery('#'+id).data('func'); 2090 if (func!=null && func!='undefined') { 2091 func(fld, aaa); 2092 } else { 2093 fld.val(aaa).css('backgroundColor', aaa).trigger('change'); 2094 } 2095 jQuery('#'+id+'_Bg').fadeOut(500); 2096 jQuery('#'+id).fadeOut(500); 2097 key.preventDefault(); 2098 return false;
2099 } 2100 }) 2101 .on('change', '#'+id+'_colorPreview input', function(key){ 2102 var aaa = jQuery(this).val(); 2103 if (aaa.substr(0,1)==='#' && (aaa.length===4 || aaa.length===7)) { 2104 jQuery('#'+id+'_colorPreview').css('background',aaa); 2105 } 2106 }) 2107 .on('click', 'thead td', function(e){ 2108 var fld = jQuery('#'+id).data('field'); 2109 var func = jQuery('#'+id).data('func'); 2110 var aaa = trx_addons_rgb2hex(jQuery(this).css('background-color')); 2111 if (func!=null && func!='undefined') { 2112 func(fld, aaa); 2113 } else { 2114 fld.val(aaa).css('backgroundColor', aaa).trigger('change'); 2115 } 2116 jQuery('#'+id+'_Bg').fadeOut(500); 2117 jQuery('#'+id).fadeOut(500); 2118 e.preventDefault(); 2119 return false; 2120 }) 2121 .on('click', 'tbody .iColorPicker_moreColors', function(e){ 2122 var thead = jQuery(this).parents('table').find('thead'); 2123 var out = ''; 2124 if (thead.hasClass('more_colors')) { 2125 for (var i=0; i < colorsList.length; i++) { 2126 if (i%16==0) out += (i>0 ? '</tr>' : '') + '<tr>'; 2127 out += '<td style="background-color:'+colorsList[i]+'"> </td>'; 2128 } 2129 thead.removeClass('more_colors').empty().html(out+'</tr>'); 2130 jQuery('#'+id+'_colorPreview').attr('colspan', 8); 2131 jQuery('#'+id+'_colorOriginal').attr('colspan', 8); 2132 } else { 2133 var rgb=[0,0,0], i=0, j=-1; // Set j=-1 or j=0 - show 2 different colors layouts 2134 while (rgb[0]<0xF || rgb[1]<0xF || rgb[2]<0xF) { 2135 if (i%18==0) out += (i>0 ? '</tr>' : '') + '<tr>'; 2136 i++; 2137 out += '<td style="background-color:'+trx_addons_components2hex(rgb[0]*16+rgb[0],rgb[1]*16+rgb[1],rgb[2]*16+rgb[2])+'"> </td>'; 2138 rgb[2]+=3; 2139 if (rgb[2]>0xF) { 2140 rgb[1]+=3; 2141 if (rgb[1]>(j===0 ? 6 : 0xF)) { 2142 rgb[0]+=3; 2143 if (rgb[0]>0xF) { 2144 if (j===0) { 2145 j=1; 2146 rgb[0]=0; 2147 rgb[1]=9; 2148 rgb[2]=0; 2149 } else { 2150 break; 2151 } 2152 } else { 2153 rgb[1]=(j < 1 ? 0 : 9); 2154 rgb[2]=0; 2155 } 2156 } else { 2157 rgb[2]=0; 2158 } 2159 } 2160 } 2161 thead.addClass('more_colors').empty().html(out+'<td style="background-color:#ffffff" colspan="8"> </td></tr>'); 2162 jQuery('#'+id+'_colorPreview').attr('colspan', 9); 2163 jQuery('#'+id+'_colorOriginal').attr('colspan', 9); 2164 } 2165 jQuery('#'+id+' table.colorPickerTable thead td') 2166 .css({ 2167 'width':'12px', 2168 'height':'14px', 2169 'border':'1px solid #000', 2170 'cursor':'pointer' 2171 }); 2172 e.preventDefault(); 2173 return false; 2174 }); 2175 jQuery(document.createElement("div")) 2176 .attr("id", id+"_Bg") 2177 .on('click', function(e) { 2178 jQuery("#"+id+"_Bg").fadeOut(500); 2179 jQuery("#"+id).fadeOut(500); 2180 e.preventDefault(); 2181 return false; 2182 }) 2183 .appendTo("body"); 2184 jQuery('#'+id+' table.colorPickerTable thead td') 2185 .css({ 2186 'width':'12px', 2187 'height':'14px', 2188 'border':'1px solid #000', 2189 'cursor':'pointer' 2190 }); 2191 jQuery('#'+id+' table.colorPickerTable') 2192 .css({'border-collapse':'collapse'}); 2193 jQuery('#'+id) 2194 .css({ 2195 'border':'1px solid #ccc', 2196 'background':'#333', 2197 'padding':'5px', 2198 'color':'#fff' 2199 }); 2200 jQuery('#'+id+'_colorPreview') 2201 .css({'height':'50px'}); 2202 return id; 2203 }; 2204 2205 window.trx_addons_color_picker_show = function(id, fld, func) { 2206 if (id === null || id === '') { 2207 id = jQuery('.iColorPickerTable').attr('id'); 2208 } 2209 var eICP = fld.offset(); 2210 var w = jQuery('#'+id).width(); 2211 var h = jQuery('#'+id).height(); 2212 var l = eICP.left + w < jQuery(window).width()-10 ? eICP.left : jQuery(window).width()-10 - w; 2213 var t = eICP.top + fld.outerHeight() + h < jQuery(document).scrollTop() + jQuery(window).height()-10 ? eICP.top + fld.outerHeight() : eICP.top - h - 13; 2214 jQuery("#"+id) 2215 .data({field: fld, func: func}) 2216 .css({ 2217 'top':t+"px", 2218 'left':l+"px", 2219 'position':'absolute', 2220 'z-index':999999 2221 }) 2222 .fadeIn(500); 2223 jQuery("#"+id+"_Bg") 2224 .css({ 2225 'position':'fixed', 2226 'z-index':999998, 2227 'top':0, 2228 'left':0, 2229 'width':'100%', 2230 'height':'100%' 2231 }) 2232 .fadeIn(500); 2233 var def = fld.val().substr(0, 1)=='#' ? fld.val() : trx_addons_rgb2hex(fld.css('backgroundColor')); 2234 jQuery('#'+id+'_colorPreview input,#'+id+'_colorOriginal input').val(def); 2235 jQuery('#'+id+'_colorPreview,#'+id+'_colorOriginal').css('background',def); 2236 }; 2237 2238 2239 /* Utils 2240 ---------------------------------------------------------------- */ 2241 2242 // Global callback to catch Googlemap loaded to prevent a warning from googlemap api 2243 window.trx_addons_googlemap_loaded = function() {}; 2244 2245 // Add unit to css value 2246 window.trx_addons_prepare_css_value = function(val) { 2247 if (val !== '' && val != 'inherit') { 2248 var parts = ('' + val).split( ' ' ); 2249 for ( var i = 0; i < parts.length; i++ ) { 2250 if ( parts[i] === '' ) { 2251 continue; 2252 } 2253 var ed = ('' + parts[i]).slice( -1 ); 2254 if ('0' <= ed && ed <= '9') { 2255 parts[i] += 'px'; 2256 } 2257 } 2258 val = parts.join( ' ' ); 2259 } 2260 return val; 2261 }; 2262 2263 // Convert CSS units to px 2264 window.trx_addons_units2px = function(val, block, dir) { 2265 var value = parseFloat( val ); 2266 var unit = ('' + val).replace( ('' + value), '' ).toLowerCase(); 2267 if ( unit ) { 2268 if ( unit == 'vw' ) { 2269 value = Math.round( value * trx_addons_window_width() / 100 ); 2270 } else if ( unit == 'vh' ) { 2271 value = Math.round( value * trx_addons_window_height() / 100 ); 2272 } else if ( unit == '%' && block && block.length ) { 2273 value = Math.round( value * ( dir == 'x' ? block.eq(0).outerWidth() : block.eq(0).outerHeight() ) / 100 ); 2274 } else if ( unit == 'em' && block && block.length ) { 2275 value = parseFloat( getComputedStyle( block.get(0) )['fontSize'] ) * value; 2276 } else if ( unit == 'rem' ) { 2277 value = parseFloat( getComputedStyle( $body.get(0) )['fontSize'] ) * value; 2278 } 2279 } 2280 return value; 2281 }; 2282 2283 // Return string with CSS rules from the shortcode's attributes 2284 window.trx_addons_get_css_from_atts = function( atts, allowed ) { 2285 var css = '', 2286 rule = '', 2287 atts_with_units = trx_addons_apply_filters( 'trx_addons_filter_atts_with_units', [ 'margin', 'padding', 'border-radius', 'border-width', 'font-size', 'line-height', 'letter-spacing', 'width', 'height', 'top', 'right', 'bottom', 'left' ] ); 2288 for ( var k in allowed ) { 2289 if ( allowed[ k ] && ( atts.hasOwnProperty( k ) || typeof allowed[ k ] == 'object' && allowed[ k ].hasOwnProperty( 'default' ) ) ) { 2290 rule = typeof allowed[ k ] == 'object' ? allowed[ k ]['rule'] : allowed[ k ]; 2291 if ( typeof allowed[ k ] == 'object' ) { 2292 css += rule + ':' + ( atts[ k ] 2293 ? ( atts_with_units.indexOf( rule ) >= 0 ? trx_addons_prepare_css_value( atts[ k ] ) : atts[ k ] ) 2294 : ( atts_with_units.indexOf( rule ) >= 0 ? trx_addons_prepare_css_value( allowed[ k ]['default'] ) : allowed[ k ]['default'] ) 2295 ) 2296 + ';'; 2297 } else { 2298 css += rule + ':' + ( atts_with_units.indexOf( rule ) >= 0 ? trx_addons_prepare_css_value( atts[ k ] ) : atts[ k ] ) + ';'; 2299 } 2300 } 2301 } 2302 return css; 2303 }; 2304 2305 // Return nested property of the object 2306 window.trx_addons_get_object_property = function(obj, property, defa) {
2307 var rez = defa === undefined ? false : defa, 2308 props = property.split('.'), 2309 cur = obj; 2310 if ( typeof cur == 'object' ) { 2311 for (var i = 0; i < props.length; i++) { 2312 if ( cur.hasOwnProperty( props[i] ) ) { 2313 cur = cur[ props[i] ]; 2314 if ( i == props.length - 1 ) { 2315 rez = cur; 2316 } 2317 } else { 2318 break; 2319 } 2320 } 2321 } 2322 return rez; 2323 }; 2324 2325 // Clone objects. Handle the 3 simple types, and null or undefined 2326 window.trx_addons_object_clone = function(obj) { 2327 var copy; 2328 // Handle null 2329 if (null === obj || "object" != typeof obj) { 2330 return obj; 2331 } 2332 // Handle Date 2333 if (obj instanceof Date) { 2334 copy = new Date(); 2335 copy.setTime(obj.getTime()); 2336 return copy; 2337 } 2338 // Handle Array 2339 if (obj instanceof Array) { 2340 copy = []; 2341 for (var i = 0, len = obj.length; i < len; i++) { 2342 copy[i] = trx_addons_object_clone(obj[i]); 2343 } 2344 return copy; 2345 } 2346 // Handle Object 2347 if (obj instanceof Object) { 2348 copy = {}; 2349 for (var attr in obj) { 2350 if (obj.hasOwnProperty(attr)) { 2351 copy[attr] = trx_addons_object_clone(obj[attr]); 2352 } 2353 } 2354 return copy; 2355 } 2356 return obj; 2357 }; 2358 2359 // Merge objects 2360 window.trx_addons_object_merge = function(o1, o2) { 2361 for (var i=1; i<arguments.length; i++) { 2362 if ( arguments[i] ) { 2363 for (var prop in arguments[i]) { 2364 if ( arguments[i].hasOwnProperty(prop) ) { 2365 o1[prop] = arguments[i][prop]; 2366 } 2367 } 2368 } 2369 } 2370 return o1; 2371 }; 2372 2373 // Return true if specified var is an object 2374 window.trx_addons_is_object = function( o ) { 2375 return typeof o === 'object' && o !== null && o.constructor && o.constructor === Object; 2376 }; 2377 2378 // Extend an object with properties other objects 2379 window.trx_addons_object_extend = function() { 2380 var args = [], total = arguments.length; 2381 while ( total-- ) { 2382 args[ total ] = arguments[ total ]; 2383 } 2384 var to = Object( args[0] ); 2385 for ( var i = 1; i < args.length; i++ ) { 2386 var nextSource = args[i]; 2387 if ( nextSource !== undefined && nextSource !== null ) { 2388 var keysArray = Object.keys( Object( nextSource ) ); 2389 for ( var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++ ) { 2390 var nextKey = keysArray[ nextIndex ]; 2391 var desc = Object.getOwnPropertyDescriptor( nextSource, nextKey ); 2392 if ( desc !== undefined && desc.enumerable ) { 2393 if ( trx_addons_is_object( to[ nextKey ] ) && trx_addons_is_object( nextSource[ nextKey ] ) ) { 2394 trx_addons_object_extend( to[ nextKey ], nextSource[ nextKey ] ); 2395 } else if ( ! trx_addons_is_object( to[ nextKey ] ) && trx_addons_is_object( nextSource[ nextKey ] ) ) { 2396 to[ nextKey ] = {}; 2397 trx_addons_object_extend( to[ nextKey ], nextSource[ nextKey ] ); 2398 } else { 2399 to[ nextKey ] = nextSource[ nextKey ]; 2400 } 2401 } 2402 } 2403 } 2404 } 2405 return to; 2406 }; 2407 2408 // Merge two arrays 2409 window.trx_addons_array_merge = function(a1, a2) { 2410 if ( a2 ) { 2411 for ( var i in a2 ) { 2412 a1[i] = a2[i]; 2413 } 2414 } 2415 return a1; 2416 }; 2417 2418 // Get first key from array 2419 window.trx_addons_array_first_key = function(arr) { 2420 var rez = null; 2421 for (var i in arr) { 2422 rez = i; 2423 break; 2424 } 2425 return rez; 2426 }; 2427 2428 // Get first value from array 2429 window.trx_addons_array_first_value = function(arr) { 2430 var rez = null; 2431 for (var i in arr) { 2432 rez = arr[i]; 2433 break; 2434 } 2435 return rez; 2436 }; 2437 2438 // Returns the name of the class of an object 2439 window.trx_addons_get_class = function(obj) { 2440 if (obj instanceof Object && !(obj instanceof Array) && !(obj instanceof Function) && obj.constructor) { 2441 var arr = obj.constructor.toString().match(/function\s*(\w+)/); 2442 if (arr && arr.length == 2) return arr[1]; 2443 } 2444 return false; 2445 }; 2446 2447 // Generates a storable representation of a value 2448 window.trx_addons_serialize = function(mixed_val) { 2449 var obj_to_array = arguments.length==1 || argument[1]===true; 2450 2451 switch ( typeof(mixed_val) ) { 2452 2453 case "number": 2454 if ( isNaN(mixed_val) || !isFinite(mixed_val) ) 2455 return false; 2456 else 2457 return (Math.floor(mixed_val) == mixed_val ? "i" : "d") + ":" + mixed_val + ";"; 2458 2459 case "string": 2460 return "s:" + mixed_val.length + ":\"" + mixed_val + "\";"; 2461 2462 case "boolean": 2463 return "b:" + (mixed_val ? "1" : "0") + ";"; 2464 2465 case "object": 2466 if (mixed_val == null) 2467 return "N;"; 2468 else if (mixed_val instanceof Array) { 2469 var idxobj = { idx: -1 }; 2470 var map = []; 2471 for (var i=0; i < mixed_val.length; i++) { 2472 idxobj.idx++; 2473 var ser = trx_addons_serialize(mixed_val[i]); 2474 if (ser) 2475 map.push(trx_addons_serialize(idxobj.idx) + ser); 2476 } 2477 return "a:" + mixed_val.length + ":{" + map.join("") + "}"; 2478 } else { 2479 var class_name = trx_addons_get_class(mixed_val); 2480 if (class_name == undefined) 2481 return false;
2482 var props = new Array(); 2483 for (var prop in mixed_val) { 2484 var ser = trx_addons_serialize(mixed_val[prop]); 2485 if (ser) 2486 props.push(trx_addons_serialize(prop) + ser); 2487 } 2488 if (obj_to_array) 2489 return "a:" + props.length + ":{" + props.join("") + "}"; 2490 else 2491 return "O:" + class_name.length + ":\"" + class_name + "\":" + props.length + ":{" + props.join("") + "}"; 2492 } 2493 2494 case "undefined": 2495 return "N;"; 2496 } 2497 return false; 2498 }; 2499 2500 // Encode / Decode Unicode string to / from single-byte characters 2501 ( function( $ ) { 2502 var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 2503 a256 = '', 2504 r64 = [256], 2505 r256 = [256], 2506 i = 0; 2507 2508 var UTF8 = { 2509 2510 /** 2511 * Encode multi-byte Unicode string into utf-8 multiple single-byte characters 2512 * (BMP / basic multilingual plane only) 2513 * 2514 * Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 - U+FFFF in 3 chars 2515 * 2516 * @param {String} strUni Unicode string to be encoded as UTF-8 2517 * @returns {String} encoded string 2518 */ 2519 encode: function(strUni) { 2520 // use regular expressions & String.replace callback function for better efficiency than procedural approaches 2521 var strUtf = strUni 2522 .replace( 2523 /[\u0080-\u07ff]/g, // U+0080 - U+07FF => 2 bytes 110yyyyy, 10zzzzzz 2524 function(c) { 2525 var cc = c.charCodeAt(0); 2526 return String.fromCharCode(0xc0 | cc >> 6, 0x80 | cc & 0x3f); 2527 } 2528 ) 2529 .replace( 2530 /[\u0800-\uffff]/g, // U+0800 - U+FFFF => 3 bytes 1110xxxx, 10yyyyyy, 10zzzzzz 2531 function(c) { 2532 var cc = c.charCodeAt(0); 2533 return String.fromCharCode(0xe0 | cc >> 12, 0x80 | cc >> 6 & 0x3F, 0x80 | cc & 0x3f); 2534 } 2535 ); 2536 return strUtf; 2537 }, 2538 2539 /** 2540 * Decode utf-8 encoded string back into multi-byte Unicode characters 2541 * 2542 * @param {String} strUtf UTF-8 string to be decoded back to Unicode 2543 * @returns {String} decoded string 2544 */ 2545 decode: function(strUtf) { 2546 // note: decode 3-byte chars first as decoded 2-byte strings could appear to be 3-byte char! 2547 var strUni = strUtf 2548 .replace( 2549 /[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g, // 3-byte chars 2550 function(c) { // (note parentheses for precence) 2551 var cc = ((c.charCodeAt(0) & 0x0f) << 12) | ((c.charCodeAt(1) & 0x3f) << 6) | (c.charCodeAt(2) & 0x3f); 2552 return String.fromCharCode(cc); 2553 } 2554 ) 2555 .replace( 2556 /[\u00c0-\u00df][\u0080-\u00bf]/g, // 2-byte chars 2557 function(c) { // (note parentheses for precence) 2558 var cc = (c.charCodeAt(0) & 0x1f) << 6 | c.charCodeAt(1) & 0x3f; 2559 return String.fromCharCode(cc); 2560 } 2561 ); 2562 return strUni; 2563 } 2564 }; 2565 2566 while( i < 256 ) { 2567 var c = String.fromCharCode(i); 2568 a256 += c; 2569 r256[i] = i; 2570 r64[i] = b64.indexOf(c); 2571 ++i; 2572 } 2573 2574 function code(s, discard, alpha, beta, w1, w2) { 2575 s = String(s); 2576 var buffer = 0, 2577 i = 0, 2578 length = s.length, 2579 result = '', 2580 bitsInBuffer = 0; 2581 2582 while (i < length) { 2583 var c = s.charCodeAt(i); 2584 c = c < 256 ? alpha[c] : -1; 2585 2586 buffer = (buffer << w1) + c; 2587 bitsInBuffer += w1; 2588 2589 while (bitsInBuffer >= w2) { 2590 bitsInBuffer -= w2; 2591 var tmp = buffer >> bitsInBuffer; 2592 result += beta.charAt(tmp); 2593 buffer ^= tmp << bitsInBuffer; 2594 } 2595 ++i; 2596 } 2597 if ( ! discard && bitsInBuffer > 0) { 2598 result += beta.charAt(buffer << (w2 - bitsInBuffer)); 2599 } 2600 return result; 2601 } 2602 2603 var Plugin = $.trx_addons_encoder = function(dir, input, encode) { 2604 return input ? Plugin[dir](input, encode) : dir ? null : this; 2605 }; 2606 2607 Plugin.btoa = Plugin.encode = function(plain, utf8encode) { 2608 plain = Plugin.raw === false || Plugin.utf8encode || utf8encode 2609 ? UTF8.encode(plain) 2610 : plain; 2611 plain = code(plain, false, r256, b64, 8, 6); 2612 return plain + '===='.slice((plain.length % 4) || 4); 2613 }; 2614 2615 Plugin.atob = Plugin.decode = function(coded, utf8decode) { 2616 coded = String(coded).split('='); 2617 var i = coded.length; 2618 do { 2619 --i; 2620 coded[i] = code(coded[i], true, r64, a256, 6, 8); 2621 } while (i > 0); 2622 coded = coded.join(''); 2623 return Plugin.raw === false || Plugin.utf8decode || utf8decode 2624 ? UTF8.decode(coded) 2625 : coded; 2626 }; 2627 }(jQuery) ); 2628 2629 2630 /* Timing functions 2631 ---------------------------------------------------------------- */ 2632 2633 // Make a first call of the 'func' immediatelly and the second call not closer then 'wait' (in ms) 2634 window.trx_addons_debounce = function(func, wait, first_call) { 2635 var timeout; 2636 if ( first_call === undefined ) { 2637 first_call = true; 2638 } 2639 return function () { 2640 var context = this, args = arguments; 2641 var later = function later() { 2642 timeout = null;
2643 func.apply(context, args); 2644 }; 2645 var callNow = !timeout && first_call; 2646 clearTimeout(timeout); 2647 timeout = setTimeout(later, wait); 2648 if (callNow) { 2649 func.apply(context, args); 2650 } 2651 }; 2652 }; 2653 2654 // First call a 'func' must be not closer then 'wait' (in ms) after the last call 2655 // a throttled function 2656 window.trx_addons_throttle = function(func, wait, debounce) { 2657 var timeout; 2658 return function () { 2659 var context = this, args = arguments; 2660 var throttler = function () { 2661 timeout = null; 2662 func.apply(context, args); 2663 }; 2664 if (debounce) clearTimeout(timeout); 2665 if (debounce || !timeout) timeout = setTimeout(throttler, wait); 2666 }; 2667 }; 2668 2669 // Linear interpolation 2670 window.trx_addons_lerp = function(start, end, amt){ 2671 return (1 - amt) * start + amt * end; 2672 }; 2673 2674 // Change value in specified time 2675 window.trx_addons_tween_value = function( args ) { 2676 // Defaults 2677 if ( args.start == args.end ) { 2678 return null; 2679 } 2680 if ( ! args.time ) { 2681 args.time = 1; // 1s 2682 } 2683 var t = { 2684 value: args.start 2685 }; 2686 // Use TweenMax (if loaded) 2687 if ( typeof TweenMax != 'undefined' ) { 2688 return TweenMax.to( t, args.time, { 2689 overwrite: true, 2690 value: args.end, 2691 ease: args.ease ? args.ease : Power2.easeOut, 2692 onUpdate: function() { 2693 args.callbacks.onUpdate( t.value ); 2694 }, 2695 onComplete: function() { 2696 if ( args.callbacks.onComplete ) { 2697 args.callbacks.onComplete(); 2698 } 2699 } 2700 } ); 2701 // Internal tween manager 2702 } else { 2703 var amount = 0.1; 2704 var interval = Math.min( args.time * 1000 / 20, Math.max( 1, Math.round( args.time * 1000 / ( Math.abs( args.end - args.start ) / amount ) ) ) ); 2705 return setInterval( function() { 2706 t.value = trx_addons_lerp( t.value, args.end, amount ); 2707 args.callbacks.onUpdate( t.value ); 2708 if ( Math.abs(t.value - args.end) < 0.0001 ) { 2709 t.value = args.end; 2710 args.callbacks.onUpdate( t.value ); 2711 if ( args.callbacks.onComplete ) { 2712 args.callbacks.onComplete(); 2713 } 2714 } 2715 }, interval ); 2716 } 2717 }; 2718 2719 // Stop changing value 2720 window.trx_addons_tween_stop = function( handler ) { 2721 // Use TweenMax (if loaded) 2722 if ( typeof TweenMax != 'undefined' ) { 2723 if ( handler ) handler.kill(); 2724 // Internal tween manager 2725 } else { 2726 if ( handler ) clearTimeout( handler ); 2727 2728 } 2729 }; 2730 2731 2732 // jQuery animate() easings 2733 //-------------------------------------------------- 2734 ( function( $ ) { 2735 2736 // Exit if easings are already extended 2737 if ( typeof $.easing['easeInSine'] != 'undefined' ) return; 2738 2739 // Based on easing equations from Robert Penner (http://www.robertpenner.com/easing) 2740 var baseEasings = {}; 2741 $.each( [ "Quad", "Cubic", "Quart", "Quint", "Expo" ], function( i, name ) { 2742 baseEasings[ name ] = function( p ) { 2743 return Math.pow( p, i + 2 ); 2744 }; 2745 } ); 2746 2747 $.extend( baseEasings, { 2748 Sine: function( p ) { 2749 return 1 - Math.cos( p * Math.PI / 2 ); 2750 }, 2751 Circ: function( p ) { 2752 return 1 - Math.sqrt( 1 - p * p ); 2753 }, 2754 Elastic: function( p ) { 2755 return p === 0 || p === 1 ? p : -Math.pow( 2, 8 * ( p - 1 ) ) * Math.sin( ( ( p - 1 ) * 80 - 7.5 ) * Math.PI / 15 ); 2756 }, 2757 Back: function( p ) { 2758 return p * p * ( 3 * p - 2 ); 2759 }, 2760 Bounce: function( p ) { 2761 var pow2, 2762 bounce = 4; 2763 while ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {} 2764 return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 ); 2765 } 2766 } ); 2767 2768 $.each( baseEasings, function( name, easeIn ) { 2769 $.easing[ "easeIn" + name ] = easeIn; 2770 $.easing[ "easeOut" + name ] = function( p ) { 2771 return 1 - easeIn( 1 - p ); 2772 }; 2773 $.easing[ "easeInOut" + name ] = function( p ) { 2774 return p < 0.5 ? easeIn( p * 2 ) / 2 : 1 - easeIn( p * -2 + 2 ) / 2; 2775 }; 2776 } ); 2777 2778 } )( jQuery ); 2779 2780 // CSS transitions and animations listener 2781 //-------------------------------------------------- 2782 2783 // Detect a name of the event "transition end" 2784 window.trx_addons_transition_end = function() { 2785 var e = document.createElement("transitionDetector"), 2786 t = { 2787 WebkitTransition: "webkitTransitionEnd", 2788 MozTransition: "transitionend", 2789 transition: "transitionend" 2790 }, 2791 r = "transitionend"; 2792 for ( var n in t ) { 2793 if ( undefined !== e.style[n] ) { 2794 r = t[n]; 2795 break; 2796 } 2797 } 2798 return r; 2799 }; 2800 2801 // Detect a name of the event "animation end" 2802 window.trx_addons_animation_end = function() { 2803 var e = document.createElement("animationDetector"), 2804 t = { 2805 animation: "animationend", 2806 OAnimation: "oAnimationEnd", 2807 MozAnimation: "animationend", 2808 WebkitAnimation: "webkitAnimationEnd" 2809 }, 2810 r = "animationend"; 2811 for ( var n in t ) { 2812 if ( undefined !== e.style[n] ) { 2813 r = t[n]; 2814 break; 2815 } 2816 } 2817 return r; 2818 }; 2819 2820 var support = { 2821 transitions: window.Modernizr ? Modernizr.csstransitions : false, 2822 animations: window.Modernizr ? Modernizr.cssanimations : false 2823 }, 2824 trans_end_event_names = { 'WebkitTransition': 'webkitTransitionEnd', 'MozTransition': 'transitionend', 'OTransition': 'oTransitionEnd', 'msTransition': 'MSTransitionEnd', 'transition': 'transitionend' }, 2825 trans_end_event_name = window.Modernizr ? trans_end_event_names[ Modernizr.prefixed( 'transition' ) ] : trx_addons_transition_end(), 2826 anima_end_event_names = { 'WebkitAnimation': 'webkitAnimationEnd', 'MozAnimation': 'animationend', 'OAnimation': 'oAnimationEnd', 'msAnimation': 'MSAnimationEnd', 'animation': 'animationend' }, 2827 anima_end_event_name = window.Modernizr ? anima_end_event_names[ Modernizr.prefixed( 'animation' ) ] : trx_addons_animation_end(); 2828 2829 window.trx_addons_on_end_transition = function( el, callback, timeout ) { 2830 var on_end_callback = function( e ) { 2831 if ( support.transitions ) { 2832 if ( e.target != this ) { 2833 return; 2834 } 2835 this.removeEventListener( trans_end_event_name, on_end_callback ); 2836 } 2837 if ( callback && typeof callback === 'function' ) { 2838 callback.call( this ); 2839 } 2840 }; 2841 if ( support.transitions ) { 2842 el.addEventListener( trans_end_event_name, on_end_callback, false ); 2843 } else { 2844 setTimeout( function() { 2845 if ( callback && typeof callback === 'function' ) { 2846 callback.call( this ); 2847 } 2848 }, timeout || 0 ); 2849 } 2850 }; 2851 2852 window.trx_addons_on_end_animation = function( el, callback, timeout ) { 2853 var on_end_callback = function( e ) { 2854 if ( support.animations ) { 2855 if ( e.target != this ) { 2856 return; 2857 } 2858 this.removeEventListener( anima_end_event_name, on_end_callback ); 2859 } 2860 if ( callback && typeof callback === 'function' ) { 2861 callback.call( this ); 2862 } 2863 }; 2864 if ( support.animations ) { 2865 el.addEventListener( anima_end_event_name, on_end_callback, false ); 2866 } else { 2867 setTimeout( function() { 2868 if ( callback && typeof callback === 'function' ) { 2869 callback.call( this ); 2870 } 2871 }, timeout || 0 ); 2872 } 2873 }; 2874 2875 2876 /* Mutation observers 2877 ---------------------------------------------------------------- */ 2878 var trx_addons_observers = {}; 2879 2880 // Create mutations observer 2881 window.trx_addons_create_observer = function( id, obj, callback, args ) { 2882 if ( typeof window.MutationObserver !== 'undefined' && obj && obj.length ) { 2883 if ( typeof trx_addons_observers[ id ] == 'undefined' ) { 2884 var defa = { 2885 attributes: false, 2886 childList: true, 2887 subtree: true 2888 }; 2889 if ( args ) { 2890 defa = trx_addons_object_merge( defa, args ); 2891 } 2892 trx_addons_observers[ id ] = { 2893 observer: new MutationObserver( callback ), 2894 obj: obj.get(0) 2895 }; 2896 trx_addons_observers[ id ].observer.observe( trx_addons_observers[ id ].obj, defa ); 2897 } 2898 return true; 2899 } 2900 return false;
2901 }; 2902 2903 // Remove mutations observer 2904 window.trx_addons_remove_observer = function( id ) { 2905 if ( typeof window.MutationObserver !== 'undefined' ) { 2906 if ( typeof trx_addons_observers[ id ] !== 'undefined' ) { 2907 trx_addons_observers[ id ].observer.disconnect( 2908// trx_addons_observers[ id ].obj 2909 ); 2910 delete trx_addons_observers[ id ]; 2911 } 2912 return true; 2913 } 2914 return false; 2915 }; 2916 2917 // Check mutations for selector 2918 window.trx_addons_check_mutations = function( mutations, selector, action ) { 2919 var rez = false; 2920 if ( typeof mutations != 'object' || ! mutations.hasOwnProperty( 'length' ) || ! mutations.length ) { 2921 return rez; 2922 } 2923 var nodes = false; 2924 for ( var i = 0; i < mutations.length; i++ ) { 2925 nodes = action == 'add' ? mutations[i].addedNodes : mutations[i].removedNodes; 2926 for ( var n = 0; n < nodes.length; n++ ) { 2927 var $node = jQuery( nodes[n] ); 2928 if ( selector.charAt(0) == '.' && $node.hasClass( selector.slice( 1 ) ) 2929 || selector.charAt(0) == '#' && $node.attr( 'id' ) == selector.slice( 1 ) 2930 ) { 2931 rez = true; 2932 break; 2933 } 2934 } 2935 if ( rez ) break; 2936 } 2937 return rez; 2938 }; 2939 2940 2941 /* Sticky observers 2942 ---------------------------------------------------------------- */ 2943 var trx_addons_sticky_observers = {}; 2944 2945 // Create sticky observer 2946 window.trx_addons_sticky_observer_create = function( id, obj, callback, args ) { 2947 if ( typeof window.IntersectionObserver !== 'undefined' && obj && obj.length ) { 2948 if ( typeof trx_addons_sticky_observers[ id ] == 'undefined' ) { 2949 var defa = { 2950 root: null, 2951 rootMargin: ( 1 + trx_addons_fixed_rows_height() ) + 'px 0px 0px 0px', 2952 threshold: 1 //[1] 2953 2954 }; 2955 if ( args ) { 2956 defa = trx_addons_object_merge( defa, args ); 2957 } 2958 trx_addons_sticky_observers[ id ] = { 2959 observer: new IntersectionObserver( function( entries ) { 2960 entries.forEach( function( entry ) { 2961 var is_sticky = entry.isIntersecting && entry.intersectionRatio >= 1; 2962 jQuery( entry.target ).toggleClass( 'trx_addons_is_sticky', is_sticky ); 2963 if ( callback && typeof callback === 'function' ) { 2964 callback( entry, is_sticky ); 2965 } 2966 } ); 2967 }, defa ), 2968 obj: obj.get(0) 2969 }; 2970 trx_addons_sticky_observers[ id ].observer.observe( trx_addons_sticky_observers[ id ].obj ); 2971 } 2972 return true; 2973 } 2974 return false; 2975 }; 2976 2977 window.trx_addons_sticky_observer_remove = function( id ) { 2978 if ( typeof window.IntersectionObserver !== 'undefined' ) { 2979 if ( typeof trx_addons_sticky_observers[ id ] !== 'undefined' ) { 2980 // trx_addons_sticky_observers[ id ].observer.unobserve( trx_addons_sticky_observers[ id ].obj ); 2981 trx_addons_sticky_observers[ id ].observer.disconnect(); 2982 delete trx_addons_sticky_observers[ id ]; 2983 } 2984 return true; 2985 } 2986 return false; 2987 }; 2988 2989 2990 /* Wordpress-style functions 2991 Attention! wp.hooks available only in the admin area 2992 ---------------------------------------------------------------- */ 2993 2994 var filters = {}; 2995 var allow_wp_filters = true; 2996 2997 // Add filter's handler 2998 window.trx_addons_add_filter = function( filter, callback, priority ) { 2999 if ( priority === undefined ) priority = 10; 3000 if ( allow_wp_filters && typeof wp != 'undefined' && typeof wp.hooks != 'undefined' && typeof wp.hooks.addFilter != 'undefined' ) { 3001 wp.hooks.addFilter( filter, 'trx_addons', callback, priority ); 3002 } else { 3003 if ( ! filters[filter] ) filters[filter] = {}; 3004 if ( ! filters[filter][priority] ) filters[filter][priority] = []; 3005 filters[filter][priority].push( callback ); 3006 } 3007 }; 3008 3009 // Apply filter's handlers 3010 window.trx_addons_apply_filters = function( filter, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ) { 3011 if ( allow_wp_filters && typeof wp != 'undefined' && typeof wp.hooks != 'undefined' && typeof wp.hooks.applyFilters != 'undefined' ) { 3012 arg1 = wp.hooks.applyFilters( filter, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); 3013 } else if ( typeof filters[filter] == 'object' ) { 3014 var keys = Object.keys(filters[filter]).sort(); 3015 for (var i=0; i < keys.length; i++ ) { 3016 for (var j=0; j < filters[filter][keys[i]].length; j++ ) { 3017 if ( typeof filters[filter][keys[i]][j] == 'function' ) { 3018 arg1 = filters[filter][keys[i]][j](arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); 3019 } 3020 } 3021 } 3022 } 3023 return arg1; 3024 }; 3025 3026 // Add action's handler 3027 window.trx_addons_add_action = function( action, callback, priority ) { 3028 if ( allow_wp_filters && typeof wp != 'undefined' && typeof wp.hooks != 'undefined' && typeof wp.hooks.addAction != 'undefined' ) { 3029 wp.hooks.addAction( action, 'trx_addons', callback, priority == undefined ? 10 : priority ); 3030 } else { 3031 trx_addons_add_filter( action, callback, priority ); 3032 } 3033 }; 3034 3035 // Do action's handlers 3036 window.trx_addons_do_action = function( action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ) { 3037 if ( allow_wp_filters && typeof wp != 'undefined' && typeof wp.hooks != 'undefined' && typeof wp.hooks.doAction != 'undefined' ) { 3038 wp.hooks.doAction( action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); 3039 } else { 3040 trx_addons_apply_filters( action, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); 3041 } 3042 }; 3043 3044})();
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.