source: other-projects/nz-flag-design/trunk/main-form/svg-edit-local/extensions/ext-advanced.js@ 29811

Last change on this file since 29811 was 29811, checked in by davidb, 9 years ago

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

File size: 5.7 KB
Line 
1/*globals svgEditor, svgCanvas, $*/
2/*jslint vars: true, eqeq: true*/
3/*
4 * ext-helloworld.js
5 *
6 * Licensed under the MIT License
7 *
8 * Copyright(c) 2010 Alexis Deveria
9 *
10 */
11var advancedClicked = false;
12
13svgEditor.addExtension("Advanced", function() {'use strict';
14
15 return {
16 name: "Advanced",
17 // The icon for 'advanced features'
18 svgicons: svgEditor.curConfig.extPath + "advanced-icon.xml",
19
20 // Multiple buttons can be added in this array
21 buttons: [{
22 // Must match the icon ID in advanced-icon.xml
23 id: "advanced",
24
25 // This indicates that the button will be added independently to the buttons in the button
26 // panel on the left side (it will not be unselected when one of the other buttons is selected)
27 type: "context",
28 panel: "tools_left",
29
30 // Tooltip text
31 title: "Show/Hide Advanced Features",
32
33 // Events
34 events: {
35 'click': function() {
36 // Toggle the advanced button
37 if (advancedClicked == true)
38 {
39 advancedClicked = false;
40 // Hide advanced features
41 advancedButton(advancedClicked);
42 }
43 else
44 {
45 advancedClicked = true;
46 // Hide advanced features
47 advancedButton(advancedClicked);
48 }
49 }
50 }
51 }],
52 // This is triggered when the main mouse button is pressed down
53 // on the editor canvas (not the tool panels)
54 mouseDown: function() {
55 advancedButton(advancedClicked);
56
57 // The returned object must include "started" with
58 // a value of true in order for mouseUp to be triggered
59 return {started: true};
60 },
61
62 // This is triggered from anywhere, but "started" must have been set
63 // to true (see above). Note that "opts" is an object with event info
64 mouseUp: function(opts) {
65 //advancedButton(advancedClicked);
66 },
67
68 elementChanged: function(opts)
69 {
70 advancedButton(advancedClicked);
71 },
72
73 callback: function(opts) {
74 advancedClicked = false;
75 advancedButton(advancedClicked);
76 }
77 };
78});
79
80// Function: advancedButton
81// Unless advanced button is selected, advanced features will be hidden
82this.advancedButton = function() {
83
84 // 'Advanced feature' elements
85 var elements = ['sidepanels', 'editor_panel', 'tool_move_top', 'tool_move_bottom', 'tool_topath', 'tool_reorient', 'tool_make_link', 'idLabel', 'tool_angle', 'tool_blur', 'tool_position', 'xy_panel', 'rect_width_tool', 'rect_height_tool', 'cornerRadiusLabel'];
86
87 // Toggle the display attributes of the selected advanced elements
88 for (var i = 0; i < elements.length; i++) {
89 if (advancedClicked == false) {
90 document.getElementById(elements[i]).style.display = 'none';
91 }
92 else {
93 document.getElementById(elements[i]).style.display = 'block';
94 }
95 }
96
97 // Remove strange extra 'tool_seps' when advanced features is not selected
98 if (advancedClicked == false)
99 {
100 $("#selected_panel :first-child").find(".tool_sep").css("display", "none")
101 }
102}
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 TracBrowser for help on using the repository browser.