Files
@ 8320d5cdccd0
Branch filter:
Location: kallithea/rhodecode/public/js/yui/swfstore/swfstore.js
8320d5cdccd0
11.5 KiB
text/javascript
Added tag v1.1.4 for changeset bdc438fb4fe4
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 | /*
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.8.0r4
*/
/**
* Provides a swf based storage implementation
*
* @module swfstore
*/
/**
* Class for the YUI SWFStore util.
*
* @namespace YAHOO.util
* @class SWFStore
* @uses YAHOO.util.AttributeProvider
* @constructor
* @param containerId {HTMLElement} Container element for the Flash Player instance.
* @param shareData {Boolean} Whether or not data should be shared across browsers
* @param useCompression {Boolean} Container element for the Flash Player instance.
*/
YAHOO.util.SWFStore = function(containerID, shareData, useCompression)
{
//browser detection
var browser;
var newValue;
//convert Booleans to strings for flashvars compatibility
shareData = shareData.toString();
useCompression = useCompression.toString();
if (YAHOO.env.ua.ie) browser = "ie";
else if (YAHOO.env.ua.gecko) browser = "gecko"; //Firefox
else if (YAHOO.env.ua.webkit) browser = "webkit"; // Safari, Webkit
else if (YAHOO.env.ua.caja) browser = "caja";
else if (YAHOO.env.ua.opera) browser = "opera";
else browser = "other";
if(YAHOO.util.Cookie.get("swfstore") == null || YAHOO.util.Cookie.get("swfstore") == "null" || YAHOO.util.Cookie.get("swfstore") == "")
{
newValue = Math.round(Math.random() * Math.PI * 100000);
YAHOO.util.Cookie.set("swfstore", newValue);
}
else
{
newValue = YAHOO.util.Cookie.get("swfstore");
}
var params =
{
version: 9.115,
useExpressInstall: false,
fixedAttributes:
{allowScriptAccess:"always", allowNetworking:"all", scale:"noScale"},
flashVars:
{shareData: shareData, browser: newValue, useCompression: useCompression}
};
this.embeddedSWF = new YAHOO.widget.SWF(containerID, YAHOO.util.SWFStore.SWFURL, params);
/**
* Fires when an error occurs
*
* @event error
* @param event.type {String} The event type
* @param event.message {String} The data
*
*/
this.createEvent("error");
/**
* Fires when there is not enough space available to store the data
*
* @event quotaExceededError
* @param event.type {String} The event type
* @param event.message {String} The data
*
*/
this.createEvent("quotaExceededError");
/**
* Fires when the url matching for the security whitelist is invalid.
* If no whitelist is used, fires when page's url does not match the embedded swf's url
*
* @event securityError
* @param event.type {String} The event type
* @param event.message {String} The data
*
*/
this.createEvent("securityError");
/**
* Fires when a store is saved successfully
*
* @event save
* @param event.type {String} The event type
*
*/
this.createEvent("save");
/**
* Fires when a store is successfully cleared
*
* @event clear
* @param event.type {String} The event type
*
*/
this.createEvent("clear");
/**
* Fires when the save is pending, due to a request for additional storage
*
* @event error
* @param event.type {String} The event type
*
*/
this.createEvent("pending");
/**
* Fires as the settings dialog displays
*
* @event openingDialog
* @param event.type {String} The event type
*
*/
this.createEvent("openingDialog");
/**
* Fires when a settings dialog is not able to be displayed due to
* the SWF not being large enough to show it. In this case, the developer
* needs to resize the SWF to width of 215px and height of 138px or above,
* or display an external settings page.
*
* @event inadequateDimensions
* @param event.type {String} The event type
*
*/
this.createEvent("inadequateDimensions");
};
YAHOO.extend(YAHOO.util.SWFStore, YAHOO.util.AttributeProvider,
{
/**
* Method to attach listeners to events
* @param type {String} The tyep of event to listen for
* @param listener {String} The function to call
*/
on: function(type, listener)
{
this.embeddedSWF.addListener(type, listener);
},
/**
* Method to attach listeners to events
* @param type {String} The tyep of event to listen for
* @param listener {String} The function to call
*/
addListener: function(type, listener)
{
this.embeddedSWF.addListener(type, listener);
},
/**
* Public accessor to the unique name of the SWFStore instance.
*
* @method toString
* @return {String} Unique name of the SWFStore instance.
*/
toString: function()
{
return "SWFStore " + this._id;
},
/**
* Public accessor to the unique name of the SWFStore instance.
*
* @method getShareData
* @return {Boolean} Whether or not data is being shared among browsers
*/
getShareData: function()
{
return this.embeddedSWF.callSWF("getShareData");
},
/**
* Public accessor to the unique name of the SWFStore instance.
*
* @method setShareData
* @param {Boolean} Whether or not to share among browsers
*/
setShareData: function(value)
{
this.embeddedSWF.callSWF("setShareData", [value]);
},
/**
* Determines if SWF's visible area is large enough to fit the settings panel
*
* @method hasAdequateDimensions
* @return {Boolean} Whether or not to share among browsers
*/
hasAdequateDimensions: function()
{
return this.embeddedSWF.callSWF("hasAdequateDimensions");
},
/**
* Public accessor to the unique name of the SWFStore instance.
*
* @method getUseCompression
* @return {Boolean} Whether or compression is being used
*/
getUseCompression: function()
{
return this.embeddedSWF.callSWF("getUseCompression");
},
/**
* Public accessor to the unique name of the SWFStore instance.
*
* @method setUseCompression
* @param {Boolean} Whether or to compress stored data
*/
setUseCompression: function(value)
{
this.embeddedSWF.callSWF("setUseCompression", [value]);
},
/**
* Saves data to local storage. It returns a String that can
* be one of three values: "true" if the storage succeeded; "false" if the user
* has denied storage on their machine or storage space allotted is not sufficient.
* <p>The size limit for the passed parameters is ~40Kb.</p>
* @method setItem
* @param data {Object} The data to store
* @param location {String} The name of the "cookie" or store
* @return {Boolean} Whether or not the save was successful
*
*/
setItem: function(location,data)
{
return this.embeddedSWF.callSWF("setItem", [location, data]);
} ,
/**
* Returns the value of the store at the specified index, if any.
* @method getValueAt
* @param index {Number} The index of the stored item
* @return {Object} The value of the store at that index
*
*/
getValueAt: function(index)
{
return this.embeddedSWF.callSWF("getValueAt", [index]);
},
/**
* Returns the key name in storage, if any, at the specified index.
*
* @param index {Number} The index of the "cookie" or store
* @return {Object}The data
* @method setItem
*
*/
getNameAt: function(index)
{
return this.embeddedSWF.callSWF("getNameAt", [index]);
},
/**
* Returns the value of the item in storage, if any.
* @method getValueOf
* @param location {String} The name of the "cookie" or store
* @return {Object} The data
*
*/
getValueOf: function(location)
{
return this.embeddedSWF.callSWF("getValueOf", [location]);
} ,
/**
* Returns the data type of of the storage.
* <p>May be one of the following types:
* <ul>
* <li>boolean</li>
* <li>function</li>
* <li>number</li>
* <li>object</li>
* <li>string</li>
* <li>number</li>
* <li>xml</li>
* </ul>
* </p>
* @method getTypeOf
* @param location {String} The name of the "cookie" or store
* @return {String} The type
*
*/
getTypeOf: function(location)
{
return this.embeddedSWF.callSWF("getTypeOf", [location]);
} ,
/**
* Returns the data type of of the storage.
* <p>May be one of the following types:
* <ul>
* <li>boolean</li>
* <li>function</li>
* <li>number</li>
* <li>object</li>
* <li>string</li>
* <li>number</li>
* <li>xml</li>
* </ul>
* </p>
* @method getTypeAt
* @param location {Number} The index of the "cookie" or store
* @return {String} The type
*
*/
getTypeAt: function(index)
{
return this.embeddedSWF.callSWF("getTypeAt", [index]);
} ,
/**
* Returns the items in storage as an array.
* @method getItems
* @return {Object} The data.
* @public
*/
getItems: function()
{
return this.embeddedSWF.callSWF("getItems", []);
},
/**
* Removes the item in storage, if any.
* @method removeItem
* @param location {String} The name of the "cookie" or store
*
*/
removeItem: function(location)
{
return this.embeddedSWF.callSWF("removeItem", [location]);
} ,
/**
* Removes the item in storage at the specified index, if any.
* @method removeItem
* @param index {Number} The index of the "cookie" or store
*
*/
removeItemAt: function(index)
{
return this.embeddedSWF.callSWF("removeItemAt", [index]);
} ,
/**
* Returns the number of items in storage, if any.
* @method getLength
* @return {Number} The number of items
*
*/
getLength: function()
{
return this.embeddedSWF.callSWF("getLength", []);
} ,
/**
* Removes all data in local storage for this domain.
* <p>Be careful when using this method, as it may
* remove stored information that is used by other applications
* in this domain </p>
* @method clear
*/
clear: function()
{
return this.embeddedSWF.callSWF("clear", []);
} ,
/**
* Gets the current size, in KB, of the amount of space taken by the current store.
* Note that this is calculated, and may take time depending on the number of items stored
* @method calculateCurrentSize
* @return {Number} The size of the store in KB
*/
calculateCurrentSize: function()
{
return this.embeddedSWF.callSWF("calculateCurrentSize", []);
} ,
/**
* Gets the timestamp of the last store. This value is automatically set when
* data is stored.
* @method getModificationDate
* @return {Date} A Date object
*/
getModificationDate: function()
{
return this.embeddedSWF.callSWF("getModificationDate", []);
} ,
/**
* This method requests more storage (if the amount is above 100KB or the current setting).
*
* The request dialog has to be displayed within the Flash player itself
* so the SWF it is called from must be visible and at least 215px x 138px (w x h) in size.
*
* @method setSize
* @param value {Number} The size, in KB
* @return {String}
*/
setSize: function(value)
{
var result = this.embeddedSWF.callSWF("setSize", [value]);
return result;
} ,
/**
* Displays the settings dialog to allow the user to configure
* storage settings manually. If the SWF height and width are smaller than
* what is allowable to display the local settings panel,
* an openExternalDialog message will be sent to JavaScript.
* @method displaySettings
*/
displaySettings: function()
{
this.embeddedSWF.callSWF("displaySettings", []);
}
});
YAHOO.util.SWFStore.SWFURL = "swfstore.swf";
YAHOO.register("swfstore", YAHOO.util.SWFStore, {version: "2.8.0r4", build: "2449"});
YAHOO.register("swfstore", YAHOO.util.SWFStore, {version: "2.8.0r4", build: "2449"});
|