GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — mojs/spec/motion-path.coffee at master · softDen/mojs Expand file tree/ Copy pathmotion-path.coffeeMore file actions 1638 lines (1481 loc) · 53.4 KB / Copy pathmotion-path.coffeeFile metadata and controls1638 lines (1481 loc) · 53.4 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 MotionPath = window.mojs.MotionPath Shape = window.mojs.Shape h = window.mojs.helpers mp = new MotionPath path: 'M0,0 L100,100', el: document.createElement 'div' isMotionReset = mp.isMotionBlurReset parseQadraticCurve = (d)-> shapes = d.split /M|Q/ m = shapes[1].split /\s|\,/ m = m.filter (e)-> !!e start = x: parseFloat(m[0]), y: parseFloat(m[1]) q = shapes[2].split /\s|\,/ q = q.filter (e)-> !!e end = x: parseFloat(q[2]), y: parseFloat(q[3]) control = x: parseFloat(q[0]), y: parseFloat(q[1]) returnObject = start: start end: end control: control coords = 'M0.55859375,593.527344L0.55859375,593.527344' describe 'MotionPath ->', -> ns = 'http://www.w3.org/2000/svg' # move to general env describe 'enviroment ->', -> it 'SVG should be supported', -> isSVG = !!document.createElementNS?(ns, "svg").createSVGRect expect(isSVG).toBeTruthy() it 'SVG path should have getTotalLength method', -> path = document.createElementNS(ns, "path") expect(path.getTotalLength).toBeDefined() it 'SVG path should have getPointAtLength method', -> path = document.createElementNS(ns, "path") expect(path.getPointAtLength).toBeDefined() it 'document.querySelector should be defined', -> expect(document.querySelector).toBeDefined() it 'style propety should be defined on DOM node', -> path = document.createElementNS(ns, "path") div = document.createElement 'div' expect(path.style).toBeDefined() expect(div.style).toBeDefined() it 'transforms should be supported', -> isTransforms = -> trS = "transform WebkitTransform MozTransform OTransform msTransform" prefixes = trS.split(" ") i = 0 while i < prefixes.length div = document.createElement("div") isProp = div.style[prefixes[i]] isnt 'undefined' return prefixes[i] if isProp i++ false expect(isTransforms()).toBeTruthy() it 'HTML el should have offsetWidth/offsetHeight propety', -> div = document.createElement('div') expect(div.offsetWidth).toBeDefined() expect(div.offsetHeight).toBeDefined() describe 'defaults ->', -> el = document.createElement 'div' mp = new MotionPath path: 'M0.55859375,593.527344L0.55859375,593.527344' el: el it 'have angle of 0', -> el = document.createElement 'div' mp = new MotionPath path: 'M0.55859375,593.527344L0.55859375,593.527344' el: el isRunLess: true isPresetPosition: false expect(mp.angle).toBe 0 it 'should have isCompositeLayer default of true', -> mp = new MotionPath path: 'M0.55859375,593.527344L0.55859375,593.527344' el: document.createElement 'div' expect(mp.defaults.isCompositeLayer).toBe true it 'have speed of 0', -> el = document.createElement 'div' mp = new MotionPath path: 'M0.55859375,593.527344L0.55859375,593.527344' el: el isRunLess: true isPresetPosition: false expect(mp.speedX).toBe 0 expect(mp.speedY).toBe 0 it 'have blur of 0', -> el = document.createElement 'div' mp = new MotionPath path: 'M0.55859375,593.527344L0.55859375,593.527344' el: el isRunLess: true isPresetPosition: false expect(mp.blurX).toBe 0 expect(mp.blurY).toBe 0 it 'have blurAmount of 20', -> el = document.createElement 'div' mp = new MotionPath path: 'M0.55859375,593.527344L0.55859375,593.527344' el: el isRunLess: true isPresetPosition: false expect(mp.blurAmount).toBe 20 it 'have prevCoords object', -> el = document.createElement 'div' mp = new MotionPath path: 'M0.55859375,593.527344L0.55859375,593.527344' el: el isRunLess: true isPresetPosition: false expect(mp.prevCoords).toBeDefined() it 'defaults should be defined', -> expect(mp.defaults.delay) .toBe 0 expect(mp.defaults.duration) .toBe 1000 expect(mp.defaults.easing) .toBe null expect(mp.defaults.repeat) .toBe 0 expect(mp.defaults.yoyo) .toBe false expect(mp.defaults.offsetX) .toBe 0 expect(mp.defaults.offsetY) .toBe 0 expect(mp.defaults.angleOffset) .toBe null expect(mp.defaults.pathStart) .toBe 0 expect(mp.defaults.pathEnd) .toBe 1 expect(mp.defaults.transformOrigin) .toBe null expect(mp.defaults.motionBlur) .toBe 0 expect(mp.defaults.isAngle) .toBe false expect(mp.defaults.isReverse) .toBe false expect(mp.defaults.isRunLess) .toBe false expect(mp.defaults.isPresetPosition).toBe true expect(mp.defaults.onStart) .toBe null expect(mp.defaults.onComplete) .toBe null expect(mp.defaults.onUpdate) .toBe null expect(mp.defaults.curvature.x) .toBe '75%' expect(mp.defaults.curvature.y) .toBe '50%' it 'should extend defaults to props', -> mp = new MotionPath path: 'M0.55859375,593.527344L0.55859375,593.527344' el: document.createElement 'div' duration: 2000 expect(mp.props.duration).toBe 2000 expect(mp.props.delay) .toBe 0 it 'should clamp pathStart and pathEnd further', -> mp = new MotionPath path: 'M0.55859375,593.527344L0.55859375,593.527344' el: document.createElement 'div' duration: 2000 pathStart: 2 pathEnd: 2 expect(mp.props.pathStart).toBe 1 expect(mp.props.pathEnd) .toBe 1 it 'should clamp pathStart and pathEnd further', -> mp = new MotionPath path: 'M0.55859375,593.527344L0.55859375,593.527344' el: document.createElement 'div' duration: 2000 pathStart: -2 pathEnd: -2 expect(mp.props.pathStart).toBe 0 expect(mp.props.pathEnd) .toBe 0 it 'pathEnd should not be smaller then pathStart', -> mp = new MotionPath path: 'M0.55859375,593.527344L0.55859375,593.527344' el: document.createElement 'div' duration: 2000 pathStart: .5 pathEnd: -2 expect(mp.props.pathStart).toBe .5 expect(mp.props.pathEnd) .toBe .5 describe 'run method ->', -> div = document.createElement 'div' coords = 'M0.55859375,593.527344L0.55859375,593.527344' it 'should extend the old options', -> mp = new MotionPath( path: coords el: document.createElement 'div' isRunLess: true pathEnd: .75 pathStart: .25 ) mp.run pathStart: .5 expect(mp.props.pathStart).toBe .5 expect(mp.props.pathEnd) .toBe .75 it 'shoud call tuneOptions if options passed', -> o = duration: 500 div = document.createElement('div') mp = new MotionPath( path: coords el: div isRunLess: true ).then pathEnd: .5 spyOn mp, 'tuneOptions' mp.run o expect(mp.tuneOptions).toHaveBeenCalledWith o it 'shoud not call tuneOptions if options wasn\'t passed', -> mp = new MotionPath( path: coords el: document.createElement 'div' isRunLess: true ).then pathEnd: .5 spyOn mp, 'tuneOptions' mp.run() expect(mp.tuneOptions).not.toHaveBeenCalled() it 'shoud override the first history item', -> mp = new MotionPath( path: coords el: document.createElement 'div' isRunLess: true pathStart: .25 pathEnd: .5 ).then pathEnd: .5 mp.run pathStart: .35 expect(mp.history[0].pathStart).toBe .35 it 'shoud warn if tweenValues changed on run', -> mp = new MotionPath( path: coords el: document.createElement 'div' isRunLess: true pathStart: .25 pathEnd: .5 duration: 2000 ).then pathEnd: .5 spyOn h, 'warn' mp.run pathStart: .35 duration: 200 delay: 100 repeat: 1 yoyo: false easing: 'Linear.None' onStart: -> onUpdate: -> onComplete: -> expect(h.warn).toHaveBeenCalled() expect(mp.history[0].duration).toBe 2000 expect(mp.props.duration) .toBe 2000 describe 'callbacks ->', -> div = document.createElement 'div' coords = 'M0.55859375,593.527344L0.55859375,593.527344' describe 'onStart callback ->', -> it 'should run on start', (dfr)-> isStarted = false mp = new MotionPath path: coords el: div duration: 200 onStart:-> isStarted = true setTimeout (-> expect(isStarted).toBe(true); dfr() ), 500 it 'should have the scope of MotionPath', (dfr)-> isRightScope = null mp = new MotionPath path: coords el: div onStart:-> isRightScope = @ instanceof MotionPath setTimeout (-> expect(isRightScope).toBe(true); dfr()), 500 describe 'onComplete callback ->', -> it 'onComplete callback should work', (dfr)-> isCompleted = false mp = new MotionPath path: coords el: div duration: 200 onComplete:-> isCompleted = true setTimeout -> expect(isCompleted).toBe(true); dfr() , 500 it 'should have the scope of MotionPath', (dfr)-> isRightScope = false mp = new MotionPath path: coords el: div duration: 200 onComplete:-> isRightScope = @ instanceof MotionPath setTimeout -> expect(isRightScope).toBe(true); dfr() , 500 describe 'onUpdate callback ->', -> it 'onUpdate callback should work', (dfr)-> isOnUpdate = false mp = new MotionPath path: coords el: div duration: 200 onUpdate:-> isOnUpdate = true setTimeout -> expect(isOnUpdate).toBe(true); dfr() , 500 it 'onUpdate callback should have "progress" argument', (dfr)-> isOnUpdate = false mp = new MotionPath path: coords el: div duration: 200 onUpdate:(progress)-> isOnUpdate = true if progress? setTimeout -> expect(isOnUpdate).toBe(true); dfr() , 500 it 'should have the scope of MotionPath', (dfr)-> isRightScope = false mp = new MotionPath path: coords el: div duration: 200 onUpdate:-> isRightScope = @ instanceof MotionPath setTimeout -> expect(isRightScope).toBe(true); dfr() , 500 it 'should be called with progress, x, y and angle', -> progress = null; x = null; y = null; angle = null mp = new MotionPath path: 'M0,100 L100,0' el: document.createElement 'div' isRunLess: true, easing: 'linear.none', onUpdate:(p, o)-> progress = p; x = o.x; y = o.y; angle = o.angle mp.timeline.setProgress .45 mp.timeline.setProgress .5 expect(progress.toFixed(1)).toBe '0.5' expect(x) .toBeCloseTo 50, 5 expect(y) .toBeCloseTo 50, 5 expect(angle) .toBeCloseTo 0, 5 describe 'fill ->', -> div = null; container = null beforeEach -> container = document.createElement 'div' div = document.createElement 'div' size = 200 container.style.width = "#{size}px" container.style.height = "#{size}px" container.style.position = 'absolute' container.style.top = '-100%' container.setAttribute 'id', 'js-container' document.body.appendChild container it 'container could be specified by selector or DOM node', -> mp = new MotionPath path: 'M0,0 L500,0' el: div fill: { container: '#js-container' } expect(mp.container instanceof HTMLElement).toBe(true) it 'if fill is specified it should have container, fillRule, cSize', -> mp = new MotionPath path: 'M0,0 L500,0' el: div fill: { container: container } expect(mp.container).toBeDefined() expect(mp.fillRule).toBeDefined() expect(mp.cSize).toBeDefined() it 'if fillRule is "all" it should keep container\'s size', (dfr)-> isFilled = false motionPath = new MotionPath path: 'M0,0 L500,500' el: div duration: 200 fill: { container: container } # all: true onComplete:-> style = motionPath.el.style; prefixed = "#{h.prefix.css}transform" tr = if style[prefixed]? then style[prefixed] else style.transform div = document.createElement 'div' args = tr.split /(translate\()|\,|\)/ width = parseInt(args[2], 10) height = parseInt(args[4], 10) isWidth = width is container.offsetWidth isHeight = height is container.offsetHeight isFilled = isWidth and isHeight expect(isFilled).toBe(true); dfr() it "if fillRule is \"width\" it should keep container\'s width and set \"height\" with aspect ratio", (dfr)-> isFilled = false mp = new MotionPath path: 'M0,0 L500,250' el: div duration: 200 fill: { container: container, fillRule: 'width' } all: true onComplete:-> style = mp.el.style; prefixed = "#{h.prefix.css}transform" tr = if style[prefixed]? then style[prefixed] else style.transform args = tr.split /(translate\()|\,|\)/ width = parseInt(args[2], 10) height = parseInt(args[4], 10) isWidth = width is container.offsetWidth isHeight = height is (width/2) isFilled = isWidth and isHeight expect(isFilled).toBe(true); dfr() it "if fillRule is \"height\" it should keep container\'s height and set \"width\" with aspect ratio", (dfr)-> isFilled = false mp = new MotionPath path: 'M0,0 L250,500' el: div duration: 200 fill: { container: container, fillRule: 'height' } onComplete:-> style = mp.el.style; prefixed = "#{h.prefix.css}transform" tr = if style[prefixed]? then style[prefixed] else style.transform args = tr.split /(translate\()|\,|\)/ width = parseInt(args[2], 10) height = parseInt(args[4], 10) isWidth = width is (height/2) isHeight = height is container.offsetHeight isFilled = isWidth and isHeight expect(isFilled).toBe(true); dfr() it 'if container size was changed should recalc scaler', (dfr)-> isSizeChange = false el = document.createElement 'div' c = document.createElement 'div' size = 200 c.style.width = "#{size}px" c.style.height = "#{size}px" c.style.position = 'absolute' c.style.top = '-100%' c.setAttribute 'id', 'js-container2' document.body.appendChild c x = -1 mp = new MotionPath path: 'M0,0 L500,0' el: el duration: 200 fill: { container: c } onUpdate:(proc)-> if proc >= .1 and !isSizeChange mp.container.style.width = '100px' isSizeChange = true setTimeout -> tr = mp.el.style.transform or mp.el.style["#{h.prefix.css}transform"] x = tr.split /(translate\()|\,|\)/ expect(parseInt(x[2], 10)).toBe(100); dfr() , 500 describe 'functionality ->', -> div = document.createElement 'div' coords = 'M0.55859375,593.527344L0.55859375,593.527344' # describe 'offsets ->', -> it 'should work with positive offsetX', (dfr)-> coords = 'M0,0 L0,10' x = 0; isEqual = false mp = new MotionPath path: coords el: div offsetX: 10 duration: 200 isAngle: true setTimeout (-> tr = mp.el.style.transform or mp.el.style["#{h.prefix.css}transform"] x = tr.split(/(translate\()|,|\)/)[2] isEqual = parseInt(x, 10) is 10 expect(isEqual).toBe(true); dfr() ), 500 it 'should work with negative offsetX', (dfr)-> coords = 'M0,0 L0,10' x = 0; isEqual = false mp = new MotionPath path: coords el: div offsetX: -10 duration: 200 onComplete: -> tr = mp.el.style.transform or mp.el.style["#{h.prefix.css}transform"] x = tr.split(/(translate\()|,|\)/)[2] x = parseInt(x, 10) isEqual = x is -10 setTimeout (-> expect(isEqual).toBe(true); dfr()), 500 it 'should work with positive offsetY', (dfr)-> coords = 'M0,0 L10,0' y = 0; isEqual = false mp = new MotionPath path: coords el: div offsetY: 10 duration: 200 onComplete: -> tr = mp.el.style.transform or mp.el.style["#{h.prefix.css}transform"] y = tr.split(/(translate\()|,|\)/)[4] y = parseInt(y, 10) isEqual = y is 10 setTimeout (-> expect(isEqual).toBe(true); dfr()), 500 it 'should work with negative offsetY', (dfr)-> coords = 'M0,0 L10,0' y = 0; isEqual = false mp = new MotionPath path: coords el: div offsetY: -10 duration: 200 onComplete: -> tr = mp.el.style.transform or mp.el.style["#{h.prefix.css}transform"] y = tr.split(/(translate\()|,|\)/)[4] isEqual = parseInt(y, 10) is -10 setTimeout (-> expect(isEqual).toBe(true); dfr()), 500 it 'should calculate current angle', (dfr)-> coords = 'M0,0 L10,0 L10,10' angle = 0; isEqual = false; isEquial2 = false; detect = {} mp = new MotionPath path: coords el: div duration: 200 isAngle: true onUpdate:-> detect.firstAngle ?= mp.angle isEquial2 = detect.firstAngle is 0 onComplete:-> isEqual = mp.angle is 90 setTimeout (-> expect(isEqual).toBe(true); dfr()), 500 it 'should calculate current angle if transformOrigin is a fun', (dfr)-> coords = 'M0,0 L10,0 L10,10' angle = 0; isEqual = false; isEquial2 = false; detect = {} mp = new MotionPath path: coords el: div duration: 200 transformOrigin: -> onUpdate:-> detect.firstAngle ?= mp.angle isEquial2 = detect.firstAngle is 0 onComplete:-> isEqual = mp.angle is 90 setTimeout (-> expect(isEqual).toBe(true); dfr()), 500 it 'should calculate current angle with isReverse', (dfr)-> coords = 'M0,0 L10,0 L10,10' angle = 0; isEqual = false; isEquial2 = false; detect = {} mp = new MotionPath path: coords el: div duration: 200 isAngle: true isReverse: true onUpdate:-> detect.firstAngle ?= mp.angle isEquial2 = detect.firstAngle is 90 onComplete: -> isEqual = mp.angle is 0 setTimeout (-> expect(isEqual).toBe(true); dfr()), 500 it 'should have transform-origin', (dfr)-> coords = 'M0,0 L10,0 L10,10' isComplete = false mp = new MotionPath path: coords el: div duration: 200 transformOrigin: '50% 50%' onComplete: -> isComplete = true setTimeout -> s = mp.el.style tr = s['transform-origin'] or s["#{h.prefix.css}transform-origin"] expect(tr.length >= 1).toBe(true); dfr() , 100 it 'transform-origin could be a function', (dfr)-> coords = 'M0,0 L10,0 L10,10' isAngle = false; isProgress = false mp = new MotionPath path: coords el: div duration: 200 transformOrigin:(angle, proc)-> isFunction = true isAngle = angle?; isProgress = proc? '50% 50%' setTimeout (-> expect(isAngle and isProgress).toBe(true); dfr()), 100 describe 'angleOffset ->', -> div = document.createElement 'div' it 'angleOffset should work with positive angles', (dfr)-> coords = 'M0,0 L10,0 L10,10' isEqual = false mp = new MotionPath path: coords el: div duration: 200 angleOffset: 90 isAngle: true onComplete:-> isEqual = mp.angle is 180 setTimeout (-> expect(isEqual).toBe(true); dfr()), 500 it 'angleOffset should work with negative angles', (dfr)-> coords = 'M0,0 L10,0 L10,10' isEqual = false mp = new MotionPath path: coords el: div duration: 200 angleOffset: -90 isAngle: true # onComplete:-> setTimeout (-> isEqual = mp.angle is 0 expect(isEqual).toBe(true); dfr() ), 500 it 'should be evaluated if a function', (dfr)-> coords = 'M0,0 L10,0 L10,10' isFunction = false mp = new MotionPath path: coords el: div duration: 200 angleOffset:(angle)-> isFunction = true angle setTimeout (-> expect(isFunction).toBe(true); dfr()), 500 it 'should get current angle', (dfr)-> coords = 'M0,0 L10,0 L10,10' isOnAngle = null angleSum1 = 0; angleSum2 = 0 mp = new MotionPath path: coords el: div duration: 200 isAngle: true isRunLess: true isPresetPosition: false angleOffset:(angle)-> angleSum1 += angle; angleSum2 += @angle angle onComplete:-> isOnAngle = angleSum1 is angleSum2 mp.run() setTimeout (-> expect(isOnAngle).toBe(true); dfr()), 500 it 'should set current angle', (dfr)-> coords = 'M0,0 L10,0 L10,10' isSet = false currAngle = 0; isAnglesArray = [] angleShift = 5 mp = new MotionPath path: coords el: div duration: 200 angleOffset:(angle)-> currAngle = angle; angle+angleShift onUpdate:-> isAnglesArray.push currAngle+angleShift is mp.angle onComplete:-> for isSetItem, i in isAnglesArray if !isSetItem then isSet = true setTimeout (-> expect(isSet).toBe(false); dfr()), 500 it 'angleOffset should get current progress as second parameter', (dfr)-> coords = 'M0,0 L10,0 L10,10' isProgress = false; proc = -1 mp = new MotionPath path: coords el: div duration: 200 angleOffset:(angle, progress)-> proc = progress; angle onComplete:-> isProgress = proc is 1 setTimeout (-> expect(isProgress).toBe(true); dfr()), 500 it 'should have scope of motion path', -> coords = 'M0,0 L10,0 L10,10' isRightScope = false angleSum1 = 0; angleSum2 = 0 mp = new MotionPath path: coords el: div duration: 200 isAngle: true angleOffset:-> isRightScope = @ instanceof MotionPath setTimeout -> expect(isRightScope).toBe(true) , 500 describe 'setProgress method ->', (dfr)-> it 'should have own function for setting up current progress', -> div = document.createElement 'div' mp = new MotionPath path: 'M0,0 L500,0' el: div isRunLess: true mp.setProgress(.5) tr = mp.el.style.transform or mp.el.style["#{h.prefix.css}transform"] pos = parseInt tr.split(/(translate\()|\,|\)/)[2], 10 expect(pos).toBe(250) it 'should call the onUpdate callback', -> div = document.createElement 'div' progress = null mp = new MotionPath path: 'M0,0 L500,0' el: div isRunLess: true onUpdate:(p)-> progress = p # spyOn mp, 'onUpdate' mp.setProgress(.5) expect(progress).toBe .5 it 'should not call the onUpdate callback on start', -> isCalled = false mp = new MotionPath path: 'M0,0 L500,0' el: document.createElement 'div' isRunLess: true onUpdate:-> isCalled = true expect(isCalled).toBe false it 'should set transform if it was returned from the onUpdate', -> transform = 'translate(20px, 50px)' mp = new MotionPath path: 'M0,0 L500,0' el: document.createElement 'div' isRunLess: true onUpdate:-> transform mp.setProgress .5 style = mp.el.style; prefixed = "#{h.prefix.css}transform" tr = if style[prefixed]? then style[prefixed] else style.transform expect(tr).toBe transform it 'should not set transform if something other then string was returned from onUpdate callback', -> transform = 'translate(20px, 50px)' mp = new MotionPath path: 'M0,0 L500,0' el: document.createElement 'div' isRunLess: true onUpdate:-> null mp.setProgress .5 expect(mp.el.style.transform).not.toBe null describe 'preset position ->', -> it 'should preset initial position by default', -> div = document.createElement 'div' mp = new MotionPath path: 'M50,0 L500,0' el: div tr = mp.el.style.transform or mp.el.style["#{h.prefix.css}transform"] pos = parseInt tr.split(/(translate\()|\,|\)/)[2], 10 expect(pos).toBe(50) it 'should not set initial position if isPresetPosition is false', -> div = document.createElement 'div' mp = new MotionPath path: 'M50,0 L500,0' el: div isRunLess: true isPresetPosition: false expect(div.style.transform).toBeFalsy() describe 'progress bounds ->', -> it 'should calc the @slicedLen and @startLen properties', -> mp = new MotionPath path: 'M0,0 L500,0' el: document.createElement 'div' isRunLess: true pathStart: .5 pathEnd: .75 expect(mp.slicedLen).toBe 125 expect(mp.startLen) .toBe 250 it 'should start from pathStart position', -> div = document.createElement 'div' mp = new MotionPath path: 'M0,0 L500,0' el: div isRunLess: true pathStart: .5 pathEnd: .75 mp.timeline.setProgress 0 tr = mp.el.style.transform or mp.el.style["#{h.prefix.css}transform"] pos = parseInt tr.split(/(translate\()|\,|\)/)[2], 10 expect(pos).toBe(250) it 'should end at pathEnd position', (dfr)-> div = document.createElement 'div' pos = -1 mp = new MotionPath path: 'M0,0 L500,0' el: div duration: 200 pathStart: .25 pathEnd: .5 onComplete:-> tr = mp.el.style.transform or mp.el.style["#{h.prefix.css}transform"] pos = tr.split(/(translate\()|\,|\)/)[2] pos = parseInt pos, 10 setTimeout (-> expect(pos).toBe(250); dfr()), 500 describe 'path option ->', -> it 'should error if path has no d attribute', -> path = document.createElementNS ns, 'path' # path.setAttribute 'd', 'M0,0 L500,500 L1000, 0' div = document.createElement 'div' spyOn h, 'error' mp = new MotionPath path: path el: div expect(h.error).toHaveBeenCalled() describe 'isCompositeLayer option ->', -> it 'should be true by default', -> mp = new MotionPath path: document.createElementNS ns, 'path' el: document.createElement 'div' expect(mp.props.isCompositeLayer).toBe true it 'should be able to be set to false', -> mp = new MotionPath path: document.createElementNS ns, 'path' el: document.createElement 'div' isCompositeLayer: false expect(mp.props.isCompositeLayer).toBe false it 'should set translateZ(0) if isCompositeLayer is set to true and h.is3d', ()-> mp = new MotionPath path: 'M0,0 L100,100' el: document.createElement 'div' isRunLess: true mp.setProgress(.5) style = mp.el.style; prefixed = "#{h.prefix.css}transform" tr = if style[prefixed]? then style[prefixed] else style.transform expect(tr.match(/translateZ/gi) or !h.is3d).toBeTruthy() it 'should not set translateZ(0) is isCompositeLayer is set to false', ()-> mp = new MotionPath path: 'M0,0 L100,100' el: document.createElement 'div' isRunLess: true isCompositeLayer: false mp.setProgress(.5) tr = mp.el.style.transform or mp.el.style["#{mojs.h.prefix.css}transform"] expect(tr.match /translateZ/gi).toBeFalsy() describe 'getPath method ->', -> it 'should have a getPath method', -> div = document.createElement 'div' mp = new MotionPath path: coords el: div expect(mp.getPath).toBeDefined() it 'getPath should return a path when was specified by coordinates', -> div = document.createElement 'div' mp = new MotionPath path: coords el: div expect(mp.getPath() instanceof SVGElement).toBe(true) it 'getPath should return a path when it was specified by SVG path', -> path = document.createElementNS ns, 'path' path.setAttribute 'd', 'M0,0 L500,500 L1000, 0' div = document.createElement 'div' mp = new MotionPath path: path el: div expect(mp.getPath() instanceof SVGElement).toBe(true) it 'getPath should return a path when it was specified by a selector', -> id = 'js-path' div = document.createElement 'div' svg = document.createElementNS ns, 'svg' path = document.createElementNS ns, 'path' path.setAttribute 'id', id path.setAttribute 'class', id svg.appendChild path document.body.appendChild svg mp = new MotionPath path: "##{id}" el: div expect(mp.getPath() instanceof SVGElement).toBe(true) mp = new MotionPath path: ".#{id}" el: div expect(mp.getPath() instanceof SVGElement).toBe(true) it 'getPath should return a path when it was specified by coords', -> mp = new MotionPath path: x: -100, y: 100 curvature: x: '50%', y: '25%' el: document.createElement 'div' d = mp.path.getAttribute 'd' expect(mp.getPath() instanceof SVGElement).toBe(true) points = parseQadraticCurve d expect(points.start.x).toBe 0 expect(points.start.y).toBe 0 expect(points.end.x).toBe -100 expect(points.end.y).toBe 100 expect(points.control.x).toBeCloseTo -75 expect(points.control.y).toBeCloseTo 25 it 'fallback to defaults if only 1 curvature coord set', -> mp = new MotionPath path: x: -100, y: 100 curvature: x: '50%' el: document.createElement 'div' d = mp.path.getAttribute 'd' expect(mp.getPath() instanceof SVGElement).toBe(true) points = parseQadraticCurve d expect(points.start.x).toBe 0 expect(points.start.y).toBe 0 expect(points.end.x).toBe -100 expect(points.end.y).toBe 100 expect(points.control.x).toBeCloseTo -100 expect(points.control.y).toBeCloseTo 0 it 'should fallback to defaults if only 1 curve coord set #2', -> mp = new MotionPath path: x: -100, y: 100 curvature: y: '50%' el: document.createElement 'div' d = mp.path.getAttribute 'd' expect(mp.getPath() instanceof SVGElement).toBe(true) points = parseQadraticCurve d expect(points.start.x).toBe 0 expect(points.start.y).toBe 0 expect(points.end.x).toBe -100 expect(points.end.y).toBe 100 expect(points.control.x).toBeCloseTo -125 expect(points.control.y).toBeCloseTo 25 it 'should fallback to 0 if only 1 path coord set', -> mp = new MotionPath path: x: -100 curvature: y: '50%' el: document.createElement 'div' d = mp.path.getAttribute 'd' expect(mp.getPath() instanceof SVGElement).toBe(true) points = parseQadraticCurve d expect(points.start.x).toBe 0 expect(points.start.y).toBe 0 expect(points.end.x).toBe -100 expect(points.end.y).toBe 0 expect(points.control.x).toBeCloseTo -75 expect(points.control.y).toBeCloseTo -50 it 'should fallback to 0 if only 1 path coord set #2', -> mp = new MotionPath path: {y: -100} curvature: {y: '50%'} el: document.createElement 'div' d = mp.path.getAttribute 'd' expect(mp.getPath() instanceof SVGElement).toBe(true) points = parseQadraticCurve d expect(points.start.x).toBe 0 expect(points.start.y).toBe 0 expect(points.end.x).toBe 0 expect(points.end.y).toBe -100 expect(points.control.x).toBeCloseTo 50 expect(points.control.y).toBeCloseTo -75 describe 'curveToPath method', -> it 'should return a path',-> mp = new MotionPath path: "M100, 299" el: document.createElement 'div' |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |