Skip to content

Commit

Permalink
fusejs: Rename fuse.env.Bug/Feature to fuse.env.test and add fuse.env…
Browse files Browse the repository at this point in the history
….addTest and fuse.env.removeTest methods. [FuseJS LH #44] [jddalton, Joe Gornick, kangax]
  • Loading branch information
jdalton committed Jan 27, 2010
1 parent 14a0ed5 commit 80a497c
Show file tree
Hide file tree
Showing 22 changed files with 135 additions and 133 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,5 @@
* Rename fuse.env.Bug/Feature to fuse.env.test and add fuse.env.addTest and fuse.env.removeTest methods. [FuseJS LH #44] [jddalton, Joe Gornick, kangax]

* Lowercase the Fuse namespaces and remove the List aliases. [jddalton] * Lowercase the Fuse namespaces and remove the List aliases. [jddalton]


* Add the overlooked reverse(), sort(), and splice() methods to the Fuseboxed Array.prototype. [jddalton] * Add the overlooked reverse(), sort(), and splice() methods to the Fuseboxed Array.prototype. [jddalton]
Expand Down
2 changes: 1 addition & 1 deletion src/ajax/ajax.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// XMLHttpRequest doesn't work with local files. // XMLHttpRequest doesn't work with local files.


var create = function create() { return false; }; var create = function create() { return false; };
if (Feature('ACTIVE_X_OBJECT')) { if (envTest('ACTIVE_X_OBJECT')) {
try { try {
new ActiveXObject('MSXML2.XMLHTTP'); new ActiveXObject('MSXML2.XMLHTTP');
create = function create() { create = function create() {
Expand Down
4 changes: 2 additions & 2 deletions src/dom/element/attribute.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


(function(plugin) { (function(plugin) {
var ATTRIBUTE_NODES_PERSIST_ON_CLONED_ELEMENTS = var ATTRIBUTE_NODES_PERSIST_ON_CLONED_ELEMENTS =
Bug('ATTRIBUTE_NODES_PERSIST_ON_CLONED_ELEMENTS'); envTest('ATTRIBUTE_NODES_PERSIST_ON_CLONED_ELEMENTS');


plugin.hasAttribute = (function() { plugin.hasAttribute = (function() {
var hasAttribute = function hasAttribute(attribute) { var hasAttribute = function hasAttribute(attribute) {
Expand Down Expand Up @@ -184,7 +184,7 @@


// get `href` and other uri attributes // get `href` and other uri attributes
// TODO: Check others attributes like cite, codeBase, lowsrc, and useMap. // TODO: Check others attributes like cite, codeBase, lowsrc, and useMap.
if (Feature('ELEMENT_GET_ATTRIBUTE_IFLAG')) { if (envTest('ELEMENT_GET_ATTRIBUTE_IFLAG')) {
// Exclude `action` attribute because: // Exclude `action` attribute because:
// Opera 9.25 will automatically translate the URI from relative to absolute. // Opera 9.25 will automatically translate the URI from relative to absolute.
// In IE this fix has the reverse effect. // In IE this fix has the reverse effect.
Expand Down
34 changes: 17 additions & 17 deletions src/dom/element/element.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
(function() { (function() {


var ELEMENT_TABLE_INNERHTML_INSERTS_TBODY = var ELEMENT_TABLE_INNERHTML_INSERTS_TBODY =
Bug('ELEMENT_TABLE_INNERHTML_INSERTS_TBODY'), envTest('ELEMENT_TABLE_INNERHTML_INSERTS_TBODY'),


FROM_STRING_PARENT_WRAPPERS = (function() { FROM_STRING_PARENT_WRAPPERS = (function() {
var T = { var T = {
Expand Down Expand Up @@ -285,7 +285,7 @@
return getFragmentFromChildNodes(node, cache); return getFragmentFromChildNodes(node, cache);
} }


if (Feature('CREATE_ELEMENT_WITH_HTML')) if (envTest('CREATE_ELEMENT_WITH_HTML'))
var create = (function(__create) { var create = (function(__create) {
function create(tagName, attributes, context) { function create(tagName, attributes, context) {
var data, element, id, name, type; var data, element, id, name, type;
Expand All @@ -312,15 +312,15 @@
return create; return create;
})(create); })(create);


if (Feature('ELEMENT_REMOVE_NODE')) if (envTest('ELEMENT_REMOVE_NODE'))
var getFragmentFromChildNodes = function(parentNode, cache) { var getFragmentFromChildNodes = function(parentNode, cache) {
// removeNode: removes the parent but keeps the children // removeNode: removes the parent but keeps the children
var fragment = cache.fragment; var fragment = cache.fragment;
fragment.appendChild(parentNode).removeNode(); fragment.appendChild(parentNode).removeNode();
return fragment; return fragment;
}; };


if (Feature('DOCUMENT_RANGE')) if (envTest('DOCUMENT_RANGE'))
var getFragmentFromChildNodes = function(parentNode, cache) { var getFragmentFromChildNodes = function(parentNode, cache) {
var range = cache.range; var range = cache.range;
range.selectNodeContents(parentNode); range.selectNodeContents(parentNode);
Expand All @@ -347,7 +347,7 @@
dom.extendByTag = extendByTag; dom.extendByTag = extendByTag;


dom.getFragmentFromString = dom.getFragmentFromString =
Feature('DOCUMENT_RANGE_CREATE_CONTEXTUAL_FRAGMENT') envTest('DOCUMENT_RANGE_CREATE_CONTEXTUAL_FRAGMENT')
? getFromContextualFragment ? getFromContextualFragment
: getFromDocumentFragment; : getFromDocumentFragment;
})(); })();
Expand Down Expand Up @@ -399,11 +399,11 @@
.data = text || ''; .data = text || '';
} }


if (Feature('ELEMENT_SCRIPT_HAS_TEXT_PROPERTY')) if (envTest('ELEMENT_SCRIPT_HAS_TEXT_PROPERTY'))
return function(element, text) { element.text = text; }; return function(element, text) { element.text = text; };


var textNode = fuse._doc.createTextNode(''); var textNode = fuse._doc.createTextNode('');
if (!Bug('ELEMENT_SCRIPT_FAILS_TO_EVAL_TEXT')) if (!envTest('ELEMENT_SCRIPT_FAILS_TO_EVAL_TEXT'))
return setScriptText; return setScriptText;


textNode = fuse._doc.createComment(''); textNode = fuse._doc.createComment('');
Expand All @@ -418,7 +418,7 @@
element.parentNode.replaceChild(node, element); element.parentNode.replaceChild(node, element);
} }


if (!Bug('ELEMENT_SCRIPT_FAILS_TO_EVAL_TEXT')) if (!envTest('ELEMENT_SCRIPT_FAILS_TO_EVAL_TEXT'))
return replaceElement; return replaceElement;


var T = ELEMENT_INSERT_METHODS, var T = ELEMENT_INSERT_METHODS,
Expand Down Expand Up @@ -582,13 +582,13 @@
var stripped, var stripped,
element = this.raw || this, element = this.raw || this,
nodeName = getNodeName(element), nodeName = getNodeName(element),
isBuggy = BUGGY[nodeName]; envTestgy = BUGGY[nodeName];


if (nodeName === 'SCRIPT') { if (nodeName === 'SCRIPT') {
setScriptText(element, content); setScriptText(element, content);
} else { } else {
// remove children // remove children
if (isBuggy) { if (envTestgy) {
while (element.lastChild) while (element.lastChild)
element.removeChild(element.lastChild); element.removeChild(element.lastChild);
} else element.innerHTML = ''; } else element.innerHTML = '';
Expand All @@ -602,7 +602,7 @@
content = Obj.toHTML(content); content = Obj.toHTML(content);
stripped = content.stripScripts(); stripped = content.stripScripts();


if (isBuggy) { if (envTestgy) {
if (stripped != '') if (stripped != '')
element.appendChild(fuse.dom.getFragmentFromString(stripped, element)); element.appendChild(fuse.dom.getFragmentFromString(stripped, element));
} }
Expand All @@ -617,13 +617,13 @@
}; };


var BUGGY = { }; var BUGGY = { };
if (Bug('ELEMENT_COLGROUP_INNERHTML_BUGGY')) if (envTest('ELEMENT_COLGROUP_INNERHTML_BUGGY'))
BUGGY.COLGROUP = 1; BUGGY.COLGROUP = 1;
if (Bug('ELEMENT_OPTGROUP_INNERHTML_BUGGY')) if (envTest('ELEMENT_OPTGROUP_INNERHTML_BUGGY'))
BUGGY.OPTGROUP = 1; BUGGY.OPTGROUP = 1;
if (Bug('ELEMENT_SELECT_INNERHTML_BUGGY')) if (envTest('ELEMENT_SELECT_INNERHTML_BUGGY'))
BUGGY.SELECT = 1; BUGGY.SELECT = 1;
if (Bug('ELEMENT_TABLE_INNERHTML_BUGGY')) if (envTest('ELEMENT_TABLE_INNERHTML_BUGGY'))
BUGGY.TABLE = BUGGY.TBODY = BUGGY.TR = BUGGY.TD = BUGGY.TABLE = BUGGY.TBODY = BUGGY.TR = BUGGY.TD =
BUGGY.TFOOT = BUGGY.TH = BUGGY.THEAD = 1; BUGGY.TFOOT = BUGGY.TH = BUGGY.THEAD = 1;


Expand Down Expand Up @@ -683,13 +683,13 @@
plugin.contains.call(element.ownerDocument, element)); plugin.contains.call(element.ownerDocument, element));
}; };


if (Feature('ELEMENT_SOURCE_INDEX', 'DOCUMENT_ALL_COLLECTION')) { if (envTest('ELEMENT_SOURCE_INDEX', 'DOCUMENT_ALL_COLLECTION')) {
isDetached = function isDetached() { isDetached = function isDetached() {
var element = this.raw || this; var element = this.raw || this;
return element.ownerDocument.all[element.sourceIndex] !== element; return element.ownerDocument.all[element.sourceIndex] !== element;
}; };
} }
if (Feature('ELEMENT_COMPARE_DOCUMENT_POSITION')) { if (envTest('ELEMENT_COMPARE_DOCUMENT_POSITION')) {
isDetached = function isDetached() { isDetached = function isDetached() {
/* DOCUMENT_POSITION_DISCONNECTED = 0x01 */ /* DOCUMENT_POSITION_DISCONNECTED = 0x01 */
var element = this.raw || this; var element = this.raw || this;
Expand Down
8 changes: 4 additions & 4 deletions src/dom/element/position.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@
var getOffset = function(element, ancestor) { var getOffset = function(element, ancestor) {
var offsetParent, position, raw, valueT = 0, valueL = 0; var offsetParent, position, raw, valueT = 0, valueL = 0;
if (BODY_OFFSETS_INHERIT_ITS_MARGINS === null) if (BODY_OFFSETS_INHERIT_ITS_MARGINS === null)
BODY_OFFSETS_INHERIT_ITS_MARGINS = Bug('BODY_OFFSETS_INHERIT_ITS_MARGINS'); BODY_OFFSETS_INHERIT_ITS_MARGINS = envTest('BODY_OFFSETS_INHERIT_ITS_MARGINS');


if (ELEMENT_COORD_OFFSETS_DONT_INHERIT_ANCESTOR_BORDER_WIDTH === null) if (ELEMENT_COORD_OFFSETS_DONT_INHERIT_ANCESTOR_BORDER_WIDTH === null)
ELEMENT_COORD_OFFSETS_DONT_INHERIT_ANCESTOR_BORDER_WIDTH = ELEMENT_COORD_OFFSETS_DONT_INHERIT_ANCESTOR_BORDER_WIDTH =
Bug('ELEMENT_COORD_OFFSETS_DONT_INHERIT_ANCESTOR_BORDER_WIDTH'); envTest('ELEMENT_COORD_OFFSETS_DONT_INHERIT_ANCESTOR_BORDER_WIDTH');


do { do {
raw = element.raw || element; raw = element.raw || element;
Expand All @@ -345,7 +345,7 @@
return returnOffset(valueL, valueT); return returnOffset(valueL, valueT);
}; };


if (Feature('ELEMENT_BOUNDING_CLIENT_RECT')) if (envTest('ELEMENT_BOUNDING_CLIENT_RECT'))
getOffset = (function(__getOffset) { getOffset = (function(__getOffset) {
return function(element, ancestor) { return function(element, ancestor) {
var doc, info, rect, raw, root, scrollEl, valueT, valueL; var doc, info, rect, raw, root, scrollEl, valueT, valueL;
Expand Down Expand Up @@ -431,7 +431,7 @@
return returnOffset(valueL, valueT); return returnOffset(valueL, valueT);
}; };


if (Feature('ELEMENT_BOUNDING_CLIENT_RECT')) { if (envTest('ELEMENT_BOUNDING_CLIENT_RECT')) {
getViewportOffset = function getViewportOffset() { getViewportOffset = function getViewportOffset() {
var valueT = 0, valueL = 0; var valueT = 0, valueL = 0;


Expand Down
20 changes: 10 additions & 10 deletions src/dom/element/style.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@
return false; return false;
} }


if (Bug('ELEMENT_COMPUTED_STYLE_DEFAULTS_TO_ZERO')) if (envTest('ELEMENT_COMPUTED_STYLE_DEFAULTS_TO_ZERO'))
nullHandlers.push(function(element, name) { nullHandlers.push(function(element, name) {
return POSITION_NAMES[name] && return POSITION_NAMES[name] &&
getComputedStyle(element, 'position') === 'static'; getComputedStyle(element, 'position') === 'static';
}); });


if (Bug('ELEMENT_COMPUTED_STYLE_HEIGHT_IS_ZERO_WHEN_HIDDEN')) if (envTest('ELEMENT_COMPUTED_STYLE_HEIGHT_IS_ZERO_WHEN_HIDDEN'))
nullHandlers.push(function(element, name) { nullHandlers.push(function(element, name) {
return DIMENSION_NAMES[name] && getComputedStyle(element, 'display') === 'none'; return DIMENSION_NAMES[name] && getComputedStyle(element, 'display') === 'none';
}); });
Expand Down Expand Up @@ -91,14 +91,14 @@




// fallback for browsers without computedStyle or currentStyle // fallback for browsers without computedStyle or currentStyle
if (!Feature('ELEMENT_COMPUTED_STYLE') && !Feature('ELEMENT_CURRENT_STYLE')) if (!envTest('ELEMENT_COMPUTED_STYLE') && !envTest('ELEMENT_CURRENT_STYLE'))
plugin.getStyle = function getStyle(name) { plugin.getStyle = function getStyle(name) {
var result = getValue(this, camelize.call(name)); var result = getValue(this, camelize.call(name));
return result === null ? result : fuse.String(result); return result === null ? result : fuse.String(result);
}; };


// Opera 9.2x // Opera 9.2x
else if (Bug('ELEMENT_COMPUTED_STYLE_DIMENSIONS_EQUAL_BORDER_BOX')) else if (envTest('ELEMENT_COMPUTED_STYLE_DIMENSIONS_EQUAL_BORDER_BOX'))
plugin.getStyle = function getStyle(name) { plugin.getStyle = function getStyle(name) {
name = camelize.call(name); name = camelize.call(name);
var dim, result, element = this.raw || this; var dim, result, element = this.raw || this;
Expand All @@ -118,7 +118,7 @@
}; };


// Firefox, Safari, Opera 9.5+ // Firefox, Safari, Opera 9.5+
else if (Feature('ELEMENT_COMPUTED_STYLE')) else if (envTest('ELEMENT_COMPUTED_STYLE'))
plugin.getStyle = function getStyle(name) { plugin.getStyle = function getStyle(name) {
name = camelize.call(name); name = camelize.call(name);
var result, element = this.raw || this; var result, element = this.raw || this;
Expand Down Expand Up @@ -298,7 +298,7 @@
return fuse.Number(parseFloat(this.style.opacity)); return fuse.Number(parseFloat(this.style.opacity));
}; };


if (Feature('ELEMENT_COMPUTED_STYLE')) { if (envTest('ELEMENT_COMPUTED_STYLE')) {
getOpacity = function getOpacity() { getOpacity = function getOpacity() {
var element = this.raw || this, var element = this.raw || this,
style = element.ownerDocument.defaultView.getComputedStyle(element, null); style = element.ownerDocument.defaultView.getComputedStyle(element, null);
Expand All @@ -307,7 +307,7 @@
: element.style.opacity)); : element.style.opacity));
}; };
} }
else if (Feature('ELEMENT_MS_CSS_FILTERS')) { else if (envTest('ELEMENT_MS_CSS_FILTERS')) {
getOpacity = function getOpacity() { getOpacity = function getOpacity() {
var element = this.raw || this, var element = this.raw || this,
currStyle = element.currentStyle || element.style, currStyle = element.currentStyle || element.style,
Expand Down Expand Up @@ -356,7 +356,7 @@
return this; return this;
}; };
} }
else if (Feature('ELEMENT_MS_CSS_FILTERS')) { else if (envTest('ELEMENT_MS_CSS_FILTERS')) {
setOpacity = function setOpacity(value) { setOpacity = function setOpacity(value) {
// strip alpha from filter style // strip alpha from filter style
var element = this.raw || this, var element = this.raw || this,
Expand Down Expand Up @@ -394,15 +394,15 @@
!!(element.offsetHeight || element.offsetWidth); !!(element.offsetHeight || element.offsetWidth);
}; };


if (Feature('ELEMENT_COMPUTED_STYLE')) { if (envTest('ELEMENT_COMPUTED_STYLE')) {
isVisible = function isVisible() { isVisible = function isVisible() {
var element = this.raw || this, var element = this.raw || this,
compStyle = element.ownerDocument.defaultView.getComputedStyle(element, null); compStyle = element.ownerDocument.defaultView.getComputedStyle(element, null);
return !!(compStyle && (element.offsetHeight || element.offsetWidth)); return !!(compStyle && (element.offsetHeight || element.offsetWidth));
}; };
} }


if (Bug('TABLE_ELEMENTS_RETAIN_OFFSET_DIMENSIONS_WHEN_HIDDEN')) { if (envTest('TABLE_ELEMENTS_RETAIN_OFFSET_DIMENSIONS_WHEN_HIDDEN')) {
var __isVisible = isVisible; var __isVisible = isVisible;


isVisible = function isVisible() { isVisible = function isVisible() {
Expand Down
8 changes: 4 additions & 4 deletions src/dom/element/traversal.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
return results; return results;
}; };


if (Bug('GET_ELEMENTS_BY_TAG_NAME_RETURNS_COMMENT_NODES')) { if (envTest('GET_ELEMENTS_BY_TAG_NAME_RETURNS_COMMENT_NODES')) {
getDescendants = function getDescendants(selectors) { getDescendants = function getDescendants(selectors) {
var match, node, i = 0, results = NodeList(), var match, node, i = 0, results = NodeList(),
nodes = (this.raw || this).getElementsByTagName('*'); nodes = (this.raw || this).getElementsByTagName('*');
Expand Down Expand Up @@ -120,7 +120,7 @@
return false; return false;
}; };


if (Feature('ELEMENT_COMPARE_DOCUMENT_POSITION')) { if (envTest('ELEMENT_COMPARE_DOCUMENT_POSITION')) {
contains = function contains(descendant) { contains = function contains(descendant) {
/* DOCUMENT_POSITION_CONTAINS = 0x08 */ /* DOCUMENT_POSITION_CONTAINS = 0x08 */
if (descendant = fuse.get(descendant)) { if (descendant = fuse.get(descendant)) {
Expand All @@ -131,7 +131,7 @@
return false; return false;
}; };
} }
else if (Feature('ELEMENT_CONTAINS')) { else if (envTest('ELEMENT_CONTAINS')) {
var __contains = contains; var __contains = contains;


contains = function contains(descendant) { contains = function contains(descendant) {
Expand Down Expand Up @@ -164,7 +164,7 @@
return null; return null;
} }


if (Bug('GET_ELEMENTS_BY_TAG_NAME_RETURNS_COMMENT_NODES')) { if (envTest('GET_ELEMENTS_BY_TAG_NAME_RETURNS_COMMENT_NODES')) {
getNth = function(nodes, index) { getNth = function(nodes, index) {
var count = 0, i = 0; var count = 0, i = 0;
while (node = nodes[i++]) while (node = nodes[i++])
Expand Down
6 changes: 3 additions & 3 deletions src/dom/event/dom-loaded.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
}, },


getStyle = function(element, styleName) { getStyle = function(element, styleName) {
return (getStyle = Feature('ELEMENT_COMPUTED_STYLE') return (getStyle = envTest('ELEMENT_COMPUTED_STYLE')
? function(element, styleName) { ? function(element, styleName) {
var style = element.ownerDocument.defaultView.getComputedStyle(element, null); var style = element.ownerDocument.defaultView.getComputedStyle(element, null);
return (style || element.style)[styleName]; return (style || element.style)[styleName];
Expand Down Expand Up @@ -221,7 +221,7 @@
// Ensure the document is not in a frame because // Ensure the document is not in a frame because
// doScroll() will not throw an error when the document // doScroll() will not throw an error when the document
// is framed. Fallback on document readyState. // is framed. Fallback on document readyState.
if (!Feature('ELEMENT_ADD_EVENT_LISTENER') && Feature('ELEMENT_DO_SCROLL')) { if (!envTest('ELEMENT_ADD_EVENT_LISTENER') && envTest('ELEMENT_DO_SCROLL')) {


// Avoid a potential browser hang when checking global.top (thanks Rich Dougherty) // Avoid a potential browser hang when checking global.top (thanks Rich Dougherty)
// Checking global.frameElement could throw if not accessible. // Checking global.frameElement could throw if not accessible.
Expand All @@ -242,7 +242,7 @@
} }
}; };
} }
else if (Feature('ELEMENT_ADD_EVENT_LISTENER')) else if (envTest('ELEMENT_ADD_EVENT_LISTENER'))
decoratedDoc.observe('DOMContentLoaded', checkDomLoadedState); decoratedDoc.observe('DOMContentLoaded', checkDomLoadedState);


// readystate and poller are used (first one to complete wins) // readystate and poller are used (first one to complete wins)
Expand Down
Loading

0 comments on commit 80a497c

Please sign in to comment.