From db4da3babc0864099c5ab48e3583d0546a2759d8 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Thu, 2 Oct 2014 11:39:51 +0200 Subject: First draft for drag and drop We can change feed category by drag and drop! Need improvements... See https://github.com/marienfressinaud/FreshRSS/issues/646 --- p/scripts/category.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 p/scripts/category.js (limited to 'p/scripts/category.js') diff --git a/p/scripts/category.js b/p/scripts/category.js new file mode 100644 index 000000000..fe80c3b22 --- /dev/null +++ b/p/scripts/category.js @@ -0,0 +1,55 @@ +"use strict"; + + +function init_draggable() { + var feeds_draggable = '.box-content > .feed', + box_dropzone = '.box-content'; + + $('.box').on('dragstart', feeds_draggable, function(e) { + e.originalEvent.dataTransfer.effectAllowed = 'move'; + e.originalEvent.dataTransfer.setData('html', e.target.outerHTML); + e.originalEvent.dataTransfer.setData('feed-id', e.target.getAttribute('data-feed-id')); + }); + $('.box').on('dragend', feeds_draggable, function(e) { + var parent = e.target.parentNode; + parent.removeChild(e.target); + }); + + $('.box').on('dragenter', box_dropzone, function(e) { + $(e.target).addClass('drag-hover'); + }); + $('.box').on('dragleave', box_dropzone, function(e) { + $(e.target).removeClass('drag-hover'); + }); + $('.box').on('dragover', box_dropzone, function(e) { + e.originalEvent.dataTransfer.dropEffect = "move"; + + return false; + }); + $('.box').on('drop', box_dropzone, function(e) { + var feed_id = e.originalEvent.dataTransfer.getData('feed-id'), + cat_id = e.target.parentNode.getAttribute('data-cat-id'); + + $.ajax({ + type: 'POST', + url: './?c=feed&a=move', + data : { + f_id: feed_id, + c_id: cat_id + } + }); + + $(e.target).after(e.originalEvent.dataTransfer.getData('html')); + $(e.target).removeClass('drag-hover'); + return false; + }); +} + + +if (document.readyState && document.readyState !== 'loading') { + init_draggable(); +} else if (document.addEventListener) { + document.addEventListener('DOMContentLoaded', function () { + init_draggable(); + }, false); +} -- cgit v1.2.3 From 50f07febaed5e839d4e7d56a664c8a208bc2aaf5 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Thu, 2 Oct 2014 12:13:16 +0200 Subject: Add dataTransfer property to event for JQuery See https://github.com/marienfressinaud/FreshRSS/issues/646 --- p/scripts/category.js | 15 +++++++++------ p/themes/Origine/origine.css | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'p/scripts/category.js') diff --git a/p/scripts/category.js b/p/scripts/category.js index fe80c3b22..4378aa9cd 100644 --- a/p/scripts/category.js +++ b/p/scripts/category.js @@ -2,17 +2,20 @@ function init_draggable() { + $.event.props.push('dataTransfer'); + var feeds_draggable = '.box-content > .feed', box_dropzone = '.box-content'; $('.box').on('dragstart', feeds_draggable, function(e) { - e.originalEvent.dataTransfer.effectAllowed = 'move'; - e.originalEvent.dataTransfer.setData('html', e.target.outerHTML); - e.originalEvent.dataTransfer.setData('feed-id', e.target.getAttribute('data-feed-id')); + e.dataTransfer.effectAllowed = 'move'; + e.dataTransfer.setData('html', e.target.outerHTML); + e.dataTransfer.setData('feed-id', e.target.getAttribute('data-feed-id')); }); $('.box').on('dragend', feeds_draggable, function(e) { var parent = e.target.parentNode; parent.removeChild(e.target); + }); $('.box').on('dragenter', box_dropzone, function(e) { @@ -22,12 +25,12 @@ function init_draggable() { $(e.target).removeClass('drag-hover'); }); $('.box').on('dragover', box_dropzone, function(e) { - e.originalEvent.dataTransfer.dropEffect = "move"; + e.dataTransfer.dropEffect = "move"; return false; }); $('.box').on('drop', box_dropzone, function(e) { - var feed_id = e.originalEvent.dataTransfer.getData('feed-id'), + var feed_id = e.dataTransfer.getData('feed-id'), cat_id = e.target.parentNode.getAttribute('data-cat-id'); $.ajax({ @@ -39,7 +42,7 @@ function init_draggable() { } }); - $(e.target).after(e.originalEvent.dataTransfer.getData('html')); + $(e.target).after(e.dataTransfer.getData('html')); $(e.target).removeClass('drag-hover'); return false; }); diff --git a/p/themes/Origine/origine.css b/p/themes/Origine/origine.css index cf6c9a2ef..c79f6cc4c 100644 --- a/p/themes/Origine/origine.css +++ b/p/themes/Origine/origine.css @@ -481,6 +481,7 @@ a.btn { border-radius: 5px 5px 0 0; } .box .box-content { + min-height: 2.5em; max-height: 260px; } -- cgit v1.2.3 From 6effa82cef4ea8fd98178e72b270de6ea4f9f80f Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Thu, 2 Oct 2014 15:02:42 +0200 Subject: Improve drag and drop - Refactoring - Better design - Item doesn't disappear if action is not completed See https://github.com/marienfressinaud/FreshRSS/issues/646 --- app/views/subscription/index.phtml | 11 ++++--- p/scripts/category.js | 63 +++++++++++++++++++++++++++++--------- p/themes/Origine/origine.css | 9 ------ p/themes/base-theme/template.css | 12 ++++++++ 4 files changed, 67 insertions(+), 28 deletions(-) (limited to 'p/scripts/category.js') diff --git a/app/views/subscription/index.phtml b/app/views/subscription/index.phtml index 3a79a34e6..2c56f79ed 100644 --- a/app/views/subscription/index.phtml +++ b/app/views/subscription/index.phtml @@ -1,6 +1,6 @@ partial('aside_subscription'); ?> -
+

@@ -113,21 +113,24 @@
-
    +
      inError() ? ' error' : ''; $empty = $feed->nbEntries() == 0 ? ' empty' : ''; ?> -
    • +
    • ✇ name(); ?>
    • -
    • +
