$debug("Defining CharacterData"); /* * CharacterData - DOM Level 2 */ /** * @class DOMCharacterData - parent abstract class for DOMText and DOMComment * @extends DOMNode * @author Jon van Noort (jon@webarcana.com.au) * @param ownerDocument : DOMDocument - The Document object associated with this node. */ var DOMCharacterData = function(ownerDocument) { this.DOMNode = DOMNode; this.DOMNode(ownerDocument); }; DOMCharacterData.prototype = new DOMNode; __extend__(DOMCharacterData.prototype,{ get data(){ return this.nodeValue; }, set data(data){ this.nodeValue = data; }, get length(){return this.nodeValue.length;}, appendData: function(arg){ // throw Exception if DOMCharacterData is readonly if (__ownerDocument__(this).implementation.errorChecking && this._readonly) { throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)); } // append data this.data = "" + this.data + arg; }, deleteData: function(offset, count){ // throw Exception if DOMCharacterData is readonly if (__ownerDocument__(this).implementation.errorChecking && this._readonly) { throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)); } if (this.data) { // throw Exception if offset is negative or greater than the data length, if (__ownerDocument__(this).implementation.errorChecking && ((offset < 0) || (offset > this.data.length) || (count < 0))) { throw(new DOMException(DOMException.INDEX_SIZE_ERR)); } // delete data if(!count || (offset + count) > this.data.length) { this.data = this.data.substring(0, offset); }else { this.data = this.data.substring(0, offset). concat(this.data.substring(offset + count)); } } }, insertData: function(offset, arg){ // throw Exception if DOMCharacterData is readonly if(__ownerDocument__(this).implementation.errorChecking && this._readonly){ throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)); } if(this.data){ // throw Exception if offset is negative or greater than the data length, if (__ownerDocument__(this).implementation.errorChecking && ((offset < 0) || (offset > this.data.length))) { throw(new DOMException(DOMException.INDEX_SIZE_ERR)); } // insert data this.data = this.data.substring(0, offset).concat(arg, this.data.substring(offset)); }else { // throw Exception if offset is negative or greater than the data length, if (__ownerDocument__(this).implementation.errorChecking && (offset != 0)) { throw(new DOMException(DOMException.INDEX_SIZE_ERR)); } // set data this.data = arg; } }, replaceData: function(offset, count, arg){ // throw Exception if DOMCharacterData is readonly if (__ownerDocument__(this).implementation.errorChecking && this._readonly) { throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)); } if (this.data) { // throw Exception if offset is negative or greater than the data length, if (__ownerDocument__(this).implementation.errorChecking && ((offset < 0) || (offset > this.data.length) || (count < 0))) { throw(new DOMException(DOMException.INDEX_SIZE_ERR)); } // replace data this.data = this.data.substring(0, offset). concat(arg, this.data.substring(offset + count)); }else { // set data this.data = arg; } }, substringData: function(offset, count){ var ret = null; if (this.data) { // throw Exception if offset is negative or greater than the data length, // or the count is negative if (__ownerDocument__(this).implementation.errorChecking && ((offset < 0) || (offset > this.data.length) || (count < 0))) { throw(new DOMException(DOMException.INDEX_SIZE_ERR)); } // if count is not specified if (!count) { ret = this.data.substring(offset); // default to 'end of string' }else{ ret = this.data.substring(offset, offset + count); } } return ret; } }); // $w.CharacterData = DOMCharacterData;