- Timestamp:
- 2015-02-20T16:46:36+13:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/nz-flag-design/trunk/main-form/svg-edit-local/ext-advanced.js
r29632 r29756 9 9 * 10 10 */ 11 12 /* 13 This is a very basic SVG-Edit extension. It adds a "Hello World" button in 14 the left panel. Clicking on the button, and then the canvas will show the 15 user the point on the canvas that was clicked on. 16 */ 17 18 svgEditor.addExtension("Advanced", function() {'use strict'; 11 var advancedClicked = false; 19 12 13 svgEditor.addExtension("Advanced", function() {'use strict'; 14 20 15 return { 21 16 name: "Advanced", 22 // For more notes on how to make an icon file, see the source of 23 // the helloworld-icon.xml 17 // The icon for 'advanced features' 24 18 svgicons: svgEditor.curConfig.extPath + "advanced-icon.xml", 25 19 26 20 // Multiple buttons can be added in this array 27 21 buttons: [{ 28 // Must match the icon ID in helloworld-icon.xml22 // Must match the icon ID in advanced-icon.xml 29 23 id: "advanced", 30 24 31 // This indicates that the button will be added to the "mode" 32 // button panel on the left side 33 type: "mode", 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", 34 29 35 30 // Tooltip text 36 title: "Show Advanced Options",31 title: "Show/Hide Advanced Features", 37 32 38 33 // Events 39 34 events: { 40 35 'click': function() { 41 // The action taken when the button is clicked on. 42 // For "mode" buttons, any other button will 43 // automatically be de-pressed. 44 if (svgCanvas.getMode() != "advanced") { 45 svgCanvas.setMode("advanced"); 36 // Toggle the advanced button 37 if (advancedClicked == true) 38 { 39 advancedClicked = false; 40 // Hide advanced features 41 advancedButton(advancedClicked); 46 42 } 47 else { 48 43 else 44 { 45 advancedClicked = true; 46 // Hide advanced features 47 advancedButton(advancedClicked); 49 48 } 50 49 } … … 54 53 // on the editor canvas (not the tool panels) 55 54 mouseDown: function() { 56 // Check the mode on mousedown 57 if(svgCanvas.getMode() == "advanced") { 58 59 // The returned object must include "started" with 60 // a value of true in order for mouseUp to be triggered 61 return {started: true}; 62 } 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}; 63 60 }, 64 61 … … 66 63 // to true (see above). Note that "opts" is an object with event info 67 64 mouseUp: function(opts) { 68 // Check the mode on mouseup 69 if(svgCanvas.getMode() == "advanced") { 70 var zoom = svgCanvas.getZoom(); 71 72 // Get the actual coordinate by dividing by the zoom value 73 var x = opts.mouse_x / zoom; 74 var y = opts.mouse_y / zoom; 75 76 var text = "These are advanced features!\n\nYou clicked here: " 77 + x + ", " + y; 78 79 // Show the text using the custom alert function 80 $.alert(text); 81 } 82 } 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 } 83 77 }; 84 78 }); 85 79 80 // Function: advancedButton 81 // Unless advanced button is selected, advanced features will be hidden 82 this.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 }
Note:
See TracChangeset
for help on using the changeset viewer.