Файл: usr/plugins/js/srax.storage.js
Строк: 1421
<?php
/**
* SRAX Storage v1.1 beta (build 2), http://www.fullajax.ru
* Based on Dojo Toolkit v1.2.3, http://dojotoolkit.org/
* Created by Ruslan Sinistkiy, 2008.
* Use is subject to license terms.
*/
SRAX.Default.STORAGE_SWF = SRAX.Default.STORAGE_SWF || '/templates/index/scripts/SRAX.Storage.v1.1.b1.swf';
SRAX.Default.STORAGE_ETAG = true;
SRAX.Default.USE_STORAGE = true;
if (!SRAX.Storage){
dojo = dojox = {};
dojo.config = {
dojoPath : '/',
swfLoc : SRAX.Default.STORAGE_SWF ? SRAX.Default.STORAGE_SWF : 'SRAX.Storage.v1.1.b1.swf'
}
dojo.byId = id;
(function(){
// fill in the rendering support information in dojo.render.*
var n = navigator;
var dua = n.userAgent;
var dav = n.appVersion;
var tv = parseFloat(dav);
dojo.isOpera = (dua.indexOf("Opera") >= 0) ? tv : 0;
// safari detection derived from:
// http://developer.apple.com/internet/safari/faq.html#anchor2
// http://developer.apple.com/internet/safari/uamatrix.html
var idx = Math.max(dav.indexOf("WebKit"), dav.indexOf("Safari"), 0);
if(idx){
// try to grab the explicit Safari version first. If we don't get
// one, look for 419.3+ as the indication that we're on something
// "Safari 3-ish". Lastly, default to "Safari 2" handling.
dojo.isSafari = parseFloat(dav.split("Version/")[1]) || ( ( parseFloat(dav.substr(idx+7)) >= 419.3 ) ? 3 : 2 ) || 2;
}
dojo.isAIR = (dua.indexOf("AdobeAIR") >= 0) ? 1 : 0;
dojo.isKhtml = (dav.indexOf("Konqueror") >= 0 || dojo.isSafari) ? tv : 0;
dojo.isMozilla = dojo.isMoz = (dua.indexOf("Gecko") >= 0 && !dojo.isKhtml) ? tv : 0;
dojo.isFF = dojo.isIE = 0;
if(dojo.isMoz){
dojo.isFF = parseFloat(dua.split("Firefox/")[1]) || 0;
}
if(document.all && !dojo.isOpera){
dojo.isIE = parseFloat(dav.split("MSIE ")[1]) || 0;
}
})();
dojo.global = this;
dojo.doc = window["document"] || null;
dojo.body = function(){
return dojo.doc.body || dojo.doc.getElementsByTagName("body")[0]; // Node
}
dojo.isString = function(it){
return !!arguments.length && it != null && (typeof it == "string" || it instanceof String);
}
dojo.isArray = function(/*anything*/ it){
return it && (it instanceof Array || typeof it == "array"); // Boolean
}
dojo.isFunction = (function(){
var _isFunction = function(/*anything*/ it){
return it && (typeof it == "function" || it instanceof Function); // Boolean
};
return dojo.isSafari ?
// only slow this down w/ gratuitious casting in Safari since it's what's b0rken
function(/*anything*/ it){
if(typeof it == "function" && it == "[object NodeList]"){ return false; }
return _isFunction(it); // Boolean
} : _isFunction;
})();
dojo._docScroll = function(){
var _b = dojo.body(), _w = dojo.global, de = dojo.doc.documentElement;
return {
y: (_w.pageYOffset || de.scrollTop || _b.scrollTop || 0),
x: (_w.pageXOffset || dojo._fixIeBiDiScrollLeft(de.scrollLeft) || _b.scrollLeft || 0)
};
};
dojo._fixIeBiDiScrollLeft = function(/*Integer*/ scrollLeft){
if(dojo.isIE){
var dd = dojo.doc;
var de = dd.compatMode == "BackCompat" ? dd.body : dd.documentElement;
return scrollLeft + de.clientWidth - de.scrollWidth; // Integer
}
return scrollLeft; // Integer
}
var _getParts = function(arr, obj, cb){
return [
dojo.isString(arr) ? arr.split("") : arr,
obj || dojo.global,
dojo.isString(cb) ? new Function("item", "index", "array", cb) : cb
];
}
dojo.forEach = function(arr, callback, thisObject){
if(!arr || !arr.length){ return; }
var _p = _getParts(arr, thisObject, callback); arr = _p[0];
for(var i=0,l=_p[0].length; i<l; i++){
_p[2].call(_p[1], arr[i], i, arr);
}
}
dojo.map = function(/*Array|String*/arr, /*Function|String*/callback, /*Function?*/thisObject){
var _p = _getParts(arr, thisObject, callback); arr = _p[0];
var outArr = (arguments[3] ? (new arguments[3]()) : []);
for(var i=0;i<arr.length;++i){
outArr.push(_p[2].call(_p[1], arr[i], i, arr));
}
return outArr; // Array
}
dojo.fromJson = function(/*String*/ json){
return eval("(" + json + ")"); // Object
}
dojo._escapeString = function(/*String*/str){
return ('"' + str.replace(/(["\])/g, '\$1') + '"').
replace(/[f]/g, "\f").replace(/[b]/g, "\b").replace(/[n]/g, "\n").
replace(/[t]/g, "\t").replace(/[r]/g, "\r"); // string
}
dojo.toJsonIndentStr = "t";
dojo.toJson = function(/*Object*/ it, /*Boolean?*/ prettyPrint, /*String?*/ _indentStr){
if(it === undefined){
return "undefined";
}
var objtype = typeof it;
if(objtype == "number" || objtype == "boolean"){
return it + "";
}
if(it === null){
return "null";
}
if(dojo.isString(it)){
return dojo._escapeString(it);
}
if(it.nodeType && it.cloneNode){ // isNode
return ""; // FIXME: would something like outerHTML be better here?
}
// recurse
var recurse = arguments.callee;
// short-circuit for objects that support "json" serialization
// if they return "self" then just pass-through...
var newObj;
_indentStr = _indentStr || "";
var nextIndent = prettyPrint ? _indentStr + dojo.toJsonIndentStr : "";
if(typeof it.__json__ == "function"){
newObj = it.__json__();
if(it !== newObj){
return recurse(newObj, prettyPrint, nextIndent);
}
}
if(typeof it.json == "function"){
newObj = it.json();
if(it !== newObj){
return recurse(newObj, prettyPrint, nextIndent);
}
}
var sep = prettyPrint ? " " : "";
var newLine = prettyPrint ? "n" : "";
// array
if(dojo.isArray(it)){
var res = dojo.map(it, function(obj){
var val = recurse(obj, prettyPrint, nextIndent);
if(typeof val != "string"){
val = "undefined";
}
return newLine + nextIndent + val;
});
return "[" + res.join("," + sep) + newLine + _indentStr + "]";
}
if(objtype == "function"){
return null; // null
}
// generic object code path
var output = [];
for(var key in it){
var keyStr;
if(typeof key == "number"){
keyStr = '"' + key + '"';
}else if(typeof key == "string"){
keyStr = dojo._escapeString(key);
}else{
// skip non-string or number keys
continue;
}
val = recurse(it[key], prettyPrint, nextIndent);
if(typeof val != "string"){
// skip non-serializable values
continue;
}
// FIXME: use += on Moz!!
// MOW NOTE: using += is a pain because you have to account for the dangling comma...
output.push(newLine + nextIndent + keyStr + ":" + sep + val);
}
return "{" + output.join("," + sep) + newLine + _indentStr + "}"; // String
}
dojox.flash = {
ready: false,
url: null,
_visible: true,
_loadedListeners: new Array(),
_installingListeners: new Array(),
setSwf: function(/* String */ url, /* boolean? */ visible){
// summary: Sets the SWF files and versions we are using.
// url: String
// The URL to this Flash file.
// visible: boolean?
// Whether the Flash file is visible or not. If it is not visible we hide it off the
// screen. This defaults to true (i.e. the Flash file is visible).
this.url = url;
if(typeof visible != "undefined"){
this._visible = visible;
}
// initialize ourselves
this._initialize();
},
addLoadedListener: function(/* Function */ listener){
// summary:
// Adds a listener to know when Flash is finished loading.
// Useful if you don't want a dependency on dojo.event.
// listener: Function
// A function that will be called when Flash is done loading.
if (this.isReady) listener(); else this._loadedListeners.push(listener);
},
addInstallingListener: function(/* Function */ listener){
// summary:
// Adds a listener to know if Flash is being installed.
// Useful if you don't want a dependency on dojo.event.
// listener: Function
// A function that will be called if Flash is being
// installed
this._installingListeners.push(listener);
},
loaded: function(){
// summary: Called back when the Flash subsystem is finished loading.
// description:
// A callback when the Flash subsystem is finished loading and can be
// worked with. To be notified when Flash is finished loading, add a
// loaded listener:
//
// dojox.flash.addLoadedListener(loadedListener);
this.isReady = dojox.flash.ready = true;
if(dojox.flash._loadedListeners.length > 0){
for(var i = 0; i < dojox.flash._loadedListeners.length; i++){
try{
dojox.flash._loadedListeners[i].call(null);
} catch (ex){
error(ex);
}
}
}
dojox.flash._loadedListeners = [];
},
installing: function(){
// summary: Called if Flash is being installed.
// description:
// A callback to know if Flash is currently being installed or
// having its version revved. To be notified if Flash is installing, connect
// your callback to this method using the following:
//
// dojo.event.connect(dojox.flash, "installing", myInstance, "myCallback");
if(dojox.flash._installingListeners.length > 0){
for(var i = 0; i < dojox.flash._installingListeners.length; i++){
dojox.flash._installingListeners[i].call(null);
}
}
},
// Initializes dojox.flash.
_initialize: function(){
dojox.flash.obj = new dojox.flash.Embed(this._visible);
dojox.flash.obj.write();
// setup the communicator
dojox.flash.comm = new dojox.flash.Communicator();
}
};
dojox.flash.Embed = function(visible){
// summary: A class that is used to write out the Flash object into the page.
// description:
// Writes out the necessary tags to embed a Flash file into the page. Note that
// these tags are written out as the page is loaded using document.write, so
// you must call this class before the page has finished loading.
this._visible = visible;
}
dojox.flash.Embed.prototype = {
// width: int
// The width of this Flash applet. The default is the minimal width
// necessary to show the Flash settings dialog. Current value is
// 215 pixels.
width: 215,
// height: int
// The height of this Flash applet. The default is the minimal height
// necessary to show the Flash settings dialog. Current value is
// 138 pixels.
height: 138,
// id: String
// The id of the Flash object. Current value is 'flashObject'.
id: "flashObject",
// Controls whether this is a visible Flash applet or not.
_visible: true,
protocol: function(){
switch(window.location.protocol){
case "https:":
return "https";
break;
default:
return "http";
break;
}
},
write: function(useWrite){
if (this.isWrited) return;
// determine our container div's styling
var containerStyle = "";
containerStyle += ("width: " + this.width + "px; ");
containerStyle += ("height: " + this.height + "px; ");
if(!this._visible){
containerStyle += "position: absolute; z-index: 10000; top: -1000px; left: -1000px; ";
}
// figure out the SWF file to get and how to write out the correct HTML
// for this Flash version
var objectHTML;
var swfloc = dojox.flash.url;
var swflocObject = swfloc;
var swflocEmbed = swfloc;
// IE/Flash has an evil bug that shows up some time: if we load the
// Flash and it isn't in the cache, ExternalInterface works fine --
// however, the second time when its loaded from the cache a timing
// bug can keep ExternalInterface from working. The trick below
// simply invalidates the Flash object in the cache all the time to
// keep it loading fresh. -- Brad Neuberg
swflocObject += "?cachebust=" + new Date().getTime();
var domain = location.protocol == 'file:' ? 'always' : 'sameDomain';
objectHTML =
'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '
+ 'codebase="'
+ this.protocol()
+ '://fpdownload.macromedia.com/pub/shockwave/cabs/flash/'
+ 'swflash.cab#version=8,0,0,0"n '
+ 'width="' + this.width + '"n '
+ 'height="' + this.height + '"n '
+ 'id="' + this.id + '"n '
+ 'name="' + this.id + '"n '
+ 'align="middle">n '
+ '<param name="allowScriptAccess" value="'+domain+'"></param>n '
+ '<param name="movie" value="' + swflocObject + '"></param>n '
+ '<param name="quality" value="high"></param>n '
+ '<param name="bgcolor" value="#ffffff"></param>n '
+ '<embed src="' + swflocEmbed + '" '
+ 'quality="high" '
+ 'bgcolor="#ffffff" '
+ 'width="' + this.width + '" '
+ 'height="' + this.height + '" '
+ 'id="' + this.id + 'Embed' + '" '
+ 'name="' + this.id + '" '
+ 'swLiveConnect="true" '
+ 'align="middle" '
+ 'allowScriptAccess="'+domain+'" '
+ 'type="application/x-shockwave-flash" '
+ 'pluginspage="'
+ this.protocol()
+'://www.macromedia.com/go/getflashplayer" '
+ '></embed>n'
+ '</object>n';
// using same mechanism on all browsers now to write out
// Flash object into page
// document.write no longer works correctly
// due to Eolas patent workaround in IE;
// nothing happens (i.e. object doesn't
// go into page if we use it)
var contId = this.id + "Container";
if (useWrite){
var html = '<div id="'+contId+'" style="'+containerStyle+'">'+objectHTML+'</div>';
SRAX.writeln(html);
this.isWrited = true;
SRAX.Storage.antiblock(contId);
} else {
var _this = this;
SRAX.onReady(function (){
if (_this.isWrited) return;
var div = document.createElement("div");
div.setAttribute("id", contId);
div.setAttribute("style", containerStyle);
div.innerHTML = objectHTML;
var body = document.getElementsByTagName("body");
if(!body || !body.length){
throw new Error("No body tag for this page");
}
body = body[0];
body.appendChild(div);
_this.isWrited = true;
SRAX.Storage.antiblock(div);
})
}
},
get: function(){ /* Object */
// summary: Gets the Flash object DOM node.
if(dojo.isIE || dojo.isSafari){
return document.getElementById(this.id);
}else{
// different IDs on OBJECT and EMBED tags or
// else Firefox will return wrong one and
// communication won't work;
// also, document.getElementById() returns a
// plugin but ExternalInterface calls don't
// work on it so we have to use
// document[id] instead
return document[this.id + "Embed"];
}
},
setVisible: function(/* Boolean */ visible){
//console.debug("setVisible, visible="+visible);
// summary: Sets the visibility of this Flash object.
var container = dojo.byId(this.id + "Container");
if(visible == true){
container.style.position = "absolute"; // IE -- Brad Neuberg
container.style.visibility = "visible";
}else{
container.style.position = "absolute";
container.style.x = "-1000px";
container.style.y = "-1000px";
container.style.visibility = "hidden";
}
},
center: function(){
// summary: Centers the flash applet on the page.
var elementWidth = this.width;
var elementHeight = this.height;
var viewport = dojo.getViewport();
// compute the centered position
var x = viewport.l + (viewport.w - elementWidth) / 2;
var y = viewport.t + (viewport.h - elementHeight) / 2;
// set the centered position
var container = dojo.byId(this.id + "Container");
container.style.top = y + "px";
container.style.left = x + "px";
}
};
dojox.flash.Communicator = function(){
}
dojox.flash.Communicator.prototype = {
// Registers the existence of a Flash method that we can call with
// JavaScript, using Flash 8's ExternalInterface.
_addExternalInterfaceCallback: function(methodName){
var _this = this;
this[methodName] = function(){
// some browsers don't like us changing values in the 'arguments' array, so
// make a fresh copy of it
var methodArgs = new Array(arguments.length);
for(var i = 0; i < arguments.length; i++){
methodArgs[i] = _this._encodeData(arguments[i]);
}
var results = _this._execFlash(methodName, methodArgs);
results = _this._decodeData(results);
return results;
};
},
// Encodes our data to get around ExternalInterface bugs that are still
// present even in Flash 9.
_encodeData: function(data){
if(!data || typeof data != "string"){
return data;
}
// transforming into \ doesn't work; just use a custom encoding
data = data.replace("\", "&custom_backslash;");
// also use custom encoding for the null character to avoid problems
data = data.replace(/ /g, "&custom_null;");
return data;
/*
//old realization
if(!data || typeof data != "string"){
return data;
}
// double encode all entity values, or they will be mis-decoded
// by Flash when returned
var entityRE = /&([^;]*);/g;
data = data.replace(entityRE, "&$1;");
// entity encode XML-ish characters, or Flash's broken XML serializer
// breaks
data = data.replace(/</g, "<");
data = data.replace(/>/g, ">");
// transforming into \ doesn't work; just use a custom encoding
data = data.replace("\", "&custom_backslash;");
data = data.replace(/ /g, "\0"); // null character
data = data.replace(/"/g, """);
return data;
*/
},
// Decodes our data to get around ExternalInterface bugs that are still
// present even in Flash 9.
_decodeData: function(data){
//console.debug("decodeData, data=", data);
// wierdly enough, Flash sometimes returns the result as an
// 'object' that is actually an array, rather than as a String;
// detect this by looking for a length property; for IE
// we also make sure that we aren't dealing with a typeof string
// since string objects have length property there
if(data && data.length && typeof data != "string"){
data = data[0];
}
if(!data || typeof data != "string"){
return data;
}
// needed for IE;