New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Object doesn't support property or method 'getElementsByClassName'? #111
Comments
Thanks for your compliments! Hm, very weird. Seems like |
Jonny, Thanks for looking at this - and sorry for my delayed reply... I just tried your suggestion on my testing server (for me, the 'if' I get the following errors in the Chrome console: SCRIPT5007: Unable to get the value of the property SCRIPT5009: List.js is undefined It seems to break the page for other browsers/version also - or else I I've posted a banner for IE8 users indicating that I don't support them - & Chip On Fri, Feb 8, 2013 at 5:20 PM, Jonny Strömberg notifications@github.comwrote:
|
@only1chip Seems like you forgot a |
Oops - that was only a typo in my email to you - working at two stations... All I was really adding was the ".body" - so I didn't touch the rest of the Since it seems you are online - I'm going to publish the change for a few Chip On Fri, Feb 15, 2013 at 5:30 PM, Jonny Strömberg
|
Hmm, well. Then I have another suggestion. Update the getByClass: function(searchClass,node,single) {
if (node.getElementsByClassName) {
if (single) {
return node.getElementsByClassName(searchClass)[0];
} else {
return node.getElementsByClassName(searchClass);
}
} else {
var classElements = [],
tag = '*';
if (node == null) {
node = document;
}
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
for (var i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
if (single) {
return els[i];
} else {
classElements[j] = els[i];
j++;
}
}
}
return classElements;
}
} |
OK, I'm trying to do that but I keep getting syntax errors... certainly Should I be replacing all the functions inside the 'h = {' or just the getByClass??? Chip On Fri, Feb 15, 2013 at 5:44 PM, Jonny Strömberg
|
Just getByClass. |
I certainly don't doubt that - I just can't figure out exactly which code feeling pretty stupid here... Chip On Fri, Feb 15, 2013 at 6:14 PM, Jonny Strömberg
|
Hehe, well, remove everything from line 600 to the end with this. /*
* These helper functions are not written by List.js author Jonny (they may have been
* adjusted, thought).
*/
h = {
/*
* Cross browser getElementsByClassName, which uses native
* if it exists. Modified version of Dustin Diaz function:
* http://www.dustindiaz.com/getelementsbyclass
*/
getByClass: function(searchClass,node,single) {
if (node.getElementsByClassName) {
if (single) {
return node.getElementsByClassName(searchClass)[0];
} else {
return node.getElementsByClassName(searchClass);
}
} else {
var classElements = [],
tag = '*';
if (node == null) {
node = document;
}
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
for (var i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
if (single) {
return els[i];
} else {
classElements[j] = els[i];
j++;
}
}
}
return classElements;
}
},
/* (elm, 'event' callback) Source: http://net.tutsplus.com/tutorials/javascript-ajax/javascript-from-null-cross-browser-event-binding/ */
addEvent: (function( window, document ) {
if ( document.addEventListener ) {
return function( elem, type, cb ) {
if ((elem && !(elem instanceof Array) && !elem.length && !h.isNodeList(elem) && (elem.length !== 0)) || elem === window ) {
elem.addEventListener(type, cb, false );
} else if ( elem && elem[0] !== undefined ) {
var len = elem.length;
for ( var i = 0; i < len; i++ ) {
h.addEvent(elem[i], type, cb);
}
}
};
}
else if ( document.attachEvent ) {
return function ( elem, type, cb ) {
if ((elem && !(elem instanceof Array) && !elem.length && !h.isNodeList(elem) && (elem.length !== 0)) || elem === window ) {
elem.attachEvent( 'on' + type, function() { return cb.call(elem, window.event); } );
} else if ( elem && elem[0] !== undefined ) {
var len = elem.length;
for ( var i = 0; i < len; i++ ) {
h.addEvent( elem[i], type, cb );
}
}
};
}
})(this, document),
/* (elm, attribute) Source: http://stackoverflow.com/questions/3755227/cross-browser-javascript-getattribute-method */
getAttribute: function(ele, attr) {
var result = (ele.getAttribute && ele.getAttribute(attr)) || null;
if( !result ) {
var attrs = ele.attributes;
var length = attrs.length;
for(var i = 0; i < length; i++) {
if (attr[i] !== undefined) {
if(attr[i].nodeName === attr) {
result = attr[i].nodeValue;
}
}
}
}
return result;
},
/* http://stackoverflow.com/questions/7238177/detect-htmlcollection-nodelist-in-javascript */
isNodeList: function(nodes) {
var result = Object.prototype.toString.call(nodes);
if (typeof nodes === 'object' && /^\[object (HTMLCollection|NodeList|Object)\]$/.test(result) && (nodes.length == 0 || (typeof nodes[0] === "object" && nodes[0].nodeType > 0))) {
return true;
}
return false;
},
hasClass: function(ele, classN) {
var classes = this.getAttribute(ele, 'class') || this.getAttribute(ele, 'className') || "";
return (classes.search(classN) > -1);
},
addClass: function(ele, classN) {
if (!this.hasClass(ele, classN)) {
var classes = this.getAttribute(ele, 'class') || this.getAttribute(ele, 'className') || "";
classes = classes + ' ' + classN + ' ';
classes = classes.replace(/\s{2,}/g, ' ');
ele.setAttribute('class', classes);
}
},
removeClass: function(ele, classN) {
if (this.hasClass(ele, classN)) {
var classes = this.getAttribute(ele, 'class') || this.getAttribute(ele, 'className') || "";
classes = classes.replace(classN, '');
ele.setAttribute('class', classes);
}
},
/*
* The sort function. From http://my.opera.com/GreyWyvern/blog/show.dml/1671288
*/
sorter: {
alphanum: function(a,b,asc) {
if (a === undefined || a === null) {
a = "";
}
if (b === undefined || b === null) {
b = "";
}
a = a.toString().replace(/&(lt|gt);/g, function (strMatch, p1){
return (p1 == "lt")? "<" : ">";
});
a = a.replace(/<\/?[^>]+(>|$)/g, "");
b = b.toString().replace(/&(lt|gt);/g, function (strMatch, p1){
return (p1 == "lt")? "<" : ">";
});
b = b.replace(/<\/?[^>]+(>|$)/g, "");
var aa = this.chunkify(a);
var bb = this.chunkify(b);
for (var x = 0; aa[x] && bb[x]; x++) {
if (aa[x] !== bb[x]) {
var c = Number(aa[x]), d = Number(bb[x]);
if (asc) {
if (c == aa[x] && d == bb[x]) {
return c - d;
} else {
return (aa[x] > bb[x]) ? 1 : -1;
}
} else {
if (c == aa[x] && d == bb[x]) {
return d-c;//c - d;
} else {
return (aa[x] > bb[x]) ? -1 : 1; //(aa[x] > bb[x]) ? 1 : -1;
}
}
}
}
return aa.length - bb.length;
},
chunkify: function(t) {
var tz = [], x = 0, y = -1, n = 0, i, j;
while (i = (j = t.charAt(x++)).charCodeAt(0)) {
var m = (i == 45 || i == 46 || (i >=48 && i <= 57));
if (m !== n) {
tz[++y] = "";
n = m;
}
tz[y] += j;
}
return tz;
}
}
};
window.List = List;
window.ListJsHelpers = h;
})(window); |
OK, thanks! No syntax errors, but no joy either... You should be able to see the live site... (note: I'm seeing "strike through' lines of code below (towards the end) I really appreciate your time on this... Chip On Fri, Feb 15, 2013 at 6:24 PM, Jonny Strömberg
|
OK - I'm leaving those changes in place. They don't seem to break the modern browsers/versions - but I still don't see it working in IE8... perhaps we can try again next week??? Wife is annoyed - almost 7pm here on Friday night... must go fix that bug... Thanks again! If you ever need any automation products - e-mail me... Chip |
Hmm, I'll take a look some other day! (its 01:00 am between Friday and Saturday here ;)) Automation products, I'll keep that in mind! 🍺 |
First off: love the script - thanks for writing it.
It's probably something stupid that I'm doing, but I'm getting this error when testing in IE pre version 9:
SCRIPT438: Object doesn't support property or method 'getElementsByClassName'
list.js, line 615 character 21
I tried adding a couple different 'getElementsByClassName' functions for older browser versions, but none have worked. I doubt this is a bug of List.js - but I am stumped - any help would be appreciated.
My page is here: www.sureservo.com/gearbox/selector/
The text was updated successfully, but these errors were encountered: