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 | */
|
---|
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';
|
---|
19 |
|
---|
20 | return {
|
---|
21 | name: "Advanced",
|
---|
22 | // For more notes on how to make an icon file, see the source of
|
---|
23 | // the helloworld-icon.xml
|
---|
24 | svgicons: svgEditor.curConfig.extPath + "advanced-icon.xml",
|
---|
25 |
|
---|
26 | // Multiple buttons can be added in this array
|
---|
27 | buttons: [{
|
---|
28 | // Must match the icon ID in helloworld-icon.xml
|
---|
29 | id: "advanced",
|
---|
30 |
|
---|
31 | // This indicates that the button will be added to the "mode"
|
---|
32 | // button panel on the left side
|
---|
33 | type: "mode",
|
---|
34 |
|
---|
35 | // Tooltip text
|
---|
36 | title: "Show Advanced Options",
|
---|
37 |
|
---|
38 | // Events
|
---|
39 | events: {
|
---|
40 | '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");
|
---|
46 | }
|
---|
47 | else {
|
---|
48 |
|
---|
49 | }
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }],
|
---|
53 | // This is triggered when the main mouse button is pressed down
|
---|
54 | // on the editor canvas (not the tool panels)
|
---|
55 | 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 | }
|
---|
63 | },
|
---|
64 |
|
---|
65 | // This is triggered from anywhere, but "started" must have been set
|
---|
66 | // to true (see above). Note that "opts" is an object with event info
|
---|
67 | 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 | }
|
---|
83 | };
|
---|
84 | });
|
---|
85 |
|
---|