From d87034b131f9cca080a14a7b71b144e1330c6b60 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Wed, 26 Feb 2014 21:58:04 -0500 Subject: [PATCH] use alert for bookmark --- public/language/en_GB/topic.json | 2 + public/src/app.js | 63 ++++++++++++++++++-------------- public/src/forum/topic.js | 21 ++++++++--- 3 files changed, 53 insertions(+), 33 deletions(-) diff --git a/public/language/en_GB/topic.json b/public/language/en_GB/topic.json index e03bada393..085f8df821 100644 --- a/public/language/en_GB/topic.json +++ b/public/language/en_GB/topic.json @@ -22,6 +22,8 @@ "tools": "Tools", "flag": "Flag", + "bookmark_instructions" : "Click here to return to your last position or close to discard.", + "flag_title": "Flag this post for moderation", "deleted_message": "This thread has been deleted. Only users with thread management privileges can see it.", diff --git a/public/src/app.js b/public/src/app.js index 39cfc8e7b3..9e7b1af06a 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -175,23 +175,27 @@ var socket, var alert = $('#' + alert_id); var title = params.title || ''; - function startTimeout(div, timeout) { + function fadeOut() { + alert.fadeOut(500, function () { + $(this).remove(); + }); + } + + function startTimeout(timeout) { var timeoutId = setTimeout(function () { - $(div).fadeOut(1000, function () { - $(this).remove(); - }); + fadeOut(); }, timeout); - $(div).attr('timeoutId', timeoutId); + alert.attr('timeoutId', timeoutId); } if (alert.length > 0) { alert.find('strong').html(title); alert.find('p').html(params.message); - alert.attr('class', "alert alert-dismissable alert-" + params.type); + alert.attr('class', 'alert alert-dismissable alert-' + params.type); clearTimeout(alert.attr('timeoutId')); - startTimeout(alert, params.timeout); + startTimeout(params.timeout); alert.children().fadeOut('100'); translator.translate(alert.html(), function(translatedHTML) { @@ -199,42 +203,45 @@ var socket, alert.html(translatedHTML); }); } else { - var div = $('
'), - button = $(''), - strong = $('' + title + ''), - p = $('

' + params.message + '

'); + alert = $('
'); - div.append(button) - .append(strong) - .append(p); + alert.append($('')) + .append($('' + title + '')) + .append($('

' + params.message + '

')); - button.on('click', function () { - div.remove(); - }); - - if (params.location == null) + if (params.location == null) { params.location = 'alert_window'; + } - translator.translate(div.html(), function(translatedHTML) { - div.html(translatedHTML); - $('#' + params.location).prepend(div.fadeIn('100')); + translator.translate(alert.html(), function(translatedHTML) { + alert.html(translatedHTML); + $('#' + params.location).prepend(alert.fadeIn('100')); + + if(typeof params.closefn === 'function') { + alert.find('button').on('click', function () { + params.closefn(); + fadeOut(); + }); + } }); if (params.timeout) { - startTimeout(div, params.timeout); + startTimeout(params.timeout); } - if (params.clickfn) { - div.on('click', function () { + if (typeof params.clickfn === 'function') { + alert.on('click', function () { params.clickfn(); - div.fadeOut(500, function () { - $(this).remove(); - }); + fadeOut(); }); } } }; + app.removeAlert = function(id) { + $('#' + 'alert_button_' + id).remove(); + } + app.alertSuccess = function (message, timeout) { if (!timeout) timeout = 2000; diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index f10839ec0e..d220494b86 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -14,6 +14,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { if(data.url.indexOf('topic') !== 0) { $('.pagination-block').addClass('hide'); $('#header-topic-title').html('').hide(); + app.removeAlert('bookmark'); } }); @@ -310,7 +311,18 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { if (window.location.hash) { Topic.scrollToPost(window.location.hash.substr(1), true); } else if (bookmark) { - Topic.scrollToPost(parseInt(bookmark, 10), true); + app.alert({ + alert_id: 'bookmark', + message: '[[topic:bookmark_instructions]]', + timeout: 0, + type: 'info', + clickfn : function() { + Topic.scrollToPost(parseInt(bookmark, 10), true); + }, + closefn : function() { + localStorage.removeItem('topic:' + tid + ':bookmark'); + } + }); } else { updateHeader(); } @@ -1023,11 +1035,10 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { var el = $(this); if (elementInView(el)) { - var index = parseInt(el.attr('data-index'), 10) + 1; - if(index === 0) { - localStorage.removeItem("topic:" + templates.get('topic_id') + ":bookmark"); + if(!parseInt(el.attr('data-index'), 10)) { + localStorage.removeItem('topic:' + templates.get('topic_id') + ':bookmark'); } else { - localStorage.setItem("topic:" + templates.get('topic_id') + ":bookmark", el.attr('data-pid')); + localStorage.setItem('topic:' + templates.get('topic_id') + ':bookmark', el.attr('data-pid')); if (!scrollingToPost) { var newUrl = window.location.protocol + '//' + window.location.host + window.location.pathname + '#' + el.attr('data-pid')