Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- HELEN Bookmarking
- Handles the adding and removing of bookmarks from site content for healthequitynetwork.org
- **/
- function Helen_Bookmarking(){
- //for referencing myself
- helen_bookmarking = this;
- this.bookmarks = [];
- /**
- * Get the user's current bookmarks, update star icon for that content on this page
- **/
- $.getJSON( "/?ACT=85&function=get_bookmarks", function( data ) {
- if(typeof data != 'undefined' && data != null && data.length > 0){
- $.each( data, function( key, val ) {
- helen_bookmarking.bookmarks.push(parseInt(val));
- //update any bookmark icons
- $.each($('.bookmark-button[data-file-id='+val+']'), function(){
- $(this).attr('data-original-title','Remove Bookmark');
- var star = $(this).children('span');
- star.removeClass('glyphicon-star-empty').addClass('glyphicon-star bookmarked');
- });
- });
- }
- });
- $('.bookmark-button').on('click',function(event){
- event.preventDefault();
- var star = $(this).children('span');
- var file_id = $(this).data('file-id');
- var y = event.screenY - 100;
- if(star.hasClass('glyphicon-star-empty')){
- $(this).attr('data-original-title','Remove Bookmark');
- star.removeClass('glyphicon-star-empty').addClass('glyphicon-star bookmarked');
- helen_bookmarking.add_bookmark(file_id);
- flash_notification('Bookmark Added!', '#090', y);
- }
- else{
- $(this).attr('data-original-title','Bookmark');
- star.removeClass('glyphicon-star').removeClass('bookmarked').addClass('glyphicon-star-empty');
- helen_bookmarking.remove_bookmark(file_id);
- flash_notification('Bookmark Removed!', '#900', y);
- if ($(this).parents('#my-bookmarks-table').length) {
- $(this).closest('tr').fadeOut().remove();
- $('#total-bookmarks').html((parseInt($('#total-bookmarks').html())-1) +'');
- }
- }
- });
- };
- Helen_Bookmarking.prototype.add_bookmark = function(file_id) {
- $.post( "/?ACT=85&function=add_bookmark&library_content_id="+file_id);
- helen_bookmarking.bookmarks.push(parseInt(file_id));
- }
- Helen_Bookmarking.prototype.remove_bookmark = function(file_id) {
- $.post( "/?ACT=85&function=remove_bookmark&library_content_id="+file_id);
- helen_bookmarking.bookmarks.splice( $.inArray(parseInt(file_id), helen_bookmarking.bookmarks), 1 );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement