MCPcopy
hub / github.com/methodofaction/Method-Draw / mkStop

Function mkStop

src/js/lib/jquery.jgraduate.js:514–603  ·  view source on GitHub ↗
(n, color, opac, sel, stop_elem)

Source from the content-addressed store, hash-verified

512 });
513
514 function mkStop(n, color, opac, sel, stop_elem) {
515 var stop = stop_elem || mkElem('stop',{'stop-color':color,'stop-opacity':opac,offset:n}, curGradient);
516 if(stop_elem) {
517 color = stop_elem.getAttribute('stop-color');
518 opac = stop_elem.getAttribute('stop-opacity');
519 n = stop_elem.getAttribute('offset');
520 } else {
521 curGradient.appendChild(stop);
522 }
523 if(opac === null) opac = 1;
524
525 var picker_d = 'M-6.2,0.9c3.6-4,6.7-4.3,6.7-12.4c-0.2,7.9,3.1,8.8,6.5,12.4c3.5,3.8,2.9,9.6,0,12.3c-3.1,2.8-10.4,2.7-13.2,0C-9.6,9.9-9.4,4.4-6.2,0.9z';
526
527 var pathbg = mkElem('path',{
528 d: picker_d,
529 fill: 'url(#jGraduate_trans)',
530 transform: 'translate(' + (10 + n * MAX) + ', 26)'
531 }, stopGroup);
532
533 var path = mkElem('path',{
534 d: picker_d,
535 fill: color,
536 'fill-opacity': opac,
537 transform: 'translate(' + (10 + n * MAX) + ', 26)',
538 stroke: '#000',
539 'stroke-width': 1.5
540 }, stopGroup);
541
542 var $path = $(path);
543
544 $path
545 .data('stop', stop)
546 .data('bg', pathbg)
547 .on("click", function(e) {
548 if (wasDragged) return wasDragged = false; // just dragged stop
549 $('div.jGraduate_LightBox').show();
550 var colorhandle = this;
551 var stopOpacity = +stop.getAttribute('stop-opacity') || 1;
552 var stopColor = stop.getAttribute('stop-color') || 1;
553 var thisAlpha = (parseFloat(stopOpacity)*255).toString(16);
554 while (thisAlpha.length < 2) { thisAlpha = "0" + thisAlpha; }
555 color = stopColor.substr(1) + thisAlpha;
556 $('#'+id+'_jGraduate_stopPicker').css({'left': 100, 'bottom': 15}).jPicker({
557 window: { title: "Pick the start color and opacity for the gradient" },
558 images: { clientPath: $settings.images.clientPath },
559 color: { active: color, alphaSupport: true }
560 }, function(color, arg2){
561 // todo if color is 'none' it should get the same color as the next color stop
562 stopColor = color.val('hex') ? ('#'+color.val('hex')) : "rgba(255,255,255,0)";
563 stopOpacity = color.val('a') !== null ? color.val('a')/256 : 1;
564 colorhandle.setAttribute('fill', stopColor);
565 colorhandle.setAttribute('fill-opacity', stopOpacity);
566 stop.setAttribute('stop-color', stopColor);
567 stop.setAttribute('stop-opacity', stopOpacity);
568 $('div.jGraduate_LightBox').hide();
569 $('#'+id+'_jGraduate_stopPicker').hide();
570 }, null, function() {
571 $('div.jGraduate_LightBox').hide();

Callers 1

Calls 3

mkElemFunction · 0.85
$Function · 0.85
selectStopFunction · 0.85

Tested by

no test coverage detected