<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<div id="DEBUG">Drag the small box or circle</div>
<div id="SVG_DND_HOLDER_1"></div>
/**
* @blog
* http://terryyoung.blogspot.com/2011/08/raphaeljs-drag-and-drop-on-steroids.html
*/
///////////////////////////////////////////////////////////////////////////////
// Scroll to the bottom to see the simple demo code.
//
// These below are a bunch of my extensions to Raphael
// that enables the final, simply usage
/**
* Too many times I've seen or written stuff like this that drives me mad:
*
* this.ox = this.type == 'rect' ? this.attr('x') : this.attr('cx');
* this.oy = this.type == 'rect' ? this.attr('y') : this.attr('cy');
*
* {...10,000 words of rant skipped here...}
*
* The last one simplifies it to:
* this.o(); // and better, it supports chaining
*
* @copyright Terry Young <terryyounghk [at] gmail.com>
* @license WTFPL Version 2 ( http://en.wikipedia.org/wiki/WTFPL )
*/
Raphael.el.is = function (type) { return this.type == (''+type).toLowerCase(); };
Raphael.el.x = function () { return this.is('circle') ? this.attr('cx') : this.attr('x'); };
Raphael.el.y = function () { return this.is('circle') ? this.attr('cy') : this.attr('y'); };
Raphael.el.o = function () { this.ox = this.x(); this.oy = this.y(); return this; };
/**
* Another one of my core extensions.
* Raphael has getBBox(), I guess the "B" stands for Basic,
* because I'd say the "A" in getABox() here stands for Advanced.
*
* It's just to free myself from calculating the same stuff over and over and over again.
* {...10,000 words of rant skipped here...}
*
* @author Terry Young <terryyounghk [at] gmail.com>
* @license WTFPL Version 2 ( http://en.wikipedia.org/wiki/WTFPL )
*/
Raphael.el.getABox = function ()
{
var b = this.getBBox(); // thanks, I'll take it from here...
var o =
{
// we'd still return what the original getBBox() provides us with
x: b.x,
y: b.y,
width: b.width,
height: b.height,
// now we can actually pre-calculate...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.