Ignore:
Timestamp:
2015-02-20T16:46:36+13:00 (9 years ago)
Author:
davidb
Message:

Latest version of extension developed by Jojo. Was originally committed to a different folder, which didn't link in with the INSTALL.sh script.

File:
1 edited

Legend:

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

    r29632 r29756  
    99 *
    1010 */
    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';
     11var advancedClicked = false;
    1912
     13svgEditor.addExtension("Advanced", function() {'use strict';                                     
     14                                               
    2015        return {
    2116            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'
    2418            svgicons: svgEditor.curConfig.extPath + "advanced-icon.xml",
    2519           
    2620            // Multiple buttons can be added in this array
    2721            buttons: [{
    28                 // Must match the icon ID in helloworld-icon.xml
     22                // Must match the icon ID in advanced-icon.xml
    2923                id: "advanced",
    3024               
    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",
    3429               
    3530                // Tooltip text
    36                 title: "Show Advanced Options",
     31                title: "Show/Hide Advanced Features",
    3732               
    3833                // Events
    3934                events: {
    4035                    '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);
    4642                        }
    47                         else {
    48                          
     43                        else
     44                        {
     45                            advancedClicked = true;
     46                            // Hide advanced features
     47                            advancedButton(advancedClicked);
    4948                        }
    5049                    }
     
    5453            // on the editor canvas (not the tool panels)
    5554            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};
    6360            },
    6461           
     
    6663            // to true (see above). Note that "opts" is an object with event info
    6764            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            }
    8377        };
    8478});
    8579
     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}
Note: See TracChangeset for help on using the changeset viewer.