Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 | "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // import * as jQuery from 'jquery'; // @ts-ignore var MathLibs_1 = require("./Math/MathLibs"); var $ = require("jquery"); var jQuery = $; /* * jquery.zoomooz-helpers.js, part of: * http://janne.aukia.com/zoomooz * * LICENCE INFORMATION: * * Copyright (c) 2010 Janne Aukia (janne.aukia.com) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL Version 2 (GPL-LICENSE.txt) licenses. * */ /*jslint sub: true */ function getElemTransform(elem) { var regexp_filter_number = /([0-9.\-e]+)/g; var regexp_is_deg = /deg$/; var regexp_trans_splitter = /([a-zA-Z]+)\(([^\)]+)\)/g; function filterNumber(x) { return x.match(regexp_filter_number); } function rawRotationToRadians(raw) { var rot = parseFloat(filterNumber(raw)); if (raw.match(regexp_is_deg)) { rot = (2 * Math.PI) * rot / 360.0; } return rot; } var transString = $.zoomooz.helpers.getElementTransform(elem); var elementTransform = { sx: 1, sy: 1, tx: 0, ty: 0 }; var items; while ((items = regexp_trans_splitter.exec(transString)) !== null) { var action = items[1].toLowerCase(); var val = items[2].split(","), sx = void 0, sy = void 0; if (action == "matrix") { sx = parseFloat(val[0]); if (val.length > 1) { sy = parseFloat(val[3]); } else { sy = sx; } elementTransform.sx = sx; elementTransform.sy = sy; elementTransform.tx = parseFloat(filterNumber(val[4])); elementTransform.ty = parseFloat(filterNumber(val[5])); //TODO:Retrieve values from the matrix itself //trans = Matrix.create([[parseFloat(val[0]), parseFloat(val[2]), parseFloat(filterNumber(val[4]))], // [parseFloat(val[1]), parseFloat(val[3]), parseFloat(filterNumber(val[5]))], // [0, 0, 1]]); } else if (action == "translate") { elementTransform.tx = parseFloat(filterNumber(val[0])); elementTransform.ty = parseFloat(filterNumber(val[1])); } else if (action == "scale") { sx = parseFloat(val[0]); if (val.length > 1) { sy = parseFloat(val[1]); } else { sy = sx; } elementTransform.sx = sx; elementTransform.sy = sy; } else if (action == "rotate") { elementTransform.r = rawRotationToRadians(val[0]); } else if (action == "skew" || action == "skewx") { // TODO: supports only one parameter skew elementTransform.skeyx = Math.tan(rawRotationToRadians(val[0])); } else if (action == "skewy") { // TODO: test that this works (or unit test them all!) elementTransform.skeyy = Math.tan(rawRotationToRadians(val[0])); } else { console.log("Problem with setMatrixValue", action, val); } } return elementTransform; } if (!$.zoomooz) { $.zoomooz = {}; } $.zoomooz.helpers = (function ($, ns) { "use strict"; //**********************************// //*** Variables ***// //**********************************// var browser_prefixes = ["-moz-", "-webkit-", "-o-", "-ms-"]; //**********************************// //*** Helpers ***// //**********************************// ns.forEachPrefix = function (func, includeNoPrefix) { for (var i = 0; i < browser_prefixes.length; i++) { func(browser_prefixes[i]); } if (includeNoPrefix) { func(""); } }; ns.getElementTransform = function (elem) { var retVal; ns.forEachPrefix(function (prefix) { retVal = retVal || $(elem).css(prefix + "transform"); }, true); return retVal; }; return ns; })(jQuery, {}); /* * jquery.zoomooz-anim.js, part of: * http://janne.aukia.com/zoomooz * * LICENCE INFORMATION: * * Copyright (c) 2010 Janne Aukia (janne.aukia.com) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL Version 2 (GPL-LICENSE.txt) licenses. * * LICENCE INFORMATION FOR DERIVED FUNCTIONS: * * Functions CubicBezierAtPosition and * CubicBezierAtTime are written by Christian Effenberger, * and correspond 1:1 to WebKit project functions. * "WebCore and JavaScriptCore are available under the * Lesser GNU Public License. WebKit is available under * a BSD-style license." * */ /*jslint sub: true */ (function ($) { "use strict"; //**********************************// //*** Variables ***// //**********************************// var animation_start_time; var animation_interval_timer; var regexp_filter_number = /([0-9.\-e]+)/g; var regexp_trans_splitter = /([a-z]+)\(([^\)]+)\)/g; var regexp_is_deg = /deg$/; var helpers = $.zoomooz.helpers; var default_settings = { duration: 450, easing: "ease", /* Native animation may cause issues with pixelated content while zooming, and there might be other issues with browser compatibility etc. so use it with care and test on your target devices/browsers :). */ nativeanimation: false }; var endCallbackTimeout; //**********************************// //*** Setup css hook for IE ***// //**********************************// jQuery.cssHooks["MsTransform"] = { set: function (elem, value) { elem.style.msTransform = value; } }; jQuery.cssHooks["MsTransformOrigin"] = { set: function (elem, value) { elem.style.msTransformOrigin = value; } }; //**********************************// //*** jQuery functions ***// //**********************************// $.fn.animateTransformation = function (transformation, settings, posOffset, animateEndCallback, animateStartedCallback) { settings = jQuery.extend({}, default_settings, settings); // FIXME: what would be the best way to handle leftover animations? if (endCallbackTimeout) { clearTimeout(endCallbackTimeout); endCallbackTimeout = null; } if (settings.nativeanimation && animateEndCallback) { endCallbackTimeout = setTimeout(animateEndCallback, settings.duration); } this.each(function () { // @ts-ignore var $target = $(this); if (!transformation) { // @ts-ignore // @ts-ignore transformation = new MathLibs_1.PureCSSMatrix(); } var current_affine = constructAffineFixingRotation($target, posOffset); var final_affine = fixRotationToSameLap(current_affine, affineTransformDecompose(transformation)); if (settings.nativeanimation) { $target.css(constructZoomRootCssTransform(matrixCompose(final_affine), settings.duration, settings.easing)); if (animateStartedCallback) { animateStartedCallback(); } } else { animateTransition($target, current_affine, final_affine, settings, animateEndCallback, animateStartedCallback); } }); }; $.fn.setTransformation = function (transformation) { this.each(function () { // @ts-ignore var $target = $(this); // @ts-ignore var current_affine = constructAffineFixingRotation($target); var final_affine = fixRotationToSameLap(current_affine, affineTransformDecompose(transformation)); // @ts-ignore $target.css(constructZoomRootCssTransform(matrixCompose(final_affine))); }); }; //**********************************// //*** Element positioning ***// //**********************************// function constructZoomRootCssTransform(trans, duration, easing) { var propMap = {}; helpers.forEachPrefix(function (prefix) { propMap[prefix + "transform"] = trans; }, true); if (duration) { var transdur = roundNumber(duration / 1000, 6) + "s"; propMap["-webkit-transition-duration"] = transdur; propMap["-o-transition-duration"] = transdur; propMap["-moz-transition-duration"] = transdur; } if (easing) { var transtiming = constructEasingCss(easing); propMap["-webkit-transition-timing-function"] = transtiming; propMap["-o-transition-timing-function"] = transtiming; propMap["-moz-transition-timing-function"] = transtiming; } return propMap; } //**********************************// //*** Non-native animation ***// //**********************************// function animateTransition($target, st, et, settings, animateEndCallback, animateStartedCallback) { if (!st) { // @ts-ignore st = affineTransformDecompose(new MathLibs_1.PureCSSMatrix()); } animation_start_time = (new Date()).getTime(); if (animation_interval_timer) { clearInterval(animation_interval_timer); animation_interval_timer = null; } if (settings.easing) { settings.easingfunction = constructEasingFunction(settings.easing, settings.duration); } // first step animationStep($target, st, et, settings, animateEndCallback); if (animateStartedCallback) { animateStartedCallback(); } animation_interval_timer = setInterval(function () { animationStep($target, st, et, settings, animateEndCallback); }, 1); } function animationStep($target, affine_start, affine_end, settings, animateEndCallback) { var current_time = (new Date()).getTime() - animation_start_time; var time_value; if (settings.easingfunction) { time_value = settings.easingfunction(current_time / settings.duration); } else { time_value = current_time / settings.duration; } var interArrays = interpolateArrays(affine_start, affine_end, time_value); // @ts-ignore $target.css(constructZoomRootCssTransform(matrixCompose(interArrays))); if (current_time > settings.duration) { clearInterval(animation_interval_timer); animation_interval_timer = null; time_value = 1.0; if (animateEndCallback) { animateEndCallback(interArrays); } } } /* Based on pseudo-code in: * https://bugzilla.mozilla.org/show_bug.cgi?id=531344 */ function affineTransformDecompose(matrix) { var m = matrix.elements(); var a = m.a, b = m.b, c = m.c, d = m.d, e = m.e, f = m.f; if (Math.abs(a * d - b * c) < 0.01) { console.log("fail!"); return; } var tx = e, ty = f; var sx = Math.sqrt(a * a + b * b); a = a / sx; b = b / sx; var k = a * c + b * d; c -= a * k; d -= b * k; var sy = Math.sqrt(c * c + d * d); c = c / sy; d = d / sy; k = k / sy; if ((a * d - b * c) < 0.0) { a = -a; b = -b; c = -c; d = -d; sx = -sx; sy = -sy; } var r = Math.atan2(b, a); return { "tx": tx, "ty": ty, "r": r, "k": Math.atan(k), "sx": sx, "sy": sy }; } function matrixCompose(ia) { var ret = ""; /* this probably made safari 5.1.1. + os 10.6.8 + non-unibody mac? */ //ret += "translateZ(0) "; ret += "translate(" + roundNumber(ia.tx, 6) + "px," + roundNumber(ia.ty, 6) + "px) "; ret += "rotate(" + roundNumber(ia.r, 6) + "rad) skewX(" + roundNumber(ia.k, 6) + "rad) "; ret += "scale(" + roundNumber(ia.sx, 6) + "," + roundNumber(ia.sy, 6) + ")"; return ret; } //**********************************// //*** Easing functions ***// //**********************************// function constructEasingCss(input) { if ((input instanceof Array)) { return "cubic-bezier(" + roundNumber(input[0], 6) + "," + roundNumber(input[1], 6) + "," + roundNumber(input[2], 6) + "," + roundNumber(input[3], 6) + ")"; } else { return input; } } function constructEasingFunction(input, dur) { var params = []; if ((input instanceof Array)) { params = input; } else { switch (input) { case "linear": params = [0.0, 0.0, 1.0, 1.0]; break; case "ease": params = [0.25, 0.1, 0.25, 1.0]; break; case "ease-in": params = [0.42, 0.0, 1.0, 1.0]; break; case "ease-out": params = [0.0, 0.0, 0.58, 1.0]; break; case "ease-in-out": params = [0.42, 0.0, 0.58, 1.0]; break; } } var easingFunc = function (t) { return cubicBezierAtTime(t, params[0], params[1], params[2], params[3], dur); }; return easingFunc; } // From: http://www.netzgesta.de/dev/cubic-bezier-timing-function.html // 1:1 conversion to js from webkit source files // UnitBezier.h, WebCore_animation_AnimationBase.cpp function cubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) { var ax = 0, bx = 0, cx = 0, ay = 0, by = 0, cy = 0; // `ax t^3 + bx t^2 + cx t' expanded using Horner's rule. function sampleCurveX(t) { return ((ax * t + bx) * t + cx) * t; } function sampleCurveY(t) { return ((ay * t + by) * t + cy) * t; } function sampleCurveDerivativeX(t) { return (3.0 * ax * t + 2.0 * bx) * t + cx; } // The epsilon value to pass given that the animation is going to run over |dur| seconds. The longer the // animation, the more precision is needed in the timing function result to avoid ugly discontinuities. function solveEpsilon(duration) { return 1.0 / (200.0 * duration); } function solve(x, epsilon) { return sampleCurveY(solveCurveX(x, epsilon)); } // Given an x value, find a parametric value it came from. function solveCurveX(x, epsilon) { var t0, t1, t2, x2, d2, i; function fabs(n) { if (n >= 0) { return n; } else { return 0 - n; } } // First try a few iterations of Newton's method -- normally very fast. for (t2 = x, i = 0; i < 8; i++) { x2 = sampleCurveX(t2) - x; if (fabs(x2) < epsilon) { return t2; } d2 = sampleCurveDerivativeX(t2); if (fabs(d2) < 1e-6) { break; } t2 = t2 - x2 / d2; } // Fall back to the bisection method for reliability. t0 = 0.0; t1 = 1.0; t2 = x; if (t2 < t0) { return t0; } if (t2 > t1) { return t1; } while (t0 < t1) { x2 = sampleCurveX(t2); if (fabs(x2 - x) < epsilon) { return t2; } if (x > x2) { t0 = t2; } else { t1 = t2; } t2 = (t1 - t0) * 0.5 + t0; } return t2; // Failure. } // Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1). cx = 3.0 * p1x; bx = 3.0 * (p2x - p1x) - cx; ax = 1.0 - cx - bx; cy = 3.0 * p1y; by = 3.0 * (p2y - p1y) - cy; ay = 1.0 - cy - by; // Convert from input time to parametric value in curve, then from that to output time. return solve(t, solveEpsilon(duration)); } function constructAffineFixingRotation(elem, posOffset) { var rawTrans = helpers.getElementTransform(elem); var matr; if (!rawTrans) { // @ts-ignore matr = new MathLibs_1.PureCSSMatrix(); } else { // @ts-ignore matr = new MathLibs_1.PureCSSMatrix(rawTrans); } if (posOffset) { matr = matr.translate(posOffset.x, posOffset.y); } var current_affine = affineTransformDecompose(matr); // @ts-ignore current_affine.r = getTotalRotation(rawTrans); return current_affine; } function getTotalRotation(transString) { var totalRot = 0; var items; while ((items = regexp_trans_splitter.exec(transString)) !== null) { var action = items[1].toLowerCase(); var val = items[2].split(","); if (action == "matrix") { var recomposedTransItem = action + "(" + items[2] + ")"; // @ts-ignore totalRot += affineTransformDecompose(new MathLibs_1.PureCSSMatrix(recomposedTransItem)).r; } else if (action == "rotate") { var raw = val[0]; var rot = parseFloat(filterNumber(raw)); if (raw.match(regexp_is_deg)) { rot = (2 * Math.PI) * rot / 360.0; } totalRot += rot; } } return totalRot; } // TODO: use modulo instead of loops function fixRotationToSameLap(current_affine, final_affine) { if (Math.abs(current_affine.r - final_affine.r) > Math.PI) { if (final_affine.r < current_affine.r) { while (Math.abs(current_affine.r - final_affine.r) > Math.PI) { final_affine.r += (2 * Math.PI); } } else { while (Math.abs(current_affine.r - final_affine.r) > Math.PI) { final_affine.r -= (2 * Math.PI); } } } return final_affine; } //**********************************// //*** Helpers ***// //**********************************// function interpolateArrays(st, et, pos) { var it = {}; for (var i in st) { if (st.hasOwnProperty(i)) { it[i] = st[i] + (et[i] - st[i]) * pos; } } return it; } function roundNumber(number, precision) { precision = Math.abs(parseInt(precision, 10)) || 0; var coefficient = Math.pow(10, precision); return Math.round(number * coefficient) / coefficient; } function filterNumber(x) { return x.match(regexp_filter_number); } })(jQuery); ; /* * jquery.zoomooz-core.js, part of: * http://janne.aukia.com/zoomooz * * Version history: * 1.1.5 zoom for scrolled pages without flickering * 1.1.0 carousel prev/next navigation * 1.0.6 support for jQuery 1.9 * 1.0.4 fixed examples, iphone tuneups, transform offset fix * 1.0.3 added closeclick, code structuring * 1.0.2 bug fix on endcallback resetting for native animation * 1.0.1 declarative syntax and fixes * 0.9.2 working scrolling * 0.9.1 simplifying code base and scrolling for non-body zoom roots * 0.9.0 fixing margin on first body child * 0.8.9 support for jQuery 1.7 * 0.8.8 fixed a bug with 90 deg rotations * 0.8.7 fixed a bug with settings and a couple of demos * 0.8.6 fixed a bug with non-body zoom root * 0.8.5 basic IE9 support * 0.8.1 basic support for scrolling * 0.8.0 refactored position code to a separate file * 0.7.2 fixed a bug with skew in Webkit * 0.7.1 fixed bugs with FF4 * 0.7.0 support for non-body zoom root * 0.6.9 better settings management * 0.6.8 root element tuning * 0.6.7 adjustable zoom origin (not fully working yet) * 0.6.5 zoom origin to center * 0.6.3 basic Opera support * 0.6.1 refactored to use CSSMatrix classes * 0.5.1 initial public version * * LICENCE INFORMATION: * * Copyright (c) 2010 Janne Aukia (janne.aukia.com) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL Version 2 (GPL-LICENSE.txt) licenses. * * LICENCE INFORMATION FOR DERIVED FUNCTIONS: * * Function computeTotalTransformation based * on jquery.fn.offset, copyright John Resig, 2010 * (MIT and GPL Version 2). * */ /*jslint sub: true */ //TODO:CHeck this one (function ($) { "use strict"; //**********************************// //*** Variables ***// //**********************************// var helpers = $.zoomooz.helpers; var animationSettings = ["duration", "easing", "nativeanimation"]; //**********************************// //*** Static setup ***// //**********************************// // document.ready needed for scroll bar width // calculation setupCssStyles(); //**********************************// //*** jQuery functions ***// //**********************************// if (!$.zoomooz) { $.zoomooz = {}; } /* this can be used for setting the default settings for zoomooz explicitly. */ $.zoomooz.setup = function (settings) { $.zoomooz.defaultSettings = jQuery.extend(constructDefaultSettings(), settings); }; /* returns the zooming settings of a particular element. used by zoomTarget. */ $.fn.zoomSettings = function (settings) { var retValue; this.each(function () { // @ts-ignore var $elem = $(this); retValue = setupElementSettings($elem, settings); }); return retValue; }; /* the main zooming method. */ $.fn.zoomTo = function (settings, skipElementSettings) { this.each(function () { // @ts-ignore var $this = $(this); if (!skipElementSettings) { settings = $this.zoomSettings(settings); } zoomTo($this, settings); if (settings.debug) { if ($("#debug").length === 0) { $(settings.root).append('<div id="debug"><div>'); } else { $("#debug").html(""); } showDebug($this, settings); } else { if ($("#debug").length !== 0) { $("#debug").html(""); } } }); return this; }; //**********************************// //*** Setup functions ***// //**********************************// function setupElementSettings($elem, baseSettings) { var settings = jQuery.extend({}, baseSettings); if (!$.zoomooz.defaultSettings) { $.zoomooz.setup(); } var defaultSettings = $.zoomooz.defaultSettings; var elementSettings = jQuery.extend({}, settings); var key; for (key in defaultSettings) { if (defaultSettings.hasOwnProperty(key) && !elementSettings[key]) { elementSettings[key] = $elem.data(key); } } // FIXME: it would be better, that the animationSettings // would come from the jquery.zoomooz-anim file somehow for (var i = 0; i < animationSettings.length; i++) { key = animationSettings[i]; if (!elementSettings[key]) { elementSettings[key] = $elem.data(key); } } return jQuery.extend({}, defaultSettings, elementSettings); } /* setup css styles in javascript to not need an extra zoomooz.css file for the user to load. having the styles here helps also at keeping the css requirements minimal. */ function setupCssStyles() { var style = document.createElement('style'); style.type = 'text/css'; var transformOrigin = ""; helpers.forEachPrefix(function () { // transformOrigin += prefix+"transform-origin: 0 0;"; }, true); // FIXME: how to remove the html height requirement? // FIXME: how to remove the transform origin? style.innerHTML = "html {height:100%;}" + ".noScroll{overflow:hidden !important;}" + "* {" + transformOrigin + "}"; document.getElementsByTagName('head')[0].appendChild(style); $(document).ready(function () { var scrollBarWidth = window.innerWidth - $("body").width(); style.innerHTML += "body.noScroll,html.noScroll body{margin-right:" + scrollBarWidth + "px;}"; }); } function constructDefaultSettings() { var retObject = { targetsize: 0.9, scalemode: "both", root: $(document.body), debug: false, animationendcallback: null, closeclick: false }; // FIXME: feat detection would be better var isFF = (window.mozInnerScreenX !== undefined); retObject.scrollresetbeforezoom = isFF; return retObject; } function zoomTo(elem, settings) { // scrolling: var useScrollResetBeforeZoom = settings.scrollresetbeforezoom; var scrollData = null; var startedZoomFromScroll; (function () { var $root = settings.root; var $scroll = $root.parent(); if (elem[0] === $root[0]) { scrollData = getExistingScrollData($root, $scroll); } else if (!$root.data("original-scroll")) { startedZoomFromScroll = true; scrollData = storeNewScrollData($root, $scroll, useScrollResetBeforeZoom); } else if (!useScrollResetBeforeZoom) { scrollData = getExistingScrollData($root, $scroll); } }()); var rootTransformation; var animationendcallback = null; //setTransformOrigin(elem, settings.root, settings); var animScrollData = null; if (elem[0] !== settings.root[0]) { var elemTransMatrices = computeTotalTransformation(elem, settings.root); //let invTranslate = elemTransMatrices.translateMatrix.inverse(); //let invScale = elemTransMatrices.scaleMatrix.inverse(); //let invTransScale = elemTransMatrices.scaleTranslationMatrix.inverse(); if (!useScrollResetBeforeZoom) { animScrollData = scrollData; } rootTransformation = computeViewportTransformation(elem, elemTransMatrices, animScrollData, settings); if (settings.animationendcallback) { animationendcallback = function (arg) { settings.animationendcallback.call(elem[0], arg); }; } } else { if (useScrollResetBeforeZoom) { // @ts-ignore rootTransformation = (new MathLibs_1.PureCSSMatrix()).translate(-scrollData.x, -scrollData.y); } animationendcallback = function () { var $root = $(settings.root); var $scroll; if (scrollData !== null) $scroll = scrollData.elem; $scroll.removeClass("noScroll"); // @ts-ignore $root.setTransformation(new MathLibs_1.PureCSSMatrix()); $root.data("original-scroll", null); $(document).off("touchmove"); if (useScrollResetBeforeZoom) { // this needs to be after the setTransformation and // done with window.scrollTo to not have iPhone repaints if ($scroll[0] == document.body || $scroll[0] == window) { if (scrollData !== null) window.scrollTo(scrollData.x, scrollData.y); } else { if (scrollData !== null) { $scroll.scrollLeft(scrollData.x); $scroll.scrollTop(scrollData.y); } } } if (settings.animationendcallback) { settings.animationendcallback.call(elem[0]); } }; } var animationstartedcallback = null; if (useScrollResetBeforeZoom && scrollData && scrollData.animationstartedcallback) { animationstartedcallback = scrollData.animationstartedcallback; } if (!startedZoomFromScroll) { animScrollData = false; } $(settings.root).animateTransformation(rootTransformation, settings, animScrollData, animationendcallback, animationstartedcallback); } //**********************************// //*** Handle scrolling ***// //**********************************// function getExistingScrollData($root, $scroll) { var scrollData = $root.data("original-scroll"); if (!scrollData) { scrollData = { "elem": $scroll, "x": 0, "y:": 0 }; } return scrollData; } function storeNewScrollData($root, $scroll, useScrollResetBeforeZoom) { // safari var scrollY = $root.scrollTop(); var scrollX = $root.scrollLeft(); var elem = $root; // moz if (!scrollY) { scrollY = $scroll.scrollTop(); scrollX = $scroll.scrollLeft(); elem = $scroll; } var scrollData = { "elem": elem, "x": scrollX, "y": scrollY }; $root.data("original-scroll", scrollData); $(document).on("touchmove", function (e) { e.preventDefault(); }); var transformStr = "translate(-" + scrollX + "px,-" + scrollY + "px)"; helpers.forEachPrefix(function (prefix) { $root.css(prefix + "transform", transformStr); }); elem.addClass("noScroll"); if (useScrollResetBeforeZoom) { scrollData.animationstartedcallback = function () { // this needs to be after the setTransformation and // done with window.scrollTo to not have iPhone repaints if (elem[0] == document.body || elem[0] == document) { window.scrollTo(0, 0); } else { elem.scrollLeft(0); elem.scrollTop(0); } }; } return scrollData; } function getOuterWidth(elem) { var outerWidth = elem.outerWidth(); if (outerWidth == 0) { outerWidth = elem.prop('scrollWidth'); } return outerWidth; } function getOuterHeight(elem) { var outerHeight = elem.outerHeight(); if (outerHeight == 0) { outerHeight = elem.prop('scrollHeight'); } return outerHeight; } //**********************************// //*** Element positioning ***// //**********************************// function getScale(dh, dw, elem, settings) { var outerHeight = getOuterHeight(elem), outerWidth = getOuterWidth(elem); var relw = dw / outerWidth; var relh = dh / outerHeight; var zoomMode = settings.scalemode; var zoomAmount = settings.targetsize; var scale; if (zoomMode == "none") { scale = 1; } else if (zoomMode == "width") { scale = zoomAmount * relw; } else if (zoomMode == "height") { scale = zoomAmount * relh; } else if (zoomMode == "both") { scale = zoomAmount * Math.min(relw, relh); } else if (zoomMode == "scale") { scale = zoomAmount; } else { console.log("wrong zoommode:" + zoomMode); throw "wrong zoommode:" + zoomMode; } return scale; } function computeViewportTransformation(elem, endtrans, scrollData, settings) { var zoomParent = settings.root; var zoomViewport = $(zoomParent); //.parent(); var dw = zoomViewport.width(); var dh = zoomViewport.height(); var scale = getScale(dh, dw, elem, settings); var domElem = elem[0]; //This is suspect, figure out what the real offset should be // @ts-ignore var xoffset = domElem.offsetLeft * scale * (1 - settings.targetsize); // @ts-ignore var yoffset = domElem.offsetTop * scale * (1 - settings.targetsize); // @ts-ignore var xrotorigin = dw / 2.0; // @ts-ignore var yrotorigin = dh / 2.0; /* fix for body margins, hope that this does not break anything .. */ /* see also the part of the fix that is in computeTotalTransformation! */ var xmarginfix = -parseFloat(zoomParent.css("margin-left")) || 0; var ymarginfix = -parseFloat(zoomParent.css("margin-top")) || 0; // @ts-ignore var initTransformation = (new MathLibs_1.PureCSSMatrix()); if (scrollData) { initTransformation = initTransformation.translate(scrollData.x, scrollData.y); } //This is a bug fix to account for when element is shifted due to it's scaling //let txTrans = ((elem.outerWidth() * (1 - elemScale.sx)) / 2); //let tyTrans = ((elem.outerHeight() * (1 - elemScale.sy)) / 2); // let scaleElemOffsetX = domElem.offsetLeft / scale; // let scaleElemOffsetY = domElem.offsetTop / scale; //let vpxTrans = container.outerWidth() * (scale - 1) / 2; //let vpyTrans = container.outerHeight() * (scale - 1) / 2; // let singleElemScale = endScale.multiply(endtrans).multiply(endtransScale); var finalMove = settings.navOffset; //Separate this into functions that return the specific matrix you need and we combine the results of each //Make it so that I can see the result of the matrix at each point rather than just at the end var viewportTransformation = initTransformation .translate(xmarginfix, ymarginfix) .translate(-xrotorigin, -yrotorigin) .translate(xoffset, yoffset) .scale(scale, scale) .multiply(endtrans) .translate(-xmarginfix, -ymarginfix) .translate(xrotorigin, yrotorigin) .translate(-xoffset, -yoffset); if (finalMove) { viewportTransformation = viewportTransformation.translate(finalMove.x + xoffset, finalMove.y + yoffset); } return viewportTransformation; } //**********************************// //*** Debugging positioning ***// //**********************************// function calcPoint(e, x, y) { return [e.a * x + e.c * y + e.e, e.b * x + e.d * y + e.f]; } function showDebug(elem, settings) { return; // @ts-ignore var e = computeTotalTransformation(elem, settings.root); e = e.scaleMatrix.multiply(e.translateMatrix); e = e.elements(); displayLabel(calcPoint(e, 0, 0)); displayLabel(calcPoint(e, 0, getOuterHeight(elem))); displayLabel(calcPoint(e, getOuterWidth(elem), getOuterHeight(elem))); displayLabel(calcPoint(e, getOuterWidth(elem), 0)); } function displayLabel(pos) { var labelStyle = "width:4px;height:4px;background-color:red;position:absolute;margin-left:-2px;margin-top:-2px;"; labelStyle += 'left:' + pos[0] + 'px;top:' + pos[1] + 'px;'; var label = '<div class="debuglabel" style="' + labelStyle + '"></div>'; $("#debug").append(label); } //**********************************// //*** Calculating element ***// //*** total transformation ***// //**********************************// /* Based on: * jQuery.fn.offset */ function computeTotalTransformation(input, transformationRootElement) { var elem = input[0]; var zoomToElem = $(elem); if (!elem || !elem.ownerDocument) { return null; } // @ts-ignore var totalTranslation = new MathLibs_1.PureCSSMatrix(); // @ts-ignore var totalScale = new MathLibs_1.PureCSSMatrix(); // @ts-ignore var totalScaleTrans = new MathLibs_1.PureCSSMatrix(); // @ts-ignore var finalTransformation = new MathLibs_1.PureCSSMatrix(); var trans; if (elem === elem.ownerDocument.body) { var bOffset = jQuery.offset.bodyOffset(elem); // @ts-ignore trans = new MathLibs_1.PureCSSMatrix(); trans = trans.translate(bOffset.left, bOffset.top); totalTranslation = totalTranslation.multiply(trans); return totalTranslation; } var support; if (jQuery.offset.initialize) { jQuery.offset.initialize(); support = { fixedPosition: jQuery.offset.supportsFixedPosition, doesNotAddBorder: jQuery.offset.doesNotAddBorder, doesAddBorderForTableAndCells: jQuery.support.doesAddBorderForTableAndCells, subtractsBorderForOverflowNotVisible: jQuery.offset.subtractsBorderForOverflowNotVisible }; } else { support = jQuery.support; } var offsetParent = elem.offsetParent; var doc = elem.ownerDocument; var computedStyle; var docElem = doc.documentElement; var body = doc.body; var root = transformationRootElement[0]; var defaultView = doc.defaultView; var prevComputedStyle; if (defaultView) { prevComputedStyle = defaultView.getComputedStyle(elem, null); } else { prevComputedStyle = elem.currentStyle; } /* function offsetParentInsideRoot($elem, $root) { // FIXME: // wondering, should this be $root.closest() // or $root.parent().closest... let $viewport = $root.parent(); let $offsetParent = $elem.offsetParent(); return ($viewport[0]==$offsetParent[0]) || $viewport.closest($offsetParent).length==0; } console.log("inside root",offsetParentInsideRoot(input, transformationRootElement)); */ var top = elem.offsetTop; var left = elem.offsetLeft; // @ts-ignore var transformation = constructTransformation().translate(left, top); var elemTransform = getElemTransform(elem); totalScale = totalScale.scale(elemTransform.sx, elemTransform.sy); transformation = transformation.translate(elemTransform.tx, elemTransform.ty); var eletxTrans = ((zoomToElem.outerWidth() * (1 - elemTransform.sx)) / 2); var eletyTrans = ((zoomToElem.outerHeight() * (1 - elemTransform.sy)) / 2); // @ts-ignore totalScaleTrans = constructTransformation().translate(eletxTrans, eletyTrans); var runningTranslationX = left + elemTransform.tx; var runningTranslationY = top + elemTransform.ty; // transformation = transformation.multiply(constructTransformation(elem)); totalTranslation = transformation.multiply((totalTranslation)); finalTransformation = finalTransformation.multiply(totalScale.inverse()).multiply(totalTranslation.inverse()).multiply(totalScaleTrans.inverse()); // loop from node down to root //Separate the calculation of the scales from the calculation of the translation somehow to make it easier to read while ((elem = elem.parentNode) && elem !== root && elem.ownerDocument.body !== elem) { var elementTransform = getElemTransform(elem); runningTranslationX *= elementTransform.sx; runningTranslationY *= elementTransform.sy; top = 0; left = 0; if (support.fixedPosition && prevComputedStyle.position === "fixed") { break; } computedStyle = defaultView ? defaultView.getComputedStyle(elem, null) : elem.currentStyle; top -= elem.scrollTop; left -= elem.scrollLeft; if (elem === offsetParent) { top += elem.offsetTop; left += elem.offsetLeft; if (support.doesNotAddBorder && !(support.doesAddBorderForTableAndCells && /^t(able|d|h)$/i.test(elem.nodeName))) { top += parseFloat(computedStyle.borderTopWidth) || 0; left += parseFloat(computedStyle.borderLeftWidth) || 0; } offsetParent = elem.offsetParent; } if (support.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== "visible") { top += parseFloat(computedStyle.borderTopWidth) || 0; left += parseFloat(computedStyle.borderLeftWidth) || 0; } prevComputedStyle = computedStyle; if (elem.offsetParent == root) { top -= parseFloat($(elem.offsetParent).css("margin-top")) || 0; left -= parseFloat($(elem.offsetParent).css("margin-left")) || 0; } runningTranslationX += left; runningTranslationY += top; runningTranslationX += elementTransform.tx; runningTranslationY += elementTransform.ty; // @ts-ignore transformation = constructTransformation().translate(left, top); transformation = transformation.translate(elementTransform.tx, elementTransform.ty); // totalTranslation = transformation.multiply(totalTranslation); totalScale = totalScale.scale(elementTransform.sx, elementTransform.sy); eletxTrans *= elementTransform.sx; eletyTrans *= elementTransform.sy; // totalScaleTrans = totalScaleTrans.scale(elementTransform.sx, elementTransform.sy); var $elem = $(elem); var txTrans = (($elem.outerWidth() * (1 - elementTransform.sx)) / 2); var tyTrans = (($elem.outerHeight() * (1 - elementTransform.sy)) / 2); totalScaleTrans = totalScaleTrans.translate(txTrans, tyTrans); eletxTrans += txTrans; eletyTrans += tyTrans; finalTransformation = finalTransformation.multiply(totalScale.inverse()) /*.multiply(totalTranslation.inverse())*/.multiply(totalScaleTrans.inverse()); } top = 0; left = 0; // fixme: should disable these for non-body roots? if (prevComputedStyle.position === "relative" || prevComputedStyle.position === "static") { top += body.offsetTop; left += body.offsetLeft; } if (support.fixedPosition && prevComputedStyle.position === "fixed") { top += Math.max(docElem.scrollTop, body.scrollTop); left += Math.max(docElem.scrollLeft, body.scrollLeft); } runningTranslationX += left; runningTranslationY += top; // @ts-ignore var itertrans = (new MathLibs_1.PureCSSMatrix()).translate(runningTranslationX, runningTranslationY); totalTranslation = itertrans; //totalTranslation.multiply(itertrans); // @ts-ignore totalScaleTrans = (new MathLibs_1.PureCSSMatrix()).translate(eletxTrans, eletyTrans); // return totalScale.inverse().multiply(totalTranslation.inverse()).multiply(totalScaleTrans.inverse()); return finalTransformation; // return totalScale.inverse().multiply(totalTranslation.inverse()).multiply(totalScaleTrans.inverse()); // return finalTransformation; //totalScale.inverse().multiply(totalTranslation.inverse()).multiply(totalScaleTrans.inverse()); //{ translateMatrix: totalTranslation, scaleMatrix: totalScale, scaleTranslationMatrix:totalScaleTrans } } //**********************************// //*** Helpers ***// //**********************************// function printFixedNumber(x) { return Number(x).toFixed(6); } function constructTransformation(elem) { var rawTrans = helpers.getElementTransform(elem); if (!rawTrans) { // @ts-ignore return new MathLibs_1.PureCSSMatrix(); } else { // @ts-ignore return new MathLibs_1.PureCSSMatrix(rawTrans); } } })(jQuery); ; /* * jquery.zoomooz-zoomTarget.js, part of: * http://janne.aukia.com/zoomooz * * LICENCE INFORMATION: * * Copyright (c) 2010 Janne Aukia (janne.aukia.com) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL Version 2 (GPL-LICENSE.txt) licenses. * */ /*jslint sub: true */ (function ($) { "use strict"; if (!$.zoomooz) { $.zoomooz = {}; } //**********************************// //*** Variables ***// //**********************************// var helpers = $.zoomooz.helpers; //**********************************// //*** jQuery functions ***// //**********************************// $.fn.zoomTarget = function (baseSettings) { this.each(function () { // @ts-ignore var settings = $(this).zoomSettings(baseSettings); // @ts-ignore setupClickHandler($(this), $(this), settings); }); }; //**********************************// //*** Helper functions ***// //**********************************// function setupClickHandler(clickTarget, zoomTarget, settings) { clickTarget.addClass("zoomTarget"); if (!settings.animationendcallback) { if (!settings.closeclick) { settings.animationendcallback = function () { $(".selectedZoomTarget").removeClass("selectedZoomTarget zoomNotClickable"); clickTarget.addClass("selectedZoomTarget zoomNotClickable"); }; } else { settings.animationendcallback = function () { $(".selectedZoomTarget").removeClass("selectedZoomTarget zoomNotClickable"); clickTarget.addClass("selectedZoomTarget"); }; } } var zoomContainer = zoomTarget.closest(".zoomContainer"); if (zoomContainer.length !== 0) { settings.root = zoomContainer; } var $root = settings.root; if (!$root.hasClass("zoomTarget")) { var rootSettings = $root.zoomSettings(jQuery); rootSettings.animationendcallback = function () { var $elem = $(this); $(".selectedZoomTarget").removeClass("selectedZoomTarget zoomNotClickable"); $elem.addClass("selectedZoomTarget zoomNotClickable"); $elem.parent().addClass("selectedZoomTarget zoomNotClickable"); }; setupClickHandler($root, $root, rootSettings); setupClickHandler($root.parent(), $root, rootSettings); // FIXME: there could be many of these called simultaneously, // don't know what would happen then $root.click(); } clickTarget.on("click", function (evt) { // closeclick not available here... if (settings.closeclick && zoomTarget.hasClass("selectedZoomTarget")) { settings.root.click(); } else { zoomTarget.zoomTo(settings); } evt.stopPropagation(); }); } //**********************************// //*** Setup functions ***// //**********************************// /* setup css styles in javascript to not need an extra zoomooz.css file for the user to load. having the styles here helps also at keeping the css requirements minimal. */ function setupCssStyles() { var style = document.createElement('style'); style.type = 'text/css'; function setupSelectionCss(enabled) { var selectionString = "-webkit-touch-callout: " + (enabled ? "default" : "none") + ";"; helpers.forEachPrefix(function (prefix) { selectionString += prefix + "user-select:" + (enabled ? "text" : "none") + ";"; }, true); return selectionString; } // FIXME: how to remove the html height requirement? // FIXME: how to remove the transform origin? style.innerHTML = ".zoomTarget{" + setupSelectionCss(false) + "}" + ".zoomTarget:hover{cursor:pointer!important;}" + ".zoomNotClickable{" + setupSelectionCss(true) + "}" + ".zoomNotClickable:hover{cursor:auto!important;}" + /* padding to fix margin collapse issues */ ".zoomContainer{position:relative;padding:1px;margin:-1px;}"; document.getElementsByTagName('head')[0].appendChild(style); } //**********************************// //*** Static setup ***// //**********************************// setupCssStyles(); // make all elements with the zoomTarget class zooming $(document).ready(function () { // this needs to be after the "$.fn.zoomTarget" has been initialized $(".zoomTarget").zoomTarget(); }); })(jQuery); ; /* * jquery.zoomooz-zoomContainer.js, part of: * http://janne.aukia.com/zoomooz * * LICENCE INFORMATION: * * Copyright (c) 2010 Janne Aukia (janne.aukia.com) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL Version 2 (GPL-LICENSE.txt) licenses. * */ /*jslint sub: true */ // @ts-ignore // @ts-ignore // @ts-ignore (function ($) { "use strict"; if (!$.zoomooz) { $.zoomooz = {}; } //**********************************// //*** Variables ***// //**********************************// //let helpers = $.zoomooz.helpers; //**********************************// //*** jQuery functions ***// //**********************************// $.fn.zoomContainer = function () { // add next and previous calls to the canvas // (auto detect next and previous buttons) }; //**********************************// //*** Static setup ***// //**********************************// // FIXME: move zoomContainer styling here? //setupCssStyles(); // make all elements with the zoomContainer class zooming containers $(document).ready(function () { // this needs to be after the "$.fn.zoomContainer" has been initialized $(".zoomContainer").zoomContainer(); }); })(jQuery); function zoomTo(element, settings, skipElementSettings) { $(element).zoomTo(settings, skipElementSettings); } exports.zoomTo = zoomTo; exports.jQ = jQuery; |