Skip to content

Instantly share code, notes, and snippets.

@cmarkle27
Created August 10, 2012 19:27
Show Gist options
  • Save cmarkle27/3317135 to your computer and use it in GitHub Desktop.
Save cmarkle27/3317135 to your computer and use it in GitHub Desktop.
ClickCounter jQuery Plugin
/**
* 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