Commit 98a38d90 authored by Gold's avatar Gold
Browse files

Bug 1907000 - fix Add entry drag n drop.

* Added a new class to force the pointer cursor.
* Added this class to the Add entry anchors.
* Added a data flag to assist spotting the drag n drop activity when Add
entry is the element clicked for dragging the block.
* Added js to test this data flag before submitting on click.
* Renamed `AddNewPostShortcut()` in recent/tagged posts JS to better
identify them.

Change-Id: I3e367cd9323e9eb5ef18495d33ce6fa9c3c7c48d
parent 7f8f9c93
function addNewPostShortcut(blockid, viewid) {
var addentry = jQuery('#blockinstance_' + blockid + ' .blockinstance-content');
addentry.find('a').first().on("click", function(e) {
function recentPostsAddNewPostShortcut(blockid, viewid) {
var addEntryAnchor = jQuery('#blockinstance_' + blockid + ' .blockinstance-content').find('a').first();
// Add support for seeing drag and drop.
addEntryAnchor.mousedown(function(){
var p = $(this).closest('div.block');
p.data('dragging', false);
})
.mousemove(function(){
var p = $(this).closest('div.block');
p.data('dragging', true);
})
.mouseup(function(){
setTimeout(function(p) {
target = $('#blockinstance_' + blockid + ' .blockinstance-content');
var p = target.find('a').first().closest('div.block');
p.data('dragging', false);
}, 1);
});
// React to the click action
addEntryAnchor.on("click", function(e) {
var p = $(this).closest('div.block');
if (p.data('dragging')) {
// We are dragging by the anchor, not clicking it.
return;
}
e.preventDefault();
var blogselect = addentry.find('select').first().val();
var blogselect = addEntryAnchor.find('select').first().val();
if (!blogselect) {
blogselect = jQuery(this).find('span').first().attr('id').match( /\d+/);
}
......
......@@ -32,7 +32,7 @@ class PluginBlocktypeRecentposts extends MaharaCoreBlocktype {
return array(
array(
'file' => 'js/recentposts.js',
'initjs' => "addNewPostShortcut($blockid, $viewid);",
'initjs' => "recentPostsAddNewPostShortcut($blockid, $viewid);",
)
);
}
......
var addNewTaggedPostShortcut = (function($) {
var taggedPostsAddNewPostShortcut = (function($) {
return function (blockid, viewid) {
$('#blockinstance_' + blockid + ' a.btnshortcut').each(function() {
$(this).off();
// Prevent the dragging of a block by the anchor from acting on
// the click event.
$(this)
.mousedown(function(){
var p = $(this).closest('div.shortcut');
p.data('dragging', false);
})
.mousemove(function(){
var p = $(this).closest('div.shortcut');
p.data('dragging', true);
})
.mouseup(function(){
setTimeout(function(p) {
var p = $(this).closest('div.shortcut');
p.data('dragging', false);
}, 1);
});
$(this).on('click', function(e) {
e.preventDefault();
var p = $(this).closest('div.shortcut');
if (p.data('dragging')) {
// We are dragging by the anchor, not clicking it.
return;
}
var selectedBlog = p.find('select.select').first();
var currentTag = p.find('input.select').first();
var BlogIDInput = $('<input>', {'name': 'blog', 'type': 'text', 'value': selectedBlog[0].value});
......
......@@ -34,7 +34,7 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
return array(
array(
'file' => 'js/taggedposts.js',
'initjs' => "addNewTaggedPostShortcut($blockid, $viewid);",
'initjs' => "taggedPostsAddNewPostShortcut($blockid, $viewid);",
)
);
}
......
{if ($editing)}
{if (count($blogs) == 1)}
<a class="card-footer {if (count($blogs) != 1)} d-none{/if}">
<a class="card-footer force-pointer {if (count($blogs) != 1)} d-none{/if}">
<span id="blog_{$blogs[0]->id}" class="icon icon-plus left" role="presentation" aria-hidden="true"></span>
{str tag='shortcutnewentry' section='artefact.blog'}
</a>
......
......@@ -15,7 +15,7 @@
</span>
</div>
</div>
<a class="btn btnshortcut feedback card-footer mtl {if (count($blogs) != 1)} d-none{/if}">
<a class="btn btnshortcut feedback card-footer force-pointer mtl {if (count($blogs) != 1)} d-none{/if}">
<span class="icon icon-plus left" role="presentation" aria-hidden="true"></span>
{str tag='shortcutnewentry' section='artefact.blog'}
</a>
......
......@@ -3,7 +3,7 @@
{str tag='alldraftposts' section='artefact.blog'}
{/if}
{if ($editing && $canaddpost)}
<a class="card-footer" href="{$WWWROOT}artefact/blog/post.php?blog={$blogid}&shortcutnewentryviewid={$view}">
<a class="card-footer force-pointer" href="{$WWWROOT}artefact/blog/post.php?blog={$blogid}&shortcutnewentryviewid={$view}">
<span class="icon icon-plus left" role="presentation" aria-hidden="true"></span>
{str tag='shortcutnewentry' section='artefact.blog'}
</a>
......
......@@ -261,6 +261,12 @@ td.btn-group {
}
}
.card-footer {
&.force-pointer {
cursor: pointer;
}
}
// Page editor column + and - controls
.btn-header {
width:100%;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment