Skip to content
This repository has been archived by the owner on Dec 20, 2019. It is now read-only.

Commit

Permalink
integrate annotatorjs (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleguido committed Dec 23, 2015
1 parent 669851f commit c40b6bc
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 33 deletions.
48 changes: 37 additions & 11 deletions client/src/js/controllers/core.js
Expand Up @@ -848,17 +848,44 @@ angular.module('histograph')
// }
});

modalInstance.result.then(function(){
modalInstance.result.then(function (result) {
if(options && typeof options.discard == "function") {
options.discard();
options.submit(options.annotator, result);
}
}, function(){
if(options && typeof options.discard == "function") {
options.discard();
options.discard(options.annotator);
}
});

}
};

/*
loadAnnotations
---
Load notes attached to the target id
*/
$scope.loadAnnotations = function(item, next) {
next([
{
"id": "39fc339cf058bd22176771b3e3187329", // unique id (added by backend)
"annotator_schema_version": "v1.0", // schema version: default v1.0
"created": "2011-05-24T18:52:08.036814", // created datetime in iso8601 format (added by backend)
"updated": "2011-05-26T12:17:05.012544", // updated datetime in iso8601 format (added by backend)
"text": "A note I wrote", // content of annotation
"quote": "the text that was annotated", // the annotated text (added by frontend)
"uri": "http://example.com",
"ranges": [{
end: "/blockquote[1]/p[1]",
endOffset: 222,
start: "/blockquote[1]/p[1]",
startOffset: 208,
}
]
}
]);
};
// $scope.contribute({id: 25723})
// $scope.inspect([26414])//27329]);
/*
Expand Down Expand Up @@ -1024,10 +1051,7 @@ angular.module('histograph')
$scope.q = options.query;
}
$scope.ok = function () {
if(options && typeof options.discard == "function") {
options.discard();
}
$uibModalInstance.close();

$log.log('ContributeModalCtrl -> ok()', 'saving...');
var entities = [].concat($scope.persons, $scope.locations, $scope.organizations)
for(var i in entities)
Expand All @@ -1037,14 +1061,16 @@ angular.module('histograph')
model: 'resource'
}, {}, function(res) {
$log.log('ContributeModalCtrl -> ok()', 'saved', res)
$uibModalInstance.close(res.result.item);

})

};

$scope.cancel = function () {
if(options && typeof options.discard == "function") {
options.discard();
}
// if(options && typeof options.discard == "function") {
// options.discard();
// }
$uibModalInstance.dismiss('cancel');
};

Expand Down
44 changes: 23 additions & 21 deletions client/src/js/directives/annotator.js
Expand Up @@ -186,10 +186,12 @@ angular.module('histograph')
Annotator.Plugin.HelloWorld = function (element) {
return {
pluginInit: function () {
var editor;
var editor,
annotator = this.annotator,
link;

this.annotator.subscribe("annotationCreated", function (annotation) {
console.log("The annotation: %o has just been created!", annotation)
console.log("The annotation: %o has just been created!", annotation, link)
})
.subscribe("annotationUpdated", function (annotation) {
console.log("The annotation: %o has just been updated!", annotation)
Expand All @@ -201,12 +203,17 @@ angular.module('histograph')
})
.subscribe("annotationEditorShown", function (editor, annotation) {
editor = editor;
console.log("The annotation: has just been annotationEditorShown!", arguments);
console.log("The annotation: has just been annotationEditorShown!", arguments, annotator);

scope.contribute(scope.item, "entity", {
query: annotation.quote,
discard: function() {
editor.hide()
annotator: annotator,
submit: function(annotator, result) {
link = result;
annotator.editor.submit();
},
discard: function(annotator) {
annotator.editor.hide();
}
});
scope.$apply();
Expand All @@ -220,24 +227,19 @@ angular.module('histograph')
}

var annotator = angular.element(element).annotator().data('annotator');
annotator.addPlugin('Unsupported');
annotator.addPlugin('HelloWorld');//' /*, any other options */);
// element..annotator()bind('mouseup', function(e){
// var selection;

// if (window.getSelection) {
// selection = window.getSelection();
// } else if (document.selection) {
// selection = document.selection.createRange();
// }

// if (selection.toString() !== '') {
// var s = selection.toString();
// $log.log('::annotator -> ',selection)

// }
// });

annotator.addPlugin('Unsupported');
annotator.addPlugin('HelloWorld');

// lazyload annotation for this specific goddamn element
// setTimeout(function(){
// attrs.target && scope.loadAnnotations({
// id: attrs.target
// }, function (annotations) {debugger
// annotator.loadAnnotations(annotations);
// });
// }, 20)
}
}
});
Expand Down

0 comments on commit c40b6bc

Please sign in to comment.