Created
August 10, 2012 19:27
-
-
Save cmarkle27/3317135 to your computer and use it in GitHub Desktop.
ClickCounter jQuery Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* clickCounter Plugin | |
* counts clicks | |
* | |
* @events: "panel-loader-clicked", "panel-loader-complete" | |
* @requirements: jQuery 1.7, bbq | |
* @author: Chris Markle | |
* | |
*/ | |
(function($) { | |
var ClickCounter = function(options, element) { | |
var selector = options.itemSelector, | |
highlight = options.highlight, | |
color = options.textColor, | |
count = 0; | |
function clickIt(thisElement) { | |
count += 1; | |
if (highlight === true) { | |
$(thisElement).css({ "color" : color}); | |
} | |
console.log(highlight); | |
} | |
function getClicked() { | |
return count; | |
} | |
// click handler | |
$(element).on("click", selector, function(e) { | |
e.preventDefault(); | |
clickIt(this); | |
$(element).trigger("paragraph-clicked"); | |
}); | |
$(document).on("ready", function() { | |
// initialize | |
$(element).css({ "cursor" : "pointer" }); | |
}); | |
return { | |
getClicked: getClicked | |
}; | |
}; | |
/////////////////////////////////////////////////////////////////////// | |
// clickCounter plugin | |
/////////////////////////////////////////////////////////////////////// | |
$.fn.clickCounter = function(options) { | |
options = $.extend({ | |
itemSelector: "p", | |
highlight: true, | |
textColor: "#BADA55" | |
}, options || {}); | |
return this.each(function() { | |
var clickCounter = new ClickCounter(options, this); | |
$(this).data("clickCounter", clickCounter); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment