PageRenderTime 64ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/10.9-libcxx/stable/main/finkinfo/web/libjs-yui.patch

https://github.com/danielj7/fink-dists
Patch | 1649 lines | 1647 code | 2 blank | 0 comment | 0 complexity | 4960d363147977b4f12a1165c10c9cfe MD5 | raw file
  1. From: Jaldhar H. Vyas <jaldhar@debian.org>
  2. Date: Thu Jun 29 06:43:38 EDT 2012
  3. Subject: as-src
  4. Description: ActionScript source for the flash files included in the package.
  5. Origin: https://github.com/yui/yui2.git (master branch)
  6. ---
  7. create mode 100755 src/connection/as/com/yui/util/connection.as
  8. create mode 100755 src/swfstore/as/SWFStore.as
  9. create mode 100755 src/swfstore/as/com/yahoo/util/YUIBridge.as
  10. create mode 100755 src/uploader/as/Uploader.as
  11. create mode 100755 src/uploader/as/com/yahoo/yui/YUIAdapter.as
  12. diff --git a/src/connection/as/com/yui/util/connection.as b/src/connection/as/com/yui/util/connection.as
  13. new file mode 100755
  14. index 0000000..a93b89c
  15. --- /dev/null
  16. +++ b/src/connection/as/com/yui/util/connection.as
  17. @@ -0,0 +1,162 @@
  18. +package com.yui.util
  19. +{
  20. + import flash.display.Sprite;
  21. + import flash.events.Event;
  22. + import flash.events.IOErrorEvent;
  23. + import flash.events.TimerEvent;
  24. + import flash.events.IEventDispatcher;
  25. + import flash.net.URLRequest;
  26. + import flash.net.URLRequestMethod;
  27. + import flash.net.URLRequestHeader;
  28. + import flash.net.URLLoader;
  29. + import flash.net.URLVariables;
  30. + import flash.utils.Timer;
  31. + import flash.external.ExternalInterface;
  32. +
  33. + public class connection extends Sprite
  34. + {
  35. + private var httpComplete:Function;
  36. + private var httpError:Function;
  37. + private var httpTimeout:Function;
  38. + private var loaderMap:Object = {};
  39. + private var yId:String;
  40. + private var handler:String = 'YAHOO.util.Connect.handleXdrResponse';
  41. +
  42. + public function connection() {
  43. + ExternalInterface.addCallback("send", send);
  44. + ExternalInterface.addCallback("abort", abort);
  45. + ExternalInterface.addCallback("isCallInProgress", isCallInProgress);
  46. + ExternalInterface.call('YAHOO.util.Connect.xdrReady');
  47. + }
  48. +
  49. + public function send(uri:String, cb:Object, id:uint):void {
  50. + var loader:URLLoader = new URLLoader(),
  51. + request:URLRequest = new URLRequest(uri),
  52. + timer:Timer,
  53. + prop:String;
  54. +
  55. + for (prop in cb) {
  56. + switch (prop) {
  57. + case "method":
  58. + if(cb.method === 'POST') {
  59. + request.method = URLRequestMethod.POST;
  60. + }
  61. + break;
  62. + case "data":
  63. + request.data = cb.data;
  64. + break;
  65. + case "timeout":
  66. + timer = new Timer(cb.timeout, 1);
  67. + break;
  68. + }
  69. + }
  70. +
  71. + loaderMap[id] = { c:loader, readyState: 0, t:timer };
  72. + defineListeners(id, timer);
  73. + addListeners(loader, timer);
  74. + loader.load(request);
  75. + start(id);
  76. +
  77. + if (timer) {
  78. + timer.start();
  79. + }
  80. + }
  81. +
  82. + private function defineListeners(id:uint, timer:Timer):void {
  83. + httpComplete = function(e:Event):void { success(e, id, timer); };
  84. + httpError = function(e:IOErrorEvent):void { failure(e, id, timer); };
  85. +
  86. + if (timer) {
  87. + httpTimeout = function(e:TimerEvent):void { abort(id); };
  88. + }
  89. + }
  90. +
  91. + private function addListeners(loader:IEventDispatcher, timer:IEventDispatcher):void {
  92. + loader.addEventListener(Event.COMPLETE, httpComplete);
  93. + loader.addEventListener(IOErrorEvent.IO_ERROR, httpError);
  94. +
  95. + if (timer) {
  96. + timer.addEventListener(TimerEvent.TIMER_COMPLETE, httpTimeout);
  97. + }
  98. + }
  99. +
  100. + private function removeListeners(id:uint):void {
  101. + loaderMap[id].c.removeEventListener(Event.COMPLETE, httpComplete);
  102. + loaderMap[id].c.removeEventListener(IOErrorEvent.IO_ERROR, httpError);
  103. +
  104. + if (loaderMap[id].t) {
  105. + loaderMap[id].t.removeEventListener(TimerEvent.TIMER_COMPLETE, httpTimeout);
  106. + }
  107. + }
  108. +
  109. + private function start(id:uint):void {
  110. + var response:Object = { tId: id, statusText: 'xdr:start' };
  111. +
  112. + loaderMap[id].readyState = 2;
  113. + ExternalInterface.call(handler, response);
  114. + }
  115. +
  116. + private function success(e:Event, id:uint, timer:Timer):void {
  117. + var data:String = encodeURI(e.target.data),
  118. + response:Object = {
  119. + tId: id,
  120. + statusText: 'xdr:success',
  121. + responseText: data
  122. + };
  123. +
  124. + loaderMap[id].readyState = 4;
  125. +
  126. + if (timer && timer.running) {
  127. + timer.stop();
  128. + }
  129. +
  130. + ExternalInterface.call(handler, response);
  131. + destroy(id);
  132. + }
  133. +
  134. + private function failure(e:Event, id:uint, timer:Timer):void {
  135. + var data:String,
  136. + response:Object = { tId: id, statusText: 'xdr:error' };
  137. +
  138. + loaderMap[id].readyState = 4;
  139. +
  140. + if (e is IOErrorEvent) {
  141. + response.responseText = encodeURI(e.target.data);
  142. + }
  143. +
  144. + if (timer && timer.running) {
  145. + timer.stop();
  146. + }
  147. +
  148. + ExternalInterface.call(handler, response);
  149. + destroy(id);
  150. + }
  151. +
  152. + public function abort(id:uint):void {
  153. + var response:Object = { tId: id, statusText: 'xdr:abort' };
  154. +
  155. + loaderMap[id].c.close();
  156. +
  157. + if (loaderMap[id].t && loaderMap[id].t.running) {
  158. + loaderMap[id].t.stop();
  159. + }
  160. +
  161. + ExternalInterface.call(handler, response);
  162. + destroy(id);
  163. + }
  164. +
  165. + public function isCallInProgress(id:uint):Boolean {
  166. + if (loaderMap[id]) {
  167. + return loaderMap[id].readyState !== 4;
  168. + }
  169. + else {
  170. + return false;
  171. + }
  172. + }
  173. +
  174. + private function destroy(id:uint):void {
  175. + removeListeners(id);
  176. + delete loaderMap[id];
  177. + }
  178. + }
  179. +}
  180. \ No newline at end of file
  181. diff --git a/src/swfstore/as/SWFStore.as b/src/swfstore/as/SWFStore.as
  182. new file mode 100755
  183. index 0000000..e7758de
  184. --- /dev/null
  185. +++ b/src/swfstore/as/SWFStore.as
  186. @@ -0,0 +1,949 @@
  187. +package
  188. +{
  189. + import com.yahoo.util.YUIBridge;
  190. +
  191. + import flash.display.Sprite;
  192. + import flash.events.Event;
  193. + import flash.events.IOErrorEvent;
  194. + import flash.events.SecurityErrorEvent;
  195. + import flash.events.NetStatusEvent;
  196. + import flash.external.ExternalInterface;
  197. + import flash.net.SharedObject;
  198. + import flash.net.SharedObjectFlushStatus;
  199. + import flash.net.URLLoader;
  200. + import flash.net.URLRequest;
  201. + import flash.system.Security;
  202. + import flash.system.SecurityPanel;
  203. + import flash.utils.ByteArray;
  204. +
  205. + //We set width/height is set here to be large enough to display the settings panel in Flash Player
  206. + //It will typically be shrunk to 0 x 0 via the embed code
  207. + [SWF(width=215, height=138)]
  208. +
  209. + /**
  210. + * A wrapper for Flash SharedObjects to allow them to be used in JavaScript.
  211. + *
  212. + * @author Alaric Cole
  213. + */
  214. + public class SWFStore extends Sprite
  215. + {
  216. +
  217. + //--------------------------------------------------------------------------
  218. + //
  219. + // Private Variables
  220. + //
  221. + //--------------------------------------------------------------------------
  222. +
  223. +
  224. + /**
  225. + * The Shared Object instance in which to store entries.
  226. + * @private
  227. + * @fucktown
  228. + */
  229. + private var _sharedObject:SharedObject;
  230. +
  231. +
  232. + /**
  233. + * An object used to temporarily store entries.
  234. + * @private
  235. + */
  236. + private var _archive:Object;
  237. +
  238. + /**
  239. + * Storage for useCompression getter/setter
  240. + * @private
  241. + */
  242. + private var _useCompression:Boolean;
  243. +
  244. + /**
  245. + * Storage for shareData getter/setter
  246. + * @private
  247. + */
  248. + private var _shareData:Boolean;
  249. + //--------------------------------------------------------------------------
  250. + //
  251. + // Static Variables
  252. + //
  253. + //--------------------------------------------------------------------------
  254. +
  255. + /**
  256. + * The minimum width required to be able to display the settings panel within the SWF
  257. + *
  258. + */
  259. + public static var MINIMUM_WIDTH:Number = 215;
  260. +
  261. + /**
  262. + * The minimum height required to be able to display the settings panel within the SWF
  263. + *
  264. + */
  265. + public static var MINIMUM_HEIGHT:Number = 138;
  266. +
  267. + /**
  268. + * @private
  269. + * Initialization flag
  270. + */
  271. + private var _initialized:Boolean;
  272. +
  273. + /**
  274. + * @private
  275. + * Whitelist xml path
  276. + */
  277. + private var _whitelistFileName:String = "storage-whitelist.xml";
  278. +
  279. + /**
  280. + * @private
  281. + * YUI Embedding framework
  282. + */
  283. + private var yuibridge:YUIBridge;
  284. +
  285. + //--------------------------------------
  286. + // Constructor
  287. + //--------------------------------------
  288. +
  289. + /**
  290. + * Creates a store, which can be used to set and get information on a
  291. + * user's local machine. This is typically invoked through the YUI JS API.
  292. + *
  293. + *
  294. + * <p>If multiple SWF files need access to the same store,
  295. + * or if the SWF file that creates a store will later be moved,
  296. + * the value of this parameter affects how accessible the store will be.</p>
  297. + * <p>For example, if you create a store with localPath set to the default value
  298. + * (the full path to the SWF file), no other SWF file can access that shared object.
  299. + * If you later move the original SWF file to another location,
  300. + * not even that SWF file can access the data already stored.</p>
  301. + * <p>To avoid inadvertently restricting access to a store, set this parameter.
  302. + * The most permissive approach is to set localPath to <code>/ </code> (forward slash),
  303. + * which makes the store available to all SWF files in the domain,
  304. + * but increases the likelihood of name conflicts with other stores in the domain.
  305. + * A more restrictive approach is to append localPath with folder names
  306. + * that are in the full path to the SWF file. Note that not just any folder path
  307. + * can be placed here, but only those that are in the path of the SWF.
  308. + * For instance, if the SWF is located at company.com/products/mail/mail.swf,
  309. + * the available options for localPath would be "/products/mail/",
  310. + * "/products/", or "/".</p>
  311. + *
  312. + */
  313. + public function SWFStore()
  314. + {
  315. + loadWhitelist();
  316. +
  317. + var callbacks:Object = {};
  318. + callbacks.getValueOf = getValueOf;
  319. + callbacks.getItems = getItems;
  320. + callbacks.getValueAt = getValueAt;
  321. + callbacks.getNameAt = getNameAt;
  322. + callbacks.getLength = getLength;
  323. + callbacks.getModificationDate = getModificationDate;
  324. + callbacks.calculateCurrentSize = calculateCurrentSize;
  325. + callbacks.setItem = setItem;
  326. + callbacks.removeItem = removeItem;
  327. + callbacks.removeItemAt = removeItemAt;
  328. + callbacks.clear = clear;
  329. + callbacks.setSize = setSize;
  330. + callbacks.displaySettings = displaySettings;
  331. + callbacks.getTypeOf = getTypeOf;
  332. + callbacks.getTypeAt = getTypeAt;
  333. + callbacks.setUseCompression = setUseCompression;
  334. + callbacks.getUseCompression = getUseCompression;
  335. + callbacks.setShareData = setShareData;
  336. + callbacks.getShareData = getShareData;
  337. + callbacks.setShareData = setShareData;
  338. + callbacks.hasAdequateDimensions = hasAdequateDimensions;
  339. +
  340. + yuibridge = new YUIBridge(stage);
  341. + yuibridge.addCallbacks(callbacks);
  342. +
  343. +
  344. + }
  345. +
  346. +
  347. + //--------------------------------------------------------------------------
  348. + //
  349. + // Properties
  350. + //
  351. + //--------------------------------------------------------------------------
  352. +
  353. + /**
  354. + *
  355. + * Whether or not compression is used
  356. + */
  357. + public function getUseCompression():Boolean
  358. + {
  359. + return _useCompression;
  360. +
  361. + }
  362. +
  363. + /**
  364. + * Whether or not to use compression
  365. + */
  366. + public function setUseCompression(value:Boolean):void
  367. + {
  368. + _useCompression = value;
  369. +
  370. + //if we're not already compressed, this setting should force current data to be compressed
  371. + if( !(_sharedObject.data.archive is ByteArray) && value)
  372. + {
  373. + var bytes:ByteArray = new ByteArray();
  374. + bytes.writeObject(_archive);
  375. + bytes.compress();
  376. + _sharedObject.data.archive = bytes;
  377. + _sharedObject.flush();
  378. + }
  379. +
  380. + }
  381. +
  382. + /**
  383. + *
  384. + * Whether or not to data is being shared among different browsers
  385. + */
  386. + public function getShareData():Boolean
  387. + {
  388. + return _useCompression;
  389. + }
  390. + /**
  391. + *
  392. + * Whether or not to share data among different browsers
  393. + */
  394. + public function setShareData(value:Boolean):void
  395. + {
  396. + _shareData = value;
  397. + initializeSharedObject();
  398. + }
  399. +
  400. + //--------------------------------------------------------------------------
  401. + //
  402. + // Public Methods
  403. + //
  404. + //--------------------------------------------------------------------------
  405. +
  406. + /**
  407. + * Saves data to local storage. It returns "true" if the storage succeeded; "false" if the user
  408. + * has denied storage on their machine or if the current limit is too low.
  409. + * <p>The size limit for the passed parameters is ~40Kb.</p>
  410. + *
  411. + * @param item The data to store
  412. + * @param location The name of the "cookie" or store
  413. + * @return Boolean Whether or not the save was successful
  414. + *
  415. + */
  416. + public function setItem(location:String, item:* ):Boolean
  417. + {
  418. + var oldValue:Object = null;
  419. + var info:String;
  420. +
  421. + //check to see if this has already been added
  422. + if(_archive.storage.hasOwnProperty(location))
  423. + {
  424. + //entry already exists with this value, ignore
  425. + if(_archive.storage[location] == item) return false;
  426. +
  427. + else //it's there but has a different value
  428. + {
  429. + oldValue = getValueOf(location);
  430. + _archive.storage[location] = item;
  431. + info = "update";
  432. + }
  433. + }
  434. +
  435. + else //doesn't exist, create and index it
  436. + {
  437. + info = "add";
  438. +
  439. + _archive.storage[location] = item;
  440. + _archive.hash.push(location);
  441. +
  442. + }
  443. +
  444. + //write it immediately
  445. + var result:Boolean = save(location, info, oldValue, item);
  446. + if(!result)
  447. + {
  448. + //return archive to its original state, as this did not propagate to the SharedObject
  449. + switch(info)
  450. + {
  451. + case "update":
  452. + _archive.storage[location] = oldValue;
  453. + break;
  454. +
  455. + case "add":
  456. + delete _archive.storage[location];
  457. + _archive.hash.pop();
  458. + break;
  459. +
  460. + }
  461. + }
  462. + return result;
  463. + }
  464. +
  465. +
  466. + /**
  467. + * Returns the value of the key in local storage, if any. This corresponds to the
  468. + * HTML5 spec getItem(key).
  469. + * <p>Note: to return an item at a specific index, use the helper function</p>:
  470. + * <code>getValueAt(index)</code>
  471. + *
  472. + * @param location The name of the "cookie" or key
  473. + * @return The data
  474. + * @see getValueAt
  475. + */
  476. + public function getValueOf(location:String):*
  477. + {
  478. + if(_archive.storage.hasOwnProperty(location))
  479. + {
  480. + return _archive.storage[location];
  481. + }
  482. +
  483. + return null;
  484. + }
  485. +
  486. + /**
  487. + * Returns the value of the key in local storage, if any, at the specified index.
  488. + * Corresponds to the key(n) method in the HTML5 spec.
  489. + *
  490. + * @param index The index of the "cookie" or store
  491. + * @return The value stored
  492. + *
  493. + */
  494. + public function getValueAt(index:int):*
  495. + {
  496. + var keyname:String = getNameAt(index);
  497. +
  498. + if(!keyname) return null;
  499. +
  500. + var value:Object = _archive.storage[keyname];
  501. +
  502. + if(!value) return null;
  503. +
  504. + return value;
  505. + }
  506. +
  507. + /**
  508. + * Returns the data type of of the storage.
  509. + *
  510. + * <p>May be one of the following types:
  511. + * <ul>
  512. + * <li>boolean</li>
  513. + * <li>function</li>
  514. + * <li>number</li>
  515. + * <li>object</li>
  516. + * <li>string</li>
  517. + * <li>number</li>
  518. + * <li>xml</li>
  519. + * </ul>
  520. + * </p>
  521. + *
  522. + * @param location The name of the "cookie" or store
  523. + * @return The data type.
  524. + *
  525. + */
  526. + public function getTypeOf(location:String):String
  527. + {
  528. + if(_archive.storage.hasOwnProperty(location))
  529. + {
  530. + return typeof _archive.storage[location];
  531. + }
  532. +
  533. + return null;
  534. + }
  535. +
  536. + /**
  537. + * Returns the data type of of the storage.
  538. + *
  539. + * @param index The index of the "cookie" or store
  540. + * @return The data type.
  541. + * @see getTypeOf
  542. + *
  543. + */
  544. + public function getTypeAt(index:int):String
  545. + {
  546. + return typeof getValueAt(index);
  547. + }
  548. +
  549. + /**
  550. + * Returns the key name in storage, if any, at the specified index.
  551. + *
  552. + * @param index The index of the "cookie" or store
  553. + * @return The data
  554. + *
  555. + */
  556. + public function getNameAt(index:int):String
  557. + {
  558. + var keyname:String = _archive.hash[index];
  559. +
  560. + if(!keyname) return null;
  561. +
  562. + return keyname;
  563. + }
  564. +
  565. + /**
  566. + * Returns the number of keys in storage.
  567. + *
  568. + * @return The number of keys
  569. + *
  570. + */
  571. + public function getLength():int
  572. + {
  573. + return _archive.hash.length;
  574. + }
  575. +
  576. + /**
  577. + * Returns the storage object as an Array of name/value pairs.
  578. + *
  579. + *
  580. + * @return The storage dictionary as an Array
  581. + *
  582. + */
  583. + public function getItems():Array
  584. + {
  585. + var len:int = getLength();
  586. + var array:Array = [];
  587. +
  588. + for (var i:uint = 0; i < len; i++)
  589. + {
  590. + array.push(_archive.storage[ _archive.hash[i] ] );
  591. + }
  592. + return array;
  593. +
  594. + }
  595. +
  596. + /**
  597. + * Removes the data in local storage at the specified location, if any.
  598. + *
  599. + * @param location The name of the "cookie" or store
  600. + * @return Whether the remove was successful
  601. + *
  602. + */
  603. + public function removeItem(location:String):Boolean
  604. + {
  605. + var index: int = getIndexOf(location);
  606. + var oldValue:Object = _archive.storage[location];
  607. +
  608. + delete _archive.storage[location];
  609. +
  610. + _archive.hash.splice(index, 1);
  611. +
  612. + var result:Boolean = save(location, "delete", oldValue, null, index);
  613. +
  614. + return result;
  615. + }
  616. +
  617. + /**
  618. + * Removes the data in local storage at the specified location, if any.
  619. + *
  620. + * @param location The name of the "cookie" or store
  621. + * @return Whether the remove was successful
  622. + *
  623. + */
  624. + public function removeItemAt(index:int):Boolean
  625. + {
  626. + var oldValue:Object = getValueAt(index);
  627. + var location:String = getNameAt(index);
  628. +
  629. + delete _archive.storage[location];
  630. +
  631. + _archive.hash.splice(index, 1);
  632. +
  633. + var result:Boolean = save(location, "delete", oldValue, null, index);
  634. +
  635. + return result;
  636. + }
  637. +
  638. + /**
  639. + * Removes all data in local storage for this domain.
  640. + * <p>Be careful when using this method, as it may
  641. + * remove stored information that is used by other applications
  642. + * in this domain </p>
  643. + *
  644. + * @return Whether the clear was successful
  645. + *
  646. + */
  647. + public function clear():Boolean
  648. + {
  649. + _sharedObject.clear();
  650. + _archive = {storage:{}, hash:[]};
  651. + var evt:Object = {type: "save"};
  652. +
  653. + yuibridge.sendEvent(evt);
  654. + return true;
  655. + }
  656. +
  657. +
  658. + /**
  659. + * Gets the amount of space taken by the current store. Note that this value is
  660. + * calculated as requested, so large datasets could result in reduced performance.
  661. + * @return the size of the store in KB
  662. + */
  663. + public function calculateCurrentSize():uint
  664. + {
  665. + var sz:uint = _sharedObject.size;
  666. + return sz;
  667. + }
  668. +
  669. + /**
  670. + * This method requests more storage if the amount is above the current limit (typically ~100KB).
  671. + * The request dialog has to be displayed within the Flash player itself
  672. + * so the SWF it is called from must be visible and at least 215px x 138px in size.
  673. + *
  674. + * Since this is a "per domain" setting, you can
  675. + * use this method on a SWF in a separate page, such as a settings page,
  676. + * if the width/height of the compiled SWF is not large enough to fit this dialog.
  677. + *
  678. + * @param value The size, in KB
  679. + */
  680. + public function setSize(value:int):String
  681. + {
  682. + var status:String;
  683. +
  684. + status = _sharedObject.flush(value * 1024);
  685. + //on error, attempt to resize div?
  686. +
  687. + return status;
  688. + }
  689. +
  690. + /**
  691. + * Displays the settings dialog to allow the user to configure
  692. + * storage settings manually. If the SWF height and width are smaller than
  693. + * what is allowable to display the local settings panel,
  694. + * an error message will be sent to JavaScript.
  695. + */
  696. + public function displaySettings():void
  697. + {
  698. + var evt:Object;
  699. + if( hasAdequateDimensions() )
  700. + {
  701. + evt = {type: "openingDialog"};
  702. + yuibridge.sendEvent(evt);
  703. +
  704. + Security.showSettings(SecurityPanel.LOCAL_STORAGE);
  705. + }
  706. + else
  707. + {
  708. +
  709. + evt = {type: "inadequateDimensions", message: "The current size of the SWF is too small to display " +
  710. + "the settings panel. Please increase the available width and height to 215px x 138px or larger."};
  711. + yuibridge.sendEvent(evt);
  712. + }
  713. +
  714. + }
  715. +
  716. +
  717. + /**
  718. + * Gets the timestamp of the last store. This value is automatically set when
  719. + * data is stored.
  720. + * @return A Date object
  721. + */
  722. + public function getModificationDate():Date
  723. + {
  724. + var lastDate:Date = new Date(_sharedObject.data.modificationDate);
  725. +
  726. + return lastDate;
  727. +
  728. + }
  729. +
  730. +
  731. +
  732. +
  733. + //--------------------------------------
  734. + // Private Methods
  735. + //--------------------------------------
  736. +
  737. + /**
  738. + * @private
  739. + * Gets the index of the item at the specified location
  740. + * @param location The name of the key
  741. + */
  742. + private function getIndexOf(location:String):int
  743. + {
  744. + return _archive.hash.indexOf(location);
  745. + }
  746. +
  747. + /**
  748. + * @private
  749. + * Loads the whitlist XML file
  750. + *
  751. + */
  752. + private function loadWhitelist():void
  753. + {
  754. + var whitelistLoader:URLLoader = new URLLoader();
  755. + whitelistLoader.addEventListener(Event.COMPLETE, onComplete);
  756. + whitelistLoader.addEventListener(IOErrorEvent.IO_ERROR, onError);
  757. + whitelistLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
  758. +
  759. + //don't use a relative path, use the swf's loaded path
  760. + //to prevent crossdomain or base param workarounds
  761. +
  762. + var fullPath:String = loaderInfo.url;
  763. +
  764. + //remove trailing slashes
  765. + var parentPath:String;
  766. +
  767. + var hasTrailingSlash:Boolean = fullPath.charAt(fullPath.length - 1) == "/";
  768. + if(hasTrailingSlash) fullPath = fullPath.slice(0, -1);
  769. +
  770. + //now get the path before the final slash (something like "/swffile.swf")
  771. + parentPath = fullPath.slice(0,fullPath.lastIndexOf("/"));
  772. +
  773. + var localpath:String = parentPath + "/" + _whitelistFileName;
  774. + whitelistLoader.load(new URLRequest(localpath));
  775. + }
  776. +
  777. + /**
  778. + * @private
  779. + * Parses the config xml data and populates path array
  780. + *
  781. + */
  782. + private function onComplete (event:Event) : void
  783. + {
  784. +
  785. + var contentXML:XML;
  786. + try
  787. + {
  788. + contentXML = new XML(event.target.data);
  789. + }
  790. + catch(error:TypeError)
  791. + {
  792. + yuibridge.sendEvent({type:"error", message:error.message});
  793. + }
  794. +
  795. + var valid:Boolean;
  796. +
  797. + var pageURL:String = ExternalInterface.call("function(){return window.location.href;}");
  798. +
  799. + for each (var path:XML in contentXML["allow-access-from"] )
  800. + {
  801. + var url:String = path.@url;
  802. +
  803. + if(pathMatches(pageURL, url))
  804. + {
  805. + valid = true;
  806. + break;
  807. + }
  808. + }
  809. +
  810. +
  811. + if(valid) initializeSharedObject();
  812. +
  813. + //not a valid whitelist, dispatch error
  814. + else
  815. + {
  816. + var evt:Object = {type: "securityError", message: "Security Error: the whitelist does not allow access to storage from this location" };
  817. +
  818. + yuibridge.sendEvent(evt);
  819. + }
  820. + }
  821. +
  822. +
  823. + private function pathMatches(page:String, path:String):Boolean
  824. + {
  825. + //remove the protocol when matching domains, because protocols are not to be specified in the whitelist
  826. + /* var protocolPattern: RegExp = new RegExp("(http|https|file)\:\/\/");
  827. + var pathWithoutProtocol:String = url.replace(protocolPattern, "");
  828. +
  829. + var pageURLWithoutProtocol:String = url.replace(pageURL, ""); */
  830. +
  831. + //ExternalInterface.call("alert('this page's url: " + page + "/nproposed url: " + path + "')");
  832. +
  833. +
  834. + if(page.indexOf(path) > -1)
  835. + {
  836. + //if the loading page's url contains the whitelisted url as a substring, pass it
  837. + return true;
  838. + }
  839. +
  840. + else return false;
  841. + }
  842. + /**
  843. + * @private
  844. + * Dispatches an IOErrorEvent
  845. + *
  846. + */
  847. + private function onError(event:IOErrorEvent) : void
  848. + {
  849. + //trace("no whitelist file");
  850. +
  851. + //try matching the url, a default action since no whitelist was specified
  852. +
  853. + performURLMatch();
  854. + }
  855. +
  856. + /**
  857. + * @private
  858. + * Dispatches a SecurityErrorEvent
  859. + *
  860. + */
  861. + private function onSecurityError(event:SecurityErrorEvent) : void
  862. + {
  863. + var evt:Object = {type: "securityError", message: event.text };
  864. +
  865. + yuibridge.sendEvent(evt);
  866. + }
  867. +
  868. + /**
  869. + * Expands a path with shorthands to url
  870. + *
  871. + * @param path Path with shorthands
  872. + * @return Path with shorthands expanded
  873. + */
  874. + public function getPath (path:String) : String {
  875. + var newPath:String = path.replace(/%(.*)%/, getPath);
  876. + return newPath;
  877. + }
  878. +
  879. + private function performURLMatch():void
  880. + {
  881. + try
  882. + {
  883. + //check that page url is the same as the swf's url //host gives main domain?
  884. + //ExternalInterface.call("function(){alert(window.location.href)}");
  885. + var currentURL:String = ExternalInterface.call("function(){return window.location.href;}");
  886. + if(currentURL.indexOf("?") > -1)
  887. + {
  888. + currentURL = currentURL.slice(0,currentURL.indexOf("?"));
  889. + }
  890. +
  891. + currentURL = currentURL.slice(0,currentURL.lastIndexOf("/"));
  892. +
  893. + var loadedURL:String = loaderInfo.url;
  894. + if(loadedURL.indexOf("?") > -1)
  895. + {
  896. + loadedURL = loadedURL.slice(0,loadedURL.indexOf("?"));
  897. + }
  898. + loadedURL = loadedURL.slice(0,loadedURL.lastIndexOf("/"));
  899. +
  900. + var currentURL_ESC:String = unescape(currentURL) ;
  901. + var loadedURL_ESC:String = unescape(loadedURL)
  902. +
  903. + if(currentURL_ESC == loadedURL_ESC )
  904. + {
  905. + initializeSharedObject();
  906. +
  907. + }
  908. + else
  909. + {
  910. + var evt:Object = {type: "securityError", message: "The domain of the page must match the SWF's domain.\nPage's URL: " +
  911. + currentURL + "\n" + "SWF's URL: " + loadedURL};
  912. +
  913. + yuibridge.sendEvent(evt);
  914. + }
  915. + }
  916. +
  917. + catch(e:Error)
  918. + {
  919. + yuibridge.sendEvent(e);
  920. + }
  921. +
  922. + }
  923. + protected function initializeSharedObject():void
  924. + {
  925. + var allowedDomain:String = loaderInfo.parameters.allowedDomain || null;
  926. +
  927. + if(allowedDomain)
  928. + {
  929. + //allows "cross-scripting" of html container and swf
  930. + Security.allowDomain(allowedDomain);
  931. + }
  932. +
  933. + else
  934. + {
  935. + var evt:Object = {type: "securityError", message: "The domain of the page does not have appropriate permissions.\nPage's URL: "};
  936. + yuibridge.sendEvent(evt);
  937. + }
  938. +
  939. + var localPath:String = null;//loaderInfo.parameters.localPath || null;
  940. +
  941. + var browser:String = loaderInfo.parameters.browser || "other";
  942. +
  943. + if(!_initialized)
  944. + {
  945. + _shareData = loaderInfo.parameters.shareData == "true";
  946. + _useCompression = loaderInfo.parameters.useCompression == "true";
  947. + }
  948. +
  949. + var loc:String = "DataStore_" + (_shareData?"":browser);
  950. + _sharedObject = SharedObject.getLocal(loc, localPath);
  951. +
  952. + _sharedObject.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
  953. +
  954. + //initialize
  955. + if(!_sharedObject.data.hasOwnProperty("archive"))
  956. + {
  957. + _archive = {storage:{}, hash:[]};
  958. + }
  959. + else
  960. + {
  961. + //if compression is detected to be in use, we must decompress it first
  962. + if(_sharedObject.data.archive is ByteArray)
  963. + {
  964. + //remember that sharedobjects are flushed automatically when the page destroys the SWF.
  965. + var tempBytes:ByteArray = _sharedObject.data.archive as ByteArray;
  966. +
  967. + //make a clone of the current shared object
  968. + var bytes:ByteArray = new ByteArray();
  969. + tempBytes.readBytes(bytes, 0, tempBytes.length);
  970. +
  971. + //NOTE: there may be a way to read the first few bytes and determine if it is compressed
  972. +
  973. + try
  974. + {
  975. + bytes.uncompress();
  976. + }
  977. + catch(error:Error)
  978. + {
  979. + //there's an error decompressing
  980. + yuibridge.sendEvent({type: "error", message:error.message});
  981. + }
  982. +
  983. + _archive = bytes.readObject();
  984. + }
  985. + else
  986. + {
  987. + _archive = _sharedObject.data.archive;
  988. + }
  989. +
  990. + }
  991. +
  992. + //if(!_initialized)
  993. + {
  994. + _initialized = true;
  995. + //once initialization is complete, let JS know
  996. + yuibridge.sendEvent({type:"contentReady"});
  997. + }
  998. +
  999. + }
  1000. +
  1001. +
  1002. + /**
  1003. + * @private
  1004. + * Returns the key/value pair in storage, if any, at the specified index.
  1005. + * Similar to get key() in HTML5
  1006. + * @param index The index of the "cookie" or store
  1007. + * @return The data
  1008. + *
  1009. + */
  1010. + protected function getKeyValueAt(index:int):Object
  1011. + {
  1012. + return getItems()[index];
  1013. + }
  1014. +
  1015. +
  1016. + /**
  1017. + * @private
  1018. + * Writes the store to disk. While this will be called by Flash
  1019. + * whenever the application is closed, calling it immediately after
  1020. + * new information allows that info to be instantly available.
  1021. + *
  1022. + * @return Whether or not the save was successful
  1023. + */
  1024. + protected function save( location:String = null, info:String = "add", oldValue:Object = null, newValue:Object = null, index:int = -1):Boolean
  1025. + {
  1026. + var evt:Object = {};
  1027. + var type:String = "save";
  1028. +
  1029. + //set the time modified UTC
  1030. + if(newValue)
  1031. + {
  1032. + setTime(new Date().getTime());
  1033. + }
  1034. +
  1035. + if(_useCompression)
  1036. + {
  1037. + var bytes:ByteArray = new ByteArray();
  1038. + bytes.writeObject(_archive);
  1039. + bytes.compress();
  1040. + _sharedObject.data.archive = bytes;
  1041. + }
  1042. + else _sharedObject.data.archive = _archive;
  1043. +
  1044. + var result:String;
  1045. +
  1046. + try
  1047. + {
  1048. + result = _sharedObject.flush();
  1049. + }
  1050. + catch(e:Error)
  1051. + {
  1052. + //event will be throw further down
  1053. + }
  1054. + //return status
  1055. + if(result == SharedObjectFlushStatus.FLUSHED)
  1056. + {
  1057. + //there may be future issues here with 40k+ storage, because due to the HTML5 spec,
  1058. + //old and new values must be sent back--for a 40k update, this means sending 80k back in the event
  1059. + evt.type = type;
  1060. + evt.info = info;
  1061. + evt.key = location;
  1062. + evt.oldValue = oldValue;
  1063. + evt.newValue = newValue;
  1064. + evt.index = index;
  1065. + yuibridge.sendEvent(evt);
  1066. + return true;
  1067. + }
  1068. + if(result == SharedObjectFlushStatus.PENDING)
  1069. + {
  1070. + //let JS know theres going to be a dialog
  1071. + evt = {type: "pending"};
  1072. + yuibridge.sendEvent(evt);
  1073. + return false;
  1074. + }
  1075. +
  1076. + else
  1077. + {
  1078. + evt = {type: "error", message:"Unable to save. Client-side storage has been disabled for this domain. To enable, display the Flash settings panel and set a storage amount."};
  1079. + yuibridge.sendEvent(evt);
  1080. + return false;
  1081. +
  1082. + }
  1083. + return false;
  1084. + }
  1085. +
  1086. + /**
  1087. + * @private
  1088. + * Sets the date modified for the store, based on the user's clock.
  1089. + *
  1090. + * @param value The time to set, as a Number.
  1091. + *
  1092. + */
  1093. + protected function setTime(value:Number):void
  1094. + {
  1095. + _sharedObject.data.modificationDate = value;
  1096. + }
  1097. +
  1098. + /**
  1099. + * @private
  1100. + * Called when a larger shared object size is requested
  1101. + * @param the NetStatusEvent object.
  1102. + */
  1103. + protected function onNetStatus(event:NetStatusEvent):void
  1104. + {
  1105. +
  1106. + var evt:Object;
  1107. + if(event.info.level =="error")
  1108. + {
  1109. + //this is most likely the result of maxing out storage for the domain. There's no way to tell for certain
  1110. + evt = {type: "quotaExceededError", info:"NetStatus Error: " + event.info.code,
  1111. + message: "Storage capacity requested exceeds available amount."};
  1112. +
  1113. + yuibridge.sendEvent(evt);
  1114. + }
  1115. + else
  1116. + {
  1117. + //this is normally executed when additional storage is requested and allowed by the user
  1118. + evt = {type: "success"};
  1119. + yuibridge.sendEvent(evt);
  1120. + }
  1121. +
  1122. + }
  1123. +
  1124. + /**
  1125. + *
  1126. + * Helper function to determine if SWF visible area is large enough to fit
  1127. + * the settings panel
  1128. + * @return Boolean Whether or not the area is large enough.
  1129. + */
  1130. + public function hasAdequateDimensions():Boolean
  1131. + {
  1132. + return (stage.stageHeight >= MINIMUM_HEIGHT) && (stage.stageWidth >= MINIMUM_WIDTH);
  1133. + }
  1134. + }
  1135. +}
  1136. diff --git a/src/swfstore/as/com/yahoo/util/YUIBridge.as b/src/swfstore/as/com/yahoo/util/YUIBridge.as
  1137. new file mode 100755
  1138. index 0000000..e532d42
  1139. --- /dev/null
  1140. +++ b/src/swfstore/as/com/yahoo/util/YUIBridge.as
  1141. @@ -0,0 +1,45 @@
  1142. + package com.yahoo.util
  1143. + {
  1144. + import flash.display.Stage;
  1145. + import flash.external.ExternalInterface;
  1146. +
  1147. + public class YUIBridge extends Object
  1148. + {
  1149. + private var _stage:Stage;
  1150. + public var flashvars:Object;
  1151. + private var _jsHandler:String;
  1152. + private var _swfID:String;
  1153. +
  1154. + public function YUIBridge(stage:Stage)
  1155. + {
  1156. + _stage = stage;
  1157. + flashvars = _stage.loaderInfo.parameters;
  1158. + if (flashvars["YUIBridgeCallback"] && flashvars["YUISwfId"] && ExternalInterface.available) {
  1159. + _jsHandler = flashvars["YUIBridgeCallback"];
  1160. + var jsCheck:RegExp = /^[A-Za-z0-9.]*$/g;
  1161. + if (!jsCheck.test(_jsHandler)) {
  1162. + _jsHandler = "";
  1163. + }
  1164. +
  1165. + _swfID = flashvars["YUISwfId"];
  1166. + }
  1167. + }
  1168. +
  1169. + public function addCallbacks (callbacks:Object) : void {
  1170. + if (ExternalInterface.available) {
  1171. + for (var callback:String in callbacks) {
  1172. + ExternalInterface.addCallback(callback, callbacks[callback]);
  1173. + trace("Added callback for " + callbacks[callback] + " named " + callback);
  1174. + }
  1175. + sendEvent({type:"swfReady"});
  1176. + }
  1177. + }
  1178. +
  1179. + public function sendEvent (evt:Object) : void {
  1180. + if (ExternalInterface.available) {
  1181. + trace("Sending event " + evt.type);
  1182. + ExternalInterface.call(_jsHandler, _swfID, evt);
  1183. + }
  1184. + }
  1185. + }
  1186. + }
  1187. \ No newline at end of file
  1188. diff --git a/src/uploader/as/Uploader.as b/src/uploader/as/Uploader.as
  1189. new file mode 100755
  1190. index 0000000..dd9b0af
  1191. --- /dev/null
  1192. +++ b/src/uploader/as/Uploader.as
  1193. @@ -0,0 +1,988 @@
  1194. +package
  1195. +
  1196. +{
  1197. +
  1198. + import com.yahoo.yui.YUIAdapter;
  1199. +
  1200. + import flash.display.Loader;
  1201. + import flash.display.Sprite;
  1202. + import flash.display.StageAlign;
  1203. + import flash.display.StageScaleMode;
  1204. + import flash.events.DataEvent;
  1205. + import flash.events.Event;
  1206. + import flash.events.FocusEvent;
  1207. + import flash.events.HTTPStatusEvent;
  1208. + import flash.events.IOErrorEvent;
  1209. + import flash.events.KeyboardEvent;
  1210. + import flash.events.MouseEvent;
  1211. + import flash.events.ProgressEvent;
  1212. + import flash.events.SecurityErrorEvent;
  1213. + import flash.external.ExternalInterface;
  1214. + import flash.net.FileFilter;
  1215. + import flash.net.FileReference;
  1216. + import flash.net.FileReferenceList;
  1217. + import flash.net.URLRequest;
  1218. + import flash.net.URLVariables;
  1219. + import flash.ui.Keyboard;
  1220. + import flash.utils.Dictionary;
  1221. +
  1222. +
  1223. +
  1224. + [SWF(backgroundColor=0xffffff)]
  1225. +
  1226. + /**
  1227. + * The base Uploader class for YUI's Flash-based file uploader.
  1228. + *
  1229. + * @author Allen Rabinovich
  1230. + */
  1231. +
  1232. + public class Uploader extends YUIAdapter {
  1233. +
  1234. + //--------------------------------------
  1235. + // Constructor
  1236. + //--------------------------------------
  1237. +
  1238. + public function Uploader()
  1239. + {
  1240. + super();
  1241. + }
  1242. +
  1243. +
  1244. + //--------------------------------------------------------------------------
  1245. + //
  1246. + // Variables
  1247. + //
  1248. + //--------------------------------------------------------------------------
  1249. +
  1250. + private var allowMultiple:Boolean = false;
  1251. + private var allowLog:Boolean = false;
  1252. + private var filterArray:Array;
  1253. +
  1254. + private var fileDataList:Object;
  1255. + private var fileRefList:Object;
  1256. + private var fileIDList:Dictionary;
  1257. + private var fileIDCounter:Number;
  1258. + private var filesToUpload:Array;
  1259. + private var actualLimit:Number;
  1260. +
  1261. + private var singleFile:FileReference;
  1262. + private var multipleFiles:FileReferenceList;
  1263. +
  1264. +
  1265. + /**
  1266. + * Determines how many files will be uploaded simultaneously
  1267. + *
  1268. + * @see setSimUploadLimit
  1269. + * @langversion 3.0
  1270. + * @playerversion Flash 9.0.28.0
  1271. + */
  1272. + public var simultaneousUploadLimit:Number = 2;
  1273. +
  1274. + // Track the number of current upload threads
  1275. + private var currentUploadThreads:Number = 0;
  1276. +
  1277. + // How the uploader is rendered, either "button" or "transparent"
  1278. + private var renderType:String;
  1279. +
  1280. + // The Sprite containing the rendered UI.
  1281. + private var buttonSprite:Sprite = new Sprite();
  1282. +
  1283. + // The skin for the button, if "button" renderType is used.
  1284. + private var buttonSkin:Loader = new Loader();
  1285. +
  1286. + // Height and width for the button
  1287. + private var buttonHeight:Number;
  1288. + private var buttonWidth:Number;
  1289. +
  1290. + //--------------------------------------
  1291. + // Public Methods
  1292. + //--------------------------------------
  1293. +
  1294. + /**
  1295. + * Sets the number of simultaneous file uploads possible.
  1296. + * The maximum is 5.
  1297. + * @param numberOfUploads Number of simultaneous uploads, no fewer than 1
  1298. + * and no larger than 5.
  1299. + */
  1300. + public function setSimUploadLimit (simUploadLimit:int) : void {
  1301. + if (simUploadLimit <= 1) {
  1302. + this.simultaneousUploadLimit = 1;
  1303. + }
  1304. + else if (simUploadLimit >= 5) {
  1305. + this.simultaneousUploadLimit = 5;
  1306. + }
  1307. + else {
  1308. + this.simultaneousUploadLimit = simUploadLimit;
  1309. + }
  1310. + }
  1311. +
  1312. +
  1313. + /**
  1314. + * Sets a list of file type filters for the "Open File(s)" dialog.
  1315. + *
  1316. + * @param newFilterArray An array of sets of key-value pairs of the form
  1317. + * {extensions: extensionString, description: descriptionString, macType: macTypeString [optional]}
  1318. + * The extension string is a semicolon-delimited list of elements of the form "*.xxx",
  1319. + * e.g. "*.jpg;*.gif;*.png".
  1320. + */
  1321. + public function setFileFilters(newFilterArray:Array) : void {
  1322. + filterArray = processFileFilterObjects(newFilterArray);
  1323. +
  1324. + if (allowLog) {
  1325. + var logString:String = "File filters have been set to the following: \n";
  1326. + for each (var ff:FileFilter in filterArray) {
  1327. + logString += ff.extension + ": " + ff.description + "\n";
  1328. + }
  1329. + logMessage(logString);
  1330. + }
  1331. + }
  1332. +
  1333. + /**
  1334. + * Sets a flag allowing logging in Flash trace and Yahoo logger.
  1335. + *
  1336. + * @param allowLogging Whether to allow log messages.
  1337. + *
  1338. + */
  1339. + public function setAllowLogging(allowLogging:Boolean) : void {
  1340. + this.allowLog = allowLogging;
  1341. + logMessage("Logging has been turned " + (allowLog ? "on." : "off."));
  1342. + }
  1343. +
  1344. + /**
  1345. + * Sets a flag allowing multiple file selection in the "Browse" dialog.
  1346. + *
  1347. + * @param allowMultiple Whether to allow multiple file selection.
  1348. + *
  1349. + */
  1350. + public function setAllowMultipleFiles(allowMultipleFiles:Boolean) : void {
  1351. + this.allowMultiple = allowMultipleFiles;
  1352. + logMessage("Multiple file upload has been turned " + (allowMultiple ? "on." : "off."));
  1353. + }
  1354. +
  1355. +
  1356. + /**
  1357. + * Triggers a prompt for the user to browse their file system to select
  1358. + * files to be uploaded.
  1359. + *
  1360. + * @param allowMultiple Whether to allow the user to select more than
  1361. + * one file
  1362. + *
  1363. + * @param filterArray An array of filter objects, each with <code>
  1364. + * description</code>, and <code>extensions</code> properties which
  1365. + * determine which files the user is allowed to select
  1366. + */
  1367. +
  1368. + private function browse(allowMultiple:Boolean = false, filterArray:Array = null):void {
  1369. +
  1370. + if(!allowMultiple) {
  1371. + logMessage("Browsing for a single file.")
  1372. + singleFile = new FileReference();
  1373. + singleFile.addEventListener(Event.SELECT, singleFileSelected);
  1374. +
  1375. + if(filterArray) {
  1376. + singleFile.browse(filterArray);
  1377. + }
  1378. + else {
  1379. + singleFile.browse();
  1380. + }
  1381. + }
  1382. +
  1383. + else {
  1384. +
  1385. + logMessage("Browsing for one or more files.")
  1386. + multipleFiles = new FileReferenceList();
  1387. + multipleFiles.addEventListener(Event.SELECT, multipleFilesSelected);
  1388. +
  1389. + if(filterArray) {
  1390. + multipleFiles.browse(filterArray);
  1391. + }
  1392. +
  1393. + else {
  1394. + multipleFiles.browse();
  1395. + }
  1396. +
  1397. + }
  1398. +
  1399. + }
  1400. +
  1401. +
  1402. +
  1403. + /**
  1404. + * Removes the file from the set to be uploaded
  1405. + *
  1406. + * @param fileID The ID of the file to be removed
  1407. + */
  1408. +
  1409. + public function removeFile(fileID:String):Object {
  1410. +
  1411. + // TODO: Do we need to remove the item from filesToUpload also?
  1412. + cancel(fileID);
  1413. +
  1414. + delete fileDataList[fileID];
  1415. + delete fileRefList[fileID];
  1416. +
  1417. + return fileDataList;
  1418. + }
  1419. +
  1420. + public function enable () : void {
  1421. + if (renderType == "button") {
  1422. + this.addEventListener(MouseEvent.ROLL_OVER, buttonMouseOver);
  1423. + this.addEventListener(MouseEvent.ROLL_OUT, buttonMouseOut);
  1424. + this.addEventListener(MouseEvent.MOUSE_DOWN, buttonMouseDown);
  1425. + this.addEventListener(MouseEvent.MOUSE_UP, buttonMouseUp);
  1426. + this.addEventListener(MouseEvent.CLICK, handleMouseClick);
  1427. + buttonSkin.y = 0;
  1428. + }
  1429. + else {
  1430. + this.addEventListener(MouseEvent.CLICK, handleMouseClick);
  1431. + this.addEventListener(MouseEvent.CLICK, transparentClick);
  1432. +
  1433. + this.addEventListener(MouseEvent.MOUSE_DOWN, transparentDown);
  1434. + this.addEventListener(MouseEvent.MOUSE_UP, transparentUp);
  1435. + this.addEventListener(MouseEvent.ROLL_OVER, transparentRollOver);
  1436. + this.addEventListener(MouseEvent.ROLL_OUT, transparentRollOut);
  1437. + }
  1438. +
  1439. + logMessage("Uploader UI has been enabled.");
  1440. + }
  1441. +
  1442. + public function disable () : void {
  1443. + if (renderType == "button") {
  1444. + this.removeEventListener(MouseEvent.ROLL_OVER, buttonMouseOver);
  1445. + this.removeEventListener(MouseEvent.ROLL_OUT, buttonMouseOut);
  1446. + this.removeEventListener(MouseEvent.MOUSE_DOWN, buttonMouseDown);
  1447. + this.removeEventListener(MouseEvent.MOUSE_UP, buttonMouseUp);
  1448. + this.removeEventListener(MouseEvent.CLICK, handleMouseClick);
  1449. + buttonSkin.y = -3*buttonHeight;
  1450. + }
  1451. + else {
  1452. + this.removeEventListener(MouseEvent.CLICK, handleMouseClick);
  1453. + this.removeEventListener(MouseEvent.CLICK, transparentClick);
  1454. +
  1455. + this.removeEventListener(MouseEvent.MOUSE_DOWN, transparentDown);
  1456. + this.removeEventListener(MouseEvent.MOUSE_UP, transparentUp);
  1457. + this.removeEventListener(MouseEvent.ROLL_OVER, transparentRollOver);
  1458. + this.removeEventListener(MouseEvent.ROLL_OUT, transparentRollOut);
  1459. + }
  1460. +
  1461. + logMessage("Uploader UI has been disabled.");
  1462. + }
  1463. +
  1464. + /**
  1465. + * Clears the set of files that had been selected for upload
  1466. + */
  1467. +
  1468. + public function clearFileList():Boolean {
  1469. +
  1470. + // TODO: Remove event listeners (or weak references?)
  1471. +
  1472. + filesToUpload = [];
  1473. + fileDataList = new Object();
  1474. + fileRefList = new Object();
  1475. + fileIDList = new Dictionary();
  1476. + fileIDCounter = 0;
  1477. +
  1478. + logMessage("The file list has been cleared.");
  1479. +
  1480. + return true;
  1481. + }
  1482. +
  1483. +
  1484. +
  1485. + /**
  1486. + * Uploads a file corresponding to a specified ID to a specified path where a script handles writing to the server.
  1487. + *
  1488. + * @param fileID The ID of the file to be uploaded
  1489. + * @param url The path to the serverside script
  1490. + * @param method The HTTP submission method. Possible values are "GET" and "POST"
  1491. + * @param vars An object containing variables to be sent along with the request
  1492. + * @param fieldName The field name that precedes the file data in the upload POST operation.
  1493. + * The uploadDataFieldName value must be non-null and a non-empty String.
  1494. + * @param headers An object containing variables that should be set as headers in the POST request. The following header names
  1495. + * cannot be used:
  1496. + * <code>
  1497. + * Accept-Charset, Accept-Encoding, Accept-Ranges, Age, Allow, Allowed, Authorization, Charge-To, Connect, Connection,
  1498. + * Content-Length, Content-Location, Content-Range, Cookie, Date, Delete, ETag, Expect, Get, Head, Host, Keep-Alive,
  1499. + * Last-Modified, Location, Max-Forwards, Options, Post, Proxy-Authenticate, Proxy-Authorization, Proxy-Connection,
  1500. + * Public, Put, Range, Referer, Request-Range, Retry-After, Server, TE, Trace, Trailer, Transfer-Encoding, Upgrade,
  1501. + * URI, User-Agent, Vary, Via, Warning, WWW-Authenticate, x-flash-version.
  1502. + * </code>
  1503. + */
  1504. +
  1505. + public function upload(fileID:String, url:String, method:String = "GET", vars:Object = null, fieldName:String = "Filedata"):void {
  1506. +
  1507. + // null checking in the params is not working correctly
  1508. + filesToUpload = [];
  1509. +
  1510. + if(isEmptyString(method)) {
  1511. + method = "GET";
  1512. + }
  1513. +
  1514. + if(isEmptyString(fieldName)) {
  1515. + fieldName = "Filedata";
  1516. + }
  1517. +
  1518. + var request:URLRequest = formURLRequest(url, method, vars);
  1519. + var fr:FileReference = fileRefList[fileID];
  1520. +
  1521. + this.currentUploadThreads++;
  1522. + fr.upload(request,fieldName);
  1523. + }
  1524. +
  1525. + /**
  1526. + * Uploads the specified files to a specified path where a script handles writing to the server.
  1527. + *
  1528. + * @param fileIDs The IDs of the files to be uploaded
  1529. + * @param url The path to the serverside script
  1530. + * @param method The HTTP submission method. Possible values are "GET" and "POST"
  1531. + * @param vars An object containing data to be sent along with the request
  1532. + * @param fieldName The field name that precedes the file data in the upload POST operation. The uploadDataFieldName value must be non-null and a non-empty String.
  1533. + */
  1534. +
  1535. + public function uploadThese(fileIDs:Array, url:String, method:String = "GET", vars:Object = null, fieldName:String = "Filedata"):void {
  1536. + if(isEmptyString(method)) {
  1537. + method = "GET";
  1538. + }
  1539. +
  1540. + if(isEmptyString(fieldName)) {
  1541. + fieldName = "Filedata";
  1542. + }
  1543. +
  1544. + var request:URLRequest = formURLRequest(url, method, vars);
  1545. +
  1546. + for each(var fileID:String in fileIDs) {
  1547. + queueForUpload(fileRefList[fileID], request, fieldName);
  1548. + }
  1549. +
  1550. + processQueue();
  1551. + }
  1552. +
  1553. + /**
  1554. + * Uploads all files to a specified path where a script handles writing to the server.
  1555. + *
  1556. + * @param fileID The ID of the file to be uploaded
  1557. + * @param url The path to the serverside script
  1558. + * @param method The HTTP submission method. Possible values are "GET" and "POST"
  1559. + * @param vars An object containing data to be sent along with the request
  1560. + * @param fieldName The field name that precedes the file data in the upload POST operation. The uploadDataFieldName value must be non-null and a non-empty String.
  1561. + * @param headers An object containing variables that should be set as headers in the POST request. The following header names
  1562. + * cannot be used:
  1563. + * <code>
  1564. + * Accept-Charset, Accept-Encoding, Accept-Ranges, Age, Allow, Allowed, Authorization, Charge-To, Connect, Connection,
  1565. + * Content-Length, Content-Location, Content-Range, Cookie, Date, Delete, ETag, Expect, Get, Head, Host, Keep-Alive,
  1566. + * Last-Modified, Location, Max-Forwards, Options, Post, Proxy-Authenticate, Proxy-Authorization, Proxy-Connection,
  1567. + * Public, Put, Range, Referer, Request-Range, Retry-After, Server, TE, Trace, Trailer, Transfer-Encoding, Upgrade,
  1568. + * URI, User-Agent, Vary, Via, Warning, WWW-Authenticate, x-flash-version.
  1569. + * </code>
  1570. + */
  1571. +
  1572. + public function uploadAll(url:String, method:String = "GET", vars:Object = null, fieldName:String = "Filedata", headers:Object = null):void {
  1573. + if(isEmptyString(method)) {
  1574. + method = "GET";
  1575. + }
  1576. +
  1577. + if(isEmptyString(fieldName)) {
  1578. + fieldName = "Filedata";
  1579. + }
  1580. +
  1581. + var request:URLRequest = formURLRequest(url, method, vars);
  1582. +
  1583. + filesToUpload = [];
  1584. +
  1585. + // sort files in the order that they were given to us
  1586. + var fileIds:Array = [];
  1587. + for (var fileId:String in fileRefList) {
  1588. + fileIds.push(parseInt(fileId.substr(4)));
  1589. + }
  1590. + fileIds.sort(Array.NUMERIC);
  1591. + for each(var fileId2:int in fileIds) {
  1592. + queueForUpload(fileRefList["file"+fileId2], request, fieldName);
  1593. + }
  1594. +
  1595. + if (filesToUpload.length < this.simultaneousUploadLimit) {
  1596. + this.actualLimit = filesToUpload.length;
  1597. + } else {
  1598. + this.actualLimit = this.simultaneousUploadLimit;
  1599. + }
  1600. +
  1601. + processQueue();
  1602. + }
  1603. +
  1604. + /**
  1605. + * Cancels either an upload of the file corresponding to a given fileID, or in the absence of the specified fileID, all active files being uploaded.
  1606. + *
  1607. + * @param fileID The ID of the file to be uploaded
  1608. + */
  1609. +
  1610. + public function cancel(fileID:String = null):void {
  1611. +
  1612. + logMessage("Canceling upload");
  1613. +
  1614. + if (fileID == null) { // cancel all files
  1615. + for each (var item:FileReference in fileRefList) {
  1616. + item.cancel();
  1617. + }
  1618. + this.currentUploadThreads = 0;
  1619. + filesToUpload = [];
  1620. + }
  1621. +
  1622. + else if (fileRefList[fileID] != null) { // cancel specified file
  1623. + var fr:FileReference = fileRefList[fileID];
  1624. + if (this.currentUploadThreads > 0)
  1625. + this.currentUploadThreads--;
  1626. + fr.cancel();
  1627. + }
  1628. +
  1629. + }
  1630. +
  1631. +
  1632. +
  1633. + /*
  1634. + Events
  1635. + -------------------------------
  1636. + mouseDown - fires when the mouse button is pressed over uploader
  1637. + mouseUp - fires when the mouse button is released over uploader
  1638. + rollOver - fires when the mouse rolls over the uploader
  1639. + rollOut - fires when the mouse rolls out of the uploader
  1640. + click - fires when the uploader is clicked
  1641. + fileSelect - fires when the user selects one or more files (after browse is called). Passes the array of currently selected files (if prior browse calls were made and clearFileList hasn't been called, all files the user has ever selected will be returned), along with all information available about them (name, size, type, creationDate, modificationDate, creator).
  1642. + uploadStart - fires when a file starts uploading. Passes a file id for identifying the file.
  1643. + uploadProgress - fires when a file upload reports progress. Passes the file id, as well as bytesUploaded and bytesTotal for the given file.
  1644. + uploadComplete - fires when a file upload is completed successfully and passes the corresponding file id.
  1645. + uploadCompleteData - fires when data is received from the server after upload and passes the corresponding file id and the said data.
  1646. + uploadError - fires when an error occurs during download. Passes the id of the file that was being uploaded and an error type.
  1647. + *