diff --git a/p/scripts/category.js b/p/scripts/category.js index 4378aa9cd..37ad36b17 100644 --- a/p/scripts/category.js +++ b/p/scripts/category.js @@ -1,38 +1,66 @@ "use strict"; +var loading = false, + dnd_successful = false; + +function dragend_process(t) { + if (loading) { + window.setTimeout(function() { + dragend_process(t); + }, 50); + } + + if (!dnd_successful) { + t.style.opacity = 1.0; + } else { + t.parentNode.removeChild(t); + } +} + function init_draggable() { + if (!(window.$ && window.url_freshrss)) { + if (window.console) { + console.log('FreshRSS waiting for JS…'); + } + window.setTimeout(init_draggable, 50); + return; + } + $.event.props.push('dataTransfer'); - var feeds_draggable = '.box-content > .feed', - box_dropzone = '.box-content'; + var draggable = '[draggable="true"]', + dropzone = '[dropzone="move"]'; - $('.box').on('dragstart', feeds_draggable, function(e) { + $('.drop-section').on('dragstart', draggable, function(e) { e.dataTransfer.effectAllowed = 'move'; - e.dataTransfer.setData('html', e.target.outerHTML); - e.dataTransfer.setData('feed-id', e.target.getAttribute('data-feed-id')); + e.dataTransfer.setData('text/html', e.target.outerHTML); + e.dataTransfer.setData('text', e.target.getAttribute('data-feed-id')); + e.target.style.opacity = 0.3; + + dnd_successful = false; }); - $('.box').on('dragend', feeds_draggable, function(e) { - var parent = e.target.parentNode; - parent.removeChild(e.target); - + $('.drop-section').on('dragend', draggable, function(e) { + dragend_process(e.target); }); - $('.box').on('dragenter', box_dropzone, function(e) { + $('.drop-section').on('dragenter', dropzone, function(e) { $(e.target).addClass('drag-hover'); }); - $('.box').on('dragleave', box_dropzone, function(e) { + $('.drop-section').on('dragleave', dropzone, function(e) { $(e.target).removeClass('drag-hover'); }); - $('.box').on('dragover', box_dropzone, function(e) { + $('.drop-section').on('dragover', dropzone, function(e) { e.dataTransfer.dropEffect = "move"; return false; }); - $('.box').on('drop', box_dropzone, function(e) { - var feed_id = e.dataTransfer.getData('feed-id'), + $('.drop-section').on('drop', dropzone, function(e) { + var feed_id = e.dataTransfer.getData('text'), cat_id = e.target.parentNode.getAttribute('data-cat-id'); + loading = true; + $.ajax({ type: 'POST', url: './?c=feed&a=move', @@ -40,10 +68,15 @@ function init_draggable() { f_id: feed_id, c_id: cat_id } + }).success(function() { + $(e.target).after(e.dataTransfer.getData('text/html')); + loading = false; + }).complete(function() { + dnd_successful = true; }); - $(e.target).after(e.dataTransfer.getData('html')); $(e.target).removeClass('drag-hover'); + return false; }); } diff --git a/p/themes/Origine/origine.css b/p/themes/Origine/origine.css index c79f6cc4c..b25deab0c 100644 --- a/p/themes/Origine/origine.css +++ b/p/themes/Origine/origine.css @@ -498,15 +498,6 @@ a.btn { visibility: visible; } -/*=== Draggable */ -.drag-hover { - background: #dfd; - transition: all linear 0.2s; -} -[draggable=true] { - cursor: grab; -} - /*=== STRUCTURE */ /*===============*/ /*=== Header */ diff --git a/p/themes/base-theme/template.css b/p/themes/base-theme/template.css index e6c832ee4..06874c9fe 100644 --- a/p/themes/base-theme/template.css +++ b/p/themes/base-theme/template.css @@ -304,6 +304,10 @@ a.btn { .box .box-content .item { display: block; } +.box .box-content .item.disabled { + text-align: center; + font-style: italic; +} .box .box-content-centered { padding: 30px 5px; @@ -313,6 +317,14 @@ a.btn { margin: 20px 0 0; } +/*=== Draggable */ +.drag-hover { + margin: 0 0 5px; + border-bottom: 2px solid #ccc; +} +[draggable=true] { + cursor: grab; +} /*=== STRUCTURE */ /*===============*/ -- cgit v1.2.3 From 408ac31dd8751eba037db216243958d396df1c8e Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Thu, 2 Oct 2014 19:02:43 +0200 Subject: Hack for dragleave (triggered on children!) See https://github.com/marienfressinaud/FreshRSS/issues/646 --- app/Controllers/feedController.php | 7 ++++++- p/scripts/category.js | 33 ++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 8 deletions(-) (limited to 'p/scripts/category.js') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index 315665ef3..b2b53185e 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -389,7 +389,12 @@ class FreshRSS_feed_Controller extends Minz_ActionController { 'category' => $cat_id, ); - $feedDAO->updateFeed($feed_id, $values); + if (!$feedDAO->updateFeed($feed_id, $values)) { + Minz_Error::error( + 404, + array('error' => array(_t('error_occurred'))) + ); + } } } diff --git a/p/scripts/category.js b/p/scripts/category.js index 37ad36b17..872d14490 100644 --- a/p/scripts/category.js +++ b/p/scripts/category.js @@ -4,6 +4,8 @@ var loading = false, dnd_successful = false; function dragend_process(t) { + t.style.display = 'none'; + if (loading) { window.setTimeout(function() { dragend_process(t); @@ -11,13 +13,13 @@ function dragend_process(t) { } if (!dnd_successful) { + t.style.display = 'block'; t.style.opacity = 1.0; } else { t.parentNode.removeChild(t); } } - function init_draggable() { if (!(window.$ && window.url_freshrss)) { if (window.console) { @@ -45,14 +47,31 @@ function init_draggable() { }); $('.drop-section').on('dragenter', dropzone, function(e) { - $(e.target).addClass('drag-hover'); + $(this).addClass('drag-hover'); + + e.preventDefault(); }); $('.drop-section').on('dragleave', dropzone, function(e) { - $(e.target).removeClass('drag-hover'); + var pos_this = $(this).position(), + scroll_top = $(document).scrollTop(), + top = pos_this.top, + left = pos_this.left, + right = left + $(this).width(), + bottom = top + $(this).height(), + mouse_x = e.originalEvent.screenX, + mouse_y = e.originalEvent.clientY + scroll_top; + + if (left <= mouse_x && mouse_x <= right && + top <= mouse_y && mouse_y <= bottom) { + // HACK because dragleave is triggered when hovering children! + return; + } + $(this).removeClass('drag-hover'); }); $('.drop-section').on('dragover', dropzone, function(e) { e.dataTransfer.dropEffect = "move"; + e.preventDefault(); return false; }); $('.drop-section').on('drop', dropzone, function(e) { @@ -70,14 +89,14 @@ function init_draggable() { } }).success(function() { $(e.target).after(e.dataTransfer.getData('text/html')); - loading = false; - }).complete(function() { dnd_successful = true; + }).complete(function() { + loading = false; }); - $(e.target).removeClass('drag-hover'); + $(this).removeClass('drag-hover'); - return false; + e.preventDefault(); }); } -- cgit v1.2.3 From ce43b1761b810c89e5e8660e8ae2638e97ca6339 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Thu, 2 Oct 2014 19:47:02 +0200 Subject: Fix box when no feed in category See https://github.com/marienfressinaud/FreshRSS/issues/646 --- app/views/helpers/javascript_vars.phtml | 1 + p/scripts/category.js | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'p/scripts/category.js') diff --git a/app/views/helpers/javascript_vars.phtml b/app/views/helpers/javascript_vars.phtml index 1139eb446..71798369d 100644 --- a/app/views/helpers/javascript_vars.phtml +++ b/app/views/helpers/javascript_vars.phtml @@ -54,6 +54,7 @@ echo 'authType="', $authType, '",', echo 'str_confirmation_default="', Minz_Translate::t('confirm_action'), '"', ",\n"; echo 'str_notif_title_articles="', Minz_Translate::t('notif_title_new_articles'), '"', ",\n"; echo 'str_notif_body_articles="', Minz_Translate::t('notif_body_new_articles'), '"', ",\n"; +echo 'str_category_empty="', Minz_Translate::t('category_empty'), '"', ",\n"; echo 'html5_notif_timeout=', $this->conf->html5_notif_timeout,",\n"; diff --git a/p/scripts/category.js b/p/scripts/category.js index 872d14490..dc5df67e4 100644 --- a/p/scripts/category.js +++ b/p/scripts/category.js @@ -16,7 +16,12 @@ function dragend_process(t) { t.style.display = 'block'; t.style.opacity = 1.0; } else { - t.parentNode.removeChild(t); + var parent = $(t.parentNode); + $(t).remove(); + + if (parent.children().length <= 0) { + parent.append('
  • ' + str_category_empty + '
  • '); + } } } @@ -89,6 +94,9 @@ function init_draggable() { } }).success(function() { $(e.target).after(e.dataTransfer.getData('text/html')); + if ($(e.target).hasClass('disabled')) { + $(e.target).remove(); + } dnd_successful = true; }).complete(function() { loading = false; -- cgit v1.2.3 From d8ed718aab99ad47897fb70ea9086fa704bb912b Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sun, 5 Oct 2014 17:29:09 +0200 Subject: Refactor javascript_vars.phtml Introduce kind of context objectin JavaScript See https://github.com/marienfressinaud/FreshRSS/issues/634 See https://github.com/marienfressinaud/FreshRSS/issues/655 --- app/views/helpers/javascript_vars.phtml | 79 ++++++++++++++++----------------- p/scripts/category.js | 4 +- p/scripts/global_view.js | 2 +- p/scripts/main.js | 66 ++++++++++++--------------- 4 files changed, 70 insertions(+), 81 deletions(-) (limited to 'p/scripts/category.js') diff --git a/app/views/helpers/javascript_vars.phtml b/app/views/helpers/javascript_vars.phtml index 011b17b7a..cdbf24eab 100644 --- a/app/views/helpers/javascript_vars.phtml +++ b/app/views/helpers/javascript_vars.phtml @@ -1,21 +1,30 @@ +"use strict"; conf->mark_when; -echo 'var ', - 'help_url="', FRESHRSS_WIKI, '"', - ',hide_posts=', ($this->conf->display_posts || Minz_Request::param('output') === 'reader') ? 'false' : 'true', - ',display_order="', Minz_Request::param('order', $this->conf->sort_order), '"', - ',auto_mark_article=', $mark['article'] ? 'true' : 'false', - ',auto_mark_site=', $mark['site'] ? 'true' : 'false', - ',auto_mark_scroll=', $mark['scroll'] ? 'true' : 'false', - ',auto_load_more=', $this->conf->auto_load_more ? 'true' : 'false', - ',does_lazyload=', $this->conf->lazyload ? 'true' : 'false', - ',sticky_post=', $this->conf->sticky_post ? 'true' : 'false'; - +$mail = Minz_Session::param ('mail', false); +$auto_actualize = Minz_Session::param('actualize_feeds', false); +$hide_posts = ($this->conf->display_posts || + Minz_Request::param('output') === 'reader'); $s = $this->conf->shortcuts; -echo ',shortcuts={', + +echo 'var context={', + 'hide_posts:', $hide_posts ? 'false' : 'true', ',', + 'display_order:"', Minz_Request::param('order', $this->conf->sort_order), '",', + 'auto_mark_article:', $mark['article'] ? 'true' : 'false', ',', + 'auto_mark_site:', $mark['site'] ? 'true' : 'false', ',', + 'auto_mark_scroll:', $mark['scroll'] ? 'true' : 'false', ',', + 'auto_load_more:', $this->conf->auto_load_more ? 'true' : 'false', ',', + 'auto_actualize_feeds:', $auto_actualize ? 'true' : 'false', ',', + 'does_lazyload:', $this->conf->lazyload ? 'true' : 'false', ',', + 'sticky_post:', $this->conf->sticky_post ? 'true' : 'false', ',', + 'html5_notif_timeout:', $this->conf->html5_notif_timeout, ',', + 'auth_type:"', Minz_Configuration::authType(), '",', + 'current_user_mail:', $mail ? ('"' . $mail . '"') : 'null', ',', + 'current_view:"', Minz_Request::param('output', 'normal'), '"', +"},\n"; + +echo 'shortcuts={', 'mark_read:"', $s['mark_read'], '",', 'mark_favorite:"', $s['mark_favorite'], '",', 'go_website:"', $s['go_website'], '",', @@ -32,32 +41,20 @@ echo ',shortcuts={', 'close_dropdown:"', $s['close_dropdown'], '"', "},\n"; -if (Minz_Request::param ('output') === 'global') { - echo "iconClose='", _i('close'), "',\n"; -} - -$authType = Minz_Configuration::authType(); -if ($authType === 'persona') { - // If user is disconnected, current_user_mail MUST be null - $mail = Minz_Session::param ('mail', false); - if ($mail) { - echo 'current_user_mail="' . $mail . '",'; - } else { - echo 'current_user_mail=null,'; - } -} - -echo 'authType="', $authType, '",', - 'url_freshrss="', _url ('index', 'index'), '",', - 'url_login="', _url ('index', 'login'), '",', - 'url_logout="', _url ('index', 'logout'), '",'; - -echo 'str_confirmation_default="', _t('confirm_action'), '"', ",\n"; -echo 'str_notif_title_articles="', _t('notif_title_new_articles'), '"', ",\n"; -echo 'str_notif_body_articles="', _t('notif_body_new_articles'), '"', ",\n"; -echo 'str_category_empty="', _t('category_empty'), '"', ",\n"; -echo 'html5_notif_timeout=', $this->conf->html5_notif_timeout,",\n"; +echo 'url={', + 'index:"', _url('index', 'index'), '",', + 'login:"', _url('index', 'login'), '",', + 'logout:"', _url('index', 'logout'), '",', + 'help:"', FRESHRSS_WIKI, '"', +"},\n"; +echo 'i18n={', + 'confirmation_default:"', _t('confirm_action'), '",', + 'notif_title_articles:"', _t('notif_title_new_articles'), '",', + 'notif_body_articles:"', _t('notif_body_new_articles'), '",', + 'category_empty:"', _t('category_empty'), '"', +"},\n"; -$autoActualise = Minz_Session::param('actualize_feeds', false); -echo 'auto_actualize_feeds=', $autoActualise ? 'true' : 'false', ";\n"; +echo 'icons={', + 'close:\'', _i('close'), '\'', +"}\n"; \ No newline at end of file diff --git a/p/scripts/category.js b/p/scripts/category.js index dc5df67e4..c33e68528 100644 --- a/p/scripts/category.js +++ b/p/scripts/category.js @@ -20,13 +20,13 @@ function dragend_process(t) { $(t).remove(); if (parent.children().length <= 0) { - parent.append('
  • ' + str_category_empty + '
  • '); + parent.append('
  • ' + i18n['category_empty'] + '
  • '); } } } function init_draggable() { - if (!(window.$ && window.url_freshrss)) { + if (!(window.$ && window.i18n)) { if (window.console) { console.log('FreshRSS waiting for JS…'); } diff --git a/p/scripts/global_view.js b/p/scripts/global_view.js index 7105520a6..6e1f61066 100644 --- a/p/scripts/global_view.js +++ b/p/scripts/global_view.js @@ -40,7 +40,7 @@ function load_panel(link) { function init_close_panel() { $("#panel .close").click(function () { - $("#panel").html('' + window.iconClose + ''); + $("#panel").html('' + icons['close'] + ''); init_close_panel(); $("#panel").slideToggle(); $("#overlay").fadeOut(); diff --git a/p/scripts/main.js b/p/scripts/main.js index 5793bb50b..ad33f6c57 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -4,14 +4,6 @@ var $stream = null, shares = 0, ajax_loading = false; -function is_normal_mode() { - return $stream.hasClass('normal'); -} - -function is_global_mode() { - return $stream.hasClass('global'); -} - function redirect(url, new_tab) { if (url) { if (new_tab) { @@ -226,7 +218,7 @@ function toggleContent(new_active, old_active) { return; } - if (does_lazyload) { + if (context['does_lazyload']) { new_active.find('img[data-original], iframe[data-original]').each(function () { this.setAttribute('src', this.getAttribute('data-original')); this.removeAttribute('data-original'); @@ -245,12 +237,12 @@ function toggleContent(new_active, old_active) { var box_to_move = "html,body", relative_move = false; - if (is_global_mode()) { + if (context['current_view'] == 'global') { box_to_move = "#panel"; relative_move = true; } - if (sticky_post) { + if (context['sticky_post']) { var prev_article = new_active.prevAll('.flux'), new_pos = new_active.position().top, old_scroll = $(box_to_move).scrollTop(); @@ -259,7 +251,7 @@ function toggleContent(new_active, old_active) { new_pos = prev_article.position().top; } - if (hide_posts) { + if (context['hide_posts']) { if (relative_move) { new_pos += old_scroll; } @@ -278,7 +270,7 @@ function toggleContent(new_active, old_active) { } } - if (auto_mark_article && new_active.hasClass('active')) { + if (context['auto_mark_article'] && new_active.hasClass('active')) { mark_read(new_active, true); } } @@ -378,7 +370,7 @@ function collapse_entry() { var flux_current = $(".flux.current"); flux_current.toggleClass("active"); - if (isCollapsed && auto_mark_article) { + if (isCollapsed && context['auto_mark_article']) { mark_read(flux_current, true); } } @@ -457,12 +449,12 @@ function inMarkViewport(flux, box_to_follow, relative_follow) { function init_posts() { var box_to_follow = $(window), relative_follow = false; - if (is_global_mode()) { + if (context['current_view'] == 'global') { box_to_follow = $("#panel"); relative_follow = true; } - if (auto_mark_scroll) { + if (context['auto_mark_scroll']) { box_to_follow.scroll(function () { $('.not_read:visible').each(function () { if ($(this).children(".flux_content").is(':visible') && inMarkViewport($(this), box_to_follow, relative_follow)) { @@ -472,7 +464,7 @@ function init_posts() { }); } - if (auto_load_more) { + if (context['auto_load_more']) { box_to_follow.scroll(function () { var load_more = $("#load_more"); if (!load_more.is(':visible')) { @@ -492,7 +484,7 @@ function init_posts() { } function init_column_categories() { - if (!is_normal_mode()) { + if (context['current_view'] !== 'normal') { return; } $('#aside_flux').on('click', '.category>a.dropdown-toggle', function () { @@ -632,7 +624,7 @@ function init_shortcuts() { shortcut.add(shortcuts.go_website, function () { var url_website = $('.flux.current > .flux_header > .title > a').attr("href"); - if (auto_mark_site) { + if (context['auto_mark_site']) { $(".flux.current").each(function () { mark_read($(this), true); }); @@ -656,7 +648,7 @@ function init_shortcuts() { }); shortcut.add(shortcuts.help, function () { - redirect(help_url, true); + redirect(url['help'], true); }, { 'disable_in_input': true }); @@ -678,7 +670,7 @@ function init_stream(divStream) { new_active = $(this).parent(); isCollapsed = true; if (e.target.tagName.toUpperCase() === 'A') { //Leave real links alone - if (auto_mark_article) { + if (context['auto_mark_article']) { mark_read(new_active, true); } return true; @@ -724,7 +716,7 @@ function init_stream(divStream) { $(this).attr('target', '_blank'); }); - if (auto_mark_site) { + if (context['auto_mark_site']) { // catch mouseup instead of click so we can have the correct behaviour // with middle button click (scroll button). divStream.on('mouseup', '.flux .link > a', function (e) { @@ -784,7 +776,7 @@ function init_actualize() { return false; }); - if (auto_actualize_feeds) { + if (context['auto_actualize_feeds']) { auto = true; $("#actualize").click(); } @@ -855,9 +847,9 @@ function notifs_html5_show(nb) { return } - var notification = new window.Notification(str_notif_title_articles, { + var notification = new window.Notification(i18n['notif_title_articles'], { icon: "../themes/icons/favicon-256.png", - body: str_notif_body_articles.replace("\d", nb), + body: i18n['notif_body_articles.replace("\d", nb)'], tag: "freshRssNewArticles" }); @@ -865,10 +857,10 @@ function notifs_html5_show(nb) { window.location.reload(); } - if (html5_notif_timeout !== 0){ + if (context['html5_notif_timeout'] !== 0){ setTimeout(function() { notification.close(); - }, html5_notif_timeout * 1000); + }, context['html5_notif_timeout'] * 1000); } } @@ -922,7 +914,7 @@ function load_more_posts() { $.get(url_load_more, function (data) { box_load_more.children('.flux:last').after($('#stream', data).children('.flux, .day')); $('.pagination').replaceWith($('.pagination', data)); - if (display_order === 'ASC') { + if (context['display_order'] === 'ASC') { $('#nav_menu_read_all > .read_all').attr( 'formaction', $('#bigMarkAsRead').attr('formaction') ); @@ -953,7 +945,7 @@ function focus_search() { function init_load_more(box) { box_load_more = box; - if (!does_lazyload) { + if (!context['does_lazyload']) { $('img[postpone], audio[postpone], iframe[postpone], video[postpone]').each(function () { this.removeAttribute('postpone'); }); @@ -1062,7 +1054,7 @@ function init_persona() { }); navigator.id.watch({ - loggedInUser: current_user_mail, + loggedInUser: context['current_user_mail'], onlogin: function(assertion) { // A user has logged in! Here you need to: @@ -1070,13 +1062,13 @@ function init_persona() { // 2. Update your UI. $.ajax ({ type: 'POST', - url: url_login, + url: url['login'], data: {assertion: assertion}, success: function(res, status, xhr) { /*if (res.status === 'failure') { alert (res_obj.reason); } else*/ if (res.status === 'okay') { - location.href = url_freshrss; + location.href = url['index']; } }, error: function(res, status, xhr) { @@ -1091,9 +1083,9 @@ function init_persona() { // (That's a literal JavaScript null. Not false, 0, or undefined. null.) $.ajax ({ type: 'POST', - url: url_logout, + url: url['logout'], success: function(res, status, xhr) { - location.href = url_freshrss; + location.href = url['index']; }, error: function(res, status, xhr) { //alert("logout failure" + res); @@ -1108,7 +1100,7 @@ function init_confirm_action() { $('body').on('click', '.confirm', function () { var str_confirmation = $(this).attr('data-str-confirm'); if (!str_confirmation) { - str_confirmation = str_confirmation_default; + str_confirmation = i18n['confirmation_default']; } return confirm(str_confirmation); @@ -1274,7 +1266,7 @@ function init_slider_observers() { } function init_all() { - if (!(window.$ && window.url_freshrss)) { + if (!(window.$ && window.context)) { if (window.console) { console.log('FreshRSS waiting for JS…'); } @@ -1282,7 +1274,7 @@ function init_all() { return; } init_notifications(); - switch (authType) { + switch (context['auth_type']) { case 'persona': init_persona(); break; -- cgit v1.2.3 From 3652dea854200f31492a71243727f6a1be317c4a Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 6 Aug 2016 13:18:46 +0200 Subject: JSHint and safer async init_normal --- p/scripts/category.js | 4 +- p/scripts/global_view.js | 3 + p/scripts/install.js | 1 + p/scripts/main.js | 140 +++++++++++++++++++++++++---------------------- p/scripts/repartition.js | 18 +++--- p/scripts/stats.js | 3 + 6 files changed, 93 insertions(+), 76 deletions(-) (limited to 'p/scripts/category.js') diff --git a/p/scripts/category.js b/p/scripts/category.js index c33e68528..be9605bec 100644 --- a/p/scripts/category.js +++ b/p/scripts/category.js @@ -1,4 +1,6 @@ "use strict"; +/* globals i18n */ +/* jshint globalstrict: true */ var loading = false, dnd_successful = false; @@ -20,7 +22,7 @@ function dragend_process(t) { $(t).remove(); if (parent.children().length <= 0) { - parent.append('
  • ' + i18n['category_empty'] + '
  • '); + parent.append('
  • ' + i18n.category_empty + '
  • '); } } } diff --git a/p/scripts/global_view.js b/p/scripts/global_view.js index 7d7ba22b5..f1b9c8ad4 100644 --- a/p/scripts/global_view.js +++ b/p/scripts/global_view.js @@ -1,4 +1,7 @@ "use strict"; +/* globals init_load_more, init_posts, init_stream */ +/* jshint globalstrict: true */ + var panel_loading = false; function load_panel(link) { diff --git a/p/scripts/install.js b/p/scripts/install.js index 57fc2450a..d7f4e7b02 100644 --- a/p/scripts/install.js +++ b/p/scripts/install.js @@ -1,4 +1,5 @@ "use strict"; +/* jshint globalstrict: true */ function show_password() { var button = this; diff --git a/p/scripts/main.js b/p/scripts/main.js index 01c8c9cf5..21e26d6df 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -1,4 +1,7 @@ "use strict"; +/* globals context, i18n, shortcut, shortcuts, url */ +/* jshint globalstrict: true */ + var $stream = null, isCollapsed = true, shares = 0, @@ -49,9 +52,7 @@ function numberFormat(nStr) { function incLabel(p, inc, spaceAfter) { var i = str2int(p) + inc; - return i > 0 - ? ((spaceAfter ? '' : ' ') + '(' + numberFormat(i) + ')' + (spaceAfter ? ' ' : '')) - : ''; + return i > 0 ? ((spaceAfter ? '' : ' ') + '(' + numberFormat(i) + ')' + (spaceAfter ? ' ' : '')) : ''; } function incUnreadsFeed(article, feed_id, nb) { @@ -217,7 +218,7 @@ function toggleContent(new_active, old_active) { return; } - if (context['does_lazyload']) { + if (context.does_lazyload) { new_active.find('img[data-original], iframe[data-original]').each(function () { this.setAttribute('src', this.getAttribute('data-original')); this.removeAttribute('data-original'); @@ -230,17 +231,17 @@ function toggleContent(new_active, old_active) { } old_active.removeClass("active current"); new_active.addClass("current"); - if (context['auto_remove_article'] && !old_active.hasClass('not_read')) { + if (context.auto_remove_article && !old_active.hasClass('not_read')) { auto_remove(old_active); } } else { new_active.toggleClass('active'); } - var relative_move = context['current_view'] === 'global', + var relative_move = context.current_view === 'global', box_to_move = $(relative_move ? "#panel" : "html,body"); - if (context['sticky_post']) { + if (context.sticky_post) { var prev_article = new_active.prevAll('.flux'), new_pos = new_active.offset().top, old_scroll = box_to_move.scrollTop(); @@ -252,7 +253,7 @@ function toggleContent(new_active, old_active) { } } - if (context['hide_posts']) { + if (context.hide_posts) { if (relative_move) { new_pos += old_scroll; } @@ -271,7 +272,7 @@ function toggleContent(new_active, old_active) { } } - if (context['auto_mark_article'] && new_active.hasClass('active')) { + if (context.auto_mark_article && new_active.hasClass('active')) { mark_read(new_active, true); } } @@ -381,7 +382,7 @@ function collapse_entry() { var flux_current = $(".flux.current"); flux_current.toggleClass("active"); - if (isCollapsed && context['auto_mark_article']) { + if (isCollapsed && context.auto_mark_article) { mark_read(flux_current, true); } } @@ -456,11 +457,11 @@ function inMarkViewport(flux, box_to_follow) { function init_posts() { var box_to_follow = $(window); - if (context['current_view'] === 'global') { + if (context.current_view === 'global') { box_to_follow = $("#panel"); } - if (context['auto_mark_scroll']) { + if (context.auto_mark_scroll) { box_to_follow.scroll(function () { $('.not_read:visible').each(function () { if ($(this).children(".flux_content").is(':visible') && inMarkViewport($(this), box_to_follow)) { @@ -470,7 +471,7 @@ function init_posts() { }); } - if (context['auto_load_more']) { + if (context.auto_load_more) { box_to_follow.scroll(function () { var load_more = $("#load_more"); if (!load_more.is(':visible')) { @@ -487,7 +488,7 @@ function init_posts() { } function init_column_categories() { - if (context['current_view'] !== 'normal') { + if (context.current_view !== 'normal') { return; } @@ -559,14 +560,16 @@ function init_shortcuts() { }, { 'disable_in_input': true }); - for(var i = 1; i < 10; i++){ - shortcut.add(i.toString(), function (e) { - if ($('#dropdown-query').siblings('.dropdown-menu').is(':visible')) { - user_filter(String.fromCharCode(e.keyCode)); - } else { - auto_share(String.fromCharCode(e.keyCode)); - } - }, { + + function addShortcut(evt) { + if ($('#dropdown-query').siblings('.dropdown-menu').is(':visible')) { + user_filter(String.fromCharCode(evt.keyCode)); + } else { + auto_share(String.fromCharCode(evt.keyCode)); + } + } + for(var i = 1; i < 10; i++) { + shortcut.add(i.toString(), addShortcut, { 'disable_in_input': true }); } @@ -628,7 +631,7 @@ function init_shortcuts() { shortcut.add(shortcuts.go_website, function () { var url_website = $('.flux.current > .flux_header > .title > a').attr("href"); - if (context['auto_mark_site']) { + if (context.auto_mark_site) { $(".flux.current").each(function () { mark_read($(this), true); }); @@ -652,7 +655,7 @@ function init_shortcuts() { }); shortcut.add(shortcuts.help, function () { - redirect(url['help'], true); + redirect(url.help, true); }, { 'disable_in_input': true }); @@ -674,7 +677,7 @@ function init_stream(divStream) { new_active = $(this).parent(); isCollapsed = true; if (e.target.tagName.toUpperCase() === 'A') { //Leave real links alone - if (context['auto_mark_article']) { + if (context.auto_mark_article) { mark_read(new_active, true); } return true; @@ -684,7 +687,7 @@ function init_stream(divStream) { divStream.on('click', '.flux a.read', function () { var active = $(this).parents(".flux"); - if (context['auto_remove_article'] && active.hasClass('not_read')) { + if (context.auto_remove_article && active.hasClass('not_read')) { auto_remove(active); } mark_read(active, false); @@ -710,9 +713,9 @@ function init_stream(divStream) { if (e.which == 2) { // If middle click, we want same behaviour as CTRL+click. - var e = jQuery.Event("click"); - e.ctrlKey = true; - $(this).trigger(e); + var ev = jQuery.Event("click"); + ev.ctrlKey = true; + $(this).trigger(ev); } else if(e.which == 1) { // Normal click, just toggle article. $(this).parent().click(); @@ -723,7 +726,7 @@ function init_stream(divStream) { $(this).attr('target', '_blank'); }); - if (context['auto_mark_site']) { + if (context.auto_mark_site) { // catch mouseup instead of click so we can have the correct behaviour // with middle button click (scroll button). divStream.on('mouseup', '.flux .link > a', function (e) { @@ -765,17 +768,17 @@ var feed_processed = 0; function updateFeed(feeds, feeds_count) { var feed = feeds.pop(); - if (feed == undefined) { + if (!feed) { return; } $.ajax({ type: 'POST', - url: feed['url'], + url: feed.url, }).complete(function (data) { feed_processed++; $("#actualizeProgress .progress").html(feed_processed + " / " + feeds_count); - $("#actualizeProgress .title").html(feed['title']); + $("#actualizeProgress .title").html(feed.title); if (feed_processed === feeds_count) { window.location.reload(); @@ -819,7 +822,7 @@ function init_actualize() { return false; }); - if (context['auto_actualize_feeds']) { + if (context.auto_actualize_feeds) { auto = true; $("#actualize").click(); } @@ -887,12 +890,12 @@ function notifs_html5_ask_permission() { function notifs_html5_show(nb) { if (notifs_html5_permission !== "granted") { - return + return; } - var notification = new window.Notification(i18n['notif_title_articles'], { + var notification = new window.Notification(i18n.notif_title_articles, { icon: "../themes/icons/favicon-256.png", - body: i18n['notif_body_articles'].replace('%d', nb), + body: i18n.notif_body_articles.replace('%d', nb), tag: "freshRssNewArticles" }); @@ -900,10 +903,10 @@ function notifs_html5_show(nb) { window.location.reload(); }; - if (context['html5_notif_timeout'] !== 0) { + if (context.html5_notif_timeout !== 0) { setTimeout(function() { notification.close(); - }, context['html5_notif_timeout'] * 1000); + }, context.html5_notif_timeout * 1000); } } @@ -930,7 +933,7 @@ function refreshUnreads() { (nbUnreads - feed_unreads > 0)) { $('#new-article').attr('aria-hidden', 'false').show(); new_articles = true; - }; + } }); var nb_unreads = str2int($('.category.all .title').attr('data-unread')); @@ -957,7 +960,7 @@ function load_more_posts() { $.get(url_load_more, function (data) { box_load_more.children('.flux:last').after($('#stream', data).children('.flux, .day')); $('.pagination').replaceWith($('.pagination', data)); - if (context['display_order'] === 'ASC') { + if (context.display_order === 'ASC') { $('#nav_menu_read_all > .read_all').attr( 'formaction', $('#bigMarkAsRead').attr('formaction') ); @@ -988,7 +991,7 @@ function focus_search() { function init_load_more(box) { box_load_more = box; - if (!context['does_lazyload']) { + if (!context.does_lazyload) { $('img[postpone], audio[postpone], iframe[postpone], video[postpone]').each(function () { this.removeAttribute('postpone'); }); @@ -1027,6 +1030,7 @@ function poormanSalt() { //If crypto.getRandomValues is not available } function init_crypto_form() { + /* globals dcodeIO */ var $crypto_form = $('#crypto-form'); if ($crypto_form.length === 0) { return; @@ -1050,7 +1054,7 @@ function init_crypto_form() { dataType: 'json', async: false }).done(function (data) { - if (data.salt1 == '' || data.nonce == '') { + if (!data.salt1 || !data.nonce) { openNotification('Invalid user!', 'bad'); } else { try { @@ -1058,7 +1062,7 @@ function init_crypto_form() { s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? dcodeIO.bcrypt.genSaltSync(4) : poormanSalt()); $('#challenge').val(c); - if (s == '' || c == '') { + if (!s || !c) { openNotification('Crypto error!', 'bad'); } else { success = true; @@ -1083,7 +1087,7 @@ function init_confirm_action() { $('body').on('click', '.confirm', function () { var str_confirmation = $(this).attr('data-str-confirm'); if (!str_confirmation) { - str_confirmation = i18n['confirmation_default']; + str_confirmation = i18n.confirmation_default; } return confirm(str_confirmation); @@ -1092,13 +1096,13 @@ function init_confirm_action() { function init_print_action() { $('.item.share > a[href="#"]').click(function () { - var content = "" - + $(".flux.current .content").html() - + ""; + var content = "" + + $(".flux.current .content").html() + + ""; var tmp_window = window.open(); tmp_window.document.writeln(content); @@ -1291,6 +1295,22 @@ function parseJsonVars() { window.icons = json.icons; } +function init_normal() { + $stream = $('#stream'); + if ($stream.length < 1) { + if (window.console) { + console.log('FreshRSS waiting for content…'); + } + window.setTimeout(init_normal, 50); + return; + } + init_column_categories(); + init_stream($stream); + init_shortcuts(); + init_actualize(); + faviconNbUnread(); +} + function init_beforeDOM() { if (!window.$) { if (window.console) { @@ -1300,20 +1320,8 @@ function init_beforeDOM() { return; } init_confirm_action(); - if (['normal', 'reader', 'global'].indexOf(context['current_view']) >= 0) { - $stream = $('#stream'); - if ($stream.length < 1) { - if (window.console) { - console.log('FreshRSS waiting for content…'); - } - window.setTimeout(init_beforeDOM, 50); - return; - } - init_column_categories(); - init_stream($stream); - init_shortcuts(); - init_actualize(); - faviconNbUnread(); + if (['normal', 'reader', 'global'].indexOf(context.current_view) >= 0) { + init_normal(); } } diff --git a/p/scripts/repartition.js b/p/scripts/repartition.js index a391de2f2..be70456fa 100644 --- a/p/scripts/repartition.js +++ b/p/scripts/repartition.js @@ -1,4 +1,7 @@ "use strict"; +/* globals Flotr, numberFormat */ +/* jshint globalstrict: true */ + function initStats() { if (!window.Flotr) { if (window.console) { @@ -19,9 +22,8 @@ function initStats() { { grid: {verticalLines: false}, xaxis: {noTicks: 23, - tickFormatter: function(x) { - var x = parseInt(x); - return x + 1; + tickFormatter: function(x1) { + return 1 + parseInt(x1); }, min: -0.9, max: 23.9, @@ -38,9 +40,8 @@ function initStats() { { grid: {verticalLines: false}, xaxis: {noTicks: 6, - tickFormatter: function(x) { - var x = parseInt(x); - return stats.days[x]; + tickFormatter: function(x2) { + return stats.days[parseInt(x2)]; }, min: -0.9, max: 6.9, @@ -57,9 +58,8 @@ function initStats() { { grid: {verticalLines: false}, xaxis: {noTicks: 12, - tickFormatter: function(x) { - var x = parseInt(x); - return stats.months[(x - 1)]; + tickFormatter: function(x3) { + return stats.months[parseInt(x3) - 1]; }, min: 0.1, max: 12.9, diff --git a/p/scripts/stats.js b/p/scripts/stats.js index 2e8ab6e27..9cd14721c 100644 --- a/p/scripts/stats.js +++ b/p/scripts/stats.js @@ -1,4 +1,7 @@ "use strict"; +/* globals Flotr, numberFormat */ +/* jshint globalstrict: true */ + function initStats() { if (!window.Flotr) { if (window.console) { -- cgit v1.2.3 From a051970d5b15a60e79ac2428280652486644c11c Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 6 Aug 2016 14:13:03 +0200 Subject: jQuery 3 compatibility https://jquery.com/upgrade-guide/3.0/ * event.props removed https://jquery.com/upgrade-guide/3.0/#breaking-change-jquery-event-props-and-jquery-event-fixhooks-removed https://github.com/jquery/api.jquery.com/issues/405 * jqXHR.success(), jqXHR.error(), and jqXHR.complete() removed --- p/scripts/category.js | 18 ++++++++---------- p/scripts/main.js | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'p/scripts/category.js') diff --git a/p/scripts/category.js b/p/scripts/category.js index c33e68528..8c7ba37b0 100644 --- a/p/scripts/category.js +++ b/p/scripts/category.js @@ -34,15 +34,13 @@ function init_draggable() { return; } - $.event.props.push('dataTransfer'); - var draggable = '[draggable="true"]', dropzone = '[dropzone="move"]'; $('.drop-section').on('dragstart', draggable, function(e) { - e.dataTransfer.effectAllowed = 'move'; - e.dataTransfer.setData('text/html', e.target.outerHTML); - e.dataTransfer.setData('text', e.target.getAttribute('data-feed-id')); + e.originalEvent.dataTransfer.effectAllowed = 'move'; + e.originalEvent.dataTransfer.setData('text/html', e.target.outerHTML); + e.originalEvent.dataTransfer.setData('text', e.target.getAttribute('data-feed-id')); e.target.style.opacity = 0.3; dnd_successful = false; @@ -74,13 +72,13 @@ function init_draggable() { $(this).removeClass('drag-hover'); }); $('.drop-section').on('dragover', dropzone, function(e) { - e.dataTransfer.dropEffect = "move"; + e.originalEvent.dataTransfer.dropEffect = "move"; e.preventDefault(); return false; }); $('.drop-section').on('drop', dropzone, function(e) { - var feed_id = e.dataTransfer.getData('text'), + var feed_id = e.originalEvent.dataTransfer.getData('text'), cat_id = e.target.parentNode.getAttribute('data-cat-id'); loading = true; @@ -92,13 +90,13 @@ function init_draggable() { f_id: feed_id, c_id: cat_id } - }).success(function() { - $(e.target).after(e.dataTransfer.getData('text/html')); + }).done(function() { + $(e.target).after(e.originalEvent.dataTransfer.getData('text/html')); if ($(e.target).hasClass('disabled')) { $(e.target).remove(); } dnd_successful = true; - }).complete(function() { + }).always(function() { loading = false; }); diff --git a/p/scripts/main.js b/p/scripts/main.js index 01c8c9cf5..c95df54fa 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -772,7 +772,7 @@ function updateFeed(feeds, feeds_count) { $.ajax({ type: 'POST', url: feed['url'], - }).complete(function (data) { + }).always(function (data) { feed_processed++; $("#actualizeProgress .progress").html(feed_processed + " / " + feeds_count); $("#actualizeProgress .title").html(feed['title']); -- cgit v1.2.3 From de2c6fab7ae2f6c456c2e98196b01f368dba9917 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 6 Aug 2016 15:43:28 +0200 Subject: Fix drag in Chrome --- p/scripts/category.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'p/scripts/category.js') diff --git a/p/scripts/category.js b/p/scripts/category.js index fe8b4c058..e882da0c8 100644 --- a/p/scripts/category.js +++ b/p/scripts/category.js @@ -40,10 +40,11 @@ function init_draggable() { dropzone = '[dropzone="move"]'; $('.drop-section').on('dragstart', draggable, function(e) { + var drag = $(e.target).closest('[draggable]')[0]; e.originalEvent.dataTransfer.effectAllowed = 'move'; - e.originalEvent.dataTransfer.setData('text/html', e.target.outerHTML); - e.originalEvent.dataTransfer.setData('text', e.target.getAttribute('data-feed-id')); - e.target.style.opacity = 0.3; + e.originalEvent.dataTransfer.setData('text/html', drag.outerHTML); + e.originalEvent.dataTransfer.setData('text', drag.getAttribute('data-feed-id')); + drag.style.opacity = 0.3; dnd_successful = false; }); @@ -81,6 +82,7 @@ function init_draggable() { }); $('.drop-section').on('drop', dropzone, function(e) { var feed_id = e.originalEvent.dataTransfer.getData('text'), + html = e.originalEvent.dataTransfer.getData('text/html'), cat_id = e.target.parentNode.getAttribute('data-cat-id'); loading = true; @@ -93,7 +95,7 @@ function init_draggable() { c_id: cat_id } }).done(function() { - $(e.target).after(e.originalEvent.dataTransfer.getData('text/html')); + $(e.target).after(html); if ($(e.target).hasClass('disabled')) { $(e.target).remove(); } -- cgit v1.2.3 From 157781c8eb91531627adfe9220ac3197e6b15325 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 6 Aug 2016 20:52:08 +0200 Subject: Fix drag in Internet Explorer Internet Explorer does not support setData('text/html') and setData() is deprecated https://msdn.microsoft.com/en-us/library/ms536744(v=vs.85).aspx --- p/scripts/category.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'p/scripts/category.js') diff --git a/p/scripts/category.js b/p/scripts/category.js index e882da0c8..29c049924 100644 --- a/p/scripts/category.js +++ b/p/scripts/category.js @@ -27,6 +27,9 @@ function dragend_process(t) { } } +var dragFeedId = '', + dragHtml = ''; + function init_draggable() { if (!(window.$ && window.i18n)) { if (window.console) { @@ -42,8 +45,9 @@ function init_draggable() { $('.drop-section').on('dragstart', draggable, function(e) { var drag = $(e.target).closest('[draggable]')[0]; e.originalEvent.dataTransfer.effectAllowed = 'move'; - e.originalEvent.dataTransfer.setData('text/html', drag.outerHTML); - e.originalEvent.dataTransfer.setData('text', drag.getAttribute('data-feed-id')); + dragHtml = drag.outerHTML; + dragFeedId = drag.getAttribute('data-feed-id'); + e.originalEvent.dataTransfer.setData('text', dragFeedId); drag.style.opacity = 0.3; dnd_successful = false; @@ -81,27 +85,25 @@ function init_draggable() { return false; }); $('.drop-section').on('drop', dropzone, function(e) { - var feed_id = e.originalEvent.dataTransfer.getData('text'), - html = e.originalEvent.dataTransfer.getData('text/html'), - cat_id = e.target.parentNode.getAttribute('data-cat-id'); - loading = true; $.ajax({ type: 'POST', url: './?c=feed&a=move', data : { - f_id: feed_id, - c_id: cat_id + f_id: dragFeedId, + c_id: e.target.parentNode.getAttribute('data-cat-id'), } }).done(function() { - $(e.target).after(html); + $(e.target).after(dragHtml); if ($(e.target).hasClass('disabled')) { $(e.target).remove(); } dnd_successful = true; }).always(function() { loading = false; + dragFeedId = ''; + dragHtml = ''; }); $(this).removeClass('drag-hover'); -- cgit v1.2.3 From 396ebb0fd20400d2aa014bf05187d3e1ae1b26a0 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 7 Aug 2016 00:17:34 +0200 Subject: Minor JavaScript problems with drag & drop Independent of the jQuery update --- p/scripts/category.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'p/scripts/category.js') diff --git a/p/scripts/category.js b/p/scripts/category.js index 29c049924..eb08ecd6e 100644 --- a/p/scripts/category.js +++ b/p/scripts/category.js @@ -6,17 +6,19 @@ var loading = false, dnd_successful = false; function dragend_process(t) { - t.style.display = 'none'; + t.setAttribute('draggable', 'false'); if (loading) { window.setTimeout(function() { dragend_process(t); }, 50); + return; } if (!dnd_successful) { - t.style.display = 'block'; - t.style.opacity = 1.0; + t.style.display = ''; + t.style.opacity = ''; + t.setAttribute('draggable', 'true'); } else { var parent = $(t.parentNode); $(t).remove(); -- cgit v1.2.3 From d9bf9b2c6f0b2cc9dec3b638841b7e3040dcf46f Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 24 Sep 2016 17:32:30 +0200 Subject: Fix bug move feed to another category CSRF --- p/scripts/category.js | 1 + 1 file changed, 1 insertion(+) (limited to 'p/scripts/category.js') diff --git a/p/scripts/category.js b/p/scripts/category.js index eb08ecd6e..fbcd83a01 100644 --- a/p/scripts/category.js +++ b/p/scripts/category.js @@ -95,6 +95,7 @@ function init_draggable() { data : { f_id: dragFeedId, c_id: e.target.parentNode.getAttribute('data-cat-id'), + _csrf: context.csrf, } }).done(function() { $(e.target).after(dragHtml); -- cgit v1.2.3