j1m_app 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +21 -0
  3. data/README.md +41 -0
  4. data/_data/modules/default/j1_app-0.0.1/j1_iframe_resizer.yml +270 -0
  5. data/_data/resources/default/j1_app-0.0.1/resource.yml +22 -0
  6. data/assets/themes/j1/iframe_resizer/.npmignore +9 -0
  7. data/assets/themes/j1/iframe_resizer/.travis.yml +6 -0
  8. data/assets/themes/j1/iframe_resizer/CONTRIBUTING.md +86 -0
  9. data/assets/themes/j1/iframe_resizer/Iframe-resizer by davidjbradshaw.url +2 -0
  10. data/assets/themes/j1/iframe_resizer/LICENSE +21 -0
  11. data/assets/themes/j1/iframe_resizer/README.md +608 -0
  12. data/assets/themes/j1/iframe_resizer/bower.json +45 -0
  13. data/assets/themes/j1/iframe_resizer/example/frame.absolute.html +88 -0
  14. data/assets/themes/j1/iframe_resizer/example/frame.content.html +58 -0
  15. data/assets/themes/j1/iframe_resizer/example/frame.hover.html +51 -0
  16. data/assets/themes/j1/iframe_resizer/example/frame.nested.html +72 -0
  17. data/assets/themes/j1/iframe_resizer/example/frame.textarea.html +46 -0
  18. data/assets/themes/j1/iframe_resizer/example/frame.tolerance.html +79 -0
  19. data/assets/themes/j1/iframe_resizer/example/index.html +70 -0
  20. data/assets/themes/j1/iframe_resizer/example/two.html +71 -0
  21. data/assets/themes/j1/iframe_resizer/gruntfile.js +215 -0
  22. data/assets/themes/j1/iframe_resizer/iframeResizer.jquery.json +41 -0
  23. data/assets/themes/j1/iframe_resizer/index.js +4 -0
  24. data/assets/themes/j1/iframe_resizer/js/_client.js +1131 -0
  25. data/assets/themes/j1/iframe_resizer/js/_server.js +1126 -0
  26. data/assets/themes/j1/iframe_resizer/js/ie8.polyfils.js +85 -0
  27. data/assets/themes/j1/iframe_resizer/js/ie8.polyfils.map +1 -0
  28. data/assets/themes/j1/iframe_resizer/js/ie8.polyfils.min.js +4 -0
  29. data/assets/themes/j1/iframe_resizer/js/iframeResizer.contentWindow.js +1104 -0
  30. data/assets/themes/j1/iframe_resizer/js/iframeResizer.contentWindow.map +1 -0
  31. data/assets/themes/j1/iframe_resizer/js/iframeResizer.contentWindow.min.js +10 -0
  32. data/assets/themes/j1/iframe_resizer/js/iframeResizer.js +1007 -0
  33. data/assets/themes/j1/iframe_resizer/js/iframeResizer.js.modified +1004 -0
  34. data/assets/themes/j1/iframe_resizer/js/iframeResizer.map +1 -0
  35. data/assets/themes/j1/iframe_resizer/js/iframeResizer.min.js +9 -0
  36. data/assets/themes/j1/iframe_resizer/js/index.js +2 -0
  37. data/assets/themes/j1/iframe_resizer/karma.conf.js +92 -0
  38. data/assets/themes/j1/iframe_resizer/package.json +111 -0
  39. data/assets/themes/j1/iframe_resizer/spec/_initSpec.js +63 -0
  40. data/assets/themes/j1/iframe_resizer/spec/anchorSpec.js +62 -0
  41. data/assets/themes/j1/iframe_resizer/spec/childSpec.js +403 -0
  42. data/assets/themes/j1/iframe_resizer/spec/closeSpecSpec.js +44 -0
  43. data/assets/themes/j1/iframe_resizer/spec/getPageInfoSpec.js +32 -0
  44. data/assets/themes/j1/iframe_resizer/spec/initCssSpec.js +28 -0
  45. data/assets/themes/j1/iframe_resizer/spec/initDomSpec.js +27 -0
  46. data/assets/themes/j1/iframe_resizer/spec/initDoubleCallSpec.js +33 -0
  47. data/assets/themes/j1/iframe_resizer/spec/initErrorSpec.js +57 -0
  48. data/assets/themes/j1/iframe_resizer/spec/initJQuerySpec.js +29 -0
  49. data/assets/themes/j1/iframe_resizer/spec/initUndefinedDomSpec.js +25 -0
  50. data/assets/themes/j1/iframe_resizer/spec/javascripts/fixtures/iframe.html +2 -0
  51. data/assets/themes/j1/iframe_resizer/spec/javascripts/fixtures/iframe600.html +4 -0
  52. data/assets/themes/j1/iframe_resizer/spec/javascripts/fixtures/iframe600WithId.html +4 -0
  53. data/assets/themes/j1/iframe_resizer/spec/lib/common.js +59 -0
  54. data/assets/themes/j1/iframe_resizer/spec/parentSpec.js +88 -0
  55. data/assets/themes/j1/iframe_resizer/spec/resources/djb.jpg +0 -0
  56. data/assets/themes/j1/iframe_resizer/spec/resources/frame.content.html +176 -0
  57. data/assets/themes/j1/iframe_resizer/spec/resources/frame.lateload.html +33 -0
  58. data/assets/themes/j1/iframe_resizer/spec/resources/frame.nested.html +40 -0
  59. data/assets/themes/j1/iframe_resizer/spec/scrollSpec.js +53 -0
  60. data/assets/themes/j1/iframe_resizer/spec/sendMessageSpec.js +58 -0
  61. data/assets/themes/j1/iframe_resizer/spec/support/jasmine.json +9 -0
  62. data/assets/themes/j1/iframe_resizer/src/ie8.polyfils.js +64 -0
  63. data/assets/themes/j1/iframe_resizer/src/iframeResizer.contentWindow.js +1123 -0
  64. data/assets/themes/j1/iframe_resizer/src/iframeResizer.js +1002 -0
  65. data/assets/themes/j1/iframe_resizer/test-main.js +33 -0
  66. data/assets/themes/j1/iframe_resizer/test/_init.html +44 -0
  67. data/assets/themes/j1/iframe_resizer/test/_init_once.html +45 -0
  68. data/assets/themes/j1/iframe_resizer/test/_init_once_async.html +72 -0
  69. data/assets/themes/j1/iframe_resizer/test/background.html +47 -0
  70. data/assets/themes/j1/iframe_resizer/test/changePage.html +50 -0
  71. data/assets/themes/j1/iframe_resizer/test/close.html +44 -0
  72. data/assets/themes/j1/iframe_resizer/test/getId.html +44 -0
  73. data/assets/themes/j1/iframe_resizer/test/interval.html +56 -0
  74. data/assets/themes/j1/iframe_resizer/test/jqueryNoConflict.html +47 -0
  75. data/assets/themes/j1/iframe_resizer/test/lateImageLoad.html +90 -0
  76. data/assets/themes/j1/iframe_resizer/test/margin.html +73 -0
  77. data/assets/themes/j1/iframe_resizer/test/mutationObserver.html +63 -0
  78. data/assets/themes/j1/iframe_resizer/test/nested.html +46 -0
  79. data/assets/themes/j1/iframe_resizer/test/resize.contentWidth.html +51 -0
  80. data/assets/themes/j1/iframe_resizer/test/resize.width.html +63 -0
  81. data/assets/themes/j1/iframe_resizer/test/resources/djb.jpg +0 -0
  82. data/assets/themes/j1/iframe_resizer/test/resources/frame.content.html +191 -0
  83. data/assets/themes/j1/iframe_resizer/test/resources/frame.lateload.html +33 -0
  84. data/assets/themes/j1/iframe_resizer/test/resources/frame.nested.html +40 -0
  85. data/assets/themes/j1/iframe_resizer/test/resources/jquery.js +6 -0
  86. data/assets/themes/j1/iframe_resizer/test/resources/qunit.css +244 -0
  87. data/assets/themes/j1/iframe_resizer/test/resources/qunit.js +2212 -0
  88. data/assets/themes/j1/iframe_resizer/test/resources/require.js +2103 -0
  89. data/assets/themes/j1/iframe_resizer/test/resources/testLib.js +9 -0
  90. data/assets/themes/j1/iframe_resizer/test/scrolling.html +65 -0
  91. data/assets/themes/j1/iframe_resizer/test/sendMessage.html +61 -0
  92. data/assets/themes/j1/iframe_resizer/test/setHeightCalculationMethod.html +51 -0
  93. data/assets/themes/j1/iframe_resizer/test/size.html +64 -0
  94. data/assets/themes/j1/iframe_resizer/test/v1.html +189 -0
  95. data/exe/console +14 -0
  96. data/exe/setup +8 -0
  97. data/lib/j1m_app.rb +5 -0
  98. data/lib/j1m_app/version.rb +3 -0
  99. metadata +187 -0
