Browse Source

bring in uBlock's changes to uDom

pull/2/head
gorhill 9 years ago
parent
commit
c8765697e1
  1. 4
      src/js/popup.js
  2. 66
      src/js/udom.js

4
src/js/popup.js

@ -482,7 +482,7 @@ var createMatrixGroup = function() {
if ( group ) {
return uDom(group).removeClass().addClass('matGroup');
}
return uDom('<div>').addClass('matGroup');
return uDom(document.createElement('div')).addClass('matGroup');
};
var createMatrixSection = function() {
@ -490,7 +490,7 @@ var createMatrixSection = function() {
if ( section ) {
return uDom(section).removeClass().addClass('matSection');
}
return uDom('<div>').addClass('matSection');
return uDom(document.createElement('div')).addClass('matSection');
};
var createMatrixRow = function() {

66
src/js/udom.js

@ -58,9 +58,6 @@ var DOMListFactory = function(selector, context) {
var r = new DOMList();
if ( typeof selector === 'string' ) {
selector = selector.trim();
if ( selector.charAt(0) === '<' ) {
return addHTMLToList(r, selector);
}
if ( selector !== '' ) {
return addSelectorToList(r, selector, context);
}
@ -85,6 +82,16 @@ DOMListFactory.onLoad = function(callback) {
/******************************************************************************/
DOMListFactory.nodeFromId = function(id) {
return document.getElementById(id);
};
DOMListFactory.nodeFromSelector = function(selector) {
return document.querySelector(selector);
};
/******************************************************************************/
var addNodeToList = function(list, node) {
if ( node ) {
list.nodes.push(node);
@ -125,51 +132,6 @@ var addSelectorToList = function(list, selector, context) {
/******************************************************************************/
var pTagOfChildTag = {
'tr': 'table',
'option': 'select'
};
// TODO: documentFragment
var addHTMLToList = function(list, html) {
var matches = html.match(/^<([a-z]+)/);
if ( !matches || matches.length !== 2 ) {
return this;
}
var cTag = matches[1];
var pTag = pTagOfChildTag[cTag] || 'div';
var p = document.createElement(pTag);
vAPI.insertHTML(p, html);
// Find real parent
var c = p.querySelector(cTag);
p = c.parentNode;
while ( p.firstChild ) {
list.nodes.push(p.removeChild(p.firstChild));
}
return list;
};
/******************************************************************************/
var isChildOf = function(child, parent) {
return child !== null && parent !== null && child.parentNode === parent;
};
/******************************************************************************/
var isDescendantOf = function(descendant, ancestor) {
while ( descendant.parentNode !== null ) {
if ( descendant.parentNode === ancestor ) {
return true;
}
descendant = descendant.parentNode;
}
return false;
};
/******************************************************************************/
var nodeInNodeList = function(node, nodeList) {
var i = nodeList.length;
while ( i-- ) {
@ -555,8 +517,14 @@ DOMList.prototype.css = function(prop, value) {
if ( value === undefined ) {
return i ? this.nodes[0].style[prop] : undefined;
}
if ( value !== '' ) {
while ( i-- ) {
this.nodes[i].style.setProperty(prop, value);
}
return this;
}
while ( i-- ) {
this.nodes[i].style[prop] = value;
this.nodes[i].style.removeProperty(prop);
}
return this;
};

Loading…
Cancel
Save