Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
patching up my aweful attempt to resolve some git issues that were ov…
…er my head
  • Loading branch information
thatcher committed Aug 11, 2009
1 parent 7d6d96a commit 97b19bd
Show file tree
Hide file tree
Showing 3 changed files with 292 additions and 534 deletions.
285 changes: 18 additions & 267 deletions dist/env.js
Expand Up @@ -5129,262 +5129,6 @@ __extend__(HTMLDocument.prototype, {
});

$w.HTMLDocument = HTMLDocument;
$debug("Defining HTMLElement");
/*
* HTMLElement - DOM Level 2
*/
var HTMLElement = function(ownerDocument) {
this.DOMElement = DOMElement;
this.DOMElement(ownerDocument);

this.$css2props = null;
};
HTMLElement.prototype = new DOMElement;
__extend__(HTMLElement.prototype, {
get className() {
return this.getAttribute("class")||"";

},
set className(val) {
return this.setAttribute("class",trim(val));

},
get dir() {
return this.getAttribute("dir")||"ltr";

},
set dir(val) {
return this.setAttribute("dir",val);

},
get id(){
return this.getAttribute('id')||'';

},
set id(id){
this.setAttribute('id', id);

},
get innerHTML(){
return this.childNodes.xml;

},
set innerHTML(html){
//$debug("htmlElement.innerHTML("+html+")");
//Should be replaced with HTMLPARSER usage
var doc = new DOMParser().
parseFromString('<div>'+html+'</div>');
var parent = doc.documentElement;
while(this.firstChild != null){
this.removeChild( this.firstChild );
}
var importedNode;
while(parent.firstChild != null){
importedNode = this.importNode(
parent.removeChild( parent.firstChild ), true);
this.appendChild( importedNode );
}
//Mark for garbage collection
doc = null;
},
get lang() {
return this.getAttribute("lang")||"";

},
set lang(val) {
return this.setAttribute("lang",val);

},
get offsetHeight(){
return Number(this.style["height"].replace("px",""));
},
get offsetWidth(){
return Number(this.style["width"].replace("px",""));
},
offsetLeft: 0,
offsetRight: 0,
get offsetParent(){
/* TODO */
return;
},
set offsetParent(element){
/* TODO */
return;
},
scrollHeight: 0,
scrollWidth: 0,
scrollLeft: 0,
scrollRight: 0,
get style(){
if(this.$css2props === null){
this.updateCss2Props();
}
return this.$css2props
},
updateCss2Props: function() {
this.$css2props = new CSS2Properties({
onSet: (function(that) {
return function() { that.__setAttribute("style", this.cssText); }
})(this),
cssText:this.getAttribute("style")
});
},
__setAttribute: HTMLElement.prototype.setAttribute,
setAttribute: function (name, value) {
this.__setAttribute(name, value);
if (name === "style") {
this.updateCss2Props();
}
},
get title() {
return this.getAttribute("title")||"";

},
set title(val) {
return this.setAttribute("title",val);

},
//Not in the specs but I'll leave it here for now.
get outerHTML(){
return this.xml;

},
scrollIntoView: function(){
/*TODO*/
return;

},

onclick: function(event){
__eval__(this.getAttribute('onclick')||'', this)
},
// non-ECMA function, but no other way for click events to enter env.js
__click__: function(element){
var event = new Event({
target:element,
currentTarget:element
});
event.initEvent("click");
element.dispatchEvent(event);
},

ondblclick: function(event){
__eval__(this.getAttribute('ondblclick')||'', this);
},
onkeydown: function(event){
__eval__(this.getAttribute('onkeydown')||'', this);
},
onkeypress: function(event){
__eval__(this.getAttribute('onkeypress')||'', this);
},
onkeyup: function(event){
__eval__(this.getAttribute('onkeyup')||'', this);
},
onmousedown: function(event){
__eval__(this.getAttribute('onmousedown')||'', this);
},
onmousemove: function(event){
__eval__(this.getAttribute('onmousemove')||'', this);
},
onmouseout: function(event){
__eval__(this.getAttribute('onmouseout')||'', this);
},
onmouseover: function(event){
__eval__(this.getAttribute('onmouseover')||'', this);
},
onmouseup: function(event){
__eval__(this.getAttribute('onmouseup')||'', this);
}
});

var __eval__ = function(script, startingNode){
if (script == "")
return; // don't assemble environment if no script...

try{
var doEval = function(scriptText){
eval(scriptText);
}

var listOfScopes = [];
for (var node = startingNode; node != null; node = node.parentNode)
listOfScopes.push(node);
listOfScopes.push(window);


var oldScopesArray = configureFunctionObjectsScopeChain(
doEval, // the function whose scope chain to change
listOfScopes); // last array element is "head" of new chain
doEval.call(startingNode, script);
restoreScopeOfSetOfObjects(oldScopesArray);
// oldScopesArray is N-element array of two-element
// arrays. First element is JS object whose scope
// was modified, second is original value to restore.
}catch(e){
$error(e);
}
};

