Revert "in the middle of switching to rangy highlighter for better persisting of highlights."

This reverts commit 68b90f893c.
This commit is contained in:
Nils Norman Haukås 2015-11-29 12:17:25 +01:00
parent 68b90f893c
commit ff4b796eae
5 changed files with 29 additions and 66 deletions

View file

@ -72,10 +72,7 @@ gulp.task('dist-node-modules', function () {
'node_modules/ngstorage/ngStorage.js',
'node_modules/node-uuid/uuid.js',
'node_modules/rangy/lib/rangy-core.js',
'node_modules/rangy/lib/rangy-textrange.js',
'node_modules/rangy/lib/rangy-serializer.js',
'node_modules/rangy/lib/rangy-classapplier.js',
'node_modules/rangy/lib/rangy-highlighter.js'
'node_modules/rangy/lib/rangy-serializer.js'
], {base: 'node_modules'})
.pipe($.sourcemaps.init())
.pipe($.concat('vendor.js'))

View file

@ -33,14 +33,17 @@ module tagIt {
// Reload existing tags
var tagsToLoad = this.tagStorageService.loadTags();
this.$log.debug('these tags were found in storage');
this.$log.debug(tagsToLoad);
this.webPageService.readdTagsToPage(tagsToLoad);
}
onSenseSelected (sense: ISense) {
onSenseSelect (sense: ISense) {
var senseTag = this.webPageService.addNewTagToPage(sense);
this.tagStorageService.saveTag(senseTag);
this.tagStorageService.saveTag(senseTag)
this.backendService.sendTaggedDataToServer(senseTag);
this.clearMenuVariables();
}

View file

@ -18,7 +18,7 @@
<input type="text" ng-model="wordToFilterBy" class="form-control" placeholder="Filter tags" />
<ul id="senses">
<li ng-click="vm.onSenseSelected(sense)" id="sense.senseid" ng-repeat="sense in vm.senses | filter:wordToFilterBy" class="list-unstyled">
<li ng-click="vm.onSenseSelect(sense)" id="sense.senseid" ng-repeat="sense in vm.senses | filter:wordToFilterBy" class="list-unstyled">
<strong>{{sense.word}}</strong> {{sense.explanation}}
</li>
</ul>

View file

@ -11,16 +11,14 @@ module tagIt {
$http : ng.IHttpService;
$log : ng.ILogService;
$localStorage : any;
backendService : BackendService;
/* @ngInject */
constructor($http: ng.IHttpService, $log: ng.ILogService,
$localStorage: any, BackendService: BackendService) {
$localStorage: any) {
this.$http = $http;
this.$log = $log;
this.$localStorage = $localStorage;
this.backendService = BackendService;
this.deleteTags(); // reset tag storage
// this.deleteTags(); // reset tag storage
}
deleteTagById (uuid: string) {
@ -46,7 +44,6 @@ module tagIt {
this.$log.debug('saving tag in localstorage:');
this.$log.debug(tagToSave);
this.$localStorage.tagStorage.push(tagToSave);
this.backendService.sendTaggedDataToServer(tagToSave);
}
loadTags () {

View file

@ -3,8 +3,7 @@
module tagIt {
/**
* Takes care of figuring out what word
* is selected on the web page as well as
* performing page edits.
* is selected.
*/
declare var rangy: any;
@ -17,37 +16,11 @@ module tagIt {
// we need to remember what the currently selected word was
currentSelectionRange : any;
tagStorageService: TagStorageService;
highlighter: any;
/* @ngInject */
constructor($log: ng.ILogService, TagStorageService: TagStorageService) {
this.$log = $log;
this.tagStorageService = TagStorageService;
this.initializeRangy();
}
initializeRangy () {
rangy.init();
this.highlighter = rangy.createHighlighter();
this.highlighter.addClassApplier(rangy.createClassApplier("tagit-tag", {
ignoreWhiteSpace: true,
tagNames: ["span", "a"]
}));
// this.highlighter.addClassApplier(rangy.createClassApplier("note", {
// ignoreWhiteSpace: true,
// elementTagName: "a",
// elementProperties: {
// href: "#",
// onclick: function() {
// var highlight = this.highlighter.getHighlightForElement(this);
// if (window.confirm("Delete this note (ID " + highlight.id + ")?")) {
// this.highlighter.removeHighlights( [highlight] );
// }
// return false;
// }
// }
// }));
}
wireUpListener (callbackOnSelectFunc : (result : Object) => void,
@ -64,8 +37,7 @@ module tagIt {
this.tagStorageService.deleteTagById(evt.target.parentElement.id);
}
else if(this.findSelectedText()) {
// this.currentSelectionRange = this.getClonedSelectionRange();
this.currentSelectionRange = rangy.getSelection().getRangeAt(0);
this.currentSelectionRange = this.getClonedSelectionRange();
callbackOnSelectFunc(joinLongWords(this.findSelectedText()));
} else {
callbackOnDeSelectFunc();
@ -107,8 +79,8 @@ module tagIt {
addNewTagToPage = (sense : ISense) : ISenseTag => {
this.$log.debug('addNewTagToPage');
var range = this.currentSelectionRange;
// var serializedRange = rangy.serializeRange(
// range, false, document.getElementById('tagit-body'));
var serializedRange = rangy.serializeRange(
range, false, document.getElementById('tagit-body'));
var generatedUuid : string = uuid.v4();
this.surroundRangeWithSpan(sense, range, generatedUuid);
@ -117,7 +89,7 @@ module tagIt {
userEmail: 'testEmail',
sense: sense,
context: range.commonAncestorContainer.innerText,
serializedSelectionRange: null
serializedSelectionRange: serializedRange
}
};
@ -157,29 +129,23 @@ module tagIt {
selection.getRangeAt(0).cloneRange(), tagToLoad.id);
}
private surroundRangeWithSpan (sense: ISense, range: any, uuid: string) {
debugger;
this.highlighter.highlightSelection('tagit-tag', {
selection: range,
containerElementId: 'tagit-body'
});
private surroundRangeWithSpan (sense: ISense, range: Range, uuid: string) {
// add span around content
var span : HTMLSpanElement = document.createElement('span');
span.id = uuid;
span.title = sense.explanation;
span.className = 'tagit-tag';
range.surroundContents(span);
// // add span around content
// var span : HTMLSpanElement = document.createElement('span');
// span.id = uuid;
// span.title = sense.explanation;
// span.className = 'tagit-tag';
// range.surroundContents(span);
// add a button for removing the tag.
var btn = document.createElement("BUTTON");
btn.className = 'js-tagit-remove-tag';
btn.appendChild(document.createTextNode("X"));
span.appendChild(btn);
// // add a button for removing the tag.
// var btn = document.createElement("BUTTON");
// btn.className = 'js-tagit-remove-tag';
// btn.appendChild(document.createTextNode("X"));
// span.appendChild(btn);
// //unselect everything
// window.getSelection()
// .removeAllRanges();
//unselect everything
window.getSelection()
.removeAllRanges();
}
}