|
@@ -128,7 +128,7 @@ $(document).ready(function() {
|
|
|
$("div.jump-to").removeClass("jump-to-toggle");
|
|
|
$("div.jump-to-list").removeClass("jump-to-list-toggle");
|
|
|
$("img.jump-to-img").removeClass("jump-to-img-toggle");
|
|
|
-
|
|
|
+
|
|
|
// If the user clicks on a link and scrolls up the page, toggle list
|
|
|
$("div.jump-to-list").show();
|
|
|
hasScrolledDown = false;
|
|
@@ -261,7 +261,7 @@ $(document).ready(function() {
|
|
|
tags = returnData;
|
|
|
|
|
|
// For every added item
|
|
|
- $("li.added_item div").each(function() {
|
|
|
+ $("li.added_item .expandable").each(function() {
|
|
|
var thisDiv = $(this); // Delete the declaration (because it's ugly!)
|
|
|
|
|
|
// For every tag in the database that belongs to the active user
|
|
@@ -293,7 +293,7 @@ $(document).ready(function() {
|
|
|
var loopCounter = 0;
|
|
|
|
|
|
// For every added item
|
|
|
- $("li.added_item div").each(function() {
|
|
|
+ $("li.added_item .expandable").each(function() {
|
|
|
var thisDiv = $(this); // Delete the declaration (because it's ugly)
|
|
|
|
|
|
// For every tag that belongs to the active user
|
|
@@ -319,57 +319,12 @@ $(document).ready(function() {
|
|
|
*/
|
|
|
}
|
|
|
|
|
|
- /* ================================================
|
|
|
- If the user clicks on a tag, show the tag window
|
|
|
- ================================================= */
|
|
|
- // If the user clicks on a tag
|
|
|
- function showTagWindowOnTagClick() {
|
|
|
- $("a.tag").on("click", function() { // Event not triggered...
|
|
|
- // Declarations
|
|
|
- tag = $(this).text();
|
|
|
-
|
|
|
- // If the user is logged in
|
|
|
- if($("input[name='username']").val() != "") {
|
|
|
- // Show the tag window
|
|
|
- showTagWindow();
|
|
|
- }
|
|
|
- else {
|
|
|
- // Show a dialog
|
|
|
- $("div#shadow").css("display", "block");
|
|
|
- $("div#dialog-log-in").css("display", "block");
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- // Mouse-enabled devices
|
|
|
- $("tag").mouseenter(function() {
|
|
|
- timer = setTimeout(function() {
|
|
|
- showTagWindow(); // showTagWindow needs a parameter!
|
|
|
- }, 400);
|
|
|
- }).mouseleave(function() {
|
|
|
- clearTimeout(timer);
|
|
|
- });
|
|
|
-
|
|
|
- // Touch devices
|
|
|
- try {
|
|
|
- document.createEvent("TouchEvent");
|
|
|
-
|
|
|
- $("a.tag").on("click", showTagWindow()); // showTagWindow needs a parameter!
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
- catch(e) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- */
|
|
|
-
|
|
|
/* ================================================
|
|
|
Get the user's tags from the database and apply them on the canvas
|
|
|
================================================= */
|
|
|
|
|
|
// Apply tags (Incoming parameter is an array with every tag from the database belonging to the active user)
|
|
|
- function applyTags() {
|
|
|
+ function updateTags() {
|
|
|
// Apply tags on the canvas
|
|
|
/*
|
|
|
IMPORTANT! A timer was needed in order to solve several bugs related to tags not being applied on the canvas.
|
|
@@ -380,8 +335,7 @@ $(document).ready(function() {
|
|
|
var text;
|
|
|
|
|
|
// For every added item
|
|
|
- // $("li.added_item textarea").each(function() {
|
|
|
- $("li.added_item div").each(function() {
|
|
|
+ $("li.added_item .expandable").each(function() {
|
|
|
// Declarations
|
|
|
|
|
|
var loopCounter = 0;
|
|
@@ -449,8 +403,8 @@ $(document).ready(function() {
|
|
|
return a.toLowerCase().localeCompare(b.toLowerCase())
|
|
|
});
|
|
|
|
|
|
- // Apply the tags on the canvas
|
|
|
- applyTags();
|
|
|
+ // Update tags on the canvas
|
|
|
+ updateTags();
|
|
|
}
|
|
|
},
|
|
|
error: function(xhr) {
|
|
@@ -459,6 +413,44 @@ $(document).ready(function() {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /* ================================================
|
|
|
+ Toggle textarea.expandable/div.expandable on edit
|
|
|
+ ================================================= */
|
|
|
+
|
|
|
+ function toggleTextElementOnFocus() {
|
|
|
+ // If the user clicks on the added idea
|
|
|
+ $("li.added_item .expandable").on("click", function() {
|
|
|
+ var li = $(this).parent();
|
|
|
+
|
|
|
+ // Replace div with a textarea
|
|
|
+ $(this).replaceWith(
|
|
|
+ "<textarea maxlength='100' class='expandable' rows='3' data-limit-rows='true' data-autoresize name='" + $(this).attr("name") + "'>" + $(this).text() + "</textarea>"
|
|
|
+ );
|
|
|
+
|
|
|
+ // Focus immediately on click instead of having to click on the element a second time
|
|
|
+ li.find("textarea").focus();
|
|
|
+
|
|
|
+ // Zoom in animation
|
|
|
+ // li.find("textarea").addClass("zoom-in");
|
|
|
+
|
|
|
+ $("li.added_item textarea.expandable").on("focusout", function() {
|
|
|
+ // Replace textarea with a div
|
|
|
+ $(this).replaceWith(
|
|
|
+ "<div class='expandable' contenteditable='true' name='" + $(this).attr("name") + "'>" + $(this).val() + "</div>"
|
|
|
+ );
|
|
|
+
|
|
|
+ // Update tags on the canvas
|
|
|
+ window.setTimeout(updateTags(), 100);
|
|
|
+ // updateTags();
|
|
|
+
|
|
|
+ // Zoom out animation
|
|
|
+ // li.find("div").addClass("zoom-out");
|
|
|
+
|
|
|
+ toggleTextElementOnFocus();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
/* ================================================
|
|
|
Load tags if the user is logged in
|
|
|
================================================= */
|
|
@@ -618,8 +610,8 @@ $(document).ready(function() {
|
|
|
$("div#tag-window h2.similar-tags").after(htmlToAppend);
|
|
|
$("p.similar-tags-description-none").css("display", "none");
|
|
|
|
|
|
- // Apply the tags on the canvas
|
|
|
- // applyTags();
|
|
|
+ // Update tags on the canvas
|
|
|
+ // updateTags();
|
|
|
}
|
|
|
else {
|
|
|
// If the tag isn't a new tag
|
|
@@ -781,15 +773,62 @@ $(document).ready(function() {
|
|
|
});
|
|
|
|
|
|
/* ================================================
|
|
|
- If the user types a new character in the added idea field, add tag if a term could be found
|
|
|
+ If the user clicks on a tag, show the tag window
|
|
|
================================================= */
|
|
|
|
|
|
+ // If the user clicks on a tag
|
|
|
+ function showTagWindowOnTagClick() {
|
|
|
+ $("a.tag").on("click", function() {
|
|
|
+ // Declarations
|
|
|
+ tag = $(this).text();
|
|
|
+
|
|
|
+ // If the user is logged in
|
|
|
+ if($("input[name='username']").val() != "") {
|
|
|
+ // Show the tag window
|
|
|
+ showTagWindow();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // Show a dialog
|
|
|
+ $("div#shadow").css("display", "block");
|
|
|
+ $("div#dialog-log-in").css("display", "block");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ // Mouse-enabled devices
|
|
|
+ $("tag").mouseenter(function() {
|
|
|
+ timer = setTimeout(function() {
|
|
|
+ showTagWindow(); // showTagWindow needs a parameter!
|
|
|
+ }, 400);
|
|
|
+ }).mouseleave(function() {
|
|
|
+ clearTimeout(timer);
|
|
|
+ });
|
|
|
+
|
|
|
+ // Touch devices
|
|
|
+ try {
|
|
|
+ document.createEvent("TouchEvent");
|
|
|
+
|
|
|
+ $("a.tag").on("click", showTagWindow()); // showTagWindow needs a parameter!
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ catch(e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
+ /*
|
|
|
+ // ================================================
|
|
|
+ If the user types a new character in the added idea field, add tag if a term could be found
|
|
|
+ ================================================= //
|
|
|
+
|
|
|
// 8an33j24
|
|
|
|
|
|
function applyTagOnTypeMatch() {
|
|
|
- $("li.added_item div").on("focusin", function() {
|
|
|
+ $("li.added_item .expandable").on("focusin", function() {
|
|
|
// If the user presses a key in the description textarea
|
|
|
- $("li.added_item div").on("keyup", function() {
|
|
|
+ $("li.added_item .expandable").on("keyup", function() {
|
|
|
if(event.which !== 9 && // Tab
|
|
|
event.which !== 16 && // Shift
|
|
|
event.which !== 37 && // Left
|
|
@@ -807,11 +846,9 @@ $(document).ready(function() {
|
|
|
|
|
|
// Fix the bug that triggers the event twice
|
|
|
if(!bugCounter > 0) {
|
|
|
- /*
|
|
|
- console.log("tagTextHits: " + tagTextHits);
|
|
|
- console.log("tagLinkHits: " + tagLinkHits);
|
|
|
- */
|
|
|
-
|
|
|
+ // console.log("tagTextHits: " + tagTextHits);
|
|
|
+ // console.log("tagLinkHits: " + tagLinkHits);
|
|
|
+
|
|
|
// For every tag that belongs to the active user
|
|
|
for(t in tags) {
|
|
|
if($(this).html().indexOf(tags[loopCounter]) != -1) {
|
|
@@ -859,6 +896,7 @@ $(document).ready(function() {
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
+ */
|
|
|
|
|
|
/* ----------------------------------------------
|
|
|
Limiting the number of characters the user is allowed to type
|
|
@@ -874,7 +912,7 @@ $(document).ready(function() {
|
|
|
|
|
|
function limitLengthOnInput() {
|
|
|
// Limit text on key press
|
|
|
- $("li.added_item div").on("keypress", function(event) {
|
|
|
+ $("li.added_item .expandable").on("keypress", function(event) {
|
|
|
// Declarations
|
|
|
var numberOfTags = $(this).children().filter("a").length;
|
|
|
var textLength = $(this).html().length;
|
|
@@ -895,7 +933,7 @@ $(document).ready(function() {
|
|
|
/*
|
|
|
var pastedTextOriginal;
|
|
|
|
|
|
- $("li.added_item div").on("paste", function(event) {
|
|
|
+ $("li.added_item .expandable").on("paste", function(event) {
|
|
|
pastedTextOriginal = event.originalEvent.clipboardData.getData("Text");
|
|
|
|
|
|
if($(this).html().length + pastedTextOriginal > 100) {
|
|
@@ -934,7 +972,7 @@ $(document).ready(function() {
|
|
|
// Update the tag variable
|
|
|
document.onselectionchange = function() {
|
|
|
// if($("textarea").is(":focus")) {
|
|
|
- if($("li.added_item div").is(":focus")) { // This is nicer: $("li.added_item div").on("focusin", function() {
|
|
|
+ if($("li.added_item .expandable").is(":focus")) {
|
|
|
selection = window.getSelection().toString();
|
|
|
tag = selection.trim();
|
|
|
}
|
|
@@ -958,8 +996,7 @@ $(document).ready(function() {
|
|
|
});
|
|
|
|
|
|
// If the user moves the focus from the added idea, reset variables
|
|
|
- // $("li.added_item textarea").on("focusout", function() {
|
|
|
- $("li.added_item div").on("focusout", function() {
|
|
|
+ $("li.added_item .expandable").on("focusout", function() {
|
|
|
selection = "";
|
|
|
tag = "";
|
|
|
});
|
|
@@ -1054,13 +1091,13 @@ $(document).ready(function() {
|
|
|
|
|
|
itemListHTML +=
|
|
|
// '<li class="added_item"><span class="handle glyphicon glyphicon-move"></span><textarea maxlength="100" class="expandable" rows="3" data-limit-rows="true" data-autoresize name="' + key + '">' + itm + '</textarea><span class="remove glyphicon glyphicon-remove-circle"></span></li>';
|
|
|
- '<li class="added_item"><div class="expandable" name="' + key + '" contenteditable="true">' + itm + '</div><span class="handle glyphicon glyphicon-list"></span><span class="move-up glyphicon glyphicon-chevron-up"></span><span class="move-down glyphicon glyphicon-chevron-down"></span><span class="remove glyphicon glyphicon-remove-circle"></span></li>';
|
|
|
+ '<li class="added_item"><div class="expandable" contenteditable="true" name="' + key + '">' + itm + '</div><span class="handle glyphicon glyphicon-list"></span><span class="move-up glyphicon glyphicon-chevron-up"></span><span class="move-down glyphicon glyphicon-chevron-down"></span><span class="remove glyphicon glyphicon-remove-circle"></span></li>';
|
|
|
});
|
|
|
}
|
|
|
else { // a single value string
|
|
|
itemListHTML +=
|
|
|
// '<li class="added_item"><span class="handle glyphicon glyphicon-move"></span><textarea maxlength="100" class="expandable" rows="3" data-limit-rows="true" data-autoresize name="' + key + '">' + value + '</textarea><span class="remove glyphicon glyphicon-remove-circle"></span></li>';
|
|
|
- '<li class="added_item"><div class="expandable" name="' + key + '" contenteditable="true">' + value + '</div><span class="handle glyphicon glyphicon-list"></span><span class="move-up glyphicon glyphicon-chevron-up"></span><span class="move-down glyphicon glyphicon-chevron-down"></span><span class="remove glyphicon glyphicon-remove-circle"></span></li>';
|
|
|
+ '<li class="added_item"><div class="expandable" contenteditable="true" name="' + key + '">' + value + '</div><span class="handle glyphicon glyphicon-list"></span><span class="move-up glyphicon glyphicon-chevron-up"></span><span class="move-down glyphicon glyphicon-chevron-down"></span><span class="remove glyphicon glyphicon-remove-circle"></span></li>';
|
|
|
}
|
|
|
/* Append the created list items/textatreas to the right field based on the "key"*/
|
|
|
/* the str.substr(start,length)
|
|
@@ -1080,6 +1117,9 @@ $(document).ready(function() {
|
|
|
|
|
|
});
|
|
|
|
|
|
+ // Toggle textarea.expandable/div.expandable on edit
|
|
|
+ toggleTextElementOnFocus();
|
|
|
+
|
|
|
// Get the user's tags from the database and apply them on the canvas
|
|
|
getTags();
|
|
|
|
|
@@ -1203,7 +1243,7 @@ $(document).ready(function() {
|
|
|
// The height of the newly added item = the height of the add new idea textarea
|
|
|
$(this).closest('.card').find('ul.item_list').append(
|
|
|
// '<li class="added_item"><span class="handle glyphicon glyphicon-move"></span><textarea maxlength="100" class="expandable" rows="3" data-limit-rows="true" data-autoresize name="' + field_attr + '">' + new_item + '</textarea><span class="remove glyphicon glyphicon-remove-circle"></span></li>'
|
|
|
- '<li class="added_item"><div class="expandable" name="' + field_attr + '" contenteditable="true">' + new_item + '</div><span class="handle glyphicon glyphicon-list"></span><span class="move-up glyphicon glyphicon-chevron-up"></span><span class="move-down glyphicon glyphicon-chevron-down"></span><span class="remove glyphicon glyphicon-remove-circle"></span></li>'
|
|
|
+ '<li class="added_item"><div class="expandable" contenteditable="true" name="' + field_attr + '">' + new_item + '</div><span class="handle glyphicon glyphicon-list"></span><span class="move-up glyphicon glyphicon-chevron-up"></span><span class="move-down glyphicon glyphicon-chevron-down"></span><span class="remove glyphicon glyphicon-remove-circle"></span></li>'
|
|
|
);
|
|
|
|
|
|
// Fix the heights only after a new item is added
|
|
@@ -1220,7 +1260,10 @@ $(document).ready(function() {
|
|
|
limitLengthOnInput();
|
|
|
|
|
|
// Apply event listener to the added idea handling the application of tags should the user writes one of the terms in it
|
|
|
- applyTagOnTypeMatch();
|
|
|
+ // applyTagOnTypeMatch();
|
|
|
+
|
|
|
+ // Toggle textarea.expandable/div.expandable on edit
|
|
|
+ toggleTextElementOnFocus();
|
|
|
|
|
|
// Remove all tags from all fields
|
|
|
removeTags();
|
|
@@ -1264,7 +1307,7 @@ $(document).ready(function() {
|
|
|
// The height of the newly added item = the height of the add new idea textarea
|
|
|
$(this).closest('.card').find('ul.item_list').append(
|
|
|
// '<li class="added_item"><span class="handle glyphicon glyphicon-move"></span><textarea maxlength="100" class="expandable" rows="3" data-limit-rows="true" data-autoresize name="' + field_attr + '">' + new_item + '</textarea><span class="remove glyphicon glyphicon-remove-circle"></span></li>');
|
|
|
- '<li class="added_item"><div class="expandable" name="' + field_attr + '" contenteditable="true">' + new_item + '</div><span class="handle glyphicon glyphicon-list"></span><span class="move-up glyphicon glyphicon-chevron-up"></span><span class="move-down glyphicon glyphicon-chevron-down"></span><span class="remove glyphicon glyphicon-remove-circle"></span></li>'
|
|
|
+ '<li class="added_item"><div class="expandable" contenteditable="true" name="' + field_attr + '">' + new_item + '</div><span class="handle glyphicon glyphicon-list"></span><span class="move-up glyphicon glyphicon-chevron-up"></span><span class="move-down glyphicon glyphicon-chevron-down"></span><span class="remove glyphicon glyphicon-remove-circle"></span></li>'
|
|
|
);
|
|
|
// Fix the heights only after a new item is added
|
|
|
// fixHeights();
|
|
@@ -1280,7 +1323,10 @@ $(document).ready(function() {
|
|
|
limitLengthOnInput();
|
|
|
|
|
|
// Apply event listener to the added idea handling the application of tags should the user writes one of the terms in it
|
|
|
- applyTagOnTypeMatch();
|
|
|
+ // applyTagOnTypeMatch();
|
|
|
+
|
|
|
+ // Toggle textarea.expandable/div.expandable on edit
|
|
|
+ toggleTextElementOnFocus();
|
|
|
|
|
|
// Remove all tags from all fields
|
|
|
removeTags();
|
|
@@ -1502,7 +1548,7 @@ $(document).ready(function() {
|
|
|
//$(selector).attr(attribute,value)
|
|
|
var fieldAttr = $(this).closest('ul.item_list').attr('id');
|
|
|
// $(this).find('textarea').attr('name', fieldAttr + '[]');
|
|
|
- $(this).find('li.added_item div').attr('name', fieldAttr + '[]');
|
|
|
+ $(this).find('li.added_item .expandable').attr('name', fieldAttr + '[]');
|
|
|
});
|
|
|
|
|
|
});
|