Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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