Commits

msssk committed b0fd882 Draft

change: event handling now uses delegation (so it will work with endless reddit)

Comments (0)

Files changed (5)

 
 
 ClikkitExtension.checkURL = function( clikkitEvent ) {
-	var frameHREF = this.href;
+	var frameHREF = clikkitEvent.target.href;
 
 	if( frameHREF.indexOf( 'youtube.com' ) !== -1 || frameHREF.indexOf( 'youtu.be' ) !== -1 ) {
 		frameHREF = ClikkitExtension.getYoutubeEmbedURL( frameHREF );
 	}
 
 	if( ClikkitExtension.$clikkitLinks && ClikkitExtension.$clikkitLinks.length ) {
-		ClikkitExtension.$clikkitLinks.clikkit( options );
+		ClikkitExtension.$clikkitLinks.clikkit( ClikkitExtension.selector, options );
 
 		ClikkitExtension.$clikkitLinks.bind( 'clikkitAddLink', ClikkitExtension.checkURL );
 
 		if( ClikkitExtension.highlightSourceLink ) {
-			ClikkitExtension.$clikkitLinks.bind( 'clikkitShowLink', ClikkitExtension.highlightSourceLink );
+			if( ClikkitExtension.selector ) {
+				ClikkitExtension.$clikkitLinks.delegate( ClikkitExtension.selector, 'clikkitShowLink', ClikkitExtension.highlightSourceLink );
+			}
+			else {
+				ClikkitExtension.$clikkitLinks.bind( 'clikkitShowLink', ClikkitExtension.highlightSourceLink );
+			}
 		}
 
 		if( ClikkitExtension.unhighlightSourceLink ) {
-			ClikkitExtension.$clikkitLinks.bind( 'clikkitCloseLink', ClikkitExtension.unhighlightSourceLink );
+			if( ClikkitExtension.selector ) {
+				ClikkitExtension.$clikkitLinks.delegate( ClikkitExtension.selector, 'clikkitCloseLink', ClikkitExtension.unhighlightSourceLink );
+			}
+			else {
+				ClikkitExtension.$clikkitLinks.bind( 'clikkitCloseLink', ClikkitExtension.unhighlightSourceLink );
+			}
 		}
 	}
 	else {
 	msg = 'ERROR(clikkit' + source + '):  ' + e.name + ':  ' + e.message;
 
 	if( console ) {
-		console.log( msg );
+		console.log( msg, e.stack );
 	} else {
 		alert( msg );
 	}
 {
 	"name": "clikkit",
-	"version": "1.0",
+	"version": "1.0.1",
 	"description": "clikkit - framed link browser",
 	"homepage_url": "http://msssk.bitbucket.org/",
 	"icons": {
 /*global $, jQuery, ClikkitExtension */
 
-ClikkitExtension.$clikkitLinks = $( 'a.title, a.comments, a.author' );
+ClikkitExtension.$clikkitLinks = $( 'div.content' );
+ClikkitExtension.selector = 'a.title, a.comments, a.author';
 //ClikkitExtension.$otherLinks = $( 'a' ).filter( ':not(.title)' ).filter( ':not(.comments)' ).filter( ':not(.author)' );
-ClikkitExtension.$otherLinks = $( 'a' ).not( ClikkitExtension.$clikkitLinks );
+ClikkitExtension.$otherLinks = $( 'a' ).not( ClikkitExtension.selector );
 
 /**
  * @function
  * context (this):  {HTMLAnchorElement} The link to highlight (expects a reddit link nested in a specific layout for reddit)
  */
-ClikkitExtension.highlightSourceLink = function() {
-	var link = this;
+ClikkitExtension.highlightSourceLink = function( clikkitEvent ) {
+	var link = clikkitEvent.target;
 
 	if( !ClikkitExtension.normalFGColor ) {
 		ClikkitExtension.normalFGColor = $(link).css( 'color' );
  * @function
  * context (this):  {HTMLAnchorElement} The link to un-highlight (expects a reddit link nested in a specific layout for reddit)
  */
-ClikkitExtension.unhighlightSourceLink = function() {
-	var link = this;
+ClikkitExtension.unhighlightSourceLink = function( clikkitEvent ) {
+	var link = clikkitEvent.target;
 
 	$(link).css( 'color', ClikkitExtension.normalFGColor );
 	$(link.parentNode).css( 'background', '' );