var __registerEventAttrs__ = function(elm){
if(elm.hasAttribute('onclick')){
elm.addEventListener('click', elm.onclick );
}
if(elm.hasAttribute('ondblclick')){
elm.addEventListener('dblclick', elm.onclick );
}
if(elm.hasAttribute('onkeydown')){
elm.addEventListener('keydown', elm.onclick );
}
if(elm.hasAttribute('onkeypress')){
elm.addEventListener('keypress', elm.onclick );
}
if(elm.hasAttribute('onkeyup')){
elm.addEventListener('keyup', elm.onclick );
}
if(elm.hasAttribute('onmousedown')){
elm.addEventListener('mousedown', elm.onclick );
}
if(elm.hasAttribute('onmousemove')){
elm.addEventListener('mousemove', elm.onclick );
}
if(elm.hasAttribute('onmouseout')){
elm.addEventListener('mouseout', elm.onclick );
}
if(elm.hasAttribute('onmouseover')){
elm.addEventListener('mouseover', elm.onclick );
}
if(elm.hasAttribute('onmouseup')){
elm.addEventListener('mouseup', elm.onclick );
}
return elm;
};

var __submit__ = function(element){
var event = new Event({
target:element,
currentTarget:element
});
event.initEvent("submit");
element.dispatchEvent(event);
};
var __focus__ = function(element){
var event = new Event({
target:element,
currentTarget:element
});
event.initEvent("focus");
element.dispatchEvent(event);
};
var __blur__ = function(element){
var event = new Event({
target:element,
currentTarget:element
});
event.initEvent("blur");
element.dispatchEvent(event);
};

$w.HTMLElement = HTMLElement;
$debug("Defining HTMLCollection");
/*
* HTMLCollection - DOM Level 2
Expand Down Expand Up @@ -7695,9 +7439,7 @@ __extend__(CSS2Properties.prototype, {

},
getPropertyValue : function(name){
var camelCase = name.replace(/\-(\w)/g, function(all, letter){
return letter.toUpperCase();
});
var camelCase = __toCamelCase__(name);
var i, value = this[camelCase];
if(value === undefined){
for(i=0;i<this.length;i++){
Expand Down Expand Up @@ -7725,9 +7467,7 @@ __extend__(CSS2Properties.prototype, {
}
},
onSet:function(camelCaseName, value){
var dashedName = camelCaseName.replace(/[A-Z]/g, function(all) {
return "-" + all.toLowerCase();
});
var dashedName = __toDashed__(camelCaseName);
var definition = dashedName + ": " + value;
if (this.styleIndices[camelCaseName] !== undefined)
this[this.styleIndices[camelCaseName]] = definition;
Expand All @@ -7742,7 +7482,7 @@ __extend__(CSS2Properties.prototype, {
var __cssTextToStyles__ = function(css2props, cssText){
var styleArray=[];
var style, name, value, camelCaseName, w3cName, styles = cssText.split(';');
this.styleIndices = {};
css2props.styleIndices = {};
for ( var i = 0; i < styles.length; i++ ) {
//$log("Adding style property " + styles[i]);
style = styles[i].split(':');
Expand All @@ -7753,10 +7493,8 @@ var __cssTextToStyles__ = function(css2props, cssText){
styleArray[idx] = w3cName = styles[i];
//camel case for dash case
value = trim(style[1]);
camelCaseName = trim(style[0].replace(/\-(\w)/g, function(all, letter){
return letter.toUpperCase();
}));
this.styleIndices[camelCaseName] = idx;
camelCaseName = trim(__toCamelCase__(style[0]));
css2props.styleIndices[camelCaseName] = idx;
$debug('CSS Style Name: ' + camelCaseName);
if(css2props["_" + camelCaseName]!==undefined){
//set the value internally with camelcase name
Expand All @@ -7767,6 +7505,19 @@ var __cssTextToStyles__ = function(css2props, cssText){
}
__setArray__(css2props, styleArray);
};

var __toCamelCase__ = function(name) {
return name.replace(/\-(\w)/g, function(all, letter){
return letter.toUpperCase();
});
};

var __toDashed__ = function(camelCaseName) {
return camelCaseName.replace(/[A-Z]/g, function(all) {
return "-" + all.toLowerCase();
});
};

//Obviously these arent all supported but by commenting out various sections
//this provides a single location to configure what is exposed as supported.
//These getters/setters will need to get fine-tuned in the future to deal with
Expand Down

0 comments on commit 97b19bd

Please sign in to comment.