1 2/*jshint esversion: 6 */ 3( function( window ) { 4 'use strict'; 5 6 var isNumber = function( str ) { 7 return String( str ).isNumeric() && ! String( str ).startsWith( '0' ); 8 }; 9 10 var empty = function( mixedVar ) { 11 var undef; 12 var key; 13 var i; 14 var len; 15 var emptyValues = [ undef, null, false, 0, '', '0' ]; 16 for ( i = 0, len = emptyValues.length; i < len; i++ ) { 17 if ( mixedVar === emptyValues[ i ] ) { 18 return true; 19 } 20 } 21 if ( typeof mixedVar === 'object' ) { 22 for ( key in mixedVar ) { 23 if ( mixedVar.hasOwnProperty( key ) ) { 24 return false; 25 } 26 } 27 return true; 28 } 29 return false; 30 }; 31 32 var array_key_exists = function( key, search ) { 33 if ( ! search || ( search.constructor !== Array && search.constructor !== Object ) ) { 34 return false; 35 } 36 return key in search; 37 }; 38 39 var getNumberOfParameters = function( func ) { 40 const ARROW = true; 41 const FUNC_ARGS = ARROW ? /^(function)?\s*[^\(]*\(\s*([^\)]*)\)/m : /^(function)\s*[^\(]*\(\s*([^\)]*)\)/m; 42 const FUNC_ARG_SPLIT = /,/; 43 const FUNC_ARG = /^\s*(_?)(.+?)\1\s*$/; 44 const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; 45 46 return ( ( func || '' ) 47 .toString() 48 .replace( STRIP_COMMENTS, '' ) 49 .match( FUNC_ARGS ) || [ '', '', '' ] )[ 2 ] 50 .split( FUNC_ARG_SPLIT ) 51 .map( function( arg ) { 52 return arg.replace( FUNC_ARG, function( all, underscore, name ) { 53 return name.split( '=' )[ 0 ].trim(); 54 } ); 55 } ) 56 .filter( String ) 57 .length; 58 }; 59 60 var getNumberOfRequiredParameters = function( func ) { 61 return func.length; 62 }; 63 64 var is_scalar = function( mixedVar ) { 65 return ( /boolean|number|string/ ).test( typeof mixedVar ); 66 }; 67 68 var gettype = function( obj ) { 69 return window.jQuery.epoAPI.util.getType( obj ); 70 }; 71 72 var floatval = function( s, d ) { 73 var n; 74 75 if ( ! ( typeof s === 'string' || typeof s === 'number' ) || isNaN( s ) ) { 76 if ( d !== undefined ) { 77 return d; 78 } 79 return 0; 80 } 81 n = parseFloat( s ); 82 if ( isNaN( n ) ) { 83 if ( d !== undefined ) { 84 return d; 85 } 86 return s; 87 } 88 89 return n; 90 }; 91 92 var strcmp = function( str1, str2 ) { 93 return ( ( str1 === str2 ) ? 0 : ( ( str1 > str2 ) ? 1 : -1 ) ); 94 }; 95 96 var bindec = function( binaryString ) { 97 binaryString = ( binaryString + '' ).replace( /[^01]/gi, '' ); 98 return parseInt( binaryString, 2 ); 99 }; 100 101 var decbin = function( number ) { 102 if ( number < 0 ) { 103 number = 0xFFFFFFFF + number + 1; 104 } 105 return parseInt( number, 10 ).toString( 2 ); 106 }; 107 108 var dechex = function( number ) { 109 if ( number < 0 ) { 110 number = 0xFFFFFFFF + number + 1; 111 } 112 return parseInt( number, 10 ).toString( 16 ); 113 }; 114 115 var decoct = function( number ) { 116 if ( number < 0 ) { 117 number = 0xFFFFFFFF + number + 1; 118 } 119 return parseInt( number, 10 ).toString( 8 ); 120 }; 121 122 var deg2rad = function( angle ) { 123 return angle * 0.017453292519943295; // (angle / 180) * Math.PI; 124 }; 125 126 var roundWithPrecision = function( num, dec = 0 ) { 127 var num_sign = num >= 0 ? 1 : -1; 128 return dec === 0 ? Math.round( num ) : parseFloat( ( Math.round( ( num * Math.pow( 10, dec ) ) + ( num_sign * 0.0001 ) ) / Math.pow( 10, dec ) ).toFixed( dec ) ); 129 }; 130 131 var hexdec = function( hexString ) { 132 hexString = ( hexString + '' ).replace( /[^a-f0-9]/gi, '' ); 133 return parseInt( hexString, 16 ); 134 }; 135 136 var octdec = function( octString ) { 137 octString = ( octString + '' ).replace( /[^0-7]/gi, '' ); 138 return parseInt( octString, 8 ); 139 }; 140 141 var hypot = function( x, y ) { 142 var t; 143 x = Math.abs( x ); 144 y = Math.abs( y ); 145 t = Math.min( x, y ); 146 x = Math.max( x, y ); 147 t = t / x; 148 return x * Math.sqrt( 1 + ( t * t ) ) || null; 149 }; 150 151 var THEMECOMPLETE_EPO_MATH = { 152 variables: {}, 153 on_var_not_found: undefined,
154 on_var_validation: undefined, 155 operators: {}, 156 functions: {}, 157 cache: {}, 158 construct: function() { 159 this.add_defaults(); 160 this.set_division_by_zero_to_zero(); 161 return this; 162 }, 163 add_operator: function( $operator ) { 164 this.operators[ $operator.operator ] = $operator; 165 return this; 166 }, 167 evaluate: function( $expression, $cache = true ) { 168 return this.execute( $expression, $cache ); 169 }, 170 parse: function( $expression ) { 171 var $tokens; 172 var result; 173 var $calculator; 174 var count = 0; 175 var char; 176 177 for ( char of $expression ) { 178 if ( char === '(' ) { 179 count++; 180 } else if ( char === ')' ) { 181 count--; 182 } 183 184 // If count becomes negative at any point, return false 185 if ( count < 0 ) { 186 return false; 187 } 188 } 189 190 // If count is not zero at the end, parentheses are not balanced 191 if ( count !== 0 ) { 192 return false; 193 } 194 195 $tokens = new THEMECOMPLETE_EPO_MATH_Tokenizer( $expression, this.operators ); 196 $tokens = $tokens.tokenize().build_reverse_polish_notation(); 197 $calculator = new THEMECOMPLETE_EPO_MATH_Calculator( this.functions, this.operators ); 198 199 result = $calculator.calculate( $tokens, this.variables, this.on_var_not_found, this ); 200 if ( 'number' !== gettype( result ) || isNaN( result ) ) { 201 return false; 202 } 203 return result; 204 }, 205 execute: function( $expression, $cache = true, $canreturnstring = false ) { 206 var $cache_key = $expression; 207 var $calculator; 208 var $tokens; 209 var result; 210 211 if ( ! array_key_exists( $cache_key, this.cache ) ) { 212 $tokens = new THEMECOMPLETE_EPO_MATH_Tokenizer( $expression, this.operators ); 213 $tokens = $tokens.tokenize().build_reverse_polish_notation(); 214 if ( $cache ) { 215 this.cache[ $cache_key ] = $tokens; 216 } 217 } else { 218 $tokens = this.cache[ $cache_key ]; 219 } 220 221 $calculator = new THEMECOMPLETE_EPO_MATH_Calculator( this.functions, this.operators ); 222 223 result = $calculator.calculate( $tokens, this.variables, this.on_var_not_found, this ); 224 225 if ( false === $canreturnstring && ( 'number' !== gettype( result ) || isNaN( result ) ) ) { 226 result = 0; 227 } 228 229 return result; 230 }, 231 add_function: function( $name, $function ) { 232 this.functions[ $name ] = new THEMECOMPLETE_EPO_MATH_CustomFunction( $name, $function ); 233 return this; 234 }, 235 get_vars: function() { 236 return this.variables; 237 }, 238 get_var: function( $variable ) { 239 if ( ! array_key_exists( $variable, this.variables ) ) { 240 if ( this.on_var_not_found && 'function' === typeof this.on_var_not_found ) { 241 this.on_var_not_found( $variable ); 242 } 243 return THEMECOMPLETE_EPO_MATH_Error.trigger( 'Variable (' + $variable + ') not set', 'UnknownVariableError', 0 ); 244 } 245 return this.variables[ $variable ]; 246 }, 247 set_var: function( $variable, $value ) {
248 if ( this.on_var_validation && 'function' === typeof this.on_var_validation ) { 249 $value = this.on_var_validation( $variable, $value ); 250 } 251 this.variables[ $variable ] = $value; 252 return this; 253 }, 254 var_exists: function( $variable ) { 255 return array_key_exists( $variable, this.variables ); 256 }, 257 set_vars: function( $variables, $clear = true ) { 258 var $this = this; 259 if ( $clear ) { 260 this.remove_vars(); 261 } 262 $variables.forFach( function( $value, $name ) { 263 $this.set_var( $name, $value ); 264 } ); 265 return this; 266 }, 267 set_var_not_found_handler: function( $handler ) { 268 this.on_var_not_found = $handler; 269 return this; 270 }, 271 set_var_validation_handler: function( $handler ) { 272 this.on_var_validation = $handler; 273 return this; 274 }, 275 remove_var: function( $variable ) { 276 delete this.variables[ $variable ]; 277 return this; 278 }, 279 remove_vars: function() { 280 this.variables = {}; 281 this.on_var_not_found = null; 282 return this; 283 }, 284 get_operators: function() { 285 return this.operators; 286 }, 287 get_functions: function() { 288 return this.functions; 289 }, 290 remove_operator: function( $operator ) { 291 delete this.operators[ $operator ]; 292 }, 293 set_division_by_zero_to_zero: function() { 294 this.add_operator( 295 new THEMECOMPLETE_EPO_MATH_Operator( 296 '/', 297 false, 298 180, 299 function( $a, $b ) { 300 $a = Number( $a ); 301 $b = Number( $b ); 302 return 0 == $b ? 0 : $a / $b; // eslint-disable-line eqeqeq 303 } 304 ) 305 ); 306 return this; 307 }, 308 get_cache: function() { 309 return this.cache; 310 }, 311 clear_cache: function() { 312 this.cache = []; 313 }, 314 add_defaults: function() { 315 var $this = this; 316 var default_operators = this.default_operators(); 317 var default_functions = this.default_functions(); 318 Object.keys( default_operators ).forEach( function( $name ) { 319 var $operator = default_operators[ $name ]; 320 $this.add_operator( new THEMECOMPLETE_EPO_MATH_Operator( $name, $operator[ 2 ], $operator[ 1 ], $operator[ 0 ] ) ); 321 } ); 322 Object.keys( default_functions ).forEach( function( $name ) { 323 var $callable = default_functions[ $name ]; 324 $this.add_function( $name, $callable ); 325 } );
326 this.on_var_validation = this.default_var_validation; 327 this.variables = this.default_vars(); 328 return this; 329 }, 330 default_operators: function() { 331 return { 332 '+': [ 333 function( $a, $b ) { 334 $a = floatval( $a, 0 ); 335 $b = floatval( $b, 0 ); 336 return $a + $b; 337 }, 338 170, 339 false 340 ], 341 '-': [ 342 function( $a, $b ) { 343 $a = floatval( $a, 0 ); 344 $b = floatval( $b, 0 ); 345 return $a - $b; 346 }, 347 170, 348 false 349 ], 350 // unary positive token. 351 uPos: [ 352 function( $a ) { 353 $a = floatval( $a, 0 ); 354 return $a; 355 }, 356 200, 357 false 358 ], 359 // unary minus token. 360 uNeg: [ 361 function( $a ) { 362 $a = floatval( $a, 0 ); 363 return 0 - $a; 364 }, 365 200, 366 false 367 ], 368 '*': [ 369 function( $a, $b ) { 370 $a = floatval( $a, 0 ); 371 $b = floatval( $b, 0 ); 372 return $a * $b; 373 }, 374 180, 375 false 376 ], 377 '/': [ 378 function( $a, $b ) { 379 $a = floatval( $a, 0 ); 380 $b = floatval( $b, 0 ); 381 if ( empty( $b ) ) { 382 return THEMECOMPLETE_EPO_MATH_Error.trigger( 'Division By Zero', 'DivisionByZeroError', 0 ); 383 } 384 return $a / $b; 385 }, 386 180, 387 false 388 ], 389 '^': [ 390 function( $a, $b ) { 391 $a = floatval( $a, 0 ); 392 $b = floatval( $b, 0 ); 393 return Math.pow( $a, $b ); 394 }, 395 220, 396 true 397 ], 398 '%': [ 399 function( $a, $b ) { 400 $a = floatval( $a, 0 ); 401 $b = floatval( $b, 0 ); 402 return $a % $b; 403 }, 404 180, 405 false 406 ], 407 '&&': [ 408 function( $a, $b ) { 409 $a = String( $a ); 410 $b = String( $b ); 411 if ( $a.isNumeric() ) { 412 $a = floatval( $a, 0 ); 413 } 414 if ( $b.isNumeric() ) { 415 $b = floatval( $b, 0 ); 416 } 417 return $a && $b ? 1 : 0; 418 }, 419 100, 420 false 421 ], 422 '||': [ 423 function( $a, $b ) { 424 $a = String( $a ); 425 $b = String( $b ); 426 if ( $a.isNumeric() ) { 427 $a = floatval( $a, 0 ); 428 } 429 if ( $b.isNumeric() ) { 430 $b = floatval( $b, 0 ); 431 } 432 return $a || $b ? 1 : 0; 433 }, 434 90, 435 false 436 ], 437 '==': [ 438 function( $a, $b ) { 439 $a = String( $a ); 440 $b = String( $b ); 441 if ( $a.isNumeric() && $b.isNumeric() ) { 442 return floatval( $a ) === floatval( $b ) ? 1 : 0; 443 } 444 return 0 === strcmp( $a, $b ) ? 1 : 0; 445 }, 446 140, 447 false 448 ], 449 '!=': [ 450 function( $a, $b ) { 451 $a = String( $a ); 452 $b = String( $b ); 453 if ( $a.isNumeric() && $b.isNumeric() ) { 454 return floatval( $a ) !== floatval( $b ) ? 1 : 0; 455 } 456 return 0 !== strcmp( $a, $b ) ? 1 : 0; 457 }, 458 140, 459 false 460 ], 461 '>=': [ 462 function( $a, $b ) { 463 $a = String( $a ); 464 $b = String( $b ); 465 if ( $a.isNumeric() ) { 466 $a = floatval( $a, 0 ); 467 } 468 if ( $b.isNumeric() ) { 469 $b = floatval( $b, 0 ); 470 } 471 return $a >= $b ? 1 : 0; 472 }, 473 150, 474 false 475 ], 476 '>': [ 477 function( $a, $b ) { 478 $a = String( $a ); 479 $b = String( $b ); 480 if ( $a.isNumeric() ) { 481 $a = floatval( $a, 0 ); 482 } 483 if ( $b.isNumeric() ) { 484 $b = floatval( $b, 0 ); 485 } 486 return $a > $b ? 1 : 0; 487 }, 488 150, 489 false 490 ], 491 '<=': [ 492 function( $a, $b ) { 493 $a = String( $a ); 494 $b = String( $b ); 495 if ( $a.isNumeric() ) { 496 $a = floatval( $a, 0 ); 497 } 498 if ( $b.isNumeric() ) { 499 $b = floatval( $b, 0 ); 500 } 501 return $a <= $b ? 1 : 0; 502 }, 503 150, 504 false 505 ], 506 '<': [ 507 function( $a, $b ) { 508 $a = String( $a ); 509 $b = String( $b ); 510 if ( $a.isNumeric() ) { 511 $a = floatval( $a, 0 ); 512 } 513 if ( $b.isNumeric() ) { 514 $b = floatval( $b, 0 ); 515 } 516 return $a < $b ? 1 : 0; 517 }, 518 150, 519 false 520 ] 521 }; 522 }, 523 default_functions: function() { 524 var $this = this; 525 return { 526 abs: Math.abs, 527 acos: Math.acos, 528 acosh: Math.acosh, 529 arcsin: Math.asin, 530 arcctg: function( $arg ) { 531 return ( Math.PI / 2 ) - Math.atan( $arg ); 532 }, 533 arccot: function( $arg ) { 534 return ( Math.PI / 2 ) - Math.atan( $arg ); 535 }, 536 arccotan: function( $arg ) { 537 return ( Math.PI / 2 ) - Math.atan( $arg ); 538 }, 539 arcsec: function( $arg ) { 540 return Math.acos( 1 / $arg ); 541 }, 542 arccosec: function( $arg ) { 543 return Math.asin( 1 / $arg ); 544 }, 545 arccsc: function( $arg ) { 546 return Math.asin( 1 / $arg ); 547 }, 548 arccos: Math.acos, 549 arctan: Math.atan, 550 arctg: Math.atan, 551 array: function( ...$args ) { 552 return $args; 553 }, 554 asin: Math.asin, 555 atan: Math.atan, 556 atan2: Math.atan2, 557 atanh: Math.atanh, 558 atn: Math.atan, 559 560 avg: function( $arg1, ...$args ) { 561 var sum; 562 if ( Array.isArray( $arg1 ) ) { 563 if ( 0 === $arg1.length ) { 564 return THEMECOMPLETE_EPO_MATH_Error.trigger( 'Array must contain at least one element!', 'InvalidArgumentError', 0 ); 565 } 566 } 567 $args = [].concat.apply( [], [ $arg1, ...$args ] ); 568 569 sum = $args.reduce( function( previousValue, currentValue ) { 570 return floatval( currentValue, 0 ) + floatval( previousValue, 0 ); 571 } ); 572 return sum / $args.length; 573 }, 574 average: function( $arg1, ...$args ) { 575 var sum; 576 if ( Array.isArray( $arg1 ) ) { 577 if ( 0 === $arg1.length ) { 578 return THEMECOMPLETE_EPO_MATH_Error.trigger( 'Array must contain at least one element!', 'InvalidArgumentError', 0 ); 579 } 580 } 581 $args = [].concat.apply( [], [ $arg1, ...$args ] ); 582 583 sum = $args.reduce( function( previousValue, currentValue ) { 584 return floatval( currentValue, 0 ) + floatval( previousValue, 0 ); 585 } ); 586 return sum / $args.length; 587 }, 588 bindec: bindec, 589 ceil: Math.ceil, 590 cos: Math.cos, 591 cosec: function( $arg ) { 592 return Math.sin( 1 / $arg ); 593 }, 594 csc: function( $arg ) { 595 return Math.sin( 1 / $arg ); 596 }, 597 cosh: Math.cosh, 598 ctg: function( $arg ) { 599 return Math.cos( $arg ) / Math.sin( $arg ); 600 }, 601 cot: function( $arg ) { 602 return Math.cos( $arg ) / Math.sin( $arg ); 603 }, 604 cotan: function( $arg ) { 605 return Math.cos( $arg ) / Math.sin( $arg ); 606 }, 607 cotg: function( $arg ) { 608 return Math.cos( $arg ) / Math.sin( $arg ); 609 }, 610 ctn: function( $arg ) { 611 return Math.cos( $arg ) / Math.sin( $arg ); 612 }, 613 decbin: decbin, 614 dechex: dechex, 615 decoct: decoct, 616 deg2rad: deg2rad, 617 exp: Math.exp, 618 expm1: Math.expm1, 619 floor: Math.floor, 620 int: Math.floor, 621 fmod: function( $arg1, $arg2 ) { 622 return $arg1 % $arg2; 623 }, 624 hexdec: hexdec, 625 hypot: hypot, 626 if: function( ...$args ) { 627 var $exres; 628 var $expr; 629 var $trueval; 630 var $falseval; 631 var $canreturnstring; 632 $expr = $args[ 0 ]; 633 $trueval = $args[ 1 ]; 634 $falseval = $args[ 2 ]; 635 if ( 'string' === gettype( $trueval ) ) { 636 $trueval = "'" + $trueval.replace( /'/g, "\\'" ) + "'"; 637 }
638 if ( 'string' === gettype( $falseval ) ) { 639 $falseval = "'" + $falseval.replace( /'/g, "\\'" ) + "'"; 640 } 641 $canreturnstring = $args[ 3 ] !== undefined ? $args[ 3 ] : false; 642 if ( 0 === $expr || 1 === $expr || true === $expr || false === $expr ) { 643 $exres = $expr; 644 } else { 645 $exres = $this.execute( $expr, true, $canreturnstring ); 646 } 647 if ( $exres ) { 648 return $this.execute( $trueval, true, $canreturnstring ); 649 } 650 return $this.execute( $falseval, true, $canreturnstring ); 651 }, 652 intdiv: function( $arg1, $arg2 ) { 653 return Math.trunc( Math.trunc( $arg1 ) / Math.trunc( $arg2 ) ); 654 }, 655 ln: Math.log, 656 lg: Math.log10, 657 log: Math.log, 658 log1p: Math.log1p, 659 max: function( $arg1, ...$args ) { 660 var $array; 661 if ( Array.isArray( $arg1 ) && 0 === $arg1.length ) { 662 return THEMECOMPLETE_EPO_MATH_Error.trigger( 'Array must contain at least one element!', 'InvalidArgumentError', 0 ); 663 } 664 $array = Array.isArray( $arg1 ) ? $arg1 : [ $arg1, ...$args ]; 665 $array = $array.map( floatval ); 666 667 return Math.max( ...$array ); 668 }, 669 min: function( $arg1, ...$args ) { 670 var $array; 671 if ( Array.isArray( $arg1 ) && 0 === $arg1.length ) { 672 return THEMECOMPLETE_EPO_MATH_Error.trigger( 'Array must contain at least one element!', 'InvalidArgumentError', 0 ); 673 } 674 $array = Array.isArray( $arg1 ) ? $arg1 : [ $arg1, ...$args ]; 675 $array = $array.map( floatval ); 676 677 return Math.min( ...$array ); 678 }, 679 octdec: octdec, 680 pi: function() { 681 return Math.PI; 682 }, 683 pow: Math.pow, 684 rad2deg: function( angle ) { 685 return angle * 57.29577951308232; // angle / Math.PI * 180 686 }, 687 round: roundWithPrecision, 688 sin: Math.sin, 689 sinh: Math.sinh, 690 sec: function( $arg ) { 691 return 1 / Math.cos( $arg ); 692 }, 693 sqrt: Math.sqrt, 694 tan: Math.tan, 695 tanh: Math.tanh, 696 tn: Math.tan, 697 tg: Math.tan, 698 lookuptable: function( field, lookupTableId ) { 699 var lookupTables; 700 var x; 701 var y; 702 var table; 703 var xColumn; 704 var price = 0; 705 var tableNum = 0; 706 var TMEPOJS = window.TMEPOJS; 707 708 if ( TMEPOJS ) { 709 lookupTables = window.jQuery.epoAPI.util.parseJSON( TMEPOJS.lookupTables ); 710 if ( lookupTables ) { 711 if ( Array.isArray( lookupTableId ) ) { 712 tableNum = lookupTableId[ 1 ]; 713 lookupTableId = lookupTableId[ 0 ]; 714 } 715 if ( empty( lookupTableId ) ) { 716 return 0; 717 } 718 if ( empty( tableNum ) ) { 719 tableNum = 0; 720 } 721 if ( Array.isArray( field ) ) { 722 x = String( field[ 0 ] ); 723 y = String( field[ 1 ] ); 724 } else { 725 x = String( field ); 726 y = ''; 727 } 728 729 table = lookupTables[ lookupTableId ]; 730 if ( table ) { 731 table = table[ tableNum ]; 732 if ( table ) { 733 table = table.data; 734 xColumn = table[ x ]; 735 if ( xColumn === undefined && x && x !== undefined ) { 736 if ( x.isNumeric() && floatval( x ) === 0 ) { 737 xColumn = table[ Object.keys( table )[ 0 ] ]; 738 } else if ( x ) { 739 x = $this.find_lookup_table_index( x, table ); 740 xColumn = table[ x ]; 741 } 742 } 743 if ( xColumn !== undefined ) { 744 if ( y && y !== undefined ) { 745 y = $this.find_lookup_table_index( y, xColumn ); 746 } else { 747 // fetch the first row since this means we want 748 // a single row result 749 y = Object.keys( xColumn )[ 0 ]; 750 } 751 if ( y === 'max' ) { 752 price = floatval( xColumn[ Object.keys( xColumn )[ Object.keys( xColumn ).length - 1 ] ] ); 753 } else { 754 price = floatval( xColumn[ y ] ); 755 } 756 } 757 } 758 } 759 } 760 } 761 return price; 762 }, 763 concat: function( $arg1, ...$args ) { 764 var $array; 765 if ( Array.isArray( $arg1 ) && 0 === $arg1.length ) { 766 return THEMECOMPLETE_EPO_MATH_Error.trigger( 'Array must contain at least one element!', 'InvalidArgumentError', 0 ); 767 } 768 $array = Array.isArray( $arg1 ) ? $arg1 : [ $arg1, ...$args ]; 769 770 return $array.join( '' ); 771 } 772 }; 773 }, 774 find_lookup_table_index: function( value, table ) { 775 var r; 776 var keys = Object.keys( table ); 777 var hasNumericValuesOrMaxLast = function( arr ) { 778 var lastElement = arr[ arr.length - 1 ]; 779 var areAllNumericValues = arr.every( function( val ) { 780 return String( val ).isNumeric(); 781 } ); 782 return areAllNumericValues || lastElement === 'max'; 783 }; 784 785 if ( hasNumericValuesOrMaxLast( keys ) ) { 786 value = isNumber( value ) ? floatval( value ) : value; 787 r = keys.map( function( n ) { 788 return isNumber( n ) ? floatval( n ) : n; 789 } ).reduce( function( a, b ) { 790 if ( b === 'max' && value > a ) { 791 return b; 792 } 793 if ( a === 'max' && value > b ) { 794 return a; 795 } 796 if ( a < b ) { 797 if ( value > a && value <= b ) { 798 return b; 799 } 800 } else { 801 if ( ( value > b && value <= a ) || ( value > a || b === 'max' ) ) { 802 return a; 803 } 804 return b; 805 } 806 if ( value > b ) { 807 return b; 808 } 809 return a; 810 } ); 811 keys = keys.map( function( n ) { 812 return isNumber( n ) ? floatval( n ) : n; 813 } ); 814 815 if ( value > Math.max( ...keys ) || value < Math.min( ...keys ) ) { 816 return false;
817 } 818 } else { 819 r = value; 820 } 821 822 return r; 823 }, 824 default_vars: function() { 825 return { 826 pi: 3.141592653589793, 827 e: 2.718281828459045 828 }; 829 }, 830 default_var_validation: function( $variable, $value ) { 831 if ( ! is_scalar( $value ) && ! Array.isArray( $value ) && undefined !== $value ) { 832 return THEMECOMPLETE_EPO_MATH_Error.trigger( 'Variable (' + $variable + ') type (' + gettype( $value ) + ') is not scalar or array!', 0 ); 833 } 834 return $value; 835 } 836 }; 837 838 var THEMECOMPLETE_EPO_MATH_Tokenizer = function( $input, $operators ) { 839 var node = { 840 tokens: [], 841 input: '', 842 operators: {}, 843 number_buffer: '', 844 string_buffer: '', 845 allow_negative: true, 846 in_single_quoted_string: false, 847 in_double_quoted_string: false, 848 is_number: function( ch ) { 849 return ch >= '0' && ch <= '9'; 850 }, 851 is_alpha: function( ch ) { 852 return ( ch >= 'a' && ch <= 'z' ) || ( ch >= 'A' && ch <= 'Z' ) || '_' === ch; 853 }, 854 is_dot: function( ch ) { 855 return '.' === ch; 856 }, 857 is_lp: function( ch ) { 858 return '(' === ch; 859 }, 860 is_rp: function( ch ) { 861 return ')' === ch; 862 }, 863 is_comma: function( ch ) { 864 return ',' === ch; 865 }, 866 empty_number_buffer_as_literal: function() { 867 if ( this.number_buffer.length ) { 868 this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.LITERAL, this.number_buffer ) ); 869 this.number_buffer = ''; 870 } 871 }, 872 empty_str_buffer_as_variable: function() { 873 if ( '' !== this.string_buffer ) { 874 this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.VARIABLE, this.string_buffer ) ); 875 this.string_buffer = ''; 876 } 877 }, 878 tokenize: function() { 879 var is_last_char_escape = false;
880 var $this = this; 881 var $token_test = []; 882 883 this.tokens = []; 884 885 this.input.toString().split( '' ).forEach( function( ch ) { 886 switch ( true ) { 887 case $this.in_single_quoted_string: 888 if ( '\\' === ch ) { 889 if ( is_last_char_escape ) { 890 $this.string_buffer += '\\'; 891 is_last_char_escape = false; 892 } else { 893 is_last_char_escape = true; 894 } 895 break; 896 } else if ( "'" === ch ) { 897 if ( is_last_char_escape ) { 898 $this.string_buffer += "'"; 899 is_last_char_escape = false; 900 } else { 901 $this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.STRING, $this.string_buffer ) ); 902 $this.in_single_quoted_string = false; 903 $this.string_buffer = ''; 904 } 905 break; 906 } 907 if ( is_last_char_escape ) { 908 $this.string_buffer += '\\'; 909 is_last_char_escape = false; 910 } 911 $this.string_buffer += ch; 912 break; 913 case $this.in_double_quoted_string: 914 if ( '\\' === ch ) { 915 if ( is_last_char_escape ) { 916 $this.string_buffer += '\\'; 917 is_last_char_escape = false;
918 } else { 919 is_last_char_escape = true; 920 } 921 break; 922 } else if ( '"' === ch ) { 923 if ( is_last_char_escape ) { 924 $this.string_buffer += '"'; 925 is_last_char_escape = false; 926 } else { 927 $this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.STRING, $this.string_buffer ) ); 928 $this.in_double_quoted_string = false; 929 $this.string_buffer = ''; 930 } 931 break; 932 } 933 if ( is_last_char_escape ) { 934 $this.string_buffer += '\\'; 935 is_last_char_escape = false; 936 } 937 $this.string_buffer += ch; 938 break; 939 case '[' === ch: 940 $this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.FUNCTION, 'array' ) ); 941 $this.allow_negative = true; 942 $this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.LEFTPARENTHESIS, '' ) ); 943 break; 944 case ' ' === ch || '\n' === ch || '\r' === ch || '\t' === ch: 945 /** 946 * In case those tokens must not be ingored use the following 947 * 948 * $this.empty_number_buffer_as_literal(); 949 * $this.empty_str_buffer_as_variable(); 950 * $this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.SPACE, '' ) ); 951 */ 952 break; 953 case $this.is_number( ch ): 954 if ( '' !== $this.string_buffer ) { 955 $this.string_buffer += ch; 956 break; 957 } 958 $this.number_buffer += ch; 959 $this.allow_negative = false; 960 break; 961 case 'e' === ch.toLowerCase(): 962 if ( $this.number_buffer.length && -1 !== $this.number_buffer.indexOf( '.' ) ) { 963 $this.number_buffer += 'e'; 964 $this.allow_negative = false; 965 break; 966 } 967 /* falls through */ 968 case $this.is_alpha( ch ): 969 if ( $this.number_buffer.length ) { 970 $this.empty_number_buffer_as_literal(); 971 $this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.OPERATOR, '*' ) ); 972 } 973 $this.allow_negative = false; 974 $this.string_buffer += ch; 975 break; 976 case '"' === ch: 977 $this.in_double_quoted_string = true; 978 break; 979 case "'" === ch: 980 $this.in_single_quoted_string = true; 981 break; 982 case $this.is_dot( ch ): 983 $this.number_buffer += ch; 984 $this.allow_negative = false; 985 break; 986 case $this.is_lp( ch ): 987 if ( '' !== $this.string_buffer ) { 988 $this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.FUNCTION, $this.string_buffer ) ); 989 $this.string_buffer = ''; 990 } else if ( $this.number_buffer.length ) { 991 $this.empty_number_buffer_as_literal(); 992 $this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.OPERATOR, '*' ) ); 993 } 994 $this.allow_negative = true; 995 $this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.LEFTPARENTHESIS, ch ) ); 996 break; 997 case $this.is_rp( ch ) || ']' === ch : 998 $this.empty_number_buffer_as_literal(); 999 $this.empty_str_buffer_as_variable(); 1000 $this.allow_negative = false; 1001 $this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.RIGHTPARENTHESIS, ch ) ); 1002 break; 1003 case $this.is_comma( ch ): 1004 $this.empty_number_buffer_as_literal(); 1005 $this.empty_str_buffer_as_variable(); 1006 $this.allow_negative = true; 1007 $this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.PARAMSEPARATOR, ch ) ); 1008 break; 1009 default: 1010 // special case for unary operations. 1011 if ( '-' === ch || '+' === ch ) { 1012 if ( $this.allow_negative ) { 1013 $this.allow_negative = false; 1014 $this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.OPERATOR, '-' === ch ? 'uNeg' : 'uPos' ) ); 1015 break; 1016 } 1017 // could be in exponent, in which case negative should be added to the number_buffer. 1018 if ( $this.number_buffer && 'e' === $this.number_buffer[ $this.number_buffer.length - 1 ] ) { 1019 $this.number_buffer += ch; 1020 break; 1021 } 1022 } 1023 $this.empty_number_buffer_as_literal(); 1024 $this.empty_str_buffer_as_variable(); 1025 1026 if ( '$' !== ch ) { 1027 if ( $this.tokens.length > 0 ) { 1028 if ( THEMECOMPLETE_EPO_MATH_Constants.OPERATOR === $this.tokens[ $this.tokens.length - 1 ].type ) { 1029 $this.tokens[ $this.tokens.length - 1 ].value += ch; 1030 } else { 1031 $this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.OPERATOR, ch ) ); 1032 } 1033 } else { 1034 $this.tokens.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.OPERATOR, ch ) ); 1035 } 1036 } 1037 $this.allow_negative = true; 1038 } 1039 } ); 1040 this.empty_number_buffer_as_literal(); 1041 this.empty_str_buffer_as_variable(); 1042 1043 this.tokens.forEach( function( $token, $key ) { 1044 $token_test[ $key ] = $token.type; 1045 } ); 1046 $token_test.forEach( function( $type, $key ) { 1047 if ( $key > 0 && 'space' === $type && 'variable' === $token_test[ $key + 1 ] && 'variable' === $token_test[ $key - 1 ] ) { 1048 $this.tokens[ $key ] = new THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.LITERAL, 0 ); 1049 $this.tokens.splice( $key + 1, 1 ); 1050 $this.tokens.splice( $key - 1, 1 ); 1051 } 1052 } ); 1053 return this; 1054 }, 1055 build_reverse_polish_notation: function() { 1056 var $tokens = []; 1057 var $stack = []; 1058 var $param_counter = []; 1059 var $ctoken; 1060 var $f; 1061 var $op1; 1062 var $op2; 1063 var $this = this; 1064 1065 try { 1066 this.tokens.forEach( function( $token ) { 1067 switch ( $token.type ) { 1068 case THEMECOMPLETE_EPO_MATH_Constants.LITERAL: 1069 case THEMECOMPLETE_EPO_MATH_Constants.VARIABLE: 1070 case THEMECOMPLETE_EPO_MATH_Constants.STRING: 1071 $tokens.push( $token ); 1072 1073 if ( $param_counter.length > 0 && 0 === $param_counter[ $param_counter.length - 1 ] ) { 1074 $param_counter.push( $param_counter.pop() + 1 ); 1075 } 1076 1077 break; 1078 1079 case THEMECOMPLETE_EPO_MATH_Constants.FUNCTION: 1080 if ( $param_counter.length > 0 && 0 === $param_counter[ $param_counter.length - 1 ] ) { 1081 $param_counter.push( $param_counter.pop() + 1 ); 1082 } 1083 $stack.push( $token ); 1084 $param_counter.push( 0 ); 1085 1086 break; 1087 1088 case THEMECOMPLETE_EPO_MATH_Constants.LEFTPARENTHESIS: 1089 $stack.push( $token ); 1090 1091 break; 1092 1093 case THEMECOMPLETE_EPO_MATH_Constants.PARAMSEPARATOR: 1094 while ( THEMECOMPLETE_EPO_MATH_Constants.LEFTPARENTHESIS !== $stack[ $stack.length - 1 ].type ) { 1095 if ( 0 === $stack.length ) { 1096 return THEMECOMPLETE_EPO_MATH_Error.trigger( 'Incorrect Brackets', 'IncorrectBracketsError', $tokens ); 1097 } 1098 $tokens.push( $stack.pop() ); 1099 } 1100 $param_counter.push( $param_counter.pop() + 1 ); 1101 1102 break; 1103 1104 case THEMECOMPLETE_EPO_MATH_Constants.OPERATOR: 1105 if ( ! array_key_exists( $token.value, $this.operators ) ) { 1106 return THEMECOMPLETE_EPO_MATH_Error.trigger( $token.value, 'UnknownOperatorError', $tokens ); 1107 } 1108 $op1 = $this.operators[ $token.value ]; 1109 1110 while ( $stack.length > 0 && THEMECOMPLETE_EPO_MATH_Constants.OPERATOR === $stack[ $stack.length - 1 ].type ) { 1111 if ( ! array_key_exists( $stack[ $stack.length - 1 ].value, $this.operators ) ) {
1112 return THEMECOMPLETE_EPO_MATH_Error.trigger( $stack[ $stack.length - 1 ].value, 'UnknownOperatorError', $tokens ); 1113 } 1114 $op2 = $this.operators[ $stack[ $stack.length - 1 ].value ]; 1115 1116 if ( $op2.priority >= $op1.priority ) { 1117 $tokens.push( $stack.pop() ); 1118 1119 continue; 1120 } 1121 1122 break; 1123 } 1124 $stack.push( $token ); 1125 1126 break; 1127 1128 case THEMECOMPLETE_EPO_MATH_Constants.RIGHTPARENTHESIS: 1129 while ( true ) { 1130 try { 1131 $ctoken = $stack.pop(); 1132 1133 if ( THEMECOMPLETE_EPO_MATH_Constants.LEFTPARENTHESIS === $ctoken.type ) { 1134 break; 1135 } 1136 $tokens.push( $ctoken ); 1137 } catch ( $e ) { 1138 return THEMECOMPLETE_EPO_MATH_Error.trigger( 'Incorrect Brackets', 'IncorrectBracketsError', $tokens ); 1139 } 1140 } 1141 1142 if ( $stack.length > 0 && THEMECOMPLETE_EPO_MATH_Constants.FUNCTION === $stack[ $stack.length - 1 ].type ) { 1143 $f = $stack.pop(); 1144 $f.param_count = $param_counter.pop(); 1145 $tokens.push( $f ); 1146 } 1147 1148 break; 1149 1150 case THEMECOMPLETE_EPO_MATH_Constants.SPACE: 1151 // do nothing. 1152 } 1153 } ); 1154 } catch ( $e ) { 1155 $tokens = []; 1156 return THEMECOMPLETE_EPO_MATH_Error.trigger( $e, 'Error', $tokens ); 1157 } 1158 1159 while ( 0 !== $stack.length ) { 1160 if ( THEMECOMPLETE_EPO_MATH_Constants.LEFTPARENTHESIS === $stack[ $stack.length - 1 ].type || THEMECOMPLETE_EPO_MATH_Constants.RIGHTPARENTHESIS === $stack[ $stack.length - 1 ].type ) { 1161 return THEMECOMPLETE_EPO_MATH_Error.trigger( 'Incorrect Brackets', 'IncorrectBracketsError', $tokens ); 1162 } 1163 1164 if ( THEMECOMPLETE_EPO_MATH_Constants.SPACE === $stack[ $stack.length - 1 ].type ) { 1165 $stack.pop(); 1166 continue; 1167 } 1168 $tokens.push( $stack.pop() ); 1169 } 1170 1171 return $tokens; 1172 } 1173 }; 1174 node.input = $input; 1175 node.operators = $operators; 1176 return node; 1177 }; 1178 1179 var THEMECOMPLETE_EPO_MATH_Constants = { 1180 LITERAL: 'literal', 1181 VARIABLE: 'variable', 1182 OPERATOR: 'operator', 1183 LEFTPARENTHESIS: 'LP', 1184 RIGHTPARENTHESIS: 'RP', 1185 FUNCTION: 'function', 1186 PARAMSEPARATOR: 'separator', 1187 STRING: 'string', 1188 SPACE: 'space' 1189 1190 }; 1191 1192 var THEMECOMPLETE_EPO_MATH_Token = function( $type, $value, $name ) { 1193 var node = { 1194 type: THEMECOMPLETE_EPO_MATH_Constants.LITERAL, 1195 value: undefined, 1196 name: undefined, 1197 param_count: null 1198 }; 1199 node.type = $type; 1200 node.value = $value; 1201 node.name = $name; 1202 return node; 1203 }; 1204 1205 var THEMECOMPLETE_EPO_MATH_Operator = function( $operator, $is_right_assoc, $priority, $function ) { 1206 var node = { 1207 operator: '', 1208 is_right_assoc: false, 1209 priority: 0, 1210 function: null, 1211 places: 0 1212 }; 1213 node.operator = $operator; 1214 node.is_right_assoc = $is_right_assoc; 1215 node.priority = $priority; 1216 node.function = $function; 1217 node.places = getNumberOfParameters( $function ); 1218 1219 node.execute = function( $stack ) { 1220 var $args = []; 1221 var $i; 1222 var $result; 1223 1224 if ( $stack.length < this.places ) { 1225 // Empty the $stack 1226 $stack.splice( 0, $stack.length ); 1227 return THEMECOMPLETE_EPO_MATH_Error.trigger( 'Incorrect Expression', 'IncorrectExpressionError', new THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.LITERAL, 0 ) ); 1228 } 1229 1230 for ( $i = 0; $i < this.places; $i++ ) { 1231 $args.unshift( $stack.pop().value ); 1232 } 1233 1234 $result = this.function.apply( null, $args ); 1235 if ( 'number' !== gettype( $result ) && 'string' !== gettype( $result ) ) { 1236 $result = 0; 1237 } 1238 1239 return new THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.LITERAL, $result ); 1240 }; 1241 1242 return node; 1243 }; 1244 1245 var THEMECOMPLETE_EPO_MATH_CustomFunction = function( $name, $function ) { 1246 var node = { 1247 name: '', 1248 function: undefined, 1249 required_param_count: undefined 1250 }; 1251 1252 node.name = $name; 1253 node.function = $function; 1254 node.required_param_count = getNumberOfRequiredParameters( $function ); 1255 1256 node.execute = function( $stack, $param_count_in_stack ) { 1257 var $args = []; 1258 var $i; 1259 var $argument; 1260 var $result; 1261 if ( $param_count_in_stack < this.required_param_count ) { 1262 $param_count_in_stack = this.required_param_count; 1263 }
1264 // We skip this section. 1265 if ( $param_count_in_stack < this.required_param_count ) { 1266 // Empty the $stack 1267 $stack.splice( 0, $stack.length ); 1268 return THEMECOMPLETE_EPO_MATH_Error.trigger( this.name, 'IncorrectNumberOfFunctionParametersError', new THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.LITERAL, 0 ) ); 1269 } 1270 1271 if ( $param_count_in_stack > 0 ) { 1272 for ( $i = 0; $i < $param_count_in_stack; $i++ ) { 1273 $argument = $stack.length ? $stack.pop().value : 0; 1274 if ( null === $argument ) { 1275 $argument = '0'; 1276 $args.push( $argument ); 1277 } else { 1278 $args.unshift( $argument ); 1279 } 1280 } 1281 } 1282 1283 $result = this.function.apply( null, $args ); 1284 1285 if ( $result === Infinity || $result === -Infinity ) { 1286 $result = 0; 1287 } 1288 1289 return THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.LITERAL, $result ); 1290 }; 1291 1292 return node; 1293 }; 1294 1295 var THEMECOMPLETE_EPO_MATH_Calculator = function( $functions, $operators ) { 1296 var node = { 1297 functions: {}, 1298 operators: {} 1299 }; 1300 node.functions = $functions; 1301 node.operators = $operators; 1302 1303 node.calculate = function( $tokens, $variables, $on_var_not_found = null, $math_object = false ) { 1304 var $this = this; 1305 /** Array of THEMECOMPLETE_EPO_MATH_Token */ 1306 var $stack = []; 1307 var $result; 1308 1309 if ( empty( $tokens ) ) { 1310 return 0; 1311 } 1312 try { 1313 $tokens.forEach( function( $token ) { 1314 var $variable; 1315 var $value; 1316 if ( THEMECOMPLETE_EPO_MATH_Constants.LITERAL === $token.type || THEMECOMPLETE_EPO_MATH_Constants.STRING === $token.type ) { 1317 $stack.push( $token ); 1318 } else if ( THEMECOMPLETE_EPO_MATH_Constants.VARIABLE === $token.type ) { 1319 $variable = $token.value; 1320 1321 $value = null; 1322 1323 if ( array_key_exists( $variable, $variables ) ) { 1324 $value = $variables[ $variable ]; 1325 } else if ( $on_var_not_found && 'function' === typeof $on_var_not_found ) { 1326 $value = $on_var_not_found( $variable ); 1327 } else { 1328 $value = $variable; 1329 $math_object.variables[ $variable ] = $value; 1330 $variables[ $variable ] = $value; 1331 } 1332 $stack.push( THEMECOMPLETE_EPO_MATH_Token( THEMECOMPLETE_EPO_MATH_Constants.LITERAL, $value, $variable ) ); 1333 } else if ( THEMECOMPLETE_EPO_MATH_Constants.FUNCTION === $token.type ) { 1334 if ( ! array_key_exists( $token.value, $this.functions ) ) { 1335 $math_object.add_function( 1336 $token.value, 1337 function() { 1338 return 0; 1339 } 1340 ); 1341 $this.functions = $math_object.functions; 1342 if ( ! array_key_exists( $token.value, $this.functions ) ) { 1343 return THEMECOMPLETE_EPO_MATH_Error.trigger( $token.value, 'UnknownFunctionError', 0 ); 1344 } 1345 THEMECOMPLETE_EPO_MATH_Error.trigger( $token.value, 'UnknownFunctionError', 0 ); 1346 } 1347 $stack.push( $this.functions[ $token.value ].execute( $stack, $token.param_count ) ); 1348 } else if ( THEMECOMPLETE_EPO_MATH_Constants.OPERATOR === $token.type ) { 1349 if ( ! array_key_exists( $token.value, $this.operators ) ) { 1350 return THEMECOMPLETE_EPO_MATH_Error.trigger( $token.value, 'UnknownOperatorError', 0 ); 1351 } 1352 $stack.push( $this.operators[ $token.value ].execute( $stack ) ); 1353 } 1354 } ); 1355 } catch ( $e ) { 1356 if ( window.TMEPOJS && window.TMEPOJS.WP_DEBUG ) { 1357 window.console.log( $e ); 1358 } 1359 } 1360 $result = $stack.pop(); 1361 1362 if ( undefined === $result || null === $result || ! empty( $stack ) ) { 1363 return THEMECOMPLETE_EPO_MATH_Error.trigger( 'Stack must be empty', 'IncorrectExpressionError', 0 ); 1364 } 1365 1366 if ( false === $result.value ) { 1367 $result.value = 0; 1368 } 1369 1370 if ( true === $result.value ) { 1371 $result.value = 1; 1372 } 1373 1374 if ( 'string' === gettype( $result.value ) && $result.value.isNumeric() ) { 1375 $result.value = floatval( $result.value ); 1376 } 1377 1378 return $result.value; 1379 }; 1380 return node; 1381 }; 1382 1383 var THEMECOMPLETE_EPO_MATH_Error = { 1384 trigger: function( $msg, $code = '', $return = false ) { 1385 if ( window.TMEPOJS && window.TMEPOJS.WP_DEBUG ) { 1386 window.console.log( $code + '\n' + $msg ); 1387 window.console.trace(); 1388 } 1389 if ( window.TMEPOGLOBALADMINJS && window.TMEPOGLOBALADMINJS.WP_DEBUG ) { 1390 return $msg; 1391 } 1392 return $return; 1393 } 1394 }; 1395 1396 window.tcmexp = THEMECOMPLETE_EPO_MATH.construct(); 1397}( window ) );
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.