Skip to content

Commit 144aa84

Browse files
committed
add and document dragstart/dragstop feature. Issue #160
1 parent d03deda commit 144aa84

File tree

3 files changed

+94
-6
lines changed

3 files changed

+94
-6
lines changed

docs/docs.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,37 @@ $("#changeOnMoveNo").spectrum({
260260
}
261261
});
262262

263+
function prettyTime() {
264+
var date = new Date();
265+
266+
return date.toLocaleTimeString();
267+
}
268+
269+
$("#eventshow").spectrum({
270+
show: function(c) {
271+
var label = $("#eventshowLabel");
272+
label.text("show called at " + prettyTime() + " (color is " + c.toHexString() + ")");
273+
}
274+
});
275+
276+
$("#eventhide").spectrum({
277+
hide: function(c) {
278+
var label = $("#eventhideLabel");
279+
label.text("hide called at " + prettyTime() + " (color is " + c.toHexString() + ")");
280+
}
281+
});
282+
283+
$("#eventdragstart").spectrum().on("dragstart.spectrum", function(e, c) {
284+
var label = $("#eventdragstartLabel");
285+
label.text("dragstart called at " + prettyTime() + " (color is " + c.toHexString() + ")");
286+
});
287+
288+
$("#eventdragstop").spectrum().on("dragstop.spectrum", function(e, c) {
289+
var label = $("#eventdragstopLabel");
290+
label.text("dragstop called at " + prettyTime() + " (color is " + c.toHexString() + ")");
291+
});
292+
293+
263294
$(".basic").spectrum({ change: updateBorders });
264295
$(".override").spectrum({
265296
color: "yellow",

index.html

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -641,10 +641,15 @@ <h3 id="events-hide">hide</h3>
641641
</div>
642642

643643
<pre class='prettyprint'>
644-
hide: function(color) {
645-
color.toHexString(); // #ff0000
646-
}
644+
hide: function(color) {
645+
color.toHexString(); // #ff0000
646+
}
647647
</pre>
648+
649+
<div class='example'>
650+
<input type='text' value='blanchedalmond' name='eventhide' id='eventhide' />
651+
<em id='eventhideLabel' class='em-label'></em>
652+
</div>
648653
</div>
649654

650655
<h3 id="events-show">show</h3>
@@ -659,10 +664,15 @@ <h3 id="events-show">show</h3>
659664
</div>
660665

661666
<pre class='prettyprint'>
662-
show: function(color) {
663-
color.toHexString(); // #ff0000
664-
}
667+
show: function(color) {
668+
color.toHexString(); // #ff0000
669+
}
665670
</pre>
671+
672+
<div class='example'>
673+
<input type='text' value='blanchedalmond' name='eventshow' id='eventshow' />
674+
<em id='eventshowLabel' class='em-label'></em>
675+
</div>
666676
</div>
667677

668678
<h3 id="events-beforeShow">beforeShow</h3>
@@ -686,6 +696,51 @@ <h3 id="events-beforeShow">beforeShow</h3>
686696
</div>
687697
</div>
688698

699+
<h3 id="events-dragstart">dragstart</h3>
700+
701+
<div class='option-content'>
702+
<div class='description'>
703+
<p>
704+
Called at the beginning of a drag event on either
705+
hue slider, alpha slider, or main color picker areas
706+
</p>
707+
</div>
708+
709+
<pre class='prettyprint'>
710+
$(element).on("dragstart.spectrum"): function(e, color) {
711+
color.toHexString(); // #ff0000
712+
}
713+
</pre>
714+
715+
<div class='example'>
716+
<input type='text' value='blanchedalmond' name='eventdragstart' id='eventdragstart' />
717+
<em id='eventdragstartLabel' class='em-label'></em>
718+
</div>
719+
</div>
720+
721+
<h3 id="events-dragstop">dragstop</h3>
722+
723+
<div class='option-content'>
724+
<div class='description'>
725+
<p>
726+
Called at the end of a drag event on either
727+
hue slider, alpha slider, or main color picker areas
728+
</p>
729+
</div>
730+
731+
<pre class='prettyprint'>
732+
$(element).on("dragstop.spectrum"): function(e, color) {
733+
color.toHexString(); // #ff0000
734+
}
735+
</pre>
736+
737+
<div class='example'>
738+
<input type='text' value='blanchedalmond' name='eventdragstop' id='eventdragstop' />
739+
<em id='eventdragstopLabel' class='em-label'></em>
740+
</div>
741+
</div>
742+
743+
689744
<h2 id="methods">Methods</h2>
690745
<pre class='prettyprint'>
691746
$("#picker").spectrum("show");

spectrum.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,12 @@
507507
}
508508
container.addClass(draggingClass);
509509
shiftMovementDirection = null;
510+
boundElement.trigger('dragstart.spectrum', [ get() ]);
510511
}
511512

512513
function dragStop() {
513514
container.removeClass(draggingClass);
515+
boundElement.trigger('dragstop.spectrum', [ get() ]);
514516
}
515517

516518
function setFromTextInput() {

0 commit comments

Comments
 (0)