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 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (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 + '
  • '); } } } -- 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