stroll.js icon indicating copy to clipboard operation
stroll.js copied to clipboard

Binding from external file produces an error

Open gudata opened this issue 12 years ago • 2 comments

If I load the following js from external file

(function() {

  stroll.bind('#sidebar nav.categories div.scroll ul');

}).call(this);

I got an error

Uncaught TypeError: Cannot read property 'classList' of null
isCapablestroll.js:229
window.stroll.bindstroll.js:242
(anonymous function)store.js:3
(anonymous function)

If I do

  stroll.bind('#sidebar nav.categories div.scroll ul');

from the console or

<script> stroll.bind('#sidebar nav.categories div.scroll ul');</script>

tags its working.

Any ideas what I am doing wrong?

gudata avatar May 03 '12 18:05 gudata

Looks like the stroll.js script hasn't been loaded when you're calling it. Does your external JS get included before stroll.js?

hakimel avatar May 04 '12 04:05 hakimel

I have posted the wrong error, now I have correct the question.

It seems that the .js file is loaded and I see it there. The problem is in the

function isCapable() {
        return !!document.body.classList;
}

Where the document.body is null?! and thats why I get the "Cannot read property 'classList' of null".

What is the difference by invoking the stroll.bind from a js file and running it from the chrome js console? Maybe the dom isn't loaded? but I am in a function(){} so this code should be called when the dom is loaded. no idea :)

gudata avatar May 04 '12 07:05 gudata