/
host.js
3266 lines (2854 loc) · 88.1 KB
/
host.js
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
/*
* Copyright (c) 2012, Interactive Advertising Bureau
* All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
"use strict";
/**
* @namespace $sf.host Defines the Publisher side api, and helper functions
* @name $sf.host
* @author <a href="mailto:ssnider@yahoo-inc.com">Sean Snider</a>
* @author <a href="mailto:ccole[AT]emination.com">Chris Cole</a>
* @version 1.1.1
*
*/
/** @ignore */
(function(win) {
var NULL = null,
TRUE = true,
FALSE = false,
DEFAULT_RENDER_TIMEOUT = 60000,
POS_ID_AUTO_PREFIX = "sf_pos",
POS_REL_BOX_ID_PREFIX = "sf_pos_rel_el",
SF_DATATAG_CLASS = "sf_data",
SF_POSELEM_WRAPPER_CLASS = "sf_position",
AUTO_BOOT_MAX_RETRIES = 100,
GEOM_UPDATE_INTRVAL = 750,
XCOM_RESP_DELAY = 1,
IE_BORDER_ADJ = 2,
INTERSECT_FACTOR = 10,
BF_POS_MSG = "onBeforePosMsg",
POS_MSG = "onPosMsg",
SUPPORTS_FEATURES =
{
"exp-ovr": 1,
"exp-push": 0,
"bg": 0,
"pin": 0,
"read-cookie": 0,
"write-cookie": 0
},
EXPAND_COMMAND = "exp-ovr",
COLLAPSE_COMMAND = "collapse",
ERROR_COMMAND = "error",
MESSAGE_COMMAND = "msg",
NOTIFY_EXPAND = "expand",
NOTIFY_GEOM_UPDATE = "geom-update",
NOTIFY_COLLAPSE = COLLAPSE_COMMAND,
NOTIFY_FOCUS_CHANGE = "focus-change",
NOTIFY_MESSAGE = MESSAGE_COMMAND,
DEFAULT_ZINDEX = 3000,
OBJ = "object",
FUNC = "function",
STR = "string",
ST = "style",
PROTO = "prototype",
LEN = "length",
WIDTH = "width",
HEIGHT = "height",
PX = "PX",
CLIP = "clip",
SCROLL = "scroll",
SCRW = SCROLL+"Width",
SCRH = SCROLL+"Height",
SCRT = SCROLL+"Top",
SCRL = SCROLL+"Left",
OFFSET = "offset",
OFF_PAR = OFFSET+"Parent",
OFF_TOP = OFFSET+"Top",
OFF_LEFT = OFFSET+"Left",
OFSW = OFFSET+"Width",
OFSH = OFFSET+"Height",
CLW = "clientWidth",
CLH = "clientHeight",
INNRW = "innerWidth",
INNRH = "innerHeight",
ONSCROLL = "onscroll",
COMPAT_MODE = "compatMode",
DOC_EL = "documentElement",
DOC = "document",
NODE_TYPE = "nodeType",
CONTAINS = "contains",
COMPARE_DOC_POS = "compareDocumentPosition",
EL_FROM_PT = "elementFromPoint",
PAR_NODE = "parentNode",
AUTO = "auto",
HIDDEN = "hidden",
OVER = "overflow",
TFXD = "toFixed",
ATTACH = "attach",
DETACH = "detach",
MSG = "message",
PMSG = "postMessage",
GUID = "guid",
FLASH_MIME = "application/x-shockwave-flash",
sf = (win && win.$sf),
VERSION = (sf && sf.ver),
env = (sf && sf.env),
ua = (env && env.ua),
lib = (sf && sf.lib),
lang = (lib && lib.lang),
dom = (lib && lib.dom),
iframes = (dom && dom.iframes),
_cbool = (lang && lang.cbool),
_cnum = (lang && lang.cnum),
_cstr = (lang && lang.cstr),
_callable = (lang && lang.callable),
_noop = (lang && lang.noop),
_guid = (lang && lang[GUID]),
_mix = (lang && lang.mix),
_elt = (dom && dom.elt),
_par = (dom && dom.par),
_tags = (dom && dom.tags),
_attr = (dom && dom.attr),
_doc = (dom && dom.doc),
_tagName = (dom && dom.tagName),
_view = (dom && dom.view),
_ifr_view = (iframes && iframes.view),
_purge = (dom && dom.purge),
_ready = (dom && dom.ready),
_es = (win && win.escape),
M = (win && win.Math),
_max = (M && M.max),
_min = (M && M.min),
_round = (M && M.round),
_rect = NULL,
ParamHash = (lang && lang.ParamHash),
dc = (win && win[DOC]),
isIE = (env && env.isIE),
ieVer = ((ua && ua.ie) || 0),
wbVer = ((ua && ua.webkit) || 0),
geckVer = ((ua && ua.gecko) || 0),
operaVer = ((ua && ua.opera) || 0),
loc = (win && win.location),
locHost = (loc && ((loc.protocol + "//" + (loc.host||loc.hostname)) || "")), // missing the port number
rendered_ifrs = {},
msg_pipes = {},
ifr_dest_id_map = {},
initID,
pending_ifrs = {},
complete_ifrs = {},
scroll_parents_attached = {},
mgr_bounds_details = FALSE,
canUseHTML5 = FALSE,
html5Bound = FALSE,
win_events_attached = FALSE,
geom_update_timer = 0,
focus_update_timer = 0,
current_status = NULL,
msghostfb = NULL,
flash_ver = NULL,
config = NULL;
var FLASHX = "ShockwaveFlash.ShockwaveFlash",
flashActiveXVersions = [
FLASHX+".11",
FLASHX+".8",
FLASHX+".7",
FLASHX+".6",
FLASHX
];
/* --BEGIN-SafeFrames publisher data class definitions */
/**
* Configure the base-level settings for the SafeFrames library
* Note that only one configuration can be active at a given time.
* Therefore you cannot change the configuration by creating a new $sf.host.Config while
* the SafeFrames library is busy (however you can add new position configurations).
* Instatiating a new config, when the library is not busy will destroy / remove all currently
* managed positions and there configurations.
*
* @name $sf.host.Config
* @constructor
* @public
* @param {Object} conf An object containing properties for configuration
* @param {boolean} [conf.auto] Whether or not to have SafeFrames automatically boostrap an render any SafeFrames tags within the page
* @param {string} conf.cdn The protocol,host name, and port parts of a URI, that is a 2ndary origin, used with SafeFrames to render content. For example JS files would be loaded from conf.cdn+"/"+conf.root+"/"+conf.version+"/[filename]"
* @param {boolean} [conf.debug] Whether or not debug mode is on or off
* @param {string} conf.root The root path part of the URI that is a 2ndary origin, used with SafeFrames to render content. For example the HTML file for rendering content into would beloaded from conf.cdn+"/"+conf.root+"/"+conf.version+"/"+conf.renderFile
* @param {string} conf.renderFile The filename (may also include path info), for which to render content into via a SafeFrame.
* @param {string} [conf.msgFile] The filename (may also include path info), for which to use as a proxy for x-domain messaging whenever HTML5 messaging is not available. Only required if supporting older browsers.
* @param {Number} [conf.to] The maximum amount of time in milliseconds to wait for a SafeFrame to finish rendering, defaults to 60 seconds.
* @param {Function} [conf.onBeforePosMsg] A callback function that gets fired before any cancellable action is requested to be peformed from a a SafeFrame, such as expansion, etc. Return true out of this callback function to cancel/disallow the action in question.
* @param {Function} [conf.onPosMsg] A callback function that gets fired when an action requested by a SafeFrame is performed
* @param {Function} [conf.onStartPosRender] A callback function that gets fired when a SafeFrame starts to render 3rd party content.
* @param {Function} [conf.onEndPosRender] A callback function that gets fired when a SafeFrame finishes rendering 3rd party content.
* @param {Object} [conf.positions] A map of positions to automatically configure, where each key equals the id of the $sf.host.PosConfig object, and the value is an object containing said object's settings.
*
*/
function Config(conf)
{
var me = this, pos_map, conf_pos_map, posID, pos_conf, pos_id, boot_up;
if (!arguments.length) return (config) ? _mix({}, config) : NULL;
if (!(me instanceof Config)) return new Config(conf);
if (!conf) {
config = NULL;
return NULL;
}
boot_up = !!(config);
me.auto = ("auto" in conf) ? _cbool(conf.auto) : TRUE;
me.cdn = _cstr(conf.cdn);
me.debug = _cbool(conf.debug);
me.root = _cstr(conf.root);
me.renderFile = _cstr(conf.renderFile);
me.msgFile = _cstr(conf.msgFile);
me.to = _cnum(conf.to, DEFAULT_RENDER_TIMEOUT);
me.ver = _cstr(conf.ver) || VERSION;
me.onBeforePosMsg = _callable(conf.onBeforePosMsg) ? conf.onBeforePosMsg : _noop;
me.onPosMsg = _callable(conf.onPosMsg) ? conf.onPosMsg : _noop;
me.onStartPosRender = _callable(conf.onStartPosRender) ? conf.onStartPosRender : _noop;
me.onEndPosRender = _callable(conf.onEndPosRender) ? conf.onEndPosRender : _noop;
me.onFailure = _callable(conf.onFailure) ? conf.onFailure3 : _noop;
conf_pos_map = conf.positions;
me.positions = pos_map = {};
if (conf_pos_map) {
for (posID in conf_pos_map)
{
pos_conf = conf_pos_map[posID];
if (pos_conf && typeof pos_conf == OBJ) {
pos_id = posID || pos_conf.id || _guid(POS_ID_AUTO_PREFIX);
pos_map[pos_id] = new PosConfig(pos_conf);
}
}
}
config = me;
boot_up = !!(boot_up && me.auto && lang && lang.ns("$sf.host.boot"));
try {
if (boot_up) sf.host.boot();
} catch (e) {
}
return _mix({},config);
}
/**
* Configure a particualar position for rendering a SafeFrame
* Each $sf.host.PosConfig object has an id property that should be unique. Creating a new $sf.host.PosConfig with an id, that has already been
* used results in changing the old $sf.host.PosConfig settings, and can only be done if the SafeFrames library is not busy.
* Automatically ads to the position map of the $sf.host.Config object if said config has already been created.
*
* @name $sf.host.PosConfig
* @public
* @constructor
* @param {Object|string} posIDorObj The id of the $sf.host.PosConfig instance, or an object containing all settings that are to be used for the instance.
* @param {string} [posIDorObj.id] The id of the $sf.host.PosConfig instance, if not specified one will be generated automatically.
* @param {string} [posIDorObj.dest] The HTML element id attribute of the HTML element in the document where a SafeFrame will be rendered. Said element MUST exist within the page prior to a render.
* @param {string} [posIDorObj.bg] The color of the background to be used inside the SafeFrame. Default equals "transparent".
* @param {string} [posIDorObj.tgt] The name of the target window where hyperlinks inside a SafeFrame will navigate too...Note that "_self" is not allowed and always converted to "_top". Allowed values are any string value not prefixed with "_", or "_top" or "_blank".
* @param {string} [posIDorObj.css] A string of CSS rules, or a URL that points to a CSS style sheet to be used inside the SafeFrame
* @param {Number} [posIDorObj.w] The width of the SafeFrame, specified in pixels. Cannot be specified in em, % or another values.
* @param {Number} [posIDorObj.h] The height of the SafeFrame, specified in pixels. Cannot be specified in em, % or another values.
* @param {string} [posIDorObj.size] A string formated as "widthXheight", that defines the width and height of the SafeFrame. The delimiter character "X" is can be specified as lower or upper case.
* @param {string} [posIDorObj.z] The z-index of the SafeFrame.
* @param {Object} [posIDorObj.supports] An object containing key/value pairs for what features/actions are supported by the SafeFrame, and its corresponding value represents a boolean detereming whether that feature can be used. Currently supported keys are "exp-ovr" == SafeFrame can expand in overlay mode, "exp-push" == SafeFrame can expand in push mode, and "bg" == SafeFrame can change the background of the publisher / host.
* @param {string} [destID] The HTML element id attribute of the HTML element in the document where a SafeFrame will be rendered. Said element MUST exist within the page prior to a render.
* @param {Object} [baseConf] An object representing a $sf.host.Config object to automatically use / create for the SafeFrames library. Note that baseConf can only be used one time, otherwise you have to use the $sf.host.Config object directly.
*
*/
function PosConfig(posIDorObj, destID, baseConf)
{
var me = this, typ = (posIDorObj && typeof posIDorObj) || "", sz, sz_split;
if (!(me instanceof PosConfig)) return new PosConfig(posIDorObj,destID,baseConf);
if (typ == OBJ) {
me.id = _cstr(posIDorObj.id);
me.dest = _cstr(posIDorObj.dest || destID);
me.bg = _cstr(posIDorObj.bg) || "transparent";
me.tgt = _cstr(posIDorObj.tgt) || "_top";
me.css = _cstr(posIDorObj.css);
me.w = _cnum(posIDorObj.w, 0);
me.h = _cnum(posIDorObj.h, 0);
me.z = _cnum(posIDorObj.z, 0);
me.supports = _mix({}, posIDorObj.supports || SUPPORTS_FEATURES, TRUE, TRUE, TRUE);
if (!me.w || !me.h) {
sz = _cstr(posIDorObj.size);
if (sz) {
sz_split = sz.split(/x/gi);
me.w = _cnum(sz_split[0], 0);
me.h = _cnum(sz_split[1], 0);
me.size = sz;
} else {
me.size = "";
}
} else {
me.size = me.w + "x" + me.h;
}
} else if (typ == "string") {
me.id = _cstr(posIDorObj);
me.dest = _cstr(posIDorObj.dest);
} else {
me.dest = "";
me.bg = "transparent",
me.tgt = "_top";
me.css = "";
me.w = 0;
me.h = 0;
me.size = "";
me.z = 0;
me.supports = {};
}
me.id = me.id || _guid(POS_ID_AUTO_PREFIX);
if (!config && baseConf) Config(baseConf);
if (config) config.positions[me.id] = me;
return _mix({}, me);
}
/**
* Construct a set of dynamic key/value pairs that can be shared as meta-data with the 3rd party content inside a SafeFrame.
* All data is treated as protected, and can only be specfied during construction of this object.
*
* @exports PosMeta as $sf.host.PosMeta#
* @public
* @constructor
* @class
* @param {Object} shared_object An object containing keys and values to be shared as meta-data inside the SafeFrame
* @param {string} [owner_key] A key name to be used to hold pseudo private keys / values of meta data.
* @param {Object} [owned_obj] An object containing psuedo private keys and values to be shared as meta-data inside the SafeFrame.
* @example
* var shared_data = {content_id:8978098,partner_id:99},
* private_data_key = "rmx",
* private_data = {section_id:2342,site_id:23904},
* meta_data = new $sf.host.PosMeta(shared_data, private_data_key, private_data);
*
* //show section id on host side
* alert(meta_data.value("rmx", "site_id")); //== 23904
*
* @example
* //now retrieve this information inside the safe frame
*
* var content_id = $sf.vend.meta("content_id"); //== 8978098
*
* var rmx_section_id = $sf.vend.meta("rmx", "section_id") //== 2342, but note that vendor side code must know the "owner_key" upfront.
*
*/
function PosMeta(shared_obj, owner_key, owned_obj)
{
var me = this, shared, non_shared, old, posConf;
if (!(me instanceof PosMeta)) return new PosMeta(key,owned_obj,pos,shared_obj);
shared = {
sf_ver : _cstr(sf.ver),
flash_ver: _get_flash_version(),
ck_on: _cookies_enabled_test() ? '1' : '0'
};
non_shared = {};
if (shared_obj && typeof shared_obj == OBJ) shared = _mix(shared, shared_obj);
if (owner_key && typeof owner_key == STR){
if (owned_obj && typeof owned_obj == OBJ) non_shared[owner_key] = owned_obj;
}
/**
* A method retrieves a meta data value from this object.
*
* @exports get_value as $sf.host.PosMeta#value
* @param {string} propKey The name of the value to retrieve
* @param {string} [owner_key] The name of the owner key of the meta data value. By default, it is assumed to be shared, so nothing needs to be passed in unless looking for a specific proprietary value
* @return {String|Number|Boolean}
* @default {string} ""
* @public
* @function
*
*/
function get_value(propKey, owner_key)
{
var ret = "";
if (!propKey || typeof propKey != STR) return ret;
if (!owner_key || typeof owner_key != STR) owner_key = "shared";
if (owner_key == "shared") {
ret = shared[propKey] || "";
} else {
ret = (propKey in non_shared) ? (non_shared[prop_key] || "") : "";
}
return ret;
}
/**
* Return a serialized string representation (in url query string format) of the meta data object
*
* @exports serialize as $sf.host.PosMeta#toString
* @function
* @public
*
*/
function serialize()
{
var obj = new ParamHash();
obj.shared = shared;
obj.non_shared = non_shared;
return obj.toString();
}
me.toString = serialize;
me.value = get_value;
}
/** @ignore */
/* Internal logging method */
function _log(msg,is_err)
{
var head_el, err_tag;
try {
if(!lib) lib = (sf && sf.lib); // insure we have lib
if (lib && lib.logger && win == top) {
if (is_err) {
lib.logger.error(msg);
sf.info.errs.push(msg);
} else {
lib.logger.log(msg);
}
} else {
// Append error message as comment to header
head_el = d.getElementsByTagName("head")[0];
err_tag = d.createElement("script");
err_tag.type = "text/plain";
err_tag.text = "<!-- SafeFrame " + ((is_err) ? "error" : "log") + ": " + (msg || "unknown") + " -->";
head_el.appendChild(head_el, err_tag);
}
} catch (e) { }
}
/**
* Create the HTML markup for a position if a src property was used
*
* @name $sf.host-_create_pos_markup
* @function
* @private
* @static
* @return {string}
*
*/
function _create_pos_markup(src)
{
if (src) {
// TODO: Macro expansion within src url
// Spec section 4.6
// $(sf_ver}
// $(ck_on}
// $(flash_ver}
if(src.indexOf("${sf_ver}") > -1){
src = src.replace(/\${sf_ver}/gi, $sf.ver);
}
if(src.indexOf("${ck_on}") > -1){
var ckVal = _cookies_enabled_test() ? '1' : '0';
src = src.replace(/\${ck_on}/gi, ckVal);
}
if(src.indexOf("${flash_ver}") > -1){
var fVer = _get_flash_version();
src = src.replace(/\${flash_ver}/gi, fVer);
}
}
return _cstr(["<scr","ipt type='text/javascript', src='", src, "'></scr", "ipt>"]);
}
/**
* Get the flash version number
*/
function _get_flash_version(){
var mimeObj;
if(flash_ver !== NULL && flash_ver != undefined){
return flash_ver;
}
if(navigator.plugins && navigator.plugins.length>0){
var mimeTypes = navigator.mimeTypes;
if(mimeTypes && mimeTypes[FLASH_MIME] && mimeTypes[FLASH_MIME].enabledPlugin && mimeTypes[FLASH_MIME].enabledPlugin.description){
mimeObj = mimeTypes[FLASH_MIME].enabledPlugin;
if(mimeObj.version){
flash_ver = mimeObj.version;
}
else if(mimeObj.description){
flash_ver = mimeObj.description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
}
}
}
else if(sf.env.isIE){
// ActiveX detect
var i, obj, tmpVer, p;
for(i=0; i < flashActiveXVersions.length; i++){
try{
obj = new ActiveXObject(flashActiveXVersions[i]);
tmpVer = obj.GetVariable("$version");
p = tmpVer.indexOf(' ');
if(p > -1){
flash_ver = tmpVer.substr(p+1).replace(/,/gi, ".");;
}
else{
flash_ver = tmpVer.replace(/,/gi, ".");
}
break;
// "WIN 11,3,378,5"
}catch(err){
obj = NULL;
flash_ver = 0;
continue;
}
}
}
else{
flash_ver = 0;
}
return flash_ver;
}
/**
* Test to see if cookies are enabled
*/
function _cookies_enabled_test()
{
var cookieEnabled = (navigator.cookieEnabled) ? true : false;
if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled)
{
document.cookie="testcookie";
cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
if(navigator){
navigator.cookieEnabled = cookieEnabled;
}
}
return (cookieEnabled);
}
/**
* Construction a postion content object that contains HTML, optionally meta-data, and optionally a position configuration to use.
* The id specified must match an id for a $sf.host.PosConfig (although said config could be specfied directly here via arguments).
*
* @name $sf.host.Position
* @constructor
* @public
* @param {Object|String} posIDorObj The id of the position which maps to its configuration, or an object represeting the various values of an $sf.host.Position instance.
* @param {string} [posIDorObj.id] The id of the position which maps to its configuration.
* @param {string} [posIDorObj.html] The HTML content to be rendered inside the SafeFrame. Note that HTML strings which have SCRIPT tags or other special characters may need to be properly escaped in order to avoid JavaScript syntax errors.
* @param {string} [posIDorObj.src] An optional URL to be used for redering inside the SafeFrame which will automatically generate a SCRIPT tag with the specified URL.
* @param {$sf.host.PosMeta} [posIDorObj.meta] An optional instance of the $sf.host.PosMeta object to be passed along into the SafeFrame
* @param {Object} [posIDorObj.conf] An optional representation of an $sf.host.PosConfig object to be used as the configuration for the SafeFrame position.
* @param {string} [html] The HTML content to be rendered inside the SafeFrame. Note that HTML strings which have SCRIPT tags or other special characters may need to be properly escaped in order to avoid JavaScript syntax errors.
* @param {$sf.host.PosMeta} [meta] An optional instance of the $sf.host.PosMeta object to be passed along into the SafeFrame
* @param {Object} [conf] An optional representation of an $sf.host.PosConfig object to be used as the configuration for the SafeFrame position.
*
*/
/*
* This is a data objet constructor, and we don't want dom interactions placed inside here
*
*/
function Position(posIDorObj, html, meta, conf)
{
var me = this,
typ = (posIDorObj && typeof posIDorObj),
origHtml = html,
id;
// the reason for this check is so that some one doesn't have to do "new $sf.host.Position", they
// can just do "$sf.host.Position"
if (!(me instanceof Position)) return new Position(posIDorObj, html, meta, conf);
// Insure config is initialized
if(config == null){
var msg = "Publisher Config not initialized - abort";
logger.error(msg);
info.errs.push(msg);
return;
}
if (typ == OBJ) {
_mix(me, posIDorObj);
} else {
id = me.id = _cstr(posIDorObj) || _guid(POS_ID_AUTO_PREFIX);
}
if (!html) {
if (me.src) {
me.html = _create_pos_markup(me.src);
} else {
me.html = me.html || "";
me.src = "";
}
} else {
me.html = html;
me.src = "";
}
if (!me.html) me.html = "";
if(meta != null && !(meta instanceof PosMeta)){
meta = new PosMeta(meta);
}
me.meta = meta || me.meta || new PosMeta();
me.conf = conf || me.conf || {};
if (id) {
if (config && config.positions[id]) {
me.conf = config.positions[id];
} else {
if (conf) {
conf.id = id;
me.conf = new PosConfig(conf);
}
}
}
}
/* --END-SafeFrames publisher data class definitions */
/* --BEGIN--SafeFrames publisher side dom helper functions */
/* removed the concept of needing a "host" file and put all that logic to keep the file sturcture simple */
/**
* @namespace $sf.lib.dom.msghost Contains functionality to reside in the top level page for sending and receiving x-domain messages to SafeFrame containers
* @name $sf.lib.dom.msghost
*
*/
/**
* Returns the root document HTMLElement / node
* @name $sf.lib.dom-_docNode
* @private
* @static
* @function
* @param {HTMLElement} [el] An HTMLElement to use as a reference for finding the root document element.
* @returns {HTMLElement}
*
*/
function _docNode(el)
{
var d = (el && _doc(el)) || dc,
compatMode = d[COMPAT_MODE],
root = d[DOC_EL];
if (compatMode && !operaVer && compatMode != 'CSS1Compat')
root = d.body;
return root;
}
/**
* Retrieve a document for a given HTML Element
*
* @name doc
* @memberOf $sf.lib.dom-
* @public
* @function
* @param {HTMLElement} el (Required) the HTML element for which you wish to find it's parent document
* @return {Document|null} null if nothing found
*
*/
function doc(el)
{
var d = NULL, n_type;
try {
if (el) {
n_type = _get_node_type(el);
if (n_type == 9) {
d = el;
} else {
d = el[DOC] || el.ownerDocument || NULL;
}
}
} catch (e) {
d = NULL;
}
return d;
}
/**
* Retrive the parent element of an HTML element
*
* @name par
* @public
* @function
* @param {HTMLElement} el (Required) the HTML element to check
* return {HTMLElement} the new reference to the parent element or null
*
*/
function par(el) { return el && (el[PAR_NODE] || el.parentElement); }
function _is_element(el) { return _get_node_type(el) === 1; }
function _get_node_type(el)
{
var n_type = _cnum((el && el.nodeType), -1);
return n_type;
}
/**
* A wrapper around retrieving the tagName of an HTML element (normalizes values to lower case strings).
*
* @name tagName
* @memberOf $sf.lib.dom
* @public
* @function
* @param {HTMLElement} el The HTML element for which to get the tag name.
* @return {String} The tag name in all lower case of an HTML element, if it cannot be successfully retrieved, alwasys returns an empty string (which will evaluate to FALSE).
*
*/
function tagName(el)
{
return (_get_node_type(el) === 1 && el.tagName.toLowerCase()) || "";
}
/**
* Returns whether or not a value is specified in pixels
* @name $sf.lib.dom-_isPX
* @private
* @static
* @function
* @param {string} val A css value of size
* @returns {boolean}
*
*/
function _isPX(val)
{
val = _cstr(val);
if (val && val.search(/\D+/g) == -1) return TRUE;
if (val && val.search(/px/gi) != -1) return TRUE;
}
/**
* Return an array of values of clipping region information. Array represents top, right, bottom, left values respectively.
* If values are not specified in pixels, or no clip region is defined for that element, -1 is returned for each value.
*
* @name $sf.lib.dom-_getClip
* @private
* @function
* @static
* @param {HTMLStyleObject} curSt The current style object of an HTMLElement
* @return {Array}
*
*/
function _getClip(curSt)
{
var ret = [-1,-1,-1,-1], props = [CLIP+"Top",CLIP+"Right",CLIP+"Bottom",CLIP+"Left"],
idx = 0, clipVal, prop, val, len;
if (!curSt) return ret;
if (ieVer) {
while (prop = props[idx])
{
clipVal = curSt[prop];
if (_isPX(clipVal)) {
clipVal = _cnum(clipVal,-1);
if (clipVal >= 0) ret[idx] = clipVal;
}
idx++;
}
} else {
clipVal = curSt[CLIP];
if (clipVal && clipVal.search(/\d+/g) != -1) {
clipVal = clipVal.replace(/\w+\(([^\)]*?)\)/g, "$1");
ret = clipVal.split(" ");
ret = (ret[LEN] <= 1) ? ret.split(",") : ret;
len = ret[LEN];
idx = 0;
while (len--)
{
val = ret[idx];
if (!_isPX(val)) {
ret[idx] = -1;
} else {
ret[idx] = _cnum(val,-1);
}
idx++;
}
}
}
return ret;
}
/**
* Returns border values in pixels if possible to help calculate geometry of an element
*
* @name $sf.lib.dom-_calcBorders
* @private
* @static
* @function
* @param {HTMLElement} el The HTMLElement for which to look at. . .
* @param {Object} rect The rect object generated for the HTMLElement in question to be adjusted
* @returns {Object} rect
*
*/
function _calcBorders(el, rect, style)
{
var t = 0, l = 0, re = /^t(?:able|d|h|r|head|foot)$/i;
var style = style || currentStyle(el);
if (style) {
t = st["borderTopWidth"]
l = st["borderLeftWidth"];
t = (_isPX(t)) ? _cnum(t,0) : 0;
l = (_isPX(l)) ? _cnum(l,0) : 0;
if (geckVer && re.test(_tagName(el))) //getBrowserVersion should already be called since this method is only called from getRectNonIE
t = l = 0;
}
rect = rect || {t:0,l:0};
rect.t += t;
rect.l += l;
return rect;
}
/**
* Retrieve scroll values of a document
*
* @name $sf.lib.dom-_get_doc_scroll
* @private
* @static
* @function
* @param {HTMLElement} [el] An HTMLElement to use as a reference document rather than the default main document
* @return {Object} Contains x, y, w, h properties for scrolling
*
*/
function _get_doc_scroll(el)
{
var pos = {x:0,y:0,w:0,h:0},
def = {scrollLeft:0,scrollTop:0,scrollWidth:0,scrollHeight:0},
d, de, dv, db, offsetX = 0, offsetY = 0;
d = _doc(el) || dc;
de = d[DOC_EL] || def;
db = d.body || def;
dv = d.defaultView; //only for non-ie
if (dv) {
offsetX = _cnum(dv.pageXOffset,0);
offsetY = _cnum(dv.pageYOffset,0);
}
pos.x = _max(de.scrollLeft, db.scrollLeft, offsetX);
pos.y = _max(de.scrollTop, db.scrollTop, offsetY);
pos.w = _max(de.scrollWidth, db.scrollWidth, 0);
pos.h = _max(de.scrollHeight, db.scrollHeight,0);
return pos;
}
/**
* Get an object detailing where a given element is within a web page
*
* @name $sf.lib.dom.rect
* @public
* @function
* @param {HTMLElement} el The element to check
* @return {Object} t,l,r,b,w,h,z info
*
*/
function rect(el)
{
var r = {t:0,l:0,r:0,b:0,w:0,h:0,z:0},
BOUNDING = "getBoundingClientRect",
scrollTop = 0,
scrollLeft = 0,
w = 0,
h = 0,
bCheck = FALSE,
d = doc(el) || win[DOC],
compatMode = d[COMPAT_MODE],
docMode = d.documentMode || 0,
root, scroll, parentNode, last_par, cur_st, par_cur_st,
offX, offY, box, e, use_brute,
errmsg;
if (_is_element(el)) {
try {
cur_st = currentStyle(el);
root = _docNode(el);
scroll = _get_doc_scroll(el);
r.l = el[OFF_LEFT] || 0;
r.t = el[OFF_TOP] || 0;
parentNode = el;
last_par = NULL;
bCheck = (geckVer || wbVer > 519);
use_brute = (el === root);
/*
* reintroducted using bounding box native call for 2 reasons
* 1.) performance
* 2.) we get wonky results when there are fixed position elements for some
* reason. previously i removed it to avoid scroll top/left issues but i think
* that was due to a bug in the impl. Note that for root node, we still use brute
* force
* 3.) The issues mentioned, are caused when you want to measure one element
* with respect to another element that is acting as the view port.
* In the case where said other element is scrollable, getBoundingClientRect
* will return negative values if it is scrolled. We re-add in the scroll_top
* or scroll left, but b/c the values are negative in that case we just
* end up normalizing to 0.
*
* With brute force we never end up substracting out the scroll top or left
* b/c the loop bails since at the root level there are not offset parents or
* parent nodes.
*
* The idea is to have top/left report scroll top and scroll left as there top/left
* position always rather than normalizing to just the relative numbers which
* allows for comparison much easier.
*
*
*/
if (!use_brute && BOUNDING && el[BOUNDING]) {
if (isIE) {
if (!docMode || (docMode > 0 && docMode < 8) || compatMode === BACK_COMPAT) {
offX = root.clientLeft;
offY = root.clientTop;
}
}
box = el[BOUNDING]();
r.t = box.top;
r.l = box.left;
if (offX || offY) {
r.l -= offX;
r.t -= offY;
}
if (scroll.y || scroll.x) {
if (!ua.ios || ua.ios >= 4.2) {
r.l += scroll.x;
r.t += scroll.y;
}
}
} else {
while ((parentNode = parentNode[OFF_PAR]))
{
if (!_is_element(parentNode) || last_par === parentNode) break;
offX = parentNode[OFF_LEFT];
offY = parentNode[OFF_TOP];
r.t += offY;
r.l += offX;
if (bCheck) r = _calcBorders(parentNode, r);
last_par = parentNode;
}
if (cur_st["position"] != "fixed") {
parentNode = el;
last_par = NULL;
while ((parentNode = parentNode[PAR_NODE]))
{
if (!_is_element(parentNode) || last_par === parentNode) break;
if (parentNode == root) break;