1 /**
  2  * The 'handle' namespace
  3  * @namespace
  4  * The handle namespace provides an handler that encapsulates the basic functionality of a popup.
  5  * This handle is an <code>EventEmitter</code>. So it is possible to register event listener on the <code>popup</code>.
  6  * to listen to it's property value changes. A user can create custom property and emit events for it's value changes.
  7  * This popup handle is basically created in the field
  8  * editor and accessed in the popup with <code>handle</code> namespace.
  9  *
 10  * @name handle
 11  * @example
 12  *
 13  * The popup handle is created in the field editor like below:
 14  *
 15  * var editor = Require['field-editor'];
 16  * var popupHandle = editor.createPopup("http://www.example.com", "initial-value"); // created the popup handle.
 17  * popupHandle.on("popup-value-changed", function(pValue){
 18  *   //Do something with the value when the value is changed.
 19  * });
 20  * popupHandle.show();// This will make the popup visible.
 21  *
 22  * The handle is obtained in the popup like below:
 23  *
 24  * window.onload = function (){
 25  *  popupHandle = require("handle");
 26  * };
 27  * initialValue=popupHandle.data //returns the initial value.
 28  * popupHandle.emit("popup-value-changed", pValue);
 29  * popupHandle.hide();
 30  */
 31 function PopupHandler(pData) {
 32 
 33   EventEmitter.call(this);
 34   /**
 35    * The <code>popup-value-changed</code> event is fired whenever the <code>value</code>
 36    * of the popup is changed. The event name can be specified by the user.
 37    * <p>
 38    * The event is passed with an object of <code>String</code> type, Which is the value
 39    * passed from the popup.
 40    * @event
 41    * @name popup-value-changed
 42    * @memberOf handle
 43    * @param {String} pValue the string representation of the value of emitted from popup.
 44    * @example
 45    * popupHandle.on("popup-value-changed", function (pValue) {
 46    *   // do something
 47    * });
 48    */
 49 
 50   //This instance variable is used only for documentation purpose
 51   //Please do not delete it.
 52   /**
 53    * The initial value of the popup, which is null if the initial value is not set.
 54    * @memberOf handle
 55    * @type {String}
 56    * @example
 57    * The data can be access by
 58    * var data = popupHandle.data;
 59    */
 60   this.data="";
 61 
 62   var initialValue = pData;
 63   var javaPopupHandler;
 64 
 65   /**
 66    * Shows the popup created by the field editor.
 67    * @memberOf handle
 68    * @function
 69    * @name show
 70    * @example
 71    * By following we can show the popup:
 72    * popupHandle.show();
 73    */
 74   this.show = function () {
 75     javaPopupHandler.show();
 76   };
 77 
 78   /**
 79    * Hides the popup.
 80    * @memberOf handle
 81    * @function
 82    * @name hide
 83    * @example
 84    * The popup can be made hidden by simply calling:
 85    * popupHandle.hide();
 86    */
 87   this.hide = function () {
 88     javaPopupHandler.hide();
 89   };
 90 
 91   this.__defineGetter__("data", function () {
 92     return initialValue;
 93   });
 94 
 95   this.setHandler = function (pHandler) {
 96     javaPopupHandler = pHandler;
 97   };
 98 }
 99 
100 function heir(p) {
101   /** @ignore */
102   function F() {
103   }
104 
105   F.prototype = p;
106   return new F();
107 }
108 
109 PopupHandler.prototype = heir(EventEmitter.prototype);
110 
111 // set the constructor to the subclass prototype
112 PopupHandler.prototype.constructor = PopupHandler;
113