Commit 85a3f8a0 authored by Romain Loth's avatar Romain Loth

[FIX] annotations: repair free selection events

parent 7718b763
...@@ -151,12 +151,15 @@ ...@@ -151,12 +151,15 @@
transition: all 0.25s linear; transition: all 0.25s linear;
} }
.selection { /* this was used for the p or div that *contained* a selection */
/*.selection {
color: #aaa; color: #aaa;
} }*/
/* this is used for the selected text itself */
::selection { ::selection {
color: black; color: black;
background-color: rgba(0, 0, 0, 0.4); background-color: #aaa;
} }
.noselection { .noselection {
......
...@@ -50,6 +50,9 @@ ...@@ -50,6 +50,9 @@
/* /*
* Universal text selection * Universal text selection
*
* "universal" <=> (Chrome, Firefox, IE, Safari, Opera...)
* cf. quirksmode.org/dom/range_intro.html
*/ */
function getSelected() { function getSelected() {
if (window.getSelection) { if (window.getSelection) {
...@@ -68,18 +71,20 @@ ...@@ -68,18 +71,20 @@
return false; return false;
} }
// we only need one singleton at a time // we only need one singleton at a time
// (<=> is only called once per doc, but value of annotation changes)
var selection = getSelected(); var selection = getSelected();
/* /*
* When mouse selection is started, we highlight it * When mouse selection was started, this used to grey out the text panel
*/ */
function toggleSelectionHighlight(text) { // function toggleSelectionChangePanelClass(text) {
if (text.trim() !== "" && !$element.hasClass('menu-is-opened')) { // // if (text.trim() !== "" && !$element.hasClass('menu-is-opened')) {
$(".text-panel").addClass("selection"); // if (text.trim() !== "" && !$element.hasClass('menu-is-opened')) {
} else { // $(".text-panel").addClass("selection");
$(".text-panel").removeClass("selection"); // } else {
} // $(".text-panel").removeClass("selection");
} // }
// }
/* /*
* Dynamically construct the selection menu scope * Dynamically construct the selection menu scope
...@@ -107,10 +112,11 @@ ...@@ -107,10 +112,11 @@
$scope.selection_text = angular.copy(annotation); $scope.selection_text = angular.copy(annotation);
// debug // debug
// console.log("toggleMenu with context:", context) ;
// console.log("toggleMenu with annotation: '" + JSON.stringify(annotation) +"'") ;
// console.log("toggleMenu with \$scope.selection_text: '" + JSON.stringify($scope.selection_text) +"'") ; // console.log("toggleMenu with \$scope.selection_text: '" + JSON.stringify($scope.selection_text) +"'") ;
if (angular.isObject(annotation) && !$element.hasClass('menu-is-opened')) { if (angular.isObject(annotation) && !$element.hasClass('menu-is-opened')) {
// existing ngram // existing ngram
var ngramId = annotation.uuid var ngramId = annotation.uuid
var mainformId = annotation.group var mainformId = annotation.group
...@@ -210,7 +216,7 @@ ...@@ -210,7 +216,7 @@
} }
// "add" actions for non-existing ngram // "add" actions for non-existing ngram
else if (annotation.trim() !== "" && !$element.hasClass('menu-is-opened')) { else if (annotation.trim() !== "" && ! context) {
var newNgramText = annotation.trim() var newNgramText = annotation.trim()
// new ngram (first call creates then like previous case for list) // new ngram (first call creates then like previous case for list)
$scope.menuItems.push({ $scope.menuItems.push({
...@@ -252,12 +258,16 @@ ...@@ -252,12 +258,16 @@
// show the menu // show the menu
$element.fadeIn(50); $element.fadeIn(50);
$element.addClass('menu-is-opened'); $element.addClass('menu-is-opened');
// console.warn("FADE IN menu", $element)
} }
else { else {
console.warn("=> else")
// close the menu // close the menu
$scope.menuItems = []; $scope.menuItems = [];
$element.fadeOut(50); $element.fadeOut(50);
$element.removeClass('menu-is-opened'); $element.removeClass('menu-is-opened');
// console.warn("FADE OUT menu", $element)
} }
}); });
}); });
...@@ -283,25 +293,14 @@ ...@@ -283,25 +293,14 @@
}); });
/* /*
* Finish positioning the menu then display the menu * Toggle the menu when clicking on an existing ngram keyword
*/ */
$(".text-container").mouseup(function(e){ $(".text-container").mouseup(function(e){
$(".text-container").unbind("mousemove", positionMenu); $(".text-container").unbind("mousemove", positionMenu);
$rootScope.$emit("positionAnnotationMenu", e.pageX, e.pageY); $rootScope.$emit("positionAnnotationMenu", e.pageX, e.pageY);
toggleSelectionHighlight(selection.toString().trim());
toggleMenu(null, selection.toString().trim());
});
/*
* Toggle the menu when clicking on an existing ngram keyword
*
* £TODO test: apparently this is never used ?
* (superseded by TextSelectionController.onClick)
*/
$(".text-container").delegate(':not("#selection")', "click", function(e) {
// if ($(e.target).hasClass("keyword-inline")) return;
positionMenu(e); positionMenu(e);
toggleSelectionHighlight(selection.toString().trim()); // console.warn("calling toggleMenu from *mouseup*")
toggleMenu(null, selection.toString().trim()); toggleMenu(null, selection.toString().trim());
}); });
...@@ -322,9 +321,11 @@ ...@@ -322,9 +321,11 @@
$rootScope.makeChainedCalls(0, todoCrudCalls, $rootScope.refresh) $rootScope.makeChainedCalls(0, todoCrudCalls, $rootScope.refresh)
// syntax: (step_to_run_first, list_of_steps, lastCallback) // syntax: (step_to_run_first, list_of_steps, lastCallback)
// hide the highlighted text and the menu element // hide the menu element
$(".text-panel").removeClass("selection");
$element.fadeOut(100); $element.fadeOut(100);
// the highlighted text hides itself when deselected
// (thx to browser and css ::selection)
}; };
} }
]); ]);
......
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