Skip to content

Commit

Permalink
Merge pull request #78 from funktechno/dev
Browse files Browse the repository at this point in the history
v 0.3.5
  • Loading branch information
lastlink authored Jul 22, 2024
2 parents 65ed95c + c589b18 commit 4d2d1f7
Show file tree
Hide file tree
Showing 17 changed files with 1,118 additions and 158 deletions.
163 changes: 40 additions & 123 deletions Asset/Javascript/wiki.js
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);

});
19 changes: 16 additions & 3 deletions Asset/css/wiki.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
[draggable] {
/* [draggable] {
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
/* Required to make elements draggable in old WebKit */
-khtml-user-drag: element;
-webkit-user-drag: element;
} */

body.dragging, body.dragging * {
cursor: move !important;
}

.dragged {
position: absolute;
opacity: 0.5;
z-index: 2000;
}

#columns {
Expand All @@ -17,7 +26,7 @@ width: 162px;
padding-bottom: 5px;
padding-top: 5px;
text-align: left;
cursor: move;
/* cursor: move; */
}
.wikipage header {
height: 20px;
Expand Down Expand Up @@ -52,4 +61,8 @@ width: 25%;
}
.content {
width: 75%;
}

.sidebar>ul li:last-child {
margin-bottom: 0px;
}
Loading

0 comments on commit 4d2d1f7

Please sign in to comment.