]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/yui/build/swfstore/swfstore-debug.js
Release 6.2.1
[Github/sugarcrm.git] / include / javascript / yui / build / swfstore / swfstore-debug.js
1 /*
2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
5 version: 2.8.0r4
6 */
7 /**
8  * Provides a swf based storage implementation
9  *
10  * @module swfstore
11  */
12
13 /**
14  * Class for the YUI SWFStore util.
15  *
16  * @namespace YAHOO.util
17  * @class SWFStore
18  * @uses YAHOO.util.AttributeProvider
19  * @constructor
20  * @param containerId {HTMLElement} Container element for the Flash Player instance.
21  * @param shareData {Boolean} Whether or not data should be shared across browsers
22  * @param useCompression {Boolean} Container element for the Flash Player instance.
23  */
24 YAHOO.util.SWFStore = function(containerID, shareData, useCompression)
25 {
26                         //browser detection
27                         var browser;
28                         var newValue;
29                         //convert Booleans to strings for flashvars compatibility
30                         shareData = shareData.toString();
31                         useCompression = useCompression.toString();
32                         
33                         if (YAHOO.env.ua.ie) browser = "ie";
34                         else if (YAHOO.env.ua.gecko) browser =  "gecko";  //Firefox
35                         else if (YAHOO.env.ua.webkit) browser =  "webkit"; // Safari, Webkit 
36                         else if (YAHOO.env.ua.caja) browser =  "caja";   
37                         else if (YAHOO.env.ua.opera) browser =  "opera"; 
38                         else browser =  "other";
39
40                         if(YAHOO.util.Cookie.get("swfstore") == null || YAHOO.util.Cookie.get("swfstore") == "null" || YAHOO.util.Cookie.get("swfstore") == "")
41                         {
42
43                                 newValue = Math.round(Math.random() * Math.PI * 100000); 
44                                 YAHOO.util.Cookie.set("swfstore", newValue);
45
46                         }
47
48                         else 
49                         {
50                                 newValue = YAHOO.util.Cookie.get("swfstore");
51                         }
52
53                         
54                         var params = 
55                                 { 
56                                         version: 9.115,
57                                         useExpressInstall: false,
58                                         fixedAttributes:
59                                                 {allowScriptAccess:"always", allowNetworking:"all", scale:"noScale"},
60                                                 flashVars:
61                                                         {shareData: shareData, browser: newValue, useCompression: useCompression}
62                                  };
63         
64         
65         
66         this.embeddedSWF = new YAHOO.widget.SWF(containerID, YAHOO.util.SWFStore.SWFURL, params); 
67         
68         
69         /**
70          * Fires when an error occurs
71          *
72          * @event error
73          * @param event.type {String} The event type
74          * @param event.message {String} The data 
75          * 
76          */
77         this.createEvent("error");
78
79         /**
80          * Fires when there is not enough space available to store the data
81          *
82          * @event quotaExceededError
83          * @param event.type {String} The event type
84          * @param event.message {String} The data 
85          * 
86          */
87         this.createEvent("quotaExceededError");
88
89         /**
90          * Fires when the url matching for the security whitelist is invalid.
91      * If no whitelist is used, fires when page's url does not match the embedded swf's url
92          *
93          * @event securityError
94          * @param event.type {String} The event type
95          * @param event.message {String} The data 
96          * 
97          */
98         this.createEvent("securityError");
99         
100         /**
101          * Fires when a store is saved successfully
102          *
103          * @event save
104          * @param event.type {String} The event type
105          * 
106          */
107         this.createEvent("save");
108
109         /**
110          * Fires when a store is successfully cleared
111          *
112          * @event clear
113          * @param event.type {String} The event type
114          * 
115          */
116         this.createEvent("clear");
117                 
118         
119         /**
120          * Fires when the save is pending, due to a request for additional storage
121          *
122          * @event error
123          * @param event.type {String} The event type
124          * 
125          */
126         this.createEvent("pending");
127         
128         
129         /**
130          * Fires as the settings dialog displays
131          *
132          * @event openingDialog
133          * @param event.type {String} The event type
134          * 
135          */
136         this.createEvent("openingDialog");
137         
138         /**
139          * Fires when a settings dialog is not able to be displayed due to 
140          * the SWF not being large enough to show it. In this case, the developer
141          * needs to resize the SWF to width of 215px and height of 138px or above, 
142          * or display an external settings page.
143          *
144          * @event inadequateDimensions
145          * @param event.type {String} The event type
146          * 
147          */
148         this.createEvent("inadequateDimensions");
149 };
150
151 YAHOO.extend(YAHOO.util.SWFStore, YAHOO.util.AttributeProvider,
152 {
153
154
155         
156         /**
157          * Method to attach listeners to events
158          * @param type {String} The tyep of event to listen for
159          * @param listener {String} The function to call
160          */
161         on: function(type, listener)
162         {
163                 this.embeddedSWF.addListener(type, listener); 
164         },
165
166         /**
167          * Method to attach listeners to events
168          * @param type {String} The tyep of event to listen for
169          * @param listener {String} The function to call
170          */
171         addListener: function(type, listener)
172         {
173                 YAHOO.log("adding '" + type + "' listener");
174                 this.embeddedSWF.addListener(type, listener); 
175         },
176
177         /**
178          * Public accessor to the unique name of the SWFStore instance.
179          *
180          * @method toString
181          * @return {String} Unique name of the SWFStore instance.
182          */
183         toString: function()
184         {
185                 return "SWFStore " + this._id;
186         },
187         
188         /**
189          * Public accessor to the unique name of the SWFStore instance.
190          *
191          * @method getShareData
192          * @return {Boolean} Whether or not data is being shared among browsers
193          */
194         getShareData: function()
195         {
196                 return this.embeddedSWF.callSWF("getShareData");
197         },
198         /**
199          * Public accessor to the unique name of the SWFStore instance.
200          *
201          * @method setShareData
202          * @param {Boolean} Whether or not to share among browsers
203          */
204         setShareData: function(value)
205         {
206                 YAHOO.log("Setting share data to " + value);
207                 this.embeddedSWF.callSWF("setShareData", [value]);
208         },
209
210         /**
211          * Determines if SWF's visible area is large enough to fit the settings panel
212          *
213          * @method hasAdequateDimensions
214          * @return {Boolean} Whether or not to share among browsers
215          */
216         hasAdequateDimensions: function()
217         {
218                 YAHOO.log("dimensions adequate? " + this.embeddedSWF.callSWF("hasAdequateDimensions"));
219                 return this.embeddedSWF.callSWF("hasAdequateDimensions");
220         },
221
222         /**
223          * Public accessor to the unique name of the SWFStore instance.
224          *
225          * @method getUseCompression
226          * @return {Boolean} Whether or compression is being used
227          */
228         getUseCompression: function()
229         {
230                 return this.embeddedSWF.callSWF("getUseCompression");
231         },
232
233         /**
234          * Public accessor to the unique name of the SWFStore instance.
235          *
236          * @method setUseCompression
237          * @param {Boolean} Whether or to compress stored data
238          */
239         setUseCompression: function(value)
240         {
241                 YAHOO.log("Setting compression to " + value);
242                 this.embeddedSWF.callSWF("setUseCompression", [value]);
243         },      
244
245            /**
246             * Saves data to local storage. It returns a String that can
247                 * be one of three values: "true" if the storage succeeded; "false" if the user
248                 * has denied storage on their machine or storage space allotted is not sufficient.
249                 * <p>The size limit for the passed parameters is ~40Kb.</p>
250                 * @method setItem
251             * @param data {Object} The data to store
252             * @param location {String} The name of the "cookie" or store 
253                 * @return {Boolean} Whether or not the save was successful
254             * 
255             */
256                 setItem: function(location,data) 
257                 {       
258                         YAHOO.log("setting " + location + " to " + data);
259                         return this.embeddedSWF.callSWF("setItem", [location, data]);
260                 } ,
261                 
262            /**
263             * Returns the value of the store at the specified index, if any.
264                 * @method getValueAt
265             * @param index {Number} The index of the stored item
266             * @return {Object} The value of the store at that index
267             * 
268             */      
269                 getValueAt: function(index) 
270                 {
271                         YAHOO.log("value at " + index + " is " + this.embeddedSWF.callSWF("getValueAt", [index]) );
272                         return this.embeddedSWF.callSWF("getValueAt", [index]);
273                 },
274
275            /**
276             * Returns the key name in storage, if any, at the specified index.
277             * 
278             * @param index {Number} The index of the "cookie" or store
279                 * @return {Object}The data
280                 * @method setItem
281             * 
282             */      
283                 getNameAt: function(index) 
284                 {
285                         YAHOO.log("name at " + index + " is " + this.embeddedSWF.callSWF("getNameAt", [index]) );
286                         return this.embeddedSWF.callSWF("getNameAt", [index]);
287                 },
288                 
289                 
290             /**
291             * Returns the value of the item in storage, if any.
292             * @method getValueOf
293             * @param location {String} The name of the "cookie" or store
294                 * @return {Object} The data
295             * 
296             */
297                 getValueOf: function(location) 
298                 {
299                         YAHOO.log("value of " + location + " is " + this.embeddedSWF.callSWF("getValueOf", [location]) );
300                         return this.embeddedSWF.callSWF("getValueOf", [location]);
301                 } ,
302
303             /**
304             *  Returns the data type of of the storage.
305                 * <p>May be one of the following types:
306             * <ul>
307             * <li>boolean</li>
308             * <li>function</li>
309             * <li>number</li>
310             * <li>object</li>
311             * <li>string</li>
312             * <li>number</li>
313             * <li>xml</li>
314             * </ul>
315             * </p>
316             * @method getTypeOf
317             * @param location {String} The name of the "cookie" or store
318                 * @return {String} The type
319             * 
320             */
321                 getTypeOf: function(location) 
322                 {
323                         YAHOO.log("type of " + location + " is " + this.embeddedSWF.callSWF("getTypeOf", [location]) );
324                         return this.embeddedSWF.callSWF("getTypeOf", [location]);
325                 } ,
326
327             /**
328             *  Returns the data type of of the storage.
329                 * <p>May be one of the following types:
330             * <ul>
331             * <li>boolean</li>
332             * <li>function</li>
333             * <li>number</li>
334             * <li>object</li>
335             * <li>string</li>
336             * <li>number</li>
337             * <li>xml</li>
338             * </ul>
339             * </p>
340             * @method getTypeAt
341             * @param location {Number} The index of the "cookie" or store
342                 * @return {String} The type
343             * 
344             */
345                 getTypeAt: function(index) 
346                 {
347                         YAHOO.log("type at " + index + " is " + this.embeddedSWF.callSWF("getTypeAt", [index]) );
348                         return this.embeddedSWF.callSWF("getTypeAt", [index]);
349                 } ,
350                  
351                 /**
352                  * Returns the items in storage as an array.
353                  * @method getItems
354                  * @return {Object} The data.
355                  * @public
356                  */
357                 getItems: function() 
358                 {
359                         return this.embeddedSWF.callSWF("getItems", []);
360                 },
361
362             /**
363             * Removes the item in storage, if any.
364             * @method removeItem
365             * @param location {String} The name of the "cookie" or store
366             * 
367             */
368                 removeItem: function(location) 
369                 {
370                         YAHOO.log("removing " + location);
371                         return this.embeddedSWF.callSWF("removeItem", [location]);
372                 } ,
373
374             /**
375             * Removes the item in storage at the specified index, if any.
376             * @method removeItem
377             * @param index {Number} The index of the "cookie" or store
378             * 
379             */
380                 removeItemAt: function(index) 
381                 {
382                         YAHOO.log("removing item at " + index);
383                         return this.embeddedSWF.callSWF("removeItemAt", [index]);
384                 } ,
385                 
386             /**
387             * Returns the number of items in storage, if any.
388             * @method getLength
389             * @return {Number} The number of items
390             * 
391             */
392                 getLength: function() 
393                 {
394                         return this.embeddedSWF.callSWF("getLength", []);
395                 } ,
396                 
397            /**
398             * Removes all data in local storage for this domain.
399             * <p>Be careful when using this method, as it may 
400             * remove stored information that is used by other applications
401             * in this domain </p>
402             * @method clear
403             */          
404                 clear: function() 
405                 {
406                         YAHOO.log("clearing all items");
407                         return this.embeddedSWF.callSWF("clear", []);
408                 } ,
409                 
410             /**
411              * Gets the current size, in KB, of the amount of space taken by the current store.
412                  * Note that this is calculated, and may take time depending on the number of items stored
413              * @method calculateCurrentSize
414              * @return {Number} The size of the store in KB
415              */         
416                 calculateCurrentSize: function() 
417                 {
418                         YAHOO.log("calculating size");
419                         return this.embeddedSWF.callSWF("calculateCurrentSize", []);
420                 } ,
421                 
422             /**
423              * Gets the timestamp of the last store. This value is automatically set when 
424              * data is stored.
425              * @method getModificationDate
426              * @return {Date} A Date object
427              */
428                 getModificationDate: function() 
429                 {
430                         YAHOO.log("getting date");
431                         return this.embeddedSWF.callSWF("getModificationDate", []);
432                 } ,
433                 
434                 /**
435                 * This method requests more storage (if the amount is above 100KB or the current setting).
436                 * 
437                 * The request dialog has to be displayed within the Flash player itself
438                 * so the SWF it is called from must be visible and at least 215px x 138px (w x h) in size.
439                 * 
440                 * @method setSize
441                 * @param value {Number} The size, in KB
442                 * @return {String} 
443                 */              
444                 setSize: function(value) 
445                 {
446                         var result = this.embeddedSWF.callSWF("setSize", [value]);
447                         YAHOO.log("attempt to set size to " + value*1024 + " bytes resulted in " + result);
448                         return result;
449                 } ,
450                 
451                 /**
452                  * Displays the settings dialog to allow the user to configure
453                  * storage settings manually. If the SWF height and width are smaller than
454                  * what is allowable to display the local settings panel,
455                  * an openExternalDialog message will be sent to JavaScript.
456                  * @method displaySettings
457                  */             
458                 displaySettings: function() 
459                 {
460                         YAHOO.log("attempting to show settings. are dimensions adequate? " + this.embeddedSWF.callSWF("hasAdequateDimensions"));
461                         this.embeddedSWF.callSWF("displaySettings", []);
462                 } 
463
464 });
465
466
467 YAHOO.util.SWFStore.SWFURL = "swfstore.swf";
468
469 YAHOO.register("swfstore", YAHOO.util.SWFStore, {version: "2.8.0r4", build: "2449"});
470 YAHOO.register("swfstore", YAHOO.util.SWFStore, {version: "2.8.0r4", build: "2449"});