From 4ef7bf9827162e153b5ec36f377a589adb5da885 Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Sat, 21 Apr 2012 17:15:45 -0700 Subject: [PATCH] Updating bookmarklet. Showing when the bookmarklet is broken, and fixes bugs with enumerable prototype chain fucking. --- apps/api/views.py | 2 +- media/css/modals.css | 14 ++++++++++++++ templates/api/bookmarklet_subscribe.js | 20 ++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/apps/api/views.py b/apps/api/views.py index aa016f9ba..ff9ab3b80 100644 --- a/apps/api/views.py +++ b/apps/api/views.py @@ -83,7 +83,7 @@ def add_site_load_script(request, token): return render_to_response('api/bookmarklet_subscribe.js', { 'code': code, 'token': token, - 'folders': usf and usf.folders, + 'folders': (usf and usf.folders) or [], 'accept_image': accept_image, 'error_image': error_image, 'add_image': add_image, diff --git a/media/css/modals.css b/media/css/modals.css index 9188b3eb5..af5fca8d1 100644 --- a/media/css/modals.css +++ b/media/css/modals.css @@ -330,6 +330,7 @@ } .NB-bookmarklet .NB-modal-submit { margin: 24px 0 8px; + padding: 0 0 6px; } .NB-bookmarklet .NB-modal-submit-button { clear: both; @@ -337,6 +338,7 @@ line-height: 24px; width: 200px; text-align: center; + text-shadow: none; } .NB-bookmarklet .NB-modal-submit-button img { margin: 5px 6px 0 0; @@ -362,4 +364,16 @@ } .NB-bookmarklet .NB-folders { float: right; +} +.NB-bookmarklet .NB-error-invalid { + padding: 12px 12px; + font-size: 13px; + text-shadow: none; + color: white; + background-color: #690F0F; + border-radius: 8px; +} +.NB-bookmarklet .NB-error-invalid a { + color: #9FC6F5; + text-decoration: underline; } \ No newline at end of file diff --git a/templates/api/bookmarklet_subscribe.js b/templates/api/bookmarklet_subscribe.js index 453623d38..39207077d 100644 --- a/templates/api/bookmarklet_subscribe.js +++ b/templates/api/bookmarklet_subscribe.js @@ -18,6 +18,10 @@ this.options = $.extend({}, defaults, options); this.runner(); + + {% if code < 0 %} + this.show_error(); + {% endif %} }; NEWSBLUR.BookmarkletModal.prototype = { @@ -47,6 +51,15 @@ this.$modal.bind('click', $.rescope(this.handle_clicks, this)); }, + 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'), + '.' + ])); + }, + attach_css: function() { var css = "{% include_bookmarklet_css %}"; var style = ''; @@ -110,11 +123,18 @@ }, make_folder_options: function($options, items, depth) { + if (depth && depth.length > 5) { + return $options; + } + for (var i in items) { + if (!items.hasOwnProperty(i)) continue; var item = items[i]; if (typeof item == "object") { for (var o in item) { + if (!item.hasOwnProperty(o)) continue; var folder = item[o]; + console.log(["make_folder_options", folder, o, depth]); var $option = $.make('option', { value: o }, depth + ' ' + o); $options.append($option); $options = this.make_folder_options($options, folder, depth+'-');