Author: pyaschenko
Date: 2010-04-28 12:23:19 -0400 (Wed, 28 Apr 2010)
New Revision: 16827
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-base-component.js
Log:
BaseComponent: protected methods support was added, jsdocs updated
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-base-component.js
===================================================================
---
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-base-component.js 2010-04-28
15:24:38 UTC (rev 16826)
+++
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces-base-component.js 2010-04-28
16:23:19 UTC (rev 16827)
@@ -13,18 +13,30 @@
*
<pre><code>
//Inheritance example:
- (function (jQuery, richfaces, params) {
+ (function ($, richfaces, params) {
// Constructor definition
richfaces.MyComponent = function(componentId, [options]) {
- $super.constructor.call(this, componentId, [options]);
+ // call constructor of parent class
+ $super.constructor.call(this, componentId, [options]);
};
-
- // Extend component class
- var $super = richfaces.BaseComponent.extend(richfaces.BaseComponent,
richfaces.MyComponent);
+
+ // define private method
+ var myPrivateMethod = function () {
+ }
+
+ // create container for protected method's links
+ // in this example we link private method as protected
+ var $p ={myProtectedMethod: myPrivateMethod};
+
+ // Extend component class and add protected methods from parent class to our
container
+ $p = richfaces.BaseComponent.extend(richfaces.BaseComponent, richfaces.MyComponent,
$p);
+
+ // define super class link
+ var $super = richfaces.MyComponent.$super;
// Add new properties and methods
- jQuery.extend(richfaces.MyComponent.prototype, (function (params) {
+ $.extend(richfaces.MyComponent.prototype, (function (params) {
return {
name:"MyComponent",
f:function (){alert("hello");
@@ -45,23 +57,53 @@
};
/**
+ * <protected> Attach component object to DOM element by component id, DOM
element or jQuery object and returns the element
+ *
+ * @function
+ * @name RichFaces.BaseComponent#attachToDom
+ * @param {string|DOMElement|jQuery} source - component id, DOM element or DOM
elements wrapped by jQuery
+ *
+ * @return {DOMElement}
+ * */
+ var attachToDom = function(source) {
+ source = source || this.id;
+ var element = richfaces.getDomElement(source);
+ if (element) {
+ element["richfaces"] = element["richfaces"] || {};
+ element.richfaces.component = this;
+ }
+ return element;
+ }
+
+ var $p = {attachToDom:attachToDom};
+
+ /**
* Method extends child class prototype with parent prototype
- * and return parent's prototype ($super)
+ * and return the object with parent's protected methods
*
* @function
* @name RichFaces.BaseComponent.extend
*
* @return {object}
* */
- richfaces.BaseComponent.extend = function (Parent, Child) {
+ richfaces.BaseComponent.extend = function (parent, child, h) {
var F = richfaces.blankFunction;
- F.prototype = Parent.prototype;
- Child.prototype = new F();
- Child.prototype.constructor = Child;
- Child.$super = Parent.prototype;
- return Parent.prototype;
- }
-
+ F.prototype = parent.prototype;
+ child.prototype = new F();
+ child.prototype.constructor = child;
+ child.$super = parent.prototype;
+ if (child.$super == richfaces.BaseComponent.prototype) {
+ var r = jQuery.extend({}, $p, h||{});
+ }
+
+ // create wrapper with protected methods and variables
+ child.extend = function (_parent, _child, _h) {
+ var _r = jQuery.extend({}, r||h||{}, _h||{});
+ return richfaces.BaseComponent.extend(_parent, _child, _r);
+ }
+ return r||h;
+ };
+
$.extend(richfaces.BaseComponent.prototype, (function (params) {
return {
/**
@@ -99,26 +141,7 @@
* @return {String}
* */
getEventElement: function() {
- return "#"+this.id;
- },
-
- /**
- * Attach component object to DOM element by component id, DOM element or
jQuery object and returns the element
- *
- * @function
- * @name RichFaces.BaseComponent#attachToDom
- * @param {string|DOMElement|jQuery} source - component id, DOM element or
DOM elements wrapped by jQuery
- *
- * @return {DOMElement}
- * */
- attachToDom: function(source) {
- source = source || this.id;
- var element = RichFaces.getDomElement(source);
- if (element) {
- element["richfaces"] = element["richfaces"] || {};
- element.richfaces.component = this;
- }
- return element;
+ return "#"+this.id;
}
};
})(params));
Show replies by date