-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from funktechno/dev
v 0.3.5
- Loading branch information
Showing
17 changed files
with
1,118 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,134 +1,51 @@ | ||
jQuery(document).ready(function () { | ||
var dragSrcEl = null; | ||
|
||
function handleDragStart(e) { | ||
// Target (this) element is the source node. | ||
dragSrcEl = this; | ||
|
||
e.dataTransfer.effectAllowed = 'move'; | ||
e.dataTransfer.setData('text/html', this.outerHTML); | ||
|
||
this.classList.add('dragElem'); | ||
} | ||
function handleDragOver(e) { | ||
if (e.preventDefault) { | ||
e.preventDefault(); // Necessary. Allows us to drop. | ||
} | ||
this.classList.add('over'); | ||
|
||
e.dataTransfer.dropEffect = 'move'; // See the section on the DataTransfer object. | ||
|
||
return false; | ||
} | ||
|
||
function handleDragEnter(e) { | ||
// this / e.target is the current hover target. | ||
} | ||
|
||
function handleDragLeave(e) { | ||
this.classList.remove('over'); // this / e.target is previous target element. | ||
} | ||
|
||
function handleDrop(e) { | ||
// this/e.target is current target element. | ||
|
||
if (e.stopPropagation) { | ||
e.stopPropagation(); // Stops some browsers from redirecting. | ||
} | ||
|
||
// Don't do anything if dropping the same column we're dragging. | ||
if (dragSrcEl != this) { | ||
|
||
let targetRoute; | ||
if(e.target.localName == "a"){ | ||
targetRoute = e.target.href | ||
} else { | ||
targetRoute = e.target.querySelector("a").href | ||
} | ||
let targetParams = new URL(targetRoute) | ||
var targetProperties = {} | ||
for (const [key, value] of targetParams.searchParams.entries()) { | ||
targetProperties[key] = value | ||
/* | ||
page reorder and nesting support using jquery sorting plugin | ||
*/ | ||
if($("#columns").data("reorder-url")){ | ||
jQuery('#columns').sortable({ | ||
nested: true, | ||
onDrop: function ($item, container, _super) { | ||
// console.log("onDrop", $item, container, _super) | ||
container.el.removeClass("active"); | ||
var srcProperties = { | ||
...$item[0].dataset | ||
} | ||
// console.log("targetProperties", targetProperties) | ||
|
||
var srcParams = new URL(dragSrcEl.querySelector("a").href) | ||
var srcProperties = {} | ||
|
||
for (const [key, value] of srcParams.searchParams.entries()) { | ||
srcProperties[key] = value | ||
} | ||
// console.log("srcProperties", srcProperties) | ||
|
||
let project_id = srcProperties["project_id"] | ||
|
||
// console.log("project_id", project_id) | ||
var containerProperties = {...container.el[0].dataset} | ||
|
||
let request = { | ||
"src_wiki_id": srcProperties["wiki_id"], | ||
"target_wiki_id": targetProperties["wiki_id"] | ||
"src_wiki_id": srcProperties["pageId"], | ||
"index": $item.index(), | ||
"parent_id": containerProperties["parentId"] | ||
} | ||
|
||
console.log("request", request) | ||
// console.log("request", request) | ||
|
||
|
||
$.ajax({ | ||
cache: false, | ||
url: $("#columns").data("reorder-url"), | ||
contentType: "application/json", | ||
type: "POST", | ||
processData: false, | ||
data: JSON.stringify(request), | ||
success: function(data) { | ||
// self.refresh(data); | ||
// self.savingInProgress = false; | ||
}, | ||
error: function() { | ||
// self.app.hideLoadingIcon(); | ||
// self.savingInProgress = false; | ||
}, | ||
statusCode: { | ||
403: function(data) { | ||
window.alert(data.responseJSON.message); | ||
document.location.reload(true); | ||
cache: false, | ||
url: $("#columns").data("reorder-url"), | ||
contentType: "application/json", | ||
type: "POST", | ||
processData: false, | ||
data: JSON.stringify(request), | ||
success: function(data) { | ||
// self.refresh(data); | ||
// self.savingInProgress = false; | ||
}, | ||
error: function() { | ||
// self.app.hideLoadingIcon(); | ||
// self.savingInProgress = false; | ||
}, | ||
statusCode: { | ||
403: function(data) { | ||
window.alert(data.responseJSON.message); | ||
document.location.reload(true); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
// Set the source column's HTML to the HTML of the column we dropped on. | ||
//alert(this.outerHTML); | ||
//dragSrcEl.innerHTML = this.innerHTML; | ||
//this.innerHTML = e.dataTransfer.getData('text/html'); | ||
this.parentNode.removeChild(dragSrcEl); | ||
var dropHTML = e.dataTransfer.getData('text/html'); | ||
this.insertAdjacentHTML('beforebegin', dropHTML); | ||
var dropElem = this.previousSibling; | ||
addDnDHandlers(dropElem); | ||
|
||
} | ||
this.classList.remove('over'); | ||
return false; | ||
}); | ||
_super($item, container); | ||
}, | ||
}) | ||
} | ||
|
||
function handleDragEnd(e) { | ||
// this/e.target is the source node. | ||
this.classList.remove('over'); | ||
|
||
/*[].forEach.call(cols, function (col) { | ||
col.classList.remove('over'); | ||
});*/ | ||
} | ||
|
||
function addDnDHandlers(elem) { | ||
elem.addEventListener('dragstart', handleDragStart, false); | ||
elem.addEventListener('dragenter', handleDragEnter, false) | ||
elem.addEventListener('dragover', handleDragOver, false); | ||
elem.addEventListener('dragleave', handleDragLeave, false); | ||
elem.addEventListener('drop', handleDrop, false); | ||
elem.addEventListener('dragend', handleDragEnd, false); | ||
|
||
} | ||
|
||
var cols = document.querySelectorAll('#columns .wikipage'); | ||
[].forEach.call(cols, addDnDHandlers); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.