2011-01-22 18:25:16 -05:00
|
|
|
{% load bookmarklet_includes utils_tags %}
|
2011-01-22 11:22:14 -05:00
|
|
|
|
2011-01-22 21:55:10 -05:00
|
|
|
(function() {
|
2012-07-31 13:04:33 -07:00
|
|
|
window.NEWSBLUR = window.NEWSBLUR || {};
|
2011-01-22 21:53:40 -05:00
|
|
|
|
2011-01-21 20:29:19 -05:00
|
|
|
{% include_bookmarklet_js %}
|
2011-01-22 21:55:10 -05:00
|
|
|
|
2012-08-11 13:53:00 -07:00
|
|
|
NEWSBLUR.Bookmarklet = function(options) {
|
2011-01-21 20:29:19 -05:00
|
|
|
var defaults = {};
|
2011-01-22 11:22:14 -05:00
|
|
|
|
2011-01-22 18:25:16 -05:00
|
|
|
this.token = "{{ token }}";
|
|
|
|
this.active = true;
|
2011-01-21 20:29:19 -05:00
|
|
|
this.username = '{{ user.username }}';
|
2012-08-11 17:18:35 -07:00
|
|
|
this.profile = {{ user_profile|safe }};
|
2011-01-22 18:25:16 -05:00
|
|
|
this.folders = {{ folders|safe }};
|
|
|
|
this.domain = "{% current_domain %}";
|
2011-03-21 10:15:18 -04:00
|
|
|
this.flags = {
|
|
|
|
'new_folder': false
|
2011-03-21 20:37:58 -04:00
|
|
|
};
|
2012-08-24 14:34:53 -07:00
|
|
|
this.images = {
|
|
|
|
'accept_image': "{{ accept_image }}"
|
|
|
|
};
|
2011-01-21 20:29:19 -05:00
|
|
|
|
2011-01-22 18:25:16 -05:00
|
|
|
this.options = $.extend({}, defaults, options);
|
2011-01-21 20:29:19 -05:00
|
|
|
this.runner();
|
2012-04-21 17:15:45 -07:00
|
|
|
|
|
|
|
{% if code < 0 %}
|
|
|
|
this.show_error();
|
|
|
|
{% endif %}
|
2011-01-21 20:29:19 -05:00
|
|
|
};
|
|
|
|
|
2012-08-11 13:53:00 -07:00
|
|
|
NEWSBLUR.Bookmarklet.prototype = {
|
2011-01-21 20:29:19 -05:00
|
|
|
|
2012-08-17 23:29:17 -07:00
|
|
|
|
|
|
|
// ==================
|
|
|
|
// = Initialization =
|
|
|
|
// ==================
|
|
|
|
|
2011-01-21 20:29:19 -05:00
|
|
|
fix_title: function() {
|
|
|
|
var d = document;
|
2012-08-10 19:20:44 -07:00
|
|
|
d.title = d.title.replace(/\(Sharing\.\.\.\)\s?/g, '');
|
2011-01-21 20:29:19 -05:00
|
|
|
d.title = d.title.replace(/\(Adding\.\.\.\)\s?/g, '');
|
|
|
|
},
|
|
|
|
|
|
|
|
close: function() {
|
|
|
|
this.active = false;
|
2012-08-11 13:53:00 -07:00
|
|
|
$('body').css('overflow', 'scroll');
|
2011-01-21 20:29:19 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
runner: function() {
|
|
|
|
this.fix_title();
|
|
|
|
|
|
|
|
if (this.check_if_on_newsblur()) {
|
2011-01-24 09:58:16 -05:00
|
|
|
var message = "This bookmarklet is successfully installed.\nClick it while on a site you want to read in NewsBlur.";
|
2011-01-21 20:29:19 -05:00
|
|
|
this.alert(message);
|
|
|
|
return this.close();
|
|
|
|
}
|
|
|
|
|
2011-01-21 22:00:36 -05:00
|
|
|
this.attach_css();
|
2011-01-21 20:29:19 -05:00
|
|
|
this.make_modal();
|
|
|
|
this.open_modal();
|
2012-08-10 19:20:44 -07:00
|
|
|
this.get_page_content();
|
2012-08-24 14:34:53 -07:00
|
|
|
_.delay(_.bind(function() {
|
|
|
|
this.pre_share_check_story();
|
|
|
|
}, this), 0);
|
2011-01-21 20:29:19 -05:00
|
|
|
|
2011-01-22 11:22:14 -05:00
|
|
|
this.$modal.bind('click', $.rescope(this.handle_clicks, this));
|
2012-08-17 23:29:17 -07:00
|
|
|
|
|
|
|
var $comment = $('textarea[name=newsblur_comment]', this.$modal);
|
|
|
|
$comment.bind('keydown', $.rescope(this.update_share_button_title, this));
|
|
|
|
$comment.bind('keyup', $.rescope(this.update_share_button_title, this));
|
|
|
|
$comment.bind('keydown', 'ctrl+return', $.rescope(this.share_story, this));
|
|
|
|
$comment.bind('keydown', 'meta+return', $.rescope(this.share_story, this));
|
2011-01-21 20:29:19 -05:00
|
|
|
},
|
2012-08-17 23:29:17 -07:00
|
|
|
|
2011-01-21 20:29:19 -05:00
|
|
|
make_modal: function() {
|
|
|
|
var self = this;
|
2012-08-17 23:29:17 -07:00
|
|
|
|
2011-01-21 20:29:19 -05:00
|
|
|
this.$modal = $.make('div', { className: 'NB-bookmarklet NB-modal' }, [
|
|
|
|
$.make('div', { className: 'NB-modal-information' }, [
|
|
|
|
'Signed in as ',
|
|
|
|
$.make('b', { style: 'color: #505050' }, this.username)
|
|
|
|
]),
|
2012-08-19 17:24:37 -07:00
|
|
|
$.make('div', { className: 'NB-modal-title' }, 'Share this story on NewsBlur'),
|
2012-08-10 19:20:44 -07:00
|
|
|
$.make('div', { className: 'NB-bookmarklet-main'}, [
|
|
|
|
$.make('div', { className: 'NB-bookmarklet-page' }, [
|
|
|
|
$.make('div', { className: 'NB-bookmarklet-page-title' }),
|
2012-08-24 14:34:53 -07:00
|
|
|
$.make('div', { className: 'NB-bookmarklet-page-content-wrapper' }, [
|
|
|
|
$.make('div', { className: 'NB-bookmarklet-page-content' })
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-bookmarklet-page-comment NB-modal-submit' }, [
|
2012-08-11 17:18:35 -07:00
|
|
|
$.make('div', { className: 'NB-bookmarklet-comment-photo' }, [
|
|
|
|
$.make('img', { src: this.profile.photo_url })
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-bookmarklet-comment-input' }, [
|
|
|
|
$.make('textarea', { name: 'newsblur_comment', placeholder: "Comments..." })
|
2012-08-17 23:29:17 -07:00
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-bookmarklet-comment-submit NB-modal-submit-button NB-modal-submit-green' }, 'Share this story')
|
2012-08-11 17:18:35 -07:00
|
|
|
])
|
2012-08-10 19:20:44 -07:00
|
|
|
])
|
|
|
|
]),
|
2012-08-11 17:18:35 -07:00
|
|
|
$.make('div', { className: 'NB-bookmarklet-side' }, [
|
2012-08-24 14:34:53 -07:00
|
|
|
$.make('div', { className: 'NB-bookmarklet-side-half NB-bookmarklet-side-subscribe' }, [
|
|
|
|
$.make('div', { className: 'NB-subscribe-feed' }),
|
|
|
|
$.make('div', { className: 'NB-bookmarklet-folder-container' }, [
|
|
|
|
$.make('img', { className: 'NB-bookmarklet-folder-add-button', src: 'data:image/png;charset=utf-8;base64,{{ add_image }}', title: 'Add New Folder' }),
|
|
|
|
this.make_folders(),
|
|
|
|
$.make('div', { className: 'NB-bookmarklet-new-folder-container' }, [
|
|
|
|
$.make('img', { className: 'NB-bookmarklet-folder-new-label', src: 'data:image/png;charset=utf-8;base64,{{ new_folder_image }}' }),
|
|
|
|
$.make('input', { type: 'text', name: 'new_folder_name', className: 'NB-bookmarklet-folder-new' })
|
|
|
|
])
|
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-modal-submit' }, [
|
|
|
|
$.make('div', { className: 'NB-bookmarklet-button-subscribe NB-modal-submit-button NB-modal-submit-green' }, 'Subscribe to this site')
|
2012-08-11 17:18:35 -07:00
|
|
|
])
|
2012-08-24 14:34:53 -07:00
|
|
|
]),
|
|
|
|
$.make('div', { className: 'NB-bookmarklet-side-half NB-bookmarklet-side-loading' }, [
|
|
|
|
$.make('img', { className: 'NB-subscribe-loader', src: 'data:image/png;charset=utf-8;base64,{{ add_image }}', title: 'Loading...' }),
|
|
|
|
$.make('div', { className: 'NB-subscribe-load-text' }, 'Shared stories are on their way...')
|
2011-03-21 10:15:18 -04:00
|
|
|
])
|
2011-01-21 20:29:19 -05:00
|
|
|
])
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
|
|
|
make_folders: function() {
|
|
|
|
var folders = this.folders;
|
|
|
|
var $options = $.make('select', { className: 'NB-folders'});
|
|
|
|
|
|
|
|
$options = this.make_folder_options($options, folders, '-');
|
2011-01-21 22:00:36 -05:00
|
|
|
|
|
|
|
var $option = $.make('option', { value: '', selected: true }, "Top Level");
|
|
|
|
$options.prepend($option);
|
|
|
|
|
2011-01-21 20:29:19 -05:00
|
|
|
return $options;
|
|
|
|
},
|
|
|
|
|
|
|
|
make_folder_options: function($options, items, depth) {
|
2012-04-21 17:15:45 -07:00
|
|
|
if (depth && depth.length > 5) {
|
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
|
2011-01-21 20:29:19 -05:00
|
|
|
for (var i in items) {
|
2012-04-21 17:15:45 -07:00
|
|
|
if (!items.hasOwnProperty(i)) continue;
|
2011-01-21 20:29:19 -05:00
|
|
|
var item = items[i];
|
|
|
|
if (typeof item == "object") {
|
|
|
|
for (var o in item) {
|
2012-04-21 17:15:45 -07:00
|
|
|
if (!item.hasOwnProperty(o)) continue;
|
2011-01-21 20:29:19 -05:00
|
|
|
var folder = item[o];
|
|
|
|
var $option = $.make('option', { value: o }, depth + ' ' + o);
|
|
|
|
$options.append($option);
|
|
|
|
$options = this.make_folder_options($options, folder, depth+'-');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $options;
|
|
|
|
},
|
|
|
|
|
|
|
|
open_modal: function() {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.$modal.modal({
|
2012-08-10 19:20:44 -07:00
|
|
|
'minWidth': 800,
|
|
|
|
'maxWidth': 800,
|
2011-01-21 20:29:19 -05:00
|
|
|
'overlayClose': true,
|
|
|
|
'onOpen': function (dialog) {
|
|
|
|
dialog.overlay.fadeIn(200, function () {
|
|
|
|
dialog.container.fadeIn(200);
|
|
|
|
dialog.data.fadeIn(200);
|
2011-01-21 22:00:36 -05:00
|
|
|
setTimeout(function() {
|
|
|
|
$(window).resize();
|
|
|
|
}, 10);
|
2011-01-21 20:29:19 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
'onShow': function(dialog) {
|
|
|
|
$('#simplemodal-container').corner('6px');
|
|
|
|
},
|
|
|
|
'onClose': function(dialog) {
|
|
|
|
dialog.data.hide().empty().remove();
|
|
|
|
dialog.container.hide().empty().remove();
|
|
|
|
dialog.overlay.fadeOut(200, function() {
|
|
|
|
dialog.overlay.empty().remove();
|
|
|
|
$.modal.close();
|
|
|
|
self.close();
|
|
|
|
});
|
|
|
|
$('.NB-modal-holder').empty().remove();
|
|
|
|
}
|
|
|
|
});
|
2012-08-11 13:53:00 -07:00
|
|
|
|
|
|
|
$('body').css('overflow', 'hidden');
|
2011-01-21 20:29:19 -05:00
|
|
|
},
|
2011-01-22 11:22:14 -05:00
|
|
|
|
2012-08-17 23:29:17 -07:00
|
|
|
// ============
|
|
|
|
// = Add site =
|
|
|
|
// ============
|
|
|
|
|
|
|
|
show_error: function() {
|
|
|
|
$('.NB-bookmarklet-folder-container', this.$modal).hide();
|
|
|
|
$('.NB-modal-submit', this.$modal).html($.make('div', { className: 'NB-error-invalid' }, [
|
|
|
|
'This bookmarklet no longer matches an account. Re-create it in ',
|
|
|
|
$.make('a', { href: 'http://www.newsblur.com/?next=goodies' }, 'Goodies on NewsBlur'),
|
|
|
|
'.'
|
|
|
|
]));
|
|
|
|
},
|
|
|
|
|
2011-01-22 11:22:14 -05:00
|
|
|
save: function() {
|
2011-01-22 18:25:16 -05:00
|
|
|
var self = this;
|
2012-08-24 14:34:53 -07:00
|
|
|
var $submit = $('.NB-bookmarklet-button-subscribe', this.$modal);
|
2011-01-22 11:22:14 -05:00
|
|
|
var folder = $('.NB-folders').val();
|
2011-01-22 18:25:16 -05:00
|
|
|
var add_site_url = "http://"+this.domain+"{% url api-add-site token %}?callback=?";
|
|
|
|
|
|
|
|
$submit.addClass('NB-disabled').text('Fetching and parsing...');
|
2011-01-22 11:22:14 -05:00
|
|
|
|
2011-03-21 10:15:18 -04:00
|
|
|
var data = {
|
2011-01-22 11:22:14 -05:00
|
|
|
url: window.location.href,
|
|
|
|
folder: folder
|
2011-03-21 10:15:18 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
if (this.flags['new_folder']) {
|
|
|
|
var new_folder_name = $('input[name=new_folder_name]', this.$modal).val();
|
|
|
|
if (new_folder_name) {
|
2011-03-21 20:37:58 -04:00
|
|
|
data['new_folder'] = new_folder_name;
|
2011-03-21 10:15:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$.getJSON(add_site_url, data, function(resp) {
|
2012-08-24 14:34:53 -07:00
|
|
|
self.confirm_subscription(resp.code > 0, resp.message);
|
2011-01-22 11:22:14 -05:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-08-24 14:34:53 -07:00
|
|
|
confirm_subscription: function(subscribed, message) {
|
|
|
|
var $submit = $('.NB-bookmarklet-button-subscribe', this.$modal);
|
2011-01-22 18:25:16 -05:00
|
|
|
|
2012-08-24 14:34:53 -07:00
|
|
|
$submit.addClass('NB-disabled');
|
2011-01-22 18:25:16 -05:00
|
|
|
|
2012-08-24 14:34:53 -07:00
|
|
|
if (subscribed) {
|
2011-01-22 21:42:58 -05:00
|
|
|
$submit.html($.make('div', { className: 'NB-bookmarklet-accept' }, [
|
2012-08-24 14:34:53 -07:00
|
|
|
$.make('img', { src: 'data:image/png;charset=utf-8;base64,' + this.images['accept_image'] }),
|
|
|
|
'Subscribed'
|
2011-01-22 18:25:16 -05:00
|
|
|
]));
|
2012-08-24 14:34:53 -07:00
|
|
|
// setTimeout(function() {
|
|
|
|
// $.modal.close();
|
|
|
|
// }, 2000);
|
2011-01-22 18:25:16 -05:00
|
|
|
} else {
|
2011-01-22 21:42:58 -05:00
|
|
|
var $error = $.make('div', { className: 'NB-bookmarklet-error' }, [
|
|
|
|
$.make('img', { className: 'NB-bookmarklet-folder-label', src: 'data:image/png;charset=utf-8;base64,{{ error_image }}' }),
|
2012-08-24 15:07:10 -07:00
|
|
|
$.make('div', message)
|
2011-01-22 21:42:58 -05:00
|
|
|
]);
|
|
|
|
$('.NB-bookmarklet-folder-container').hide();
|
|
|
|
$submit.replaceWith($error);
|
2011-01-22 18:25:16 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-08-17 23:29:17 -07:00
|
|
|
// =============
|
|
|
|
// = Pre-share =
|
|
|
|
// =============
|
|
|
|
|
|
|
|
pre_share_check_story: function() {
|
2012-08-24 14:34:53 -07:00
|
|
|
var $side = $('.NB-bookmarklet-side', this.$modal);
|
|
|
|
var $side_loading = $('.NB-bookmarklet-side-loading', this.$modal);
|
|
|
|
var $side_subscribe = $('.NB-bookmarklet-side-subscribe', this.$modal);
|
2012-08-17 23:29:17 -07:00
|
|
|
var check_story_url = "http://"+this.domain+"{% url api-check-share-on-site token %}?callback=?";
|
|
|
|
var data = {
|
|
|
|
story_url: window.location.href,
|
2012-08-24 14:34:53 -07:00
|
|
|
rss_url: this.get_page_rss_url()
|
2012-08-17 23:29:17 -07:00
|
|
|
};
|
|
|
|
|
2012-08-24 14:34:53 -07:00
|
|
|
$.getJSON(check_story_url, data, _.bind(function(data) {
|
|
|
|
$side_loading.animate({'left': '-100%'}, {
|
|
|
|
'easing': 'easeInOutQuint',
|
|
|
|
'duration': 1650,
|
|
|
|
'queue': false
|
|
|
|
});
|
|
|
|
$side_subscribe.css('left', $side.outerWidth(true)+4).animate({'left': 0}, {
|
|
|
|
'easing': 'easeInOutQuint',
|
|
|
|
'duration': 1650,
|
|
|
|
'queue': false
|
|
|
|
});
|
|
|
|
this.feed = data.feed;
|
|
|
|
this.make_feed_subscribe(data.feed);
|
|
|
|
if (data.subscribed) {
|
|
|
|
$('.NB-bookmarklet-folder-container', this.$modal).hide();
|
|
|
|
this.confirm_subscription(data.subscribed);
|
|
|
|
}
|
|
|
|
}, this));
|
|
|
|
},
|
|
|
|
|
|
|
|
make_feed_subscribe: function(feed) {
|
|
|
|
if (feed) {
|
|
|
|
var $feed = $.make('div', { className: 'NB-subscribe-feed' }, [
|
|
|
|
$.make('img', { src: 'data:image/png;charset=utf-8;base64,' + feed.favicon }),
|
|
|
|
$.make('div', { className: 'NB-subscribe-feed-title' }, feed.feed_title)
|
|
|
|
]);
|
|
|
|
$('.NB-subscribe-feed', this.$modal).replaceWith($feed);
|
|
|
|
}
|
2012-08-17 23:29:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ===============
|
|
|
|
// = Share story =
|
|
|
|
// ===============
|
|
|
|
|
|
|
|
share_story: function() {
|
2012-08-24 14:34:53 -07:00
|
|
|
var $share = $(".NB-bookmarklet-comment-submit", this.$modal);
|
|
|
|
|
|
|
|
$share.addClass('NB-disabled').text('Sharing...');
|
|
|
|
|
2012-08-17 23:29:17 -07:00
|
|
|
$.ajax({
|
2012-08-24 14:34:53 -07:00
|
|
|
url: '//'+this.domain+"{% url api-share-story token %}",
|
|
|
|
type: 'POST',
|
|
|
|
data: {
|
|
|
|
title: this.story_title,
|
|
|
|
content: this.story_content,
|
|
|
|
comments: $('textarea[name=newsblur_comment]', this.$modal).val(),
|
|
|
|
feed_id: this.feed && this.feed.id,
|
|
|
|
story_url: window.location.href,
|
|
|
|
rss_url: this.get_page_rss_url()
|
|
|
|
},
|
|
|
|
success: _.bind(this.post_share_story, this),
|
|
|
|
error: _.bind(this.error_share_story, this)
|
|
|
|
});
|
2012-08-17 23:29:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
post_share_story: function(data) {
|
2012-08-24 14:34:53 -07:00
|
|
|
var $share = $(".NB-bookmarklet-comment-submit", this.$modal);
|
2012-08-17 23:29:17 -07:00
|
|
|
|
2012-08-24 14:34:53 -07:00
|
|
|
if (data.code < 0) {
|
|
|
|
return this.error_share_story(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
$share.html($.make('div', { className: 'NB-bookmarklet-accept' }, [
|
|
|
|
$.make('img', { src: 'data:image/png;charset=utf-8;base64,' + this.images['accept_image'] }),
|
|
|
|
'Shared'
|
|
|
|
]));
|
|
|
|
// setTimeout(function() {
|
|
|
|
// $.modal.close();
|
|
|
|
// }, 2000);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
error_share_story: function(data) {
|
2012-08-24 15:07:10 -07:00
|
|
|
var $share = $(".NB-bookmarklet-comment-submit", this.$modal);
|
|
|
|
|
2012-08-24 14:34:53 -07:00
|
|
|
$share.removeClass('NB-disabled');
|
|
|
|
console.log(["error sharing", data]);
|
|
|
|
this.update_share_button_title();
|
2012-08-17 23:29:17 -07:00
|
|
|
},
|
|
|
|
|
2011-03-21 10:15:18 -04:00
|
|
|
open_add_folder: function() {
|
|
|
|
var $new_folder = $('.NB-bookmarklet-new-folder-container', this.$modal);
|
|
|
|
$new_folder.slideDown(500);
|
|
|
|
this.flags['new_folder'] = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
close_add_folder: function() {
|
|
|
|
var $new_folder = $('.NB-bookmarklet-new-folder-container', this.$modal);
|
|
|
|
$new_folder.slideUp(500);
|
|
|
|
this.flags['new_folder'] = false;
|
|
|
|
},
|
|
|
|
|
2012-08-10 19:20:44 -07:00
|
|
|
// =========================
|
|
|
|
// = Page-specific actions =
|
|
|
|
// =========================
|
|
|
|
|
|
|
|
get_page_content: function() {
|
2012-08-17 17:32:46 -07:00
|
|
|
var selected = this.get_selected_html();
|
2012-08-11 17:18:35 -07:00
|
|
|
var $title = $('.NB-bookmarklet-page-title', this.$modal);
|
2012-08-10 19:20:44 -07:00
|
|
|
var $content = $('.NB-bookmarklet-page-content', this.$modal);
|
2012-08-17 17:32:46 -07:00
|
|
|
|
|
|
|
if (selected) {
|
|
|
|
var title = document.title;
|
|
|
|
var content = selected;
|
|
|
|
console.log(["content selected", title, content]);
|
|
|
|
} else {
|
|
|
|
var $readability = $(window.readability.init());
|
2012-08-10 19:20:44 -07:00
|
|
|
|
2012-08-24 14:34:53 -07:00
|
|
|
this.story_title = $readability.children("h1").text();
|
|
|
|
this.story_content = $("#readability-content", $readability).html();
|
2012-08-17 17:32:46 -07:00
|
|
|
}
|
|
|
|
|
2012-08-24 14:34:53 -07:00
|
|
|
$title.html(this.story_title);
|
|
|
|
$content.html(this.story_content);
|
2012-08-10 19:20:44 -07:00
|
|
|
},
|
|
|
|
|
2012-08-17 17:32:46 -07:00
|
|
|
get_selected_html: function() {
|
|
|
|
var html = "";
|
|
|
|
if (typeof window.getSelection != "undefined") {
|
|
|
|
var sel = window.getSelection();
|
|
|
|
if (sel.rangeCount) {
|
|
|
|
var container = document.createElement("div");
|
|
|
|
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
|
|
|
|
container.appendChild(sel.getRangeAt(i).cloneContents());
|
|
|
|
}
|
|
|
|
html = container.innerHTML;
|
|
|
|
}
|
|
|
|
} else if (typeof document.selection != "undefined") {
|
|
|
|
if (document.selection.type == "Text") {
|
|
|
|
html = document.selection.createRange().htmlText;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return html;
|
|
|
|
},
|
|
|
|
|
2012-08-17 23:29:17 -07:00
|
|
|
attach_css: function() {
|
|
|
|
var css = "{% include_bookmarklet_css %}";
|
|
|
|
var style = '<style id="newsblur_bookmarklet_css">' + css + '</style>';
|
|
|
|
if ($('#newsblur_bookmarklet_css').length) {
|
|
|
|
$('#newsblur_bookmarklet_css').replaceWith(style);
|
|
|
|
} else if ($('head').length) {
|
|
|
|
$('head').append(style);
|
|
|
|
} else {
|
|
|
|
$('body').append(style);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
alert: function(message) {
|
|
|
|
alert(message);
|
|
|
|
},
|
|
|
|
|
|
|
|
check_if_on_newsblur: function() {
|
|
|
|
if (window.location.href.indexOf(this.domain) != -1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get_page_title: function() {
|
|
|
|
var title = document.title;
|
|
|
|
|
|
|
|
if (title.length > 40) {
|
|
|
|
title = title.substr(0, 40) + '...';
|
|
|
|
}
|
|
|
|
|
|
|
|
return title;
|
|
|
|
},
|
|
|
|
|
2012-08-24 14:34:53 -07:00
|
|
|
get_page_rss_url: function() {
|
|
|
|
return $('link[type="application/rss+xml"]').attr('href');
|
|
|
|
},
|
|
|
|
|
2011-01-21 20:29:19 -05:00
|
|
|
// ===========
|
|
|
|
// = Actions =
|
|
|
|
// ===========
|
|
|
|
|
2011-01-22 11:22:14 -05:00
|
|
|
handle_clicks: function(elem, e) {
|
2011-01-21 20:29:19 -05:00
|
|
|
var self = this;
|
2011-03-21 10:15:18 -04:00
|
|
|
|
2012-08-24 14:34:53 -07:00
|
|
|
$.targetIs(e, { tagSelector: '.NB-bookmarklet-button-subscribe' }, function($t, $p) {
|
2011-01-21 20:29:19 -05:00
|
|
|
e.preventDefault();
|
2011-01-22 18:25:16 -05:00
|
|
|
|
|
|
|
if (!$t.hasClass('NB-disabled')) {
|
|
|
|
self.save();
|
|
|
|
}
|
|
|
|
});
|
2011-03-21 10:15:18 -04:00
|
|
|
|
|
|
|
$.targetIs(e, { tagSelector: '.NB-bookmarklet-folder-add-button' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
if ($t.hasClass('NB-active')) {
|
|
|
|
self.close_add_folder();
|
|
|
|
} else {
|
|
|
|
self.open_add_folder();
|
|
|
|
}
|
|
|
|
$t.toggleClass('NB-active');
|
|
|
|
});
|
|
|
|
|
2012-08-24 14:34:53 -07:00
|
|
|
$.targetIs(e, { tagSelector: '.NB-bookmarklet-comment-submit' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
if (!$t.hasClass('NB-disabled')) {
|
|
|
|
self.share_story();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-01-22 18:25:16 -05:00
|
|
|
$.targetIs(e, { tagSelector: '.NB-close' }, function($t, $p) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
$.modal.close();
|
2011-01-21 20:29:19 -05:00
|
|
|
});
|
2012-08-17 23:29:17 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
update_share_button_title: function() {
|
|
|
|
var $comment = $('textarea[name=newsblur_comment]', this.$modal);
|
|
|
|
var $submit = $('.NB-bookmarklet-comment-submit', this.$modal);
|
|
|
|
|
|
|
|
if ($comment.val().length) {
|
|
|
|
$submit.text('Share with comments');
|
|
|
|
} else {
|
|
|
|
$submit.text('Share this story');
|
|
|
|
}
|
2011-01-21 20:29:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-08-11 13:53:00 -07:00
|
|
|
if (NEWSBLUR.bookmarklet && NEWSBLUR.bookmarklet.active) {
|
|
|
|
NEWSBLUR.bookmarklet.fix_title();
|
2011-01-21 20:29:19 -05:00
|
|
|
return;
|
|
|
|
}
|
2012-08-11 13:53:00 -07:00
|
|
|
NEWSBLUR.bookmarklet = new NEWSBLUR.Bookmarklet();
|
2011-01-21 20:29:19 -05:00
|
|
|
|
2011-01-22 21:55:10 -05:00
|
|
|
})();
|