Google Groups Home
Help | Sign in
Problem binding to Dynamic elements in Greasemonkey
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Tane Piper  
View profile
 More options 11 May, 13:20
From: Tane Piper <digitalspaghe...@googlemail.com>
Date: Sun, 11 May 2008 05:20:43 -0700 (PDT)
Local: Sun 11 May 2008 13:20
Subject: Problem binding to Dynamic elements in Greasemonkey
Hey there,

I'm writing a script in Greasemonkey that uses jQuery + Livequery +
Lowpro.  The script is an audioscrobbler script for muxtape.com, and
provides a link to allow a user to scrobble a song.

So far I've managed to get it as far as creating the link on the page,
and passing another attach to the link once created.  It seems to
work, as the initialize function for it does the CSS change, but the
onclick seems to be ignored.

Here is what I have cut down (as there is a lot of included library
code):

ScrobbleClick = jQuery.klass({
  initialize : function(options) {
    this.element.css({'padding-left':'10px;'});
  },
  onclick: function(){
  console.log('moo');
    GM_xmlhttpRequest({
      method: 'POST',
      url: this.element.attr('href'),
      headers: {
          'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
          'Accept': 'application/atom+xml,application/xml,text/xml',
      },
      onload: function(responseDetails) {
        console.log(responseDetails);
      }
    });
    return false;
  }

});

ScrobbleSong = jQuery.klass({
  initialize : function(options) {
    var el = jQuery(this.element);

    /* Some code in here where I create the url */

    el.append('<a href="'+url+'" class="scrobble">Scrobble This</a>');
    el.find('.scrobble').attach(ScrobbleClick);
  }

});

setTimeout(function(){
  jQuery('.song').each(function(){
    jQuery(this).attach(ScrobbleSong);
  });

}, 3000);

What the script does is wait until a auth request has been made (not
shown here) which is successful, I attach the link to the div.  Then I
bind the ScrobbleClick.  As I've said, the initialize works, so it
must know the element is there, however it ignores the onclick
function.

Anyone any ideas????


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google