Ignore:
Timestamp:
2015-03-27T10:24:28+13:00 (9 years ago)
Author:
davidb
Message:

Additional coding so the colour palette choices now feed through to the svg-editor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/nz-flag-design/trunk/main-form/svg-edit-local/extensions/ext-advanced.js

    r29771 r29811  
    101101    }
    102102}
     103
     104
     105
     106
     107function setSVGEditorColourPalette(flagCanvasSettings) {
     108   
     109    var num_active_colours = flagCanvasSettings.colourPots.length;
     110    console.log("*** num active colours = " + num_active_colours);
     111
     112    $('.palette_item').each( function (index) {
     113    // Skip the first palette_item, so transparent fill is still an option
     114    if (index==0) { return true; } // jquery equivalent of continue
     115
     116    var colour_index = index-1;
     117
     118    if (colour_index<num_active_colours) {
     119        $(this).show();
     120        $(this).css("background-color",flagCanvasSettings.colourPots[colour_index]);
     121        $(this).attr("data-rgb",flagCanvasSettings.colourPots[colour_index]);
     122
     123        if (index==1) {
     124        $(this).trigger("mousedown");
     125        }
     126    }
     127    else {
     128        $(this).hide();
     129    }
     130    });
     131
     132
     133
     134    //$('#palette').empty();
     135    $('#palette').width(150);
     136   
     137    return;
     138
     139    var str = '<div class="palette_item" data-rgb="none"></div>';
     140    $.each(flagCanvasSettings.colourPots, function(i, item) {
     141    str += '<div class="palette_item" style="background-color: ' + item + ';" data-rgb="' + item + '"></div>';
     142    });
     143    $('#palette').append(str);
     144
     145
     146            // Prevent selection of elements when shift-clicking
     147            $('#palette').mouseover(function() {
     148                var inp = $('<input type="hidden">');
     149                $(this).append(inp);
     150                inp.focus().remove();
     151            });
     152
     153            $('.palette_item').mousedown(function(evt) {
     154                // shift key or right click for stroke
     155                var picker = evt.shiftKey || evt.button === 2 ? 'stroke' : 'fill';
     156                var color = $(this).data('rgb');
     157                var paint;
     158
     159                // Webkit-based browsers returned 'initial' here for no stroke
     160                if (color === 'none' || color === 'transparent' || color === 'initial') {
     161                    color = 'none';
     162                    paint = new $.jGraduate.Paint();
     163                } else {
     164                    paint = new $.jGraduate.Paint({alpha: 100, solidColor: color.substr(1)});
     165                }
     166
     167                //paintBox[picker].setPaint(paint);
     168                svgCanvas.setColor(picker, color);
     169
     170                if (color !== 'none' && svgCanvas.getPaintOpacity(picker) !== 1) {
     171                    svgCanvas.setPaintOpacity(picker, 1.0);
     172                }
     173                //updateToolButtonState();
     174            }).bind('contextmenu', function(e) {e.preventDefault();});
     175
     176
     177}
Note: See TracChangeset for help on using the changeset viewer.