Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding template option, fixing unreported issue and more #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

robertmujica
Copy link

Now for real:

  • Adding ability to create template / layout outside actual component.
  • Fixing some bugs when clicking on undo / redoing and no annotations added.
  • Adding callbacks for better interaction with component and client app

@smirolo
@paulJordaan

No idea what is going on with formatting but should be easier to follow my changes this time.

init: function() {
var self = this;
self.linewidth = self.options.linewidth;
if (self.options.storedElement) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this allows us to bring annotations from DB.

fromy: self.fromy,
tox: self.tox,
toy: self.toy
self.myCanvasContainerId = self.$el.attr('id');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small refectory no big deal here.

classPosition1 = 'btn-group-vertical';
classPosition2 = 'btn-block';
}
if (self.options.useOwnTemplate) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is where the magic happens, basically this allows to use handlebar, angular or whatever other client side framework to build toolbox template and here we pass corresponding element id, it means we don't need other handcrafted styling that is the reason of this big if-else statement.

tox: self.tox,
toy: self.toy
$('#' + self.drawingLayerId).on('mouseup touchend', function(event) {
if (self.isToolboxDisable) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this allows to disable drawing by default so user does not edit image by mistake.

toolbox$.css({
cursor: 'pointer',
});
self.isToolboxDisable = true;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default toolbox is disable now.

});
self.isToolboxDisable = true;
},
startEditing: function() {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this allows client application to control when to start / end editing, so it can persist annotation in backend repository, etc.

id: id,
path: path,
storedUndo: [],
storedElement: self.storedElement
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also needed to bring annotations from db for editing.

undoaction: function(event) {
event.preventDefault();
var self = this;
if (self.storedElement.length === 0) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixing a bug, if nothing has been added and user click on undo action, we get some undefined errors in console.

event.preventDefault();
var self = this;

if (self.storedUndo.length === 0) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

for (var i = 0; i < self.storedElement.length; i++) {
var element = self.storedElement[i];

if (element === undefined || element === null) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to prevent persisting undefined / blank annotations

default:
}
}
self.options.onRedraw(self);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notify caller a redraw just happened so it can update annotations in memory, etc.

}
if (self.storedUndo.length > 0) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't remember this change, but without it works ok

'id'));
}
} else {
if ($annotate) {
Copy link
Author

@robertmujica robertmujica May 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i hide / show the parent canvas from client app, i need to make sure all objects are destroyed otherwise it brings objects / annotations from previous instance. just a bit of memory clean up.

var opts = $.extend({}, $.fn.annotate.defaults, options);
var annotate = new Annotate($(this), opts);
$(this).data('annotate', annotate);
return annotate;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returning annotate objects so client app can use for start / stop editing, etc and access annotations as needed.

color: 'red',
type: 'rectangle',
linewidth: 2,
fontsize: '20p
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

callback to notified caller a redraw just happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant