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

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

Further icons supressed by default

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