@@ -0,0 +1,85 @@
1
+ /*
2
+ * IE8 Polyfils for iframeResizer.js
3
+ *
4
+ * Public domain code - Mozilla Contributors
5
+ * https://developer.mozilla.org/
6
+ */
7
+
8
+ if (!Array.prototype.forEach){
9
+ Array.prototype.forEach = function(fun /*, thisArg */){
10
+ "use strict";
11
+ if (this === void 0 || this === null || typeof fun !== "function") throw new TypeError();
12
+
13
+ var
14
+ t = Object(this),
15
+ len = t.length >>> 0,
16
+ thisArg = arguments.length >= 2 ? arguments[1] : void 0;
17
+
18
+ for (var i = 0; i < len; i++)
19
+ if (i in t)
20
+ fun.call(thisArg, t[i], i, t);
21
+ };
22
+ }
23
+
24
+
25
+ if (!Function.prototype.bind) {
26
+ Function.prototype.bind = function(oThis) {
27
+ if (typeof this !== 'function') {
28
+ // closest thing possible to the ECMAScript 5
29
+ // internal IsCallable function
30
+ throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
31
+ }
32
+
33
+ var aArgs = Array.prototype.slice.call(arguments, 1),
34
+ fToBind = this,
35
+ fNOP = function() {},
36
+ fBound = function() {
37
+ return fToBind.apply(this instanceof fNOP ? this : oThis,
38
+ aArgs.concat(Array.prototype.slice.call(arguments)));
39
+ };
40
+
41
+ fNOP.prototype = this.prototype;
42
+ fBound.prototype = new fNOP();
43
+
44
+ return fBound;
45
+ };
46
+ }
47
+
48
+
49
+ //addEventListener polyfill 1.0 / Eirik Backer / MIT Licence
50
+ (function(win, doc){
51
+ if(win.addEventListener) return; //No need to polyfill
52
+
53
+ function docHijack(p){
54
+ var old = doc[p];
55
+ doc[p] = function(v){
56
+ return addListen(old(v));
57
+ };
58
+ }
59
+
60
+ function addEvent(on, fn, self){
61
+ return (self = this).attachEvent('on' + on, function(e){
62
+ e = e || win.event;
63
+ e.preventDefault = e.preventDefault || function(){e.returnValue = false;};
64
+ e.stopPropagation = e.stopPropagation || function(){e.cancelBubble = true;};
65
+ fn.call(self, e);
66
+ });
67
+ }
68
+
69
+ function addListen(obj, i){
70
+ i = obj.length;
71
+ if(i) while(i--) obj[i].addEventListener = addEvent;
72
+ else obj.addEventListener = addEvent;
73
+ return obj;
74
+ }
75
+
76
+ addListen([doc, win]);
77
+ if('Element' in win)win.Element.prototype.addEventListener = addEvent; //IE8
78
+ else{ //IE < 8
79
+ doc.attachEvent('onreadystatechange', function(){addListen(doc.all);}); //Make sure we also init at domReady
80
+ docHijack('getElementsByTagName');
81
+ docHijack('getElementById');
82
+ docHijack('createElement');
83
+ addListen(doc.all);
84
+ }
85
+ })(window, document);
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/ie8.polyfils.js"],"names":["Array","prototype","forEach","fun","this","TypeError","t","Object","len","length","thisArg","arguments","i","call","Function","bind","oThis","aArgs","slice","fToBind","fNOP","fBound","apply","concat","callback","O","k"],"mappings":";;AAOMA,MAAMC,UAAUC,UACrBF,MAAMC,UAAUC,QAAU,SAASC,GAClC,YACA,IAAa,SAATC,MAA4B,OAATA,MAAgC,kBAARD,GAAoB,KAAM,IAAIE,UAO7E,KAAK,GAJJC,GAAIC,OAAOH,MACXI,EAAMF,EAAEG,SAAW,EACnBC,EAAUC,UAAUF,QAAU,EAAIE,UAAU,GAAK,OAEzCC,EAAI,EAAOJ,EAAJI,EAASA,IACpBA,IAAKN,IACRH,EAAIU,KAAKH,EAASJ,EAAEM,GAAIA,EAAGN,KAK1BQ,SAASb,UAAUc,OACtBD,SAASb,UAAUc,KAAO,SAASC,GACjC,GAAoB,kBAATZ,MAGT,KAAM,IAAIC,WAAU,uEAGtB,IAAIY,GAAUjB,MAAMC,UAAUiB,MAAML,KAAKF,UAAW,GAChDQ,EAAUf,KACVgB,EAAU,aACVC,EAAU,WACR,MAAOF,GAAQG,MAAMlB,eAAgBgB,GAAOhB,KAAOY,EAC5CC,EAAMM,OAAOvB,MAAMC,UAAUiB,MAAML,KAAKF,aAMrD,OAHAS,GAAKnB,UAAYG,KAAKH,UACtBoB,EAAOpB,UAAY,GAAImB,GAEhBC,IAINrB,MAAMC,UAAUC,UACnBF,MAAMC,UAAUC,QAAU,SAASsB,EAAUd,GAC3C,GAAa,OAATN,KAAe,KAAM,IAAIC,WAAU,+BACvC,IAAwB,kBAAbmB,GAAyB,KAAM,IAAInB,WAAUmB,EAAW,qBAMnE,KAAK,GAHHC,GAAIlB,OAAOH,MACXI,EAAMiB,EAAEhB,SAAW,EAEZiB,EAAE,EAAQlB,EAAJkB,EAAUA,IACnBA,IAAKD,IACPD,EAASX,KAAKH,EAASe,EAAEC,GAAIA,EAAGD","file":"ie8.polyfils.min.js","sourcesContent":["/*\n * IE8 Polyfils for iframeResizer.js\n *\n * Public domain code - Mozilla Contributors\n * https://developer.mozilla.org/\n */\n\n if (!Array.prototype.forEach){\n\tArray.prototype.forEach = function(fun /*, thisArg */){\n\t\t\"use strict\";\n\t\tif (this === void 0 || this === null || typeof fun !== \"function\") throw new TypeError();\n\n\t\tvar\n\t\t\tt = Object(this),\n\t\t\tlen = t.length >>> 0,\n\t\t\tthisArg = arguments.length >= 2 ? arguments[1] : void 0;\n\n\t\tfor (var i = 0; i < len; i++)\n\t\t\tif (i in t)\n\t\t\t\tfun.call(thisArg, t[i], i, t);\n\t};\n}\n\n\nif (!Function.prototype.bind) {\n Function.prototype.bind = function(oThis) {\n if (typeof this !== 'function') {\n // closest thing possible to the ECMAScript 5\n // internal IsCallable function\n throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');\n }\n\n var aArgs = Array.prototype.slice.call(arguments, 1),\n fToBind = this,\n fNOP = function() {},\n fBound = function() {\n return fToBind.apply(this instanceof fNOP ? this : oThis,\n aArgs.concat(Array.prototype.slice.call(arguments)));\n };\n\n fNOP.prototype = this.prototype;\n fBound.prototype = new fNOP();\n\n return fBound;\n };\n}\n\nif (!Array.prototype.forEach) {\n Array.prototype.forEach = function(callback, thisArg) {\n if (this === null) throw new TypeError(' this is null or not defined');\n if (typeof callback !== 'function') throw new TypeError(callback + ' is not a function');\n\n var\n O = Object(this),\n len = O.length >>> 0;\n\n for (var k=0 ; k < len ; k++) {\n if (k in O)\n callback.call(thisArg, O[k], k, O);\n }\n };\n}\n\n\n"]}
@@ -0,0 +1,4 @@
1
+ // IE8 polyfils for iframeResizer.js
2
+
3
+ Array.prototype.forEach||(Array.prototype.forEach=function(a){"use strict";if(void 0===this||null===this||"function"!=typeof a)throw new TypeError;for(var b=Object(this),c=b.length>>>0,d=arguments.length>=2?arguments[1]:void 0,e=0;c>e;e++)e in b&&a.call(d,b[e],e,b)}),Function.prototype.bind||(Function.prototype.bind=function(a){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var b=Array.prototype.slice.call(arguments,1),c=this,d=function(){},e=function(){return c.apply(this instanceof d?this:a,b.concat(Array.prototype.slice.call(arguments)))};return d.prototype=this.prototype,e.prototype=new d,e}),Array.prototype.forEach||(Array.prototype.forEach=function(a,b){if(null===this)throw new TypeError(" this is null or not defined");if("function"!=typeof a)throw new TypeError(a+" is not a function");for(var c=Object(this),d=c.length>>>0,e=0;d>e;e++)e in c&&a.call(b,c[e],e,c)});
4
+ //# sourceMappingURL=ie8.polyfils.map
@@ -0,0 +1,1104 @@
1
+ /*
2
+ * File: iframeResizer.contentWindow.js
3
+ * Desc: Include this file in any page being loaded into an iframe
4
+ * to force the iframe to resize to the content size.
5
+ * Requires: iframeResizer.js on host page.
6
+ * Doc: https://github.com/davidjbradshaw/iframe-resizer
7
+ * Author: David J. Bradshaw - dave@bradshaw.net
8
+ * Contributor: Jure Mav - jure.mav@gmail.com
9
+ * Contributor: Ian Caunce - ian@hallnet.co.uk
10
+ */
11
+
12
+
13
+ ;(function(window, undefined) {
14
+ 'use strict';
15
+
16
+ var
17
+ autoResize = true,
18
+ base = 10,
19
+ bodyBackground = '',
20
+ bodyMargin = 0,
21
+ bodyMarginStr = '',
22
+ bodyObserver = null,
23
+ bodyPadding = '',
24
+ calculateWidth = false,
25
+ doubleEventList = {'resize':1,'click':1},
26
+ eventCancelTimer = 128,
27
+ firstRun = true,
28
+ height = 1,
29
+ heightCalcModeDefault = 'bodyOffset',
30
+ heightCalcMode = heightCalcModeDefault,
31
+ initLock = true,
32
+ initMsg = '',
33
+ inPageLinks = {},
34
+ interval = 32,
35
+ intervalTimer = null,
36
+ logging = false,
37
+ msgID = '[iFrameSizer]', //Must match host page msg ID
38
+ msgIdLen = msgID.length,
39
+ myID = '',
40
+ observer = null,
41
+ resetRequiredMethods = {max:1,min:1,bodyScroll:1,documentElementScroll:1},
42
+ resizeFrom = 'child',
43
+ sendPermit = true,
44
+ target = window.parent,
45
+ targetOriginDefault = '*',
46
+ tolerance = 0,
47
+ triggerLocked = false,
48
+ triggerLockedTimer = null,
49
+ throttledTimer = 16,
50
+ width = 1,
51
+ widthCalcModeDefault = 'scroll',
52
+ widthCalcMode = widthCalcModeDefault,
53
+ win = window,
54
+ messageCallback = function(){ warn('MessageCallback function not defined'); },
55
+ readyCallback = function(){},
56
+ pageInfoCallback = function(){},
57
+ customCalcMethods = {
58
+ height: function(){
59
+ warn('Custom height calculation function not defined');
60
+ return document.documentElement.offsetHeight;
61
+ },
62
+ width: function(){
63
+ warn('Custom width calculation function not defined');
64
+ return document.body.scrollWidth;
65
+ }
66
+ },
67
+ eventHandlersByName = {};
68
+
69
+
70
+ function addEventListener(el,evt,func){
71
+ /* istanbul ignore else */ // Not testable in phantonJS
72
+ if ('addEventListener' in window){
73
+ el.addEventListener(evt,func, false);
74
+ } else if ('attachEvent' in window){ //IE
75
+ el.attachEvent('on'+evt,func);
76
+ }
77
+ }
78
+
79
+ function removeEventListener(el,evt,func){
80
+ /* istanbul ignore else */ // Not testable in phantonJS
81
+ if ('removeEventListener' in window){
82
+ el.removeEventListener(evt,func, false);
83
+ } else if ('detachEvent' in window){ //IE
84
+ el.detachEvent('on'+evt,func);
85
+ }
86
+ }
87
+
88
+ function capitalizeFirstLetter(string) {
89
+ return string.charAt(0).toUpperCase() + string.slice(1);
90
+ }
91
+
92
+ //Based on underscore.js
93
+ function throttle(func) {
94
+ var
95
+ context, args, result,
96
+ timeout = null,
97
+ previous = 0,
98
+ later = function() {
99
+ previous = getNow();
100
+ timeout = null;
101
+ result = func.apply(context, args);
102
+ if (!timeout) {
103
+ context = args = null;
104
+ }
105
+ };
106
+
107
+ return function() {
108
+ var now = getNow();
109
+
110
+ if (!previous) {
111
+ previous = now;
112
+ }
113
+
114
+ var remaining = throttledTimer - (now - previous);
115
+
116
+ context = this;
117
+ args = arguments;
118
+
119
+ if (remaining <= 0 || remaining > throttledTimer) {
120
+ if (timeout) {
121
+ clearTimeout(timeout);
122
+ timeout = null;
123
+ }
124
+
125
+ previous = now;
126
+ result = func.apply(context, args);
127
+
128
+ if (!timeout) {
129
+ context = args = null;
130
+ }
131
+
132
+ } else if (!timeout) {
133
+ timeout = setTimeout(later, remaining);
134
+ }
135
+
136
+ return result;
137
+ };
138
+ }
139
+
140
+ var getNow = Date.now || function() {
141
+ /* istanbul ignore next */ // Not testable in PhantonJS
142
+ return new Date().getTime();
143
+ };
144
+
145
+ function formatLogMsg(msg){
146
+ return msgID + '[' + myID + ']' + ' ' + msg;
147
+ }
148
+
149
+ function log(msg){
150
+ if (logging && ('object' === typeof window.console)){
151
+ console.log(formatLogMsg(msg));
152
+ }
153
+ }
154
+
155
+ function warn(msg){
156
+ if ('object' === typeof window.console){
157
+ console.warn(formatLogMsg(msg));
158
+ }
159
+ }
160
+
161
+
162
+ function init(){
163
+ readDataFromParent();
164
+ log('Initialising iFrame ('+location.href+')');
165
+ readDataFromPage();
166
+ setMargin();
167
+ setBodyStyle('background',bodyBackground);
168
+ setBodyStyle('padding',bodyPadding);
169
+ injectClearFixIntoBodyElement();
170
+ checkHeightMode();
171
+ checkWidthMode();
172
+ stopInfiniteResizingOfIFrame();
173
+ setupPublicMethods();
174
+ startEventListeners();
175
+ inPageLinks = setupInPageLinks();
176
+ sendSize('init','Init message from host page');
177
+ readyCallback();
178
+ }
179
+
180
+ function readDataFromParent(){
181
+
182
+ function strBool(str){
183
+ return 'true' === str ? true : false;
184
+ }
185
+
186
+ var data = initMsg.substr(msgIdLen).split(':');
187
+
188
+ myID = data[0];
189
+ bodyMargin = (undefined !== data[1]) ? Number(data[1]) : bodyMargin; //For V1 compatibility
190
+ calculateWidth = (undefined !== data[2]) ? strBool(data[2]) : calculateWidth;
191
+ logging = (undefined !== data[3]) ? strBool(data[3]) : logging;
192
+ interval = (undefined !== data[4]) ? Number(data[4]) : interval;
193
+ autoResize = (undefined !== data[6]) ? strBool(data[6]) : autoResize;
194
+ bodyMarginStr = data[7];
195
+ heightCalcMode = (undefined !== data[8]) ? data[8] : heightCalcMode;
196
+ bodyBackground = data[9];
197
+ bodyPadding = data[10];
198
+ tolerance = (undefined !== data[11]) ? Number(data[11]) : tolerance;
199
+ inPageLinks.enable = (undefined !== data[12]) ? strBool(data[12]): false;
200
+ resizeFrom = (undefined !== data[13]) ? data[13] : resizeFrom;
201
+ widthCalcMode = (undefined !== data[14]) ? data[14] : widthCalcMode;
202
+ }
203
+
204
+ function readDataFromPage(){
205
+ function readData(){
206
+ var data = window.iFrameResizer;
207
+
208
+ log('Reading data from page: ' + JSON.stringify(data));
209
+
210
+ messageCallback = ('messageCallback' in data) ? data.messageCallback : messageCallback;
211
+ readyCallback = ('readyCallback' in data) ? data.readyCallback : readyCallback;
212
+ targetOriginDefault = ('targetOrigin' in data) ? data.targetOrigin : targetOriginDefault;
213
+ heightCalcMode = ('heightCalculationMethod' in data) ? data.heightCalculationMethod : heightCalcMode;
214
+ widthCalcMode = ('widthCalculationMethod' in data) ? data.widthCalculationMethod : widthCalcMode;
215
+ }
216
+
217
+ function setupCustomCalcMethods(calcMode, calcFunc){
218
+ if ('function' === typeof calcMode) {
219
+ log('Setup custom ' + calcFunc + 'CalcMethod');
220
+ customCalcMethods[calcFunc] = calcMode;
221
+ calcMode = 'custom';
222
+ }
223
+
224
+ return calcMode;
225
+ }
226
+
227
+ if(('iFrameResizer' in window) && (Object === window.iFrameResizer.constructor)) {
228
+ readData();
229
+ heightCalcMode = setupCustomCalcMethods(heightCalcMode, 'height');
230
+ widthCalcMode = setupCustomCalcMethods(widthCalcMode, 'width');
231
+ }
232
+
233
+ log('TargetOrigin for parent set to: ' + targetOriginDefault);
234
+ }
235
+
236
+
237
+ function chkCSS(attr,value){
238
+ if (-1 !== value.indexOf('-')){
239
+ warn('Negative CSS value ignored for '+attr);
240
+ value='';
241
+ }
242
+ return value;
243
+ }
244
+
245
+ function setBodyStyle(attr,value){
246
+ if ((undefined !== value) && ('' !== value) && ('null' !== value)){
247
+ document.body.style[attr] = value;
248
+ log('Body '+attr+' set to "'+value+'"');
249
+ }
250
+ }
251
+
252
+ function setMargin(){
253
+ //If called via V1 script, convert bodyMargin from int to str
254
+ if (undefined === bodyMarginStr){
255
+ bodyMarginStr = bodyMargin+'px';
256
+ }
257
+
258
+ setBodyStyle('margin',chkCSS('margin',bodyMarginStr));
259
+ }
260
+
261
+ function stopInfiniteResizingOfIFrame(){
262
+ document.documentElement.style.height = '';
263
+ document.body.style.height = '';
264
+ log('HTML & body height set to "auto"');
265
+ }
266
+
267
+
268
+ function manageTriggerEvent(options){
269
+
270
+ var listener = {
271
+ add: function(eventName){
272
+ function handleEvent(){
273
+ sendSize(options.eventName,options.eventType);
274
+ }
275
+
276
+ eventHandlersByName[eventName] = handleEvent;
277
+
278
+ addEventListener(window,eventName,handleEvent);
279
+ },
280
+ remove: function(eventName){
281
+ var handleEvent = eventHandlersByName[eventName];
282
+ delete eventHandlersByName[eventName];
283
+
284
+ removeEventListener(window,eventName,handleEvent);
285
+ }
286
+ };
287
+
288
+ if(options.eventNames && Array.prototype.map){
289
+ options.eventName = options.eventNames[0];
290
+ options.eventNames.map(listener[options.method]);
291
+ } else {
292
+ listener[options.method](options.eventName);
293
+ }
294
+
295
+ log(capitalizeFirstLetter(options.method) + ' event listener: ' + options.eventType);
296
+ }
297
+
298
+ function manageEventListeners(method){
299
+ manageTriggerEvent({method:method, eventType: 'Animation Start', eventNames: ['animationstart','webkitAnimationStart'] });
300
+ manageTriggerEvent({method:method, eventType: 'Animation Iteration', eventNames: ['animationiteration','webkitAnimationIteration'] });
301
+ manageTriggerEvent({method:method, eventType: 'Animation End', eventNames: ['animationend','webkitAnimationEnd'] });
302
+ manageTriggerEvent({method:method, eventType: 'Input', eventName: 'input' });
303
+ manageTriggerEvent({method:method, eventType: 'Mouse Up', eventName: 'mouseup' });
304
+ manageTriggerEvent({method:method, eventType: 'Mouse Down', eventName: 'mousedown' });
305
+ manageTriggerEvent({method:method, eventType: 'Orientation Change', eventName: 'orientationchange' });
306
+ manageTriggerEvent({method:method, eventType: 'Print', eventName: ['afterprint', 'beforeprint'] });
307
+ manageTriggerEvent({method:method, eventType: 'Ready State Change', eventName: 'readystatechange' });
308
+ manageTriggerEvent({method:method, eventType: 'Touch Start', eventName: 'touchstart' });
309
+ manageTriggerEvent({method:method, eventType: 'Touch End', eventName: 'touchend' });
310
+ manageTriggerEvent({method:method, eventType: 'Touch Cancel', eventName: 'touchcancel' });
311
+ manageTriggerEvent({method:method, eventType: 'Transition Start', eventNames: ['transitionstart','webkitTransitionStart','MSTransitionStart','oTransitionStart','otransitionstart'] });
312
+ manageTriggerEvent({method:method, eventType: 'Transition Iteration', eventNames: ['transitioniteration','webkitTransitionIteration','MSTransitionIteration','oTransitionIteration','otransitioniteration'] });
313
+ manageTriggerEvent({method:method, eventType: 'Transition End', eventNames: ['transitionend','webkitTransitionEnd','MSTransitionEnd','oTransitionEnd','otransitionend'] });
314
+ if('child' === resizeFrom){
315
+ manageTriggerEvent({method:method, eventType: 'IFrame Resized', eventName: 'resize' });
316
+ }
317
+ }
318
+
319
+ function checkCalcMode(calcMode,calcModeDefault,modes,type){
320
+ if (calcModeDefault !== calcMode){
321
+ if (!(calcMode in modes)){
322
+ warn(calcMode + ' is not a valid option for '+type+'CalculationMethod.');
323
+ calcMode=calcModeDefault;
324
+ }
325
+ log(type+' calculation method set to "'+calcMode+'"');
326
+ }
327
+
328
+ return calcMode;
329
+ }
330
+
331
+ function checkHeightMode(){
332
+ heightCalcMode = checkCalcMode(heightCalcMode,heightCalcModeDefault,getHeight,'height');
333
+ }
334
+
335
+ function checkWidthMode(){
336
+ widthCalcMode = checkCalcMode(widthCalcMode,widthCalcModeDefault,getWidth,'width');
337
+ }
338
+
339
+ function startEventListeners(){
340
+ if ( true === autoResize ) {
341
+ manageEventListeners('add');
342
+ setupMutationObserver();
343
+ }
344
+ else {
345
+ log('Auto Resize disabled');
346
+ }
347
+ }
348
+
349
+ function stopMsgsToParent(){
350
+ log('Disable outgoing messages');
351
+ sendPermit = false;
352
+ }
353
+
354
+ function removeMsgListener(){
355
+ log('Remove event listener: Message');
356
+ removeEventListener(window, 'message', receiver);
357
+ }
358
+
359
+ function disconnectMutationObserver(){
360
+ if (null !== bodyObserver){
361
+ /* istanbul ignore next */ // Not testable in PhantonJS
362
+ bodyObserver.disconnect();
363
+ }
364
+ }
365
+
366
+ function stopEventListeners(){
367
+ manageEventListeners('remove');
368
+ disconnectMutationObserver();
369
+ clearInterval(intervalTimer);
370
+ }
371
+
372
+ function teardown(){
373
+ stopMsgsToParent();
374
+ removeMsgListener();
375
+ if (true === autoResize) stopEventListeners();
376
+ }
377
+
378
+ function injectClearFixIntoBodyElement(){
379
+ var clearFix = document.createElement('div');
380
+ clearFix.style.clear = 'both';
381
+ clearFix.style.display = 'block'; //Guard against this having been globally redefined in CSS.
382
+ document.body.appendChild(clearFix);
383
+ }
384
+
385
+ function setupInPageLinks(){
386
+
387
+ function getPagePosition (){
388
+ return {
389
+ x: (window.pageXOffset !== undefined) ? window.pageXOffset : document.documentElement.scrollLeft,
390
+ y: (window.pageYOffset !== undefined) ? window.pageYOffset : document.documentElement.scrollTop
391
+ };
392
+ }
393
+
394
+ function getElementPosition(el){
395
+ var
396
+ elPosition = el.getBoundingClientRect(),
397
+ pagePosition = getPagePosition();
398
+
399
+ return {
400
+ x: parseInt(elPosition.left,10) + parseInt(pagePosition.x,10),
401
+ y: parseInt(elPosition.top,10) + parseInt(pagePosition.y,10)
402
+ };
403
+ }
404
+
405
+ function findTarget(location){
406
+ function jumpToTarget(target){
407
+ var jumpPosition = getElementPosition(target);
408
+
409
+ log('Moving to in page link (#'+hash+') at x: '+jumpPosition.x+' y: '+jumpPosition.y);
410
+ sendMsg(jumpPosition.y, jumpPosition.x, 'scrollToOffset'); // X&Y reversed at sendMsg uses height/width
411
+ }
412
+
413
+ var
414
+ hash = location.split('#')[1] || location, //Remove # if present
415
+ hashData = decodeURIComponent(hash),
416
+ target = document.getElementById(hashData) || document.getElementsByName(hashData)[0];
417
+
418
+ if (undefined !== target){
419
+ jumpToTarget(target);
420
+ } else {
421
+ log('In page link (#' + hash + ') not found in iFrame, so sending to parent');
422
+ sendMsg(0,0,'inPageLink','#'+hash);
423
+ }
424
+ }
425
+
426
+ function checkLocationHash(){
427
+ if ('' !== location.hash && '#' !== location.hash){
428
+ findTarget(location.href);
429
+ }
430
+ }
431
+
432
+ function bindAnchors(){
433
+ function setupLink(el){
434
+ function linkClicked(e){
435
+ e.preventDefault();
436
+
437
+ /*jshint validthis:true */
438
+ findTarget(this.getAttribute('href'));
439
+ }
440
+
441
+ if ('#' !== el.getAttribute('href')){
442
+ addEventListener(el,'click',linkClicked);
443
+ }
444
+ }
445
+
446
+ Array.prototype.forEach.call( document.querySelectorAll( 'a[href^="#"]' ), setupLink );
447
+ }
448
+
449
+ function bindLocationHash(){
450
+ addEventListener(window,'hashchange',checkLocationHash);
451
+ }
452
+
453
+ function initCheck(){ //check if page loaded with location hash after init resize
454
+ setTimeout(checkLocationHash,eventCancelTimer);
455
+ }
456
+
457
+ function enableInPageLinks(){
458
+ /* istanbul ignore else */ // Not testable in phantonJS
459
+ if(Array.prototype.forEach && document.querySelectorAll){
460
+ log('Setting up location.hash handlers');
461
+ bindAnchors();
462
+ bindLocationHash();
463
+ initCheck();
464
+ } else {
465
+ warn('In page linking not fully supported in this browser! (See README.md for IE8 workaround)');
466
+ }
467
+ }
468
+
469
+ if(inPageLinks.enable){
470
+ enableInPageLinks();
471
+ } else {
472
+ log('In page linking not enabled');
473
+ }
474
+
475
+ return {
476
+ findTarget:findTarget
477
+ };
478
+ }
479
+
480
+ function setupPublicMethods(){
481
+ log('Enable public methods');
482
+
483
+ win.parentIFrame = {
484
+
485
+ autoResize: function autoResizeF(resize){
486
+ if (true === resize && false === autoResize) {
487
+ autoResize=true;
488
+ startEventListeners();
489
+ //sendSize('autoResize','Auto Resize enabled');
490
+ } else if (false === resize && true === autoResize) {
491
+ autoResize=false;
492
+ stopEventListeners();
493
+ }
494
+
495
+ return autoResize;
496
+ },
497
+
498
+ close: function closeF(){
499
+ sendMsg(0,0,'close');
500
+ teardown();
501
+ },
502
+
503
+ getId: function getIdF(){
504
+ return myID;
505
+ },
506
+
507
+ getPageInfo: function getPageInfoF(callback){
508
+ if ('function' === typeof callback){
509
+ pageInfoCallback = callback;
510
+ sendMsg(0,0,'pageInfo');
511
+ } else {
512
+ pageInfoCallback = function(){};
513
+ sendMsg(0,0,'pageInfoStop');
514
+ }
515
+ },
516
+
517
+ moveToAnchor: function moveToAnchorF(hash){
518
+ inPageLinks.findTarget(hash);
519
+ },
520
+
521
+ reset: function resetF(){
522
+ resetIFrame('parentIFrame.reset');
523
+ },
524
+
525
+ scrollTo: function scrollToF(x,y){
526
+ sendMsg(y,x,'scrollTo'); // X&Y reversed at sendMsg uses height/width
527
+ },
528
+
529
+ scrollToOffset: function scrollToF(x,y){
530
+ sendMsg(y,x,'scrollToOffset'); // X&Y reversed at sendMsg uses height/width
531
+ },
532
+
533
+ sendMessage: function sendMessageF(msg,targetOrigin){
534
+ sendMsg(0,0,'message',JSON.stringify(msg),targetOrigin);
535
+ },
536
+
537
+ setHeightCalculationMethod: function setHeightCalculationMethodF(heightCalculationMethod){
538
+ heightCalcMode = heightCalculationMethod;
539
+ checkHeightMode();
540
+ },
541
+
542
+ setWidthCalculationMethod: function setWidthCalculationMethodF(widthCalculationMethod){
543
+ widthCalcMode = widthCalculationMethod;
544
+ checkWidthMode();
545
+ },
546
+
547
+ setTargetOrigin: function setTargetOriginF(targetOrigin){
548
+ log('Set targetOrigin: '+targetOrigin);
549
+ targetOriginDefault = targetOrigin;
550
+ },
551
+
552
+ size: function sizeF(customHeight, customWidth){
553
+ var valString = ''+(customHeight?customHeight:'')+(customWidth?','+customWidth:'');
554
+ //lockTrigger();
555
+ sendSize('size','parentIFrame.size('+valString+')', customHeight, customWidth);
556
+ }
557
+ };
558
+ }
559
+
560
+ function initInterval(){
561
+ if ( 0 !== interval ){
562
+ log('setInterval: '+interval+'ms');
563
+ intervalTimer = setInterval(function(){
564
+ sendSize('interval','setInterval: '+interval);
565
+ },Math.abs(interval));
566
+ }
567
+ }
568
+
569
+ /* istanbul ignore next */ //Not testable in PhantomJS
570
+ function setupBodyMutationObserver(){
571
+ function addImageLoadListners(mutation) {
572
+ function addImageLoadListener(element){
573
+ if (false === element.complete) {
574
+ log('Attach listeners to ' + element.src);
575
+ element.addEventListener('load', imageLoaded, false);
576
+ element.addEventListener('error', imageError, false);
577
+ elements.push(element);
578
+ }
579
+ }
580
+
581
+ if (mutation.type === 'attributes' && mutation.attributeName === 'src'){
582
+ addImageLoadListener(mutation.target);
583
+ } else if (mutation.type === 'childList'){
584
+ Array.prototype.forEach.call(
585
+ mutation.target.querySelectorAll('img'),
586
+ addImageLoadListener
587
+ );
588
+ }
589
+ }
590
+
591
+ function removeFromArray(element){
592
+ elements.splice(elements.indexOf(element),1);
593
+ }
594
+
595
+ function removeImageLoadListener(element){
596
+ log('Remove listeners from ' + element.src);
597
+ element.removeEventListener('load', imageLoaded, false);
598
+ element.removeEventListener('error', imageError, false);
599
+ removeFromArray(element);
600
+ }
601
+
602
+ function imageEventTriggered(event,type,typeDesc){
603
+ removeImageLoadListener(event.target);
604
+ sendSize(type, typeDesc + ': ' + event.target.src, undefined, undefined);
605
+ }
606
+
607
+ function imageLoaded(event) {
608
+ imageEventTriggered(event,'imageLoad','Image loaded');
609
+ }
610
+
611
+ function imageError(event) {
612
+ imageEventTriggered(event,'imageLoadFailed','Image load failed');
613
+ }
614
+
615
+ function mutationObserved(mutations) {
616
+ sendSize('mutationObserver','mutationObserver: ' + mutations[0].target + ' ' + mutations[0].type);
617
+
618
+ //Deal with WebKit asyncing image loading when tags are injected into the page
619
+ mutations.forEach(addImageLoadListners);
620
+ }
621
+
622
+ function createMutationObserver(){
623
+ var
624
+ target = document.querySelector('body'),
625
+
626
+ config = {
627
+ attributes : true,
628
+ attributeOldValue : false,
629
+ characterData : true,
630
+ characterDataOldValue : false,
631
+ childList : true,
632
+ subtree : true
633
+ };
634
+
635
+ observer = new MutationObserver(mutationObserved);
636
+
637
+ log('Create body MutationObserver');
638
+ observer.observe(target, config);
639
+
640
+ return observer;
641
+ }
642
+
643
+ var
644
+ elements = [],
645
+ MutationObserver = window.MutationObserver || window.WebKitMutationObserver,
646
+ observer = createMutationObserver();
647
+
648
+ return {
649
+ disconnect: function (){
650
+ if ('disconnect' in observer){
651
+ log('Disconnect body MutationObserver');
652
+ observer.disconnect();
653
+ elements.forEach(removeImageLoadListener);
654
+ }
655
+ }
656
+ };
657
+ }
658
+
659
+ function setupMutationObserver(){
660
+ var forceIntervalTimer = 0 > interval;
661
+
662
+ /* istanbul ignore if */ // Not testable in PhantomJS
663
+ if (window.MutationObserver || window.WebKitMutationObserver){
664
+ if (forceIntervalTimer) {
665
+ initInterval();
666
+ } else {
667
+ bodyObserver = setupBodyMutationObserver();
668
+ }
669
+ } else {
670
+ log('MutationObserver not supported in this browser!');
671
+ initInterval();
672
+ }
673
+ }
674
+
675
+
676
+ // document.documentElement.offsetHeight is not reliable, so
677
+ // we have to jump through hoops to get a better value.
678
+ function getComputedStyle(prop,el) {
679
+ /* istanbul ignore next */ //Not testable in PhantomJS
680
+ function convertUnitsToPxForIE8(value) {
681
+ var PIXEL = /^\d+(px)?$/i;
682
+
683
+ if (PIXEL.test(value)) {
684
+ return parseInt(value,base);
685
+ }
686
+
687
+ var
688
+ style = el.style.left,
689
+ runtimeStyle = el.runtimeStyle.left;
690
+
691
+ el.runtimeStyle.left = el.currentStyle.left;
692
+ el.style.left = value || 0;
693
+ value = el.style.pixelLeft;
694
+ el.style.left = style;
695
+ el.runtimeStyle.left = runtimeStyle;
696
+
697
+ return value;
698
+ }
699
+
700
+ var retVal = 0;
701
+ el = el || document.body;
702
+
703
+ /* istanbul ignore else */ // Not testable in phantonJS
704
+ if (('defaultView' in document) && ('getComputedStyle' in document.defaultView)) {
705
+ retVal = document.defaultView.getComputedStyle(el, null);
706
+ retVal = (null !== retVal) ? retVal[prop] : 0;
707
+ } else {//IE8
708
+ retVal = convertUnitsToPxForIE8(el.currentStyle[prop]);
709
+ }
710
+
711
+ return parseInt(retVal,base);
712
+ }
713
+
714
+ function chkEventThottle(timer){
715
+ if(timer > throttledTimer/2){
716
+ throttledTimer = 2*timer;
717
+ log('Event throttle increased to ' + throttledTimer + 'ms');
718
+ }
719
+ }
720
+
721
+ //Idea from https://github.com/guardian/iframe-messenger
722
+ function getMaxElement(side,elements) {
723
+ var
724
+ elementsLength = elements.length,
725
+ elVal = 0,
726
+ maxVal = 0,
727
+ Side = capitalizeFirstLetter(side),
728
+ timer = getNow();
729
+
730
+ for (var i = 0; i < elementsLength; i++) {
731
+ elVal = elements[i].getBoundingClientRect()[side] + getComputedStyle('margin'+Side,elements[i]);
732
+ if (elVal > maxVal) {
733
+ maxVal = elVal;
734
+ }
735
+ }
736
+
737
+ timer = getNow() - timer;
738
+
739
+ log('Parsed '+elementsLength+' HTML elements');
740
+ log('Element position calculated in ' + timer + 'ms');
741
+
742
+ chkEventThottle(timer);
743
+
744
+ return maxVal;
745
+ }
746
+
747
+ function getAllMeasurements(dimention){
748
+ return [
749
+ dimention.bodyOffset(),
750
+ dimention.bodyScroll(),
751
+ dimention.documentElementOffset(),
752
+ dimention.documentElementScroll()
753
+ ];
754
+ }
755
+
756
+ function getTaggedElements(side,tag){
757
+ function noTaggedElementsFound(){
758
+ warn('No tagged elements ('+tag+') found on page');
759
+ return document.querySelectorAll('body *');
760
+ }
761
+
762
+ var elements = document.querySelectorAll('['+tag+']');
763
+
764
+ if (0 === elements.length) noTaggedElementsFound();
765
+
766
+ return getMaxElement(side,elements);
767
+ }
768
+
769
+ function getAllElements(){
770
+ return document.querySelectorAll('body *');
771
+ }
772
+
773
+ var
774
+ getHeight = {
775
+ bodyOffset: function getBodyOffsetHeight(){
776
+ return document.body.offsetHeight + getComputedStyle('marginTop') + getComputedStyle('marginBottom');
777
+ },
778
+
779
+ offset: function(){
780
+ return getHeight.bodyOffset(); //Backwards compatability
781
+ },
782
+
783
+ bodyScroll: function getBodyScrollHeight(){
784
+ return document.body.scrollHeight;
785
+ },
786
+
787
+ custom: function getCustomWidth(){
788
+ return customCalcMethods.height();
789
+ },
790
+
791
+ documentElementOffset: function getDEOffsetHeight(){
792
+ return document.documentElement.offsetHeight;
793
+ },
794
+
795
+ documentElementScroll: function getDEScrollHeight(){
796
+ return document.documentElement.scrollHeight;
797
+ },
798
+
799
+ max: function getMaxHeight(){
800
+ return Math.max.apply(null,getAllMeasurements(getHeight));
801
+ },
802
+
803
+ min: function getMinHeight(){
804
+ return Math.min.apply(null,getAllMeasurements(getHeight));
805
+ },
806
+
807
+ grow: function growHeight(){
808
+ return getHeight.max(); //Run max without the forced downsizing
809
+ },
810
+
811
+ lowestElement: function getBestHeight(){
812
+ return Math.max(getHeight.bodyOffset(), getMaxElement('bottom',getAllElements()));
813
+ },
814
+
815
+ taggedElement: function getTaggedElementsHeight(){
816
+ return getTaggedElements('bottom','data-iframe-height');
817
+ }
818
+ },
819
+
820
+ getWidth = {
821
+ bodyScroll: function getBodyScrollWidth(){
822
+ return document.body.scrollWidth;
823
+ },
824
+
825
+ bodyOffset: function getBodyOffsetWidth(){
826
+ return document.body.offsetWidth;
827
+ },
828
+
829
+ custom: function getCustomWidth(){
830
+ return customCalcMethods.width();
831
+ },
832
+
833
+ documentElementScroll: function getDEScrollWidth(){
834
+ return document.documentElement.scrollWidth;
835
+ },
836
+
837
+ documentElementOffset: function getDEOffsetWidth(){
838
+ return document.documentElement.offsetWidth;
839
+ },
840
+
841
+ scroll: function getMaxWidth(){
842
+ return Math.max(getWidth.bodyScroll(), getWidth.documentElementScroll());
843
+ },
844
+
845
+ max: function getMaxWidth(){
846
+ return Math.max.apply(null,getAllMeasurements(getWidth));
847
+ },
848
+
849
+ min: function getMinWidth(){
850
+ return Math.min.apply(null,getAllMeasurements(getWidth));
851
+ },
852
+
853
+ rightMostElement: function rightMostElement(){
854
+ return getMaxElement('right', getAllElements());
855
+ },
856
+
857
+ taggedElement: function getTaggedElementsWidth(){
858
+ return getTaggedElements('right', 'data-iframe-width');
859
+ }
860
+ };
861
+
862
+
863
+ function sizeIFrame(triggerEvent, triggerEventDesc, customHeight, customWidth){
864
+
865
+ function resizeIFrame(){
866
+ height = currentHeight;
867
+ width = currentWidth;
868
+
869
+ sendMsg(height,width,triggerEvent);
870
+ }
871
+
872
+ function isSizeChangeDetected(){
873
+ function checkTolarance(a,b){
874
+ var retVal = Math.abs(a-b) <= tolerance;
875
+ return !retVal;
876
+ }
877
+
878
+ currentHeight = (undefined !== customHeight) ? customHeight : getHeight[heightCalcMode]();
879
+ currentWidth = (undefined !== customWidth ) ? customWidth : getWidth[widthCalcMode]();
880
+
881
+ return checkTolarance(height,currentHeight) || (calculateWidth && checkTolarance(width,currentWidth));
882
+ }
883
+
884
+ function isForceResizableEvent(){
885
+ return !(triggerEvent in {'init':1,'interval':1,'size':1});
886
+ }
887
+
888
+ function isForceResizableCalcMode(){
889
+ return (heightCalcMode in resetRequiredMethods) || (calculateWidth && widthCalcMode in resetRequiredMethods);
890
+ }
891
+
892
+ function logIgnored(){
893
+ log('No change in size detected');
894
+ }
895
+
896
+ function checkDownSizing(){
897
+ if (isForceResizableEvent() && isForceResizableCalcMode()){
898
+ resetIFrame(triggerEventDesc);
899
+ } else if (!(triggerEvent in {'interval':1})){
900
+ logIgnored();
901
+ }
902
+ }
903
+
904
+ var currentHeight,currentWidth;
905
+
906
+ if (isSizeChangeDetected() || 'init' === triggerEvent){
907
+ lockTrigger();
908
+ resizeIFrame();
909
+ } else {
910
+ checkDownSizing();
911
+ }
912
+ }
913
+
914
+ var sizeIFrameThrottled = throttle(sizeIFrame);
915
+
916
+ function sendSize(triggerEvent, triggerEventDesc, customHeight, customWidth){
917
+ function recordTrigger(){
918
+ if (!(triggerEvent in {'reset':1,'resetPage':1,'init':1})){
919
+ log( 'Trigger event: ' + triggerEventDesc );
920
+ }
921
+ }
922
+
923
+ function isDoubleFiredEvent(){
924
+ return triggerLocked && (triggerEvent in doubleEventList);
925
+ }
926
+
927
+ if (!isDoubleFiredEvent()){
928
+ recordTrigger();
929
+ sizeIFrameThrottled(triggerEvent, triggerEventDesc, customHeight, customWidth);
930
+ } else {
931
+ log('Trigger event cancelled: '+triggerEvent);
932
+ }
933
+ }
934
+
935
+ function lockTrigger(){
936
+ if (!triggerLocked){
937
+ triggerLocked = true;
938
+ log('Trigger event lock on');
939
+ }
940
+ clearTimeout(triggerLockedTimer);
941
+ triggerLockedTimer = setTimeout(function(){
942
+ triggerLocked = false;
943
+ log('Trigger event lock off');
944
+ log('--');
945
+ },eventCancelTimer);
946
+ }
947
+
948
+ function triggerReset(triggerEvent){
949
+ height = getHeight[heightCalcMode]();
950
+ width = getWidth[widthCalcMode]();
951
+
952
+ sendMsg(height,width,triggerEvent);
953
+ }
954
+
955
+ function resetIFrame(triggerEventDesc){
956
+ var hcm = heightCalcMode;
957
+ heightCalcMode = heightCalcModeDefault;
958
+
959
+ log('Reset trigger event: ' + triggerEventDesc);
960
+ lockTrigger();
961
+ triggerReset('reset');
962
+
963
+ heightCalcMode = hcm;
964
+ }
965
+
966
+ function sendMsg(height,width,triggerEvent,msg,targetOrigin){
967
+ function setTargetOrigin(){
968
+ if (undefined === targetOrigin){
969
+ targetOrigin = targetOriginDefault;
970
+ } else {
971
+ log('Message targetOrigin: '+targetOrigin);
972
+ }
973
+ }
974
+
975
+ function sendToParent(){
976
+ var
977
+ size = height + ':' + width,
978
+ message = myID + ':' + size + ':' + triggerEvent + (undefined !== msg ? ':' + msg : '');
979
+
980
+ log('Sending message to host page (' + message + ')');
981
+ target.postMessage( msgID + message, targetOrigin);
982
+ }
983
+
984
+ if(true === sendPermit){
985
+ setTargetOrigin();
986
+ sendToParent();
987
+ }
988
+ }
989
+
990
+ function receiver(event) {
991
+ var processRequestFromParent = {
992
+ init: function initFromParent(){
993
+ function fireInit(){
994
+ initMsg = event.data;
995
+ target = event.source;
996
+
997
+ init();
998
+ firstRun = false;
999
+ setTimeout(function(){ initLock = false;},eventCancelTimer);
1000
+ }
1001
+
1002
+ if (document.body){
1003
+ fireInit();
1004
+ } else {
1005
+ log('Waiting for page ready');
1006
+ addEventListener(window,'readystatechange',processRequestFromParent.initFromParent);
1007
+ }
1008
+ },
1009
+
1010
+ reset: function resetFromParent(){
1011
+ if (!initLock){
1012
+ log('Page size reset by host page');
1013
+ triggerReset('resetPage');
1014
+ } else {
1015
+ log('Page reset ignored by init');
1016
+ }
1017
+ },
1018
+
1019
+ resize: function resizeFromParent(){
1020
+ sendSize('resizeParent','Parent window requested size check');
1021
+ },
1022
+
1023
+ moveToAnchor: function moveToAnchorF(){
1024
+ inPageLinks.findTarget(getData());
1025
+ },
1026
+ inPageLink: function inPageLinkF() {this.moveToAnchor();}, //Backward compatability
1027
+
1028
+ pageInfo: function pageInfoFromParent(){
1029
+ var msgBody = getData();
1030
+ log('PageInfoFromParent called from parent: ' + msgBody );
1031
+ pageInfoCallback(JSON.parse(msgBody));
1032
+ log(' --');
1033
+ },
1034
+
1035
+ message: function messageFromParent(){
1036
+ var msgBody = getData();
1037
+
1038
+ log('MessageCallback called from parent: ' + msgBody );
1039
+ messageCallback(JSON.parse(msgBody));
1040
+ log(' --');
1041
+ }
1042
+ };
1043
+
1044
+ function isMessageForUs(){
1045
+ return msgID === (''+event.data).substr(0,msgIdLen); //''+ Protects against non-string messages
1046
+ }
1047
+
1048
+ function getMessageType(){
1049
+ return event.data.split(']')[1].split(':')[0];
1050
+ }
1051
+
1052
+ function getData(){
1053
+ return event.data.substr(event.data.indexOf(':')+1);
1054
+ }
1055
+
1056
+ function isMiddleTier(){
1057
+ return ('iFrameResize' in window);
1058
+ }
1059
+
1060
+ function isInitMsg(){
1061
+ //Test if this message is from a child below us. This is an ugly test, however, updating
1062
+ //the message format would break backwards compatibity.
1063
+ return event.data.split(':')[2] in {'true':1,'false':1};
1064
+ }
1065
+
1066
+ function callFromParent(){
1067
+ var messageType = getMessageType();
1068
+
1069
+ if (messageType in processRequestFromParent){
1070
+ processRequestFromParent[messageType]();
1071
+ } else if (!isMiddleTier() && !isInitMsg()){
1072
+ warn('Unexpected message ('+event.data+')');
1073
+ }
1074
+ }
1075
+
1076
+ function processMessage(){
1077
+ if (false === firstRun) {
1078
+ callFromParent();
1079
+ } else if (isInitMsg()) {
1080
+ processRequestFromParent.init();
1081
+ } else {
1082
+ log('Ignored message of type "' + getMessageType() + '". Received before initialization.');
1083
+ }
1084
+ }
1085
+
1086
+ if (isMessageForUs()){
1087
+ processMessage();
1088
+ }
1089
+ }
1090
+
1091
+ //Normally the parent kicks things off when it detects the iFrame has loaded.
1092
+ //If this script is async-loaded, then tell parent page to retry init.
1093
+ function chkLateLoaded(){
1094
+ if('loading' !== document.readyState){
1095
+ window.parent.postMessage('[iFrameResizerChild]Ready','*');
1096
+ }
1097
+ }
1098
+
1099
+ addEventListener(window, 'message', receiver);
1100
+ chkLateLoaded();
1101
+
1102
+
1103
+
1104
+ })(window || {});