Solved merge conflict with memento files

This commit is contained in:
Luis Leiva 2014-05-07 19:47:59 +02:00
commit d4f211f46f
3 changed files with 17 additions and 16 deletions

View File

@ -44,7 +44,7 @@
var sketch = new jSketch(this, {
fillStyle: options.graphics.fillStyle,
strokeStyle: options.graphics.strokeStyle,
lineWidth: options.graphics.lineWidth,
lineWidth: options.graphics.lineWidth
});
// Flag drawing state on a per-canvas basis.
sketch.isDrawing = false;
@ -220,7 +220,7 @@
* destroy: function(elem, data){},
* mousedown: function(elem, data, evt){},
* mousemove: function(elem, data, evt){},
* mouseup: function(elem, data, evt){},
* mouseup: function(elem, data, evt){}
* },
* graphics: {
* firstPointSize: 0,
@ -246,7 +246,7 @@
// destroy: function(elem, data){},
// mousedown: function(elem, data, evt){},
// mousemove: function(elem, data, evt){},
// mouseup: function(elem, data, evt){},
// mouseup: function(elem, data, evt){}
},
// TODO: add more jSketch config options
graphics: {
@ -254,9 +254,9 @@
lineWidth: 3,
strokeStyle: '#F0F',
fillStyle: '#F0F'
//lineCap:
//lineJoin:
//miterLimit:
//lineCap: "round",
//lineJoin: "round",
//miterLimit: 10
}
};
@ -319,11 +319,11 @@
function touchHandler(e) {
e.preventDefault();
var elem = $(e.target);
var elem = $(e.target);
var touch = e.originalEvent.changedTouches[0];
// Copy original event properties to touch event.
for (var o in e) {
touch[o] = e[o];
if (e.hasOwnProperty(o)) touch[o] = e[o];
}
// Remove (emulated) mouse events on mobile devices.
switch (e.type) {

View File

@ -27,13 +27,13 @@
// Private stuff //////////////////////////////////////////////////////////
var stack = [];
var stpos = -1;
var self = this;
var self = this;
function prev() {
if (stpos > 0) {
stpos--;
var snapshot = new Image();
snapshot.src = stack[stpos].state;
snapshot.src = stack[stpos].image;
snapshot.onload = function() {
restore(this);
};
@ -44,7 +44,7 @@
if (stpos < stack.length - 1) {
stpos++;
var snapshot = new Image();
snapshot.src = stack[stpos].state;
snapshot.src = stack[stpos].image;
snapshot.onload = function() {
restore(this);
};
@ -122,7 +122,7 @@
stpos++;
if (stpos < stack.length) stack.length = stpos;
$canvas.sketchable('handler', function(elem, data) {
stack.push({ state: elem[0].toDataURL(), strokes: data.strokes.slice() });
stack.push({ image: elem[0].toDataURL(), strokes: data.strokes.slice() });
});
};
/**
@ -172,10 +172,10 @@
// A helper function to override user-defined event listeners.
function override(ev) {
if (options && options.events && typeof options.events[ev] === 'function') {
var _init = options.events[ev];
var fn = options.events[ev];
options.events[ev] = function() {
var args = Array.prototype.slice.call(arguments, 0);
_init.call(this, args);
fn.call(this, args);
callbacks[ev].apply(this, args);
}
} else {
@ -183,6 +183,7 @@
}
};
// Event order matters.
var events = 'init mouseup destroy'.split(" ");
for (var i = 0; i < events.length; i++) {
override(events[i]);
@ -195,7 +196,7 @@
},
redo: function() {
mc.redo();
},
}
});
return plugin.defaults;

View File

@ -1,4 +1,4 @@
/*!
* Memento plugin for jQuery sketchable | v1.1 | Luis A. Leiva | MIT license
*/
(function(d){var a=function(l){var g=[];var f=-1;var h=this;function k(){if(f>0){f--;var n=new Image();n.src=g[f].state;n.onload=function(){i(this)}}}function j(){if(f<g.length-1){f++;var n=new Image();n.src=g[f].state;n.onload=function(){i(this)}}}function i(n){l.sketchable("handler",function(o,p){p.sketch.clear();p.sketch.graphics.drawImage(n,0,0)})}function m(n){if(n.ctrlKey){switch(n.which){case 26:if(n.shiftKey){h.redo()}else{h.undo()}break;case 25:h.redo();break;default:break}}}this.undo=function(){k();l.sketchable("handler",function(n,o){o.strokes=g[f].strokes.slice()})};this.redo=function(){j();l.sketchable("handler",function(n,o){o.strokes=g[f].strokes.slice()})};this.reset=function(){g=[];f=-1};this.save=function(){f++;if(f<g.length){g.length=f}l.sketchable("handler",function(n,o){g.push({state:n[0].toDataURL(),strokes:o.strokes.slice()})})};this.init=function(){d(document).on("keypress",m)};this.destroy=function(){d(document).off("keypress",m);this.reset()}};var c=d.fn.sketchable;var e=c("methods");function b(l,f){d.extend(c.defaults,f);var m=new a(l);var k={init:function(i,n){n.memento=m;n.memento.save();n.memento.init()},mouseup:function(i,n,o){n.memento.save()},destroy:function(i,n){n.memento.destroy()}};function j(i){if(f&&f.events&&typeof f.events[i]==="function"){var n=f.events[i];f.events[i]=function(){var o=Array.prototype.slice.call(arguments,0);n.call(this,o);k[i].apply(this,o)}}else{c.defaults.events[i]=k[i]}}var h="init mouseup destroy".split(" ");for(var g=0;g<h.length;g++){j(h[g])}d.extend(e,{undo:function(){m.undo()},redo:function(){m.redo()},});return c.defaults}d.fn.sketchable=function(g){if(typeof g==="object"||!g){var f=b(this,arguments[0]);return e.init.apply(this,[f])}else{if(e[g]){return e[g].apply(this,Array.prototype.slice.call(arguments,1))}}}})(jQuery);
(function(d){var a=function(l){var g=[];var f=-1;var h=this;function k(){if(f>0){f--;var n=new Image();n.src=g[f].image;n.onload=function(){i(this)}}}function j(){if(f<g.length-1){f++;var n=new Image();n.src=g[f].image;n.onload=function(){i(this)}}}function i(n){l.sketchable("handler",function(o,p){p.sketch.clear();p.sketch.graphics.drawImage(n,0,0)})}function m(n){if(n.ctrlKey){switch(n.which){case 26:if(n.shiftKey){h.redo()}else{h.undo()}break;case 25:h.redo();break;default:break}}}this.undo=function(){k();l.sketchable("handler",function(n,o){o.strokes=g[f].strokes.slice()})};this.redo=function(){j();l.sketchable("handler",function(n,o){o.strokes=g[f].strokes.slice()})};this.reset=function(){g=[];f=-1};this.save=function(){f++;if(f<g.length){g.length=f}l.sketchable("handler",function(n,o){g.push({image:n[0].toDataURL(),strokes:o.strokes.slice()})})};this.init=function(){d(document).on("keypress",m)};this.destroy=function(){d(document).off("keypress",m);this.reset()}};var c=d.fn.sketchable;var e=c("methods");function b(l,f){d.extend(c.defaults,f);var m=new a(l);var k={init:function(i,n){n.memento=m;n.memento.save();n.memento.init()},mouseup:function(i,n,o){n.memento.save()},destroy:function(i,n){n.memento.destroy()}};function j(n){if(f&&f.events&&typeof f.events[n]==="function"){var i=f.events[n];f.events[n]=function(){var o=Array.prototype.slice.call(arguments,0);i.call(this,o);k[n].apply(this,o)}}else{c.defaults.events[n]=k[n]}}var h="init mouseup destroy".split(" ");for(var g=0;g<h.length;g++){j(h[g])}d.extend(e,{undo:function(){m.undo()},redo:function(){m.redo()}});return c.defaults}d.fn.sketchable=function(g){if(typeof g==="object"||!g){var f=b(this,arguments[0]);return e.init.apply(this,[f])}else{if(e[g]){return e[g].apply(this,Array.prototype.slice.call(arguments,1))}}}})(jQuery);