Last active
December 14, 2015 01:19
-
-
Save ahmednasir91/5005609 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$.each($('[data-download-count=true]'), function (i, e) { | |
var elem = $(e).parent().find('#download-count').addClass('loading'); | |
var id = $(e).closest('.post-body').siblings('a[name]').attr('name') + "-" + $(e).attr('id'); | |
var downloadStats = new Firebase("https://blogstats.firebaseio.com/downloads/id/" + id); | |
var data = {}, isnew = false; | |
downloadStats.once('value', function (snapshot) { | |
data = snapshot.val(); | |
if (data == null) { | |
data = {}; | |
data.value = 0; | |
data.url = window.location.href; | |
data.id = id; | |
isnew = true; | |
} | |
elem.removeClass('loading').text(data.value); | |
}); | |
$(e).click(function (e) { | |
data.value++; | |
if (isnew) downloadStats.set(data); | |
else downloadStats.child('value').set(data.value); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment