Update Jcrop to 0.9.8. Props nbachiyski. fixes #9545
git-svn-id: http://svn.automattic.com/wordpress/trunk@11015 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
dba5368640
commit
d24d57abd0
|
@ -1,18 +1,11 @@
|
||||||
/* Fixes issue here http://code.google.com/p/jcrop/issues/detail?id=1 */
|
/* Fixes issue here http://code.google.com/p/jcrop/issues/detail?id=1 */
|
||||||
.jcrop-holder
|
.jcrop-holder { text-align: left; }
|
||||||
{
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
.jcrop-vline, .jcrop-hline
|
.jcrop-vline, .jcrop-hline
|
||||||
{
|
{
|
||||||
font-size: 0;
|
font-size: 0;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
background: white url('Jcrop.gif') top left repeat;
|
background: white url('Jcrop.gif') top left repeat;
|
||||||
/*
|
|
||||||
opacity: .5;
|
|
||||||
*filter:alpha(opacity=50);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
.jcrop-vline { height: 100%; width: 1px !important; }
|
.jcrop-vline { height: 100%; width: 1px !important; }
|
||||||
.jcrop-hline { width: 100%; height: 1px !important; }
|
.jcrop-hline { width: 100%; height: 1px !important; }
|
||||||
|
@ -26,10 +19,7 @@
|
||||||
*height: 9px;
|
*height: 9px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.jcrop-tracker {
|
.jcrop-tracker { width: 100%; height: 100%; }
|
||||||
*background-color: gray;
|
|
||||||
width: 100%; height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.custom .jcrop-vline,
|
.custom .jcrop-vline,
|
||||||
.custom .jcrop-hline
|
.custom .jcrop-hline
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
/**
|
/**
|
||||||
* jquery.Jcrop.js v0.9.5
|
* jquery.Jcrop.js v0.9.8
|
||||||
* jQuery Image Cropping Plugin
|
* jQuery Image Cropping Plugin
|
||||||
* @author Kelly Hallman <khallman@wrack.org>
|
* @author Kelly Hallman <khallman@gmail.com>
|
||||||
* Copyright (c) 2008 Kelly Hallman - released under MIT License {{{
|
* Copyright (c) 2008-2009 Kelly Hallman - released under MIT License {{{
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person
|
* Permission is hereby granted, free of charge, to any person
|
||||||
* obtaining a copy of this software and associated documentation
|
* obtaining a copy of this software and associated documentation
|
||||||
|
@ -27,7 +27,9 @@
|
||||||
|
|
||||||
* }}}
|
* }}}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function($) {
|
(function($) {
|
||||||
|
|
||||||
$.Jcrop = function(obj,opt)
|
$.Jcrop = function(obj,opt)
|
||||||
{
|
{
|
||||||
// Initialization {{{
|
// Initialization {{{
|
||||||
|
@ -38,12 +40,17 @@ $.Jcrop = function(obj,opt)
|
||||||
if (typeof(obj) !== 'object') obj = $(obj)[0];
|
if (typeof(obj) !== 'object') obj = $(obj)[0];
|
||||||
if (typeof(opt) !== 'object') opt = { };
|
if (typeof(opt) !== 'object') opt = { };
|
||||||
|
|
||||||
|
// Some on-the-fly fixes for MSIE...sigh
|
||||||
if (!('trackDocument' in opt))
|
if (!('trackDocument' in opt))
|
||||||
|
{
|
||||||
opt.trackDocument = $.browser.msie ? false : true;
|
opt.trackDocument = $.browser.msie ? false : true;
|
||||||
|
if ($.browser.msie && $.browser.version.split('.')[0] == '8')
|
||||||
|
opt.trackDocument = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!('keySupport' in opt))
|
if (!('keySupport' in opt))
|
||||||
opt.keySupport = $.browser.msie ? false : true;
|
opt.keySupport = $.browser.msie ? false : true;
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// Extend the default options {{{
|
// Extend the default options {{{
|
||||||
var defaults = {
|
var defaults = {
|
||||||
|
@ -78,7 +85,10 @@ $.Jcrop = function(obj,opt)
|
||||||
animationDelay: 20,
|
animationDelay: 20,
|
||||||
swingSpeed: 3,
|
swingSpeed: 3,
|
||||||
|
|
||||||
watchShift: false,
|
allowSelect: true,
|
||||||
|
allowMove: true,
|
||||||
|
allowResize: true,
|
||||||
|
|
||||||
minSelect: [ 0, 0 ],
|
minSelect: [ 0, 0 ],
|
||||||
maxSize: [ 0, 0 ],
|
maxSize: [ 0, 0 ],
|
||||||
minSize: [ 0, 0 ],
|
minSize: [ 0, 0 ],
|
||||||
|
@ -94,7 +104,12 @@ $.Jcrop = function(obj,opt)
|
||||||
// }}}
|
// }}}
|
||||||
// Initialize some jQuery objects {{{
|
// Initialize some jQuery objects {{{
|
||||||
|
|
||||||
var $img = $(obj).css({ position: 'absolute' });
|
var $origimg = $(obj);
|
||||||
|
var $img = $origimg.clone().removeAttr('id').css({ position: 'absolute' });
|
||||||
|
|
||||||
|
$img.width($origimg.width());
|
||||||
|
$img.height($origimg.height());
|
||||||
|
$origimg.after($img).hide();
|
||||||
|
|
||||||
presize($img,options.boxWidth,options.boxHeight);
|
presize($img,options.boxWidth,options.boxHeight);
|
||||||
|
|
||||||
|
@ -106,13 +121,12 @@ $.Jcrop = function(obj,opt)
|
||||||
.addClass(cssClass('holder'))
|
.addClass(cssClass('holder'))
|
||||||
.css({
|
.css({
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
//overflow: 'hidden',
|
|
||||||
backgroundColor: options.bgColor
|
backgroundColor: options.bgColor
|
||||||
})
|
}).insertAfter($origimg).append($img);
|
||||||
;
|
;
|
||||||
|
|
||||||
if (options.addClass) $div.addClass(options.addClass);
|
if (options.addClass) $div.addClass(options.addClass);
|
||||||
$img.wrap($div);
|
//$img.wrap($div);
|
||||||
|
|
||||||
var $img2 = $('<img />')/*{{{*/
|
var $img2 = $('<img />')/*{{{*/
|
||||||
.attr('src',$img.attr('src'))
|
.attr('src',$img.attr('src'))
|
||||||
|
@ -130,11 +144,8 @@ $.Jcrop = function(obj,opt)
|
||||||
;/*}}}*/
|
;/*}}}*/
|
||||||
var $hdl_holder = $('<div />')/*{{{*/
|
var $hdl_holder = $('<div />')/*{{{*/
|
||||||
.width(pct(100)).height(pct(100))
|
.width(pct(100)).height(pct(100))
|
||||||
.css({
|
.css('zIndex',320);
|
||||||
zIndex: 320
|
/*}}}*/
|
||||||
//position: 'absolute'
|
|
||||||
})
|
|
||||||
;/*}}}*/
|
|
||||||
var $sel = $('<div />')/*{{{*/
|
var $sel = $('<div />')/*{{{*/
|
||||||
.css({
|
.css({
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
|
@ -145,38 +156,24 @@ $.Jcrop = function(obj,opt)
|
||||||
;/*}}}*/
|
;/*}}}*/
|
||||||
|
|
||||||
var bound = options.boundary;
|
var bound = options.boundary;
|
||||||
var $trk = $('<div />')
|
var $trk = newTracker().width(boundx+(bound*2)).height(boundy+(bound*2))
|
||||||
.addClass(cssClass('tracker'))
|
.css({ position: 'absolute', top: px(-bound), left: px(-bound), zIndex: 290 })
|
||||||
.width(boundx+(bound*2))
|
.mousedown(newSelection);
|
||||||
.height(boundy+(bound*2))
|
|
||||||
.css({
|
|
||||||
position: 'absolute',
|
|
||||||
top: px(-bound),
|
|
||||||
left: px(-bound),
|
|
||||||
zIndex: 290,
|
|
||||||
opacity: 0
|
|
||||||
})
|
|
||||||
.mousedown(newSelection)
|
|
||||||
;
|
|
||||||
|
|
||||||
/* }}} */
|
/* }}} */
|
||||||
// Set more variables {{{
|
// Set more variables {{{
|
||||||
|
|
||||||
var xscale, yscale;
|
var xlimit, ylimit, xmin, ymin;
|
||||||
var docOffset = getPos(obj),
|
var xscale, yscale, enabled = true;
|
||||||
|
var docOffset = getPos($img),
|
||||||
// Internal states
|
// Internal states
|
||||||
btndown, aspectLock, lastcurs, dimmed, animating,
|
btndown, lastcurs, dimmed, animating,
|
||||||
shift_down;
|
shift_down;
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
if ('trueSize' in options)/*{{{*/
|
|
||||||
{
|
|
||||||
xscale = options.trueSize[0] / boundx;
|
|
||||||
yscale = options.trueSize[1] / boundy;
|
|
||||||
}
|
|
||||||
/*}}}*/
|
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// Internal Modules {{{
|
// Internal Modules {{{
|
||||||
|
|
||||||
var Coords = function()/*{{{*/
|
var Coords = function()/*{{{*/
|
||||||
|
@ -234,12 +231,13 @@ $.Jcrop = function(obj,opt)
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
function getFixed()/*{{{*/
|
function getFixed()/*{{{*/
|
||||||
{
|
{
|
||||||
if (!options.aspectRatio && !aspectLock) return getRect();
|
if (!options.aspectRatio) return getRect();
|
||||||
|
|
||||||
// This function could use some optimization I think...
|
// This function could use some optimization I think...
|
||||||
var aspect = options.aspectRatio ? options.aspectRatio : aspectLock,
|
var aspect = options.aspectRatio,
|
||||||
min = options.minSize,
|
min_x = options.minSize[0]/xscale,
|
||||||
max = options.maxSize,
|
min_y = options.minSize[1]/yscale,
|
||||||
|
max_x = options.maxSize[0]/xscale,
|
||||||
|
max_y = options.maxSize[1]/yscale,
|
||||||
rw = x2 - x1,
|
rw = x2 - x1,
|
||||||
rh = y2 - y1,
|
rh = y2 - y1,
|
||||||
rwa = Math.abs(rw),
|
rwa = Math.abs(rw),
|
||||||
|
@ -247,7 +245,8 @@ $.Jcrop = function(obj,opt)
|
||||||
real_ratio = rwa / rha,
|
real_ratio = rwa / rha,
|
||||||
xx, yy
|
xx, yy
|
||||||
;
|
;
|
||||||
|
if (max_x == 0) { max_x = boundx * 10 }
|
||||||
|
if (max_y == 0) { max_y = boundy * 10 }
|
||||||
if (real_ratio < aspect)
|
if (real_ratio < aspect)
|
||||||
{
|
{
|
||||||
yy = y2;
|
yy = y2;
|
||||||
|
@ -285,6 +284,48 @@ $.Jcrop = function(obj,opt)
|
||||||
xx = rw < 0 ? x1 - w : w + x1;
|
xx = rw < 0 ? x1 - w : w + x1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Magic %-)
|
||||||
|
if(xx > x1) { // right side
|
||||||
|
if(xx - x1 < min_x) {
|
||||||
|
xx = x1 + min_x;
|
||||||
|
} else if (xx - x1 > max_x) {
|
||||||
|
xx = x1 + max_x;
|
||||||
|
}
|
||||||
|
if(yy > y1) {
|
||||||
|
yy = y1 + (xx - x1)/aspect;
|
||||||
|
} else {
|
||||||
|
yy = y1 - (xx - x1)/aspect;
|
||||||
|
}
|
||||||
|
} else if (xx < x1) { // left side
|
||||||
|
if(x1 - xx < min_x) {
|
||||||
|
xx = x1 - min_x
|
||||||
|
} else if (x1 - xx > max_x) {
|
||||||
|
xx = x1 - max_x;
|
||||||
|
}
|
||||||
|
if(yy > y1) {
|
||||||
|
yy = y1 + (x1 - xx)/aspect;
|
||||||
|
} else {
|
||||||
|
yy = y1 - (x1 - xx)/aspect;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(xx < 0) {
|
||||||
|
x1 -= xx;
|
||||||
|
xx = 0;
|
||||||
|
} else if (xx > boundx) {
|
||||||
|
x1 -= xx - boundx;
|
||||||
|
xx = boundx;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(yy < 0) {
|
||||||
|
y1 -= yy;
|
||||||
|
yy = 0;
|
||||||
|
} else if (yy > boundy) {
|
||||||
|
y1 -= yy - boundy;
|
||||||
|
yy = boundy;
|
||||||
|
}
|
||||||
|
|
||||||
return last = makeObj(flipCoords(x1,y1,xx,yy));
|
return last = makeObj(flipCoords(x1,y1,xx,yy));
|
||||||
};
|
};
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
|
@ -490,15 +531,18 @@ $.Jcrop = function(obj,opt)
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
function refresh()/*{{{*/
|
function refresh()/*{{{*/
|
||||||
{
|
{
|
||||||
var p = Coords.getFixed();
|
var c = Coords.getFixed();
|
||||||
Coords.setPressed([p.x,p.y]);
|
|
||||||
Coords.setCurrent([p.x2,p.y2]);
|
Coords.setPressed([c.x,c.y]);
|
||||||
|
Coords.setCurrent([c.x2,c.y2]);
|
||||||
|
|
||||||
|
updateVisible();
|
||||||
};
|
};
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
|
|
||||||
// Internal Methods
|
// Internal Methods
|
||||||
function updateVisible()/*{{{*/
|
function updateVisible()/*{{{*/
|
||||||
{ if (awake) return update(); };
|
{ if (awake) return update(); };
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
function update()/*{{{*/
|
function update()/*{{{*/
|
||||||
{
|
{
|
||||||
|
@ -532,18 +576,24 @@ $.Jcrop = function(obj,opt)
|
||||||
awake = false;
|
awake = false;
|
||||||
};
|
};
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
function hide()/*{{{*/
|
function showHandles()//{{{
|
||||||
{
|
{
|
||||||
release();
|
if (seehandles)
|
||||||
$img.css('opacity',1);
|
{
|
||||||
awake = false;
|
moveHandles(Coords.getFixed());
|
||||||
|
$hdl_holder.show();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
/*}}}*/
|
//}}}
|
||||||
function enableHandles()/*{{{*/
|
function enableHandles()/*{{{*/
|
||||||
{
|
{
|
||||||
seehandles = true;
|
seehandles = true;
|
||||||
moveHandles(Coords.getFixed());
|
if (options.allowResize)
|
||||||
$hdl_holder.show();
|
{
|
||||||
|
moveHandles(Coords.getFixed());
|
||||||
|
$hdl_holder.show();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
function disableHandles()/*{{{*/
|
function disableHandles()/*{{{*/
|
||||||
|
@ -559,29 +609,26 @@ $.Jcrop = function(obj,opt)
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
function done()/*{{{*/
|
function done()/*{{{*/
|
||||||
{
|
{
|
||||||
var c = Coords.getFixed();
|
|
||||||
animMode(false);
|
animMode(false);
|
||||||
refresh();
|
refresh();
|
||||||
};
|
};
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
|
|
||||||
disableHandles();
|
var $track = newTracker().mousedown(createDragger('move'))
|
||||||
|
.css({ cursor: 'move', position: 'absolute', zIndex: 360 })
|
||||||
|
|
||||||
$img_holder.append
|
$img_holder.append($track);
|
||||||
(
|
disableHandles();
|
||||||
$('<div />')
|
|
||||||
.addClass(cssClass('tracker'))
|
|
||||||
.mousedown(createDragger('move'))
|
|
||||||
.css({ cursor: 'move', position: 'absolute', zIndex: 360, opacity: 0 })
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
updateVisible: updateVisible,
|
updateVisible: updateVisible,
|
||||||
update: update,
|
update: update,
|
||||||
release: release,
|
release: release,
|
||||||
show: show,
|
refresh: refresh,
|
||||||
hide: hide,
|
setCursor: function (cursor) { $track.css('cursor',cursor); },
|
||||||
enableHandles: enableHandles,
|
enableHandles: enableHandles,
|
||||||
|
enableOnly: function() { seehandles = true; },
|
||||||
|
showHandles: showHandles,
|
||||||
disableHandles: disableHandles,
|
disableHandles: disableHandles,
|
||||||
animMode: animMode,
|
animMode: animMode,
|
||||||
done: done
|
done: done
|
||||||
|
@ -605,6 +652,7 @@ $.Jcrop = function(obj,opt)
|
||||||
|
|
||||||
function toFront()/*{{{*/
|
function toFront()/*{{{*/
|
||||||
{
|
{
|
||||||
|
$trk.css({zIndex:450});
|
||||||
if (trackDoc)
|
if (trackDoc)
|
||||||
{
|
{
|
||||||
$(document)
|
$(document)
|
||||||
|
@ -612,11 +660,11 @@ $.Jcrop = function(obj,opt)
|
||||||
.mouseup(trackUp)
|
.mouseup(trackUp)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
$trk.css({zIndex:450});
|
|
||||||
}
|
}
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
function toBack()/*{{{*/
|
function toBack()/*{{{*/
|
||||||
{
|
{
|
||||||
|
$trk.css({zIndex:290});
|
||||||
if (trackDoc)
|
if (trackDoc)
|
||||||
{
|
{
|
||||||
$(document)
|
$(document)
|
||||||
|
@ -624,7 +672,6 @@ $.Jcrop = function(obj,opt)
|
||||||
.unbind('mouseup',trackUp)
|
.unbind('mouseup',trackUp)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
$trk.css({zIndex:290});
|
|
||||||
}
|
}
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
function trackMove(e)/*{{{*/
|
function trackMove(e)/*{{{*/
|
||||||
|
@ -675,8 +722,7 @@ $.Jcrop = function(obj,opt)
|
||||||
{
|
{
|
||||||
var $keymgr = $('<input type="radio" />')
|
var $keymgr = $('<input type="radio" />')
|
||||||
.css({ position: 'absolute', left: '-30px' })
|
.css({ position: 'absolute', left: '-30px' })
|
||||||
.keydown(parseKey)
|
.keypress(parseKey)
|
||||||
.keyup(watchShift)
|
|
||||||
.blur(onBlur),
|
.blur(onBlur),
|
||||||
|
|
||||||
$keywrap = $('<div />')
|
$keywrap = $('<div />')
|
||||||
|
@ -701,28 +747,12 @@ $.Jcrop = function(obj,opt)
|
||||||
$keymgr.hide();
|
$keymgr.hide();
|
||||||
};
|
};
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
function watchShift(e)/*{{{*/
|
|
||||||
{
|
|
||||||
if (!options.watchShift) return;
|
|
||||||
var init_shift = shift_down, fc;
|
|
||||||
shift_down = e.shiftKey ? true : false;
|
|
||||||
|
|
||||||
if (init_shift != shift_down) {
|
|
||||||
if (shift_down && btndown) {
|
|
||||||
fc = Coords.getFixed();
|
|
||||||
aspectLock = fc.w / fc.h;
|
|
||||||
} else aspectLock = 0;
|
|
||||||
Selection.update();
|
|
||||||
}
|
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
/*}}}*/
|
|
||||||
function doNudge(e,x,y)/*{{{*/
|
function doNudge(e,x,y)/*{{{*/
|
||||||
{
|
{
|
||||||
Coords.moveOffset([x,y]);
|
if (options.allowMove) {
|
||||||
Selection.updateVisible();
|
Coords.moveOffset([x,y]);
|
||||||
|
Selection.updateVisible();
|
||||||
|
};
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
};
|
};
|
||||||
|
@ -730,7 +760,7 @@ $.Jcrop = function(obj,opt)
|
||||||
function parseKey(e)/*{{{*/
|
function parseKey(e)/*{{{*/
|
||||||
{
|
{
|
||||||
if (e.ctrlKey) return true;
|
if (e.ctrlKey) return true;
|
||||||
watchShift(e);
|
shift_down = e.shiftKey ? true : false;
|
||||||
var nudge = shift_down ? 10 : 1;
|
var nudge = shift_down ? 10 : 1;
|
||||||
switch(e.keyCode)
|
switch(e.keyCode)
|
||||||
{
|
{
|
||||||
|
@ -744,7 +774,7 @@ $.Jcrop = function(obj,opt)
|
||||||
case 9: return true;
|
case 9: return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return nothing(e);
|
||||||
};
|
};
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
|
|
||||||
|
@ -785,21 +815,26 @@ $.Jcrop = function(obj,opt)
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
function startDragMode(mode,pos)/*{{{*/
|
function startDragMode(mode,pos)/*{{{*/
|
||||||
{
|
{
|
||||||
docOffset = getPos(obj);
|
docOffset = getPos($img);
|
||||||
Tracker.setCursor(mode=='move'?mode:mode+'-resize');
|
Tracker.setCursor(mode=='move'?mode:mode+'-resize');
|
||||||
|
|
||||||
if (mode == 'move')
|
if (mode == 'move')
|
||||||
return Tracker.activateHandlers(createMover(pos), doneSelect);
|
return Tracker.activateHandlers(createMover(pos), doneSelect);
|
||||||
|
|
||||||
var fc = Coords.getFixed();
|
var fc = Coords.getFixed();
|
||||||
Coords.setPressed(Coords.getCorner(oppLockCorner(mode)));
|
var opp = oppLockCorner(mode);
|
||||||
|
var opc = Coords.getCorner(oppLockCorner(opp));
|
||||||
|
|
||||||
|
Coords.setPressed(Coords.getCorner(opp));
|
||||||
|
Coords.setCurrent(opc);
|
||||||
|
|
||||||
Tracker.activateHandlers(dragmodeHandler(mode,fc),doneSelect);
|
Tracker.activateHandlers(dragmodeHandler(mode,fc),doneSelect);
|
||||||
};
|
};
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
function dragmodeHandler(mode,f)/*{{{*/
|
function dragmodeHandler(mode,f)/*{{{*/
|
||||||
{
|
{
|
||||||
return function(pos) {
|
return function(pos) {
|
||||||
if (!options.aspectRatio && !aspectLock) switch(mode)
|
if (!options.aspectRatio) switch(mode)
|
||||||
{
|
{
|
||||||
case 'e': pos[1] = f.y2; break;
|
case 'e': pos[1] = f.y2; break;
|
||||||
case 'w': pos[1] = f.y2; break;
|
case 'w': pos[1] = f.y2; break;
|
||||||
|
@ -850,6 +885,8 @@ $.Jcrop = function(obj,opt)
|
||||||
function createDragger(ord)/*{{{*/
|
function createDragger(ord)/*{{{*/
|
||||||
{
|
{
|
||||||
return function(e) {
|
return function(e) {
|
||||||
|
if (options.disabled) return false;
|
||||||
|
if ((ord == 'move') && !options.allowMove) return false;
|
||||||
btndown = true;
|
btndown = true;
|
||||||
startDragMode(ord,mouseAbs(e));
|
startDragMode(ord,mouseAbs(e));
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
@ -897,19 +934,22 @@ $.Jcrop = function(obj,opt)
|
||||||
{
|
{
|
||||||
Selection.release();
|
Selection.release();
|
||||||
}
|
}
|
||||||
Tracker.setCursor('crosshair');
|
Tracker.setCursor( options.allowSelect?'crosshair':'default' );
|
||||||
};
|
};
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
function newSelection(e)/*{{{*/
|
function newSelection(e)/*{{{*/
|
||||||
{
|
{
|
||||||
|
if (options.disabled) return false;
|
||||||
|
if (!options.allowSelect) return false;
|
||||||
btndown = true;
|
btndown = true;
|
||||||
docOffset = getPos(obj);
|
docOffset = getPos($img);
|
||||||
Selection.release();
|
|
||||||
Selection.disableHandles();
|
Selection.disableHandles();
|
||||||
myCursor('crosshair');
|
myCursor('crosshair');
|
||||||
Coords.setPressed(mouseAbs(e));
|
var pos = mouseAbs(e);
|
||||||
|
Coords.setPressed(pos);
|
||||||
Tracker.activateHandlers(selectDrag,doneSelect);
|
Tracker.activateHandlers(selectDrag,doneSelect);
|
||||||
KeyManager.watchKeys();
|
KeyManager.watchKeys();
|
||||||
|
Selection.update();
|
||||||
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -920,29 +960,31 @@ $.Jcrop = function(obj,opt)
|
||||||
{
|
{
|
||||||
Coords.setCurrent(pos);
|
Coords.setCurrent(pos);
|
||||||
Selection.update();
|
Selection.update();
|
||||||
|
|
||||||
};
|
};
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
|
function newTracker()
|
||||||
|
{
|
||||||
|
var trk = $('<div></div>').addClass(cssClass('tracker'));
|
||||||
|
$.browser.msie && trk.css({ opacity: 0, backgroundColor: 'white' });
|
||||||
|
return trk;
|
||||||
|
};
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
// Public API {{{
|
// API methods {{{
|
||||||
|
|
||||||
function animateTo(a)/*{{{*/
|
function animateTo(a)/*{{{*/
|
||||||
{
|
{
|
||||||
var x1 = a[0],
|
var x1 = a[0] / xscale,
|
||||||
y1 = a[1],
|
y1 = a[1] / yscale,
|
||||||
x2 = a[2],
|
x2 = a[2] / xscale,
|
||||||
y2 = a[3];
|
y2 = a[3] / yscale;
|
||||||
|
|
||||||
if (animating) return;
|
if (animating) return;
|
||||||
|
|
||||||
var animto = Coords.flipCoords(x1,y1,x2,y2);
|
var animto = Coords.flipCoords(x1,y1,x2,y2);
|
||||||
var c = Coords.getFixed();
|
var c = Coords.getFixed();
|
||||||
var animat = initcr = [ c.x, c.y, c.x2, c.y2 ];
|
var animat = initcr = [ c.x, c.y, c.x2, c.y2 ];
|
||||||
var interv = options.animationDelay;
|
var interv = options.animationDelay;
|
||||||
//var ix1 = (animto[0] - initcr[0]) / steps;
|
|
||||||
//var iy1 = (animto[1] - initcr[1]) / steps;
|
|
||||||
//var ix2 = (animto[2] - initcr[2]) / steps;
|
|
||||||
//var iy2 = (animto[3] - initcr[3]) / steps;
|
|
||||||
|
|
||||||
var x = animat[0];
|
var x = animat[0];
|
||||||
var y = animat[1];
|
var y = animat[1];
|
||||||
|
@ -973,7 +1015,7 @@ $.Jcrop = function(obj,opt)
|
||||||
|
|
||||||
if (pcent >= 99.8) pcent = 100;
|
if (pcent >= 99.8) pcent = 100;
|
||||||
|
|
||||||
setSelect(animat);
|
setSelectRaw(animat);
|
||||||
};
|
};
|
||||||
}();
|
}();
|
||||||
|
|
||||||
|
@ -981,10 +1023,14 @@ $.Jcrop = function(obj,opt)
|
||||||
{ window.setTimeout(animator,interv); };
|
{ window.setTimeout(animator,interv); };
|
||||||
|
|
||||||
animateStart();
|
animateStart();
|
||||||
|
|
||||||
};
|
};
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
function setSelect(l) /*{{{*/
|
function setSelect(rect)//{{{
|
||||||
|
{
|
||||||
|
setSelectRaw([rect[0]/xscale,rect[1]/yscale,rect[2]/xscale,rect[3]/yscale]);
|
||||||
|
};
|
||||||
|
//}}}
|
||||||
|
function setSelectRaw(l) /*{{{*/
|
||||||
{
|
{
|
||||||
Coords.setPressed([l[0],l[1]]);
|
Coords.setPressed([l[0],l[1]]);
|
||||||
Coords.setCurrent([l[2],l[3]]);
|
Coords.setCurrent([l[2],l[3]]);
|
||||||
|
@ -1001,6 +1047,7 @@ $.Jcrop = function(obj,opt)
|
||||||
|
|
||||||
if (typeof(options.onSelect)!=='function')
|
if (typeof(options.onSelect)!=='function')
|
||||||
options.onSelect = function() { };
|
options.onSelect = function() { };
|
||||||
|
|
||||||
};
|
};
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
function tellSelect()/*{{{*/
|
function tellSelect()/*{{{*/
|
||||||
|
@ -1016,35 +1063,104 @@ $.Jcrop = function(obj,opt)
|
||||||
function setOptionsNew(opt)/*{{{*/
|
function setOptionsNew(opt)/*{{{*/
|
||||||
{
|
{
|
||||||
setOptions(opt);
|
setOptions(opt);
|
||||||
|
interfaceUpdate();
|
||||||
if ('setSelect' in opt) {
|
|
||||||
setSelect(opt.setSelect);
|
|
||||||
Selection.done();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
|
function disableCrop()//{{{
|
||||||
|
{
|
||||||
|
options.disabled = true;
|
||||||
|
Selection.disableHandles();
|
||||||
|
Selection.setCursor('default');
|
||||||
|
Tracker.setCursor('default');
|
||||||
|
};
|
||||||
|
//}}}
|
||||||
|
function enableCrop()//{{{
|
||||||
|
{
|
||||||
|
options.disabled = false;
|
||||||
|
interfaceUpdate();
|
||||||
|
};
|
||||||
|
//}}}
|
||||||
|
function cancelCrop()//{{{
|
||||||
|
{
|
||||||
|
Selection.done();
|
||||||
|
Tracker.activateHandlers(null,null);
|
||||||
|
};
|
||||||
|
//}}}
|
||||||
|
function destroy()//{{{
|
||||||
|
{
|
||||||
|
$div.remove();
|
||||||
|
$origimg.show();
|
||||||
|
};
|
||||||
|
//}}}
|
||||||
|
|
||||||
if (typeof(opt) != 'object') opt = { };
|
function interfaceUpdate(alt)//{{{
|
||||||
if ('setSelect' in opt) { setSelect(opt.setSelect); Selection.done(); }
|
// This method tweaks the interface based on options object.
|
||||||
|
// Called when options are changed and at end of initialization.
|
||||||
|
{
|
||||||
|
options.allowResize ?
|
||||||
|
alt?Selection.enableOnly():Selection.enableHandles():
|
||||||
|
Selection.disableHandles();
|
||||||
|
|
||||||
|
Tracker.setCursor( options.allowSelect? 'crosshair': 'default' );
|
||||||
|
Selection.setCursor( options.allowMove? 'move': 'default' );
|
||||||
|
|
||||||
|
$div.css('backgroundColor',options.bgColor);
|
||||||
|
|
||||||
|
if ('setSelect' in options) {
|
||||||
|
setSelect(opt.setSelect);
|
||||||
|
Selection.done();
|
||||||
|
delete(options.setSelect);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('trueSize' in options) {
|
||||||
|
xscale = options.trueSize[0] / boundx;
|
||||||
|
yscale = options.trueSize[1] / boundy;
|
||||||
|
}
|
||||||
|
|
||||||
|
xlimit = options.maxSize[0] || 0;
|
||||||
|
ylimit = options.maxSize[1] || 0;
|
||||||
|
xmin = options.minSize[0] || 0;
|
||||||
|
ymin = options.minSize[1] || 0;
|
||||||
|
|
||||||
|
if ('outerImage' in options)
|
||||||
|
{
|
||||||
|
$img.attr('src',options.outerImage);
|
||||||
|
delete(options.outerImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
Selection.refresh();
|
||||||
|
};
|
||||||
|
//}}}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
var xlimit = options.maxSize[0] || 0;
|
$hdl_holder.hide();
|
||||||
var ylimit = options.maxSize[1] || 0;
|
interfaceUpdate(true);
|
||||||
var xmin = options.minSize[0] || 0;
|
|
||||||
var ymin = options.minSize[1] || 0;
|
|
||||||
|
|
||||||
Tracker.setCursor('crosshair');
|
|
||||||
|
|
||||||
return {
|
var api = {
|
||||||
animateTo: animateTo,
|
animateTo: animateTo,
|
||||||
setSelect: setSelect,
|
setSelect: setSelect,
|
||||||
setOptions: setOptionsNew,
|
setOptions: setOptionsNew,
|
||||||
tellSelect: tellSelect,
|
tellSelect: tellSelect,
|
||||||
tellScaled: tellScaled
|
tellScaled: tellScaled,
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
disable: disableCrop,
|
||||||
|
enable: enableCrop,
|
||||||
|
cancel: cancelCrop,
|
||||||
|
|
||||||
|
focus: KeyManager.watchKeys,
|
||||||
|
|
||||||
|
getBounds: function() { return [ boundx * xscale, boundy * yscale ]; },
|
||||||
|
getWidgetSize: function() { return [ boundx, boundy ]; },
|
||||||
|
|
||||||
|
release: Selection.release,
|
||||||
|
destroy: destroy
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
$origimg.data('Jcrop',api);
|
||||||
|
return api;
|
||||||
|
};
|
||||||
|
|
||||||
$.fn.Jcrop = function(options)/*{{{*/
|
$.fn.Jcrop = function(options)/*{{{*/
|
||||||
{
|
{
|
||||||
|
@ -1052,11 +1168,7 @@ $.fn.Jcrop = function(options)/*{{{*/
|
||||||
{
|
{
|
||||||
var loadsrc = options.useImg || from.src;
|
var loadsrc = options.useImg || from.src;
|
||||||
var img = new Image();
|
var img = new Image();
|
||||||
var from = from;
|
img.onload = function() { $.Jcrop(from,options); };
|
||||||
img.onload = function() {
|
|
||||||
$(from).hide().after(img);
|
|
||||||
from.Jcrop = $.Jcrop(img,options);
|
|
||||||
};
|
|
||||||
img.src = loadsrc;
|
img.src = loadsrc;
|
||||||
};
|
};
|
||||||
/*}}}*/
|
/*}}}*/
|
||||||
|
@ -1066,12 +1178,12 @@ $.fn.Jcrop = function(options)/*{{{*/
|
||||||
this.each(function()
|
this.each(function()
|
||||||
{
|
{
|
||||||
// If we've already attached to this object
|
// If we've already attached to this object
|
||||||
if ('Jcrop' in this)
|
if ($(this).data('Jcrop'))
|
||||||
{
|
{
|
||||||
// The API can be requested this way (undocumented)
|
// The API can be requested this way (undocumented)
|
||||||
if (options == 'api') return this.Jcrop;
|
if (options == 'api') return $(this).data('Jcrop');
|
||||||
// Otherwise, we just reset the options...
|
// Otherwise, we just reset the options...
|
||||||
else this.Jcrop.setOptions(options);
|
else $(this).data('Jcrop').setOptions(options);
|
||||||
}
|
}
|
||||||
// If we haven't been attached, preload and attach
|
// If we haven't been attached, preload and attach
|
||||||
else attachWhenDone(this);
|
else attachWhenDone(this);
|
||||||
|
@ -1080,5 +1192,6 @@ $.fn.Jcrop = function(options)/*{{{*/
|
||||||
// Return "this" so we're chainable a la jQuery plugin-style!
|
// Return "this" so we're chainable a la jQuery plugin-style!
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
/*}}}*/
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
/*}}}*/
|
|
File diff suppressed because one or more lines are too long
|
@ -167,7 +167,7 @@ function wp_default_scripts( &$scripts ) {
|
||||||
$scripts->add( 'thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20090123');
|
$scripts->add( 'thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20090123');
|
||||||
$scripts->add_data( 'thickbox', 'group', 1 );
|
$scripts->add_data( 'thickbox', 'group', 1 );
|
||||||
|
|
||||||
$scripts->add( 'jcrop', "/wp-includes/js/jcrop/jquery.Jcrop$suffix.js", array('jquery'), '0.9.5-1');
|
$scripts->add( 'jcrop', "/wp-includes/js/jcrop/jquery.Jcrop$suffix.js", array('jquery'), '0.9.8');
|
||||||
|
|
||||||
if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
|
if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
|
||||||
$scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.2.0-20081031');
|
$scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', false, '2.2.0-20081031');
|
||||||
|
@ -442,7 +442,7 @@ function wp_default_styles( &$styles ) {
|
||||||
$styles->add( 'plugin-install', '/wp-admin/css/plugin-install.css', array(), '20081210' );
|
$styles->add( 'plugin-install', '/wp-admin/css/plugin-install.css', array(), '20081210' );
|
||||||
$styles->add( 'theme-install', '/wp-admin/css/theme-install.css', array(), '20090319' );
|
$styles->add( 'theme-install', '/wp-admin/css/theme-install.css', array(), '20090319' );
|
||||||
$styles->add( 'farbtastic', '/wp-admin/css/farbtastic.css', array(), '1.2' );
|
$styles->add( 'farbtastic', '/wp-admin/css/farbtastic.css', array(), '1.2' );
|
||||||
$styles->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.css', array(), '0.9.5' );
|
$styles->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.css', array(), '0.9.8' );
|
||||||
|
|
||||||
foreach ( $rtl_styles as $rtl_style )
|
foreach ( $rtl_styles as $rtl_style )
|
||||||
$styles->add_data( $rtl_style, 'rtl', true );
|
$styles->add_data( $rtl_style, 'rtl', true );
|
||||||
|
|
Loading…
Reference in New Issue