diff --git a/editor/svg-editor.html b/editor/svg-editor.html index 4687ec5f..559fb196 100644 --- a/editor/svg-editor.html +++ b/editor/svg-editor.html @@ -136,7 +136,7 @@
- Import SVG + Import Image
  • diff --git a/editor/svg-editor.js b/editor/svg-editor.js index c61ac1e6..a068aade 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -15,18 +15,18 @@ // 2) browser.js // 3) svgcanvas.js -(function() { - +(function() { + document.addEventListener("touchstart", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchend", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); - + if(!window.svgEditor) window.svgEditor = function($) { var svgCanvas; var Editor = {}; var is_ready = false; - + var defaultPrefs = { lang:'en', iconsize:'m', @@ -35,10 +35,10 @@ img_save:'embed' }, curPrefs = {}, - + // Note: Difference between Prefs and Config is that Prefs can be // changed in the UI and are stored in the browser, config can not - + curConfig = { canvas_expansion: 3, dimensions: [640,480], @@ -74,7 +74,7 @@ "key_down":"Down", "key_backspace":"Backspace", "key_del":"Del" - + }, // This is needed if the locale is English, since the locale strings are not read in that instance. layers: { @@ -105,15 +105,15 @@ "retrieving": 'Retrieving "%s" ...' } }; - + var curPrefs = {}; //$.extend({}, defaultPrefs); - + var customHandlers = {}; - + Editor.curConfig = curConfig; - + Editor.tool_scale = 1; - + // Store and retrieve preferences $.pref = function(key, val) { if(val) curPrefs[key] = val; @@ -123,17 +123,17 @@ store = (val != undefined), storage = false; // Some FF versions throw security errors here - try { + try { if(window.localStorage) { // && onweb removed so Webkit works locally storage = localStorage; } } catch(e) {} - try { + try { if(window.globalStorage && onweb) { storage = globalStorage[host]; } } catch(e) {} - + if(storage) { if(store) storage.setItem(key, val); else if (storage.getItem(key)) return storage.getItem(key) + ''; // Convert to string for FF (.value fails in Webkit) @@ -152,7 +152,7 @@ } } } - + Editor.setConfig = function(opts) { $.each(opts, function(key, val) { // Only allow prefs defined in defaultPrefs @@ -166,14 +166,14 @@ } } - + // Extension mechanisms must call setCustomHandlers with two functions: opts.open and opts.save // opts.open's responsibilities are: // - invoke a file chooser dialog in 'open' mode // - let user pick a SVG file // - calls setCanvas.setSvgString() with the string contents of that file // opts.save's responsibilities are: - // - accept the string contents of the current document + // - accept the string contents of the current document // - invoke a file chooser dialog in 'save' mode // - save the file to location chosen by the user Editor.setCustomHandlers = function(opts) { @@ -193,7 +193,7 @@ customHandlers = opts; }); } - + Editor.randomizeIds = function() { svgCanvas.randomizeIds(arguments) } @@ -220,26 +220,26 @@ if(urldata.dimensions) { urldata.dimensions = urldata.dimensions.split(','); } - + if(urldata.extensions) { urldata.extensions = urldata.extensions.split(','); } - + if(urldata.bkgd_color) { urldata.bkgd_color = '#' + urldata.bkgd_color; } svgEditor.setConfig(urldata); - + var src = urldata.source; var qstr = $.param.querystring(); - + if(!src) { // urldata.source may have been null if it ended with '=' if(qstr.indexOf('source=data:') >= 0) { src = qstr.match(/source=(data:[^&]*)/)[1]; } } - + if(src) { if(src.indexOf("data:") === 0) { // plusses get replaced by spaces, so re-insert @@ -256,7 +256,7 @@ } } })(); - + var extFunc = function() { $.each(curConfig.extensions, function() { var extname = this; @@ -269,17 +269,17 @@ } }); }); - + var good_langs = []; - + $('#lang_select option').each(function() { good_langs.push(this.value); }); - + // var lang = ('lang' in curPrefs) ? curPrefs.lang : null; Editor.putLocale(null, good_langs); } - + // Load extensions // Bit of a hack to run extensions in local Opera/IE9 if(document.location.protocol === 'file:') { @@ -299,10 +299,10 @@ 'source':'source.png', 'docprops':'document-properties.png', 'wireframe':'wireframe.png', - + 'undo':'undo.png', 'redo':'redo.png', - + 'select':'select.png', 'select_node':'select_node.png', 'pencil':'fhpath.png', @@ -317,7 +317,7 @@ 'text':'text.png', 'image':'image.png', 'zoom':'zoom.png', - + 'clone':'clone.png', 'node_clone':'node_clone.png', 'delete':'delete.png', @@ -329,26 +329,26 @@ 'to_path':'to_path.png', 'link_controls':'link_controls.png', 'reorient':'reorient.png', - + 'align_left':'align-left.png', 'align_center':'align-center', 'align_right':'align-right', 'align_top':'align-top', 'align_middle':'align-middle', 'align_bottom':'align-bottom', - + 'go_up':'go-up.png', 'go_down':'go-down.png', - + 'ok':'save.png', 'cancel':'cancel.png', - + 'arrow_right':'flyouth.png', 'arrow_down':'dropdown.gif' }, placement: { '#logo':'logo', - + '#tool_clear div,#layer_new':'new_image', '#tool_save div':'save', '#tool_export div':'export', @@ -357,10 +357,10 @@ '#tool_source':'source', '#tool_docprops > div':'docprops', '#tool_wireframe':'wireframe', - + '#tool_undo':'undo', '#tool_redo':'redo', - + '#tool_select':'select', '#tool_fhpath':'pencil', '#tool_line':'pen', @@ -374,7 +374,7 @@ '#tool_text,#layer_rename':'text', '#tool_image':'image', '#tool_zoom':'zoom', - + '#tool_clone,#tool_clone_multi':'clone', '#tool_node_clone':'node_clone', '#layer_delete,#tool_delete,#tool_delete_multi':'delete', @@ -389,7 +389,7 @@ '#tool_group':'group', '#tool_ungroup':'ungroup', '#tool_unlink_use':'unlink_use', - + '#tool_alignleft, #tool_posleft':'align_left', '#tool_aligncenter, #tool_poscenter':'align_center', '#tool_alignright, #tool_posright':'align_right', @@ -397,25 +397,25 @@ '#tool_alignmiddle, #tool_posmiddle':'align_middle', '#tool_alignbottom, #tool_posbottom':'align_bottom', '#cur_position':'align', - + '#linecap_butt,#cur_linecap':'linecap_butt', '#linecap_round':'linecap_round', '#linecap_square':'linecap_square', - + '#linejoin_miter,#cur_linejoin':'linejoin_miter', '#linejoin_round':'linejoin_round', '#linejoin_bevel':'linejoin_bevel', - + '#url_notice':'warning', - + '#layer_up':'go_up', '#layer_down':'go_down', '#layer_moreopts':'context_menu', '#layerlist td.layervis':'eye', - + '#tool_source_save,#tool_docprops_save,#tool_prefs_save':'ok', '#tool_source_cancel,#tool_docprops_cancel,#tool_prefs_cancel':'cancel', - + '#rwidthLabel, #iwidthLabel':'width', '#rheightLabel, #iheightLabel':'height', '#cornerRadiusLabel span':'c_radius', @@ -427,7 +427,7 @@ '#group_opacityLabel': 'opacity', '#blurLabel': 'blur', '#font_sizeLabel': 'fontsize', - + '.flyout_arrow_horiz':'arrow_right', '.dropdown button, #main_button .dropdown':'arrow_down', '#palette .palette_item:first, #fill_bg, #stroke_bg':'no_color' @@ -447,19 +447,19 @@ $('.toolbar_button button > svg, .toolbar_button button > img').each(function() { $(this).parent().prepend(this); }); - + var tleft = $('#tools_left'); if (tleft.length != 0) { var min_height = tleft.offset().top + tleft.outerHeight(); } // var size = $.pref('iconsize'); // if(size && size != 'm') { -// svgEditor.setIconSize(size); +// svgEditor.setIconSize(size); // } else if($(window).height() < min_height) { // // Make smaller // svgEditor.setIconSize('s'); // } - + // Look for any missing flyout icons from plugins $('.tools_flyout').each(function() { var shower = $('#' + this.id + '_show'); @@ -473,9 +473,9 @@ } } }); - + svgEditor.runCallbacks(); - + setTimeout(function() { $('.flyout_arrow_horiz:empty').each(function() { $(this).append($.getSvgIcon('arrow_right').width(5).height(5)); @@ -507,7 +507,7 @@ workarea = $("#workarea"), canv_menu = $("#cmenu_canvas"), layer_menu = $("#cmenu_layers"), - exportWindow = null, + exportWindow = null, tool_scale = 1, zoomInIcon = 'crosshair', zoomOutIcon = 'crosshair', @@ -518,52 +518,52 @@ // This sets up alternative dialog boxes. They mostly work the same way as // their UI counterparts, expect instead of returning the result, a callback // needs to be included that returns the result as its first parameter. - // In the future we may want to add additional types of dialog boxes, since + // In the future we may want to add additional types of dialog boxes, since // they should be easy to handle this way. (function() { $('#dialog_container').draggable({cancel:'#dialog_content, #dialog_buttons *', containment: 'window'}); var box = $('#dialog_box'), btn_holder = $('#dialog_buttons'); - + var dbox = function(type, msg, callback, defText) { $('#dialog_content').html('

    '+msg.replace(/\n/g,'

    ')+'

    ') .toggleClass('prompt',(type=='prompt')); btn_holder.empty(); - + var ok = $('').appendTo(btn_holder); - + if(type != 'alert') { $('') .appendTo(btn_holder) .click(function() { box.hide();callback(false)}); } - + if(type == 'prompt') { var input = $('').prependTo(btn_holder); input.val(defText || ''); input.bind('keydown', 'return', function() {ok.click();}); } - + if(type == 'process') { ok.hide(); } - + box.show(); - - ok.click(function() { + + ok.click(function() { box.hide(); var resp = (type == 'prompt')?input.val():true; if(callback) callback(resp); }).focus(); - + if(type == 'prompt') input.focus(); } - + $.alert = function(msg, cb) { dbox('alert', msg, cb);}; $.confirm = function(msg, cb) { dbox('confirm', msg, cb);}; $.process_cancel = function(msg, cb) { dbox('process', msg, cb);}; $.prompt = function(msg, txt, cb) { dbox('prompt', msg, cb, txt);}; }()); - + var setSelectMode = function() { var curr = $('.tool_button_current'); if(curr.length && curr[0].id !== 'tool_select') { @@ -574,7 +574,7 @@ svgCanvas.setMode('select'); workarea.css('cursor','auto'); }; - + var togglePathEditMode = function(editmode, elems) { $('#path_node_panel').toggle(editmode); $('#tools_bottom_2,#tools_bottom_3').toggle(!editmode); @@ -591,7 +591,7 @@ setIcon('#tool_select', 'select'); } } - + // used to make the flyouts stay on the screen longer the very first time var flyoutspeed = 1250; var textBeingEntered = false; @@ -602,32 +602,32 @@ var preferences = false; var cur_context = ''; var orig_title = $('title:first').text(); - + var saveHandler = function(window,svg) { Editor.show_save_warning = false; - - // by default, we add the XML prolog back, systems integrating SVG-edit (wikis, CMSs) + + // by default, we add the XML prolog back, systems integrating SVG-edit (wikis, CMSs) // can just provide their own custom save handler and might not want the XML prolog svg = '\n' + svg; - + // Opens the SVG in new window, with warning about Mozilla bug #308590 when applicable - + var ua = navigator.userAgent; // Chrome 5 (and 6?) don't allow saving, show source instead ( http://code.google.com/p/chromium/issues/detail?id=46735 ) // IE9 doesn't allow standalone Data URLs ( https://connect.microsoft.com/IE/feedback/details/542600/data-uri-images-fail-when-loaded-by-themselves ) if((~ua.indexOf('Chrome') && $.browser.version >= 533) || ~ua.indexOf('MSIE')) { showSourceEditor(0,true); - return; + return; } var win = window.open("data:image/svg+xml;base64," + Utils.encode64(svg)); - + // Alert will only appear the first time saved OR the first time the bug is encountered var done = $.pref('save_notice_done'); if(done !== "all") { - + var note = uiStrings.notification.saveFromBrowser.replace('%s', 'SVG'); - + // Check if FF and has if(ua.indexOf('Gecko/') !== -1) { if(svg.indexOf('', {id: 'export_canvas'}).hide().appendTo('body'); } var c = $('#export_canvas')[0]; - + c.width = svgCanvas.contentW; c.height = svgCanvas.contentH; canvg(c, data.svg, {renderCallback: function() { @@ -663,21 +663,21 @@ var done = $.pref('export_notice_done'); if(done !== "all") { var note = uiStrings.notification.saveFromBrowser.replace('%s', 'PNG'); - + // Check if there's issues if(issues.length) { var pre = "\n \u2022 "; note += ("\n\n" + uiStrings.notification.noteTheseIssues + pre + issues.join(pre)); - } - + } + // Note that this will also prevent the notice even though new issues may appear later. // May want to find a way to deal with that without annoying the user - $.pref('export_notice_done', 'all'); + $.pref('export_notice_done', 'all'); exportWindow.alert(note); } }}); }; - + // called when we've selected a different element var selectedChanged = function(window,elems) { var mode = svgCanvas.getMode(); @@ -693,10 +693,10 @@ if (!is_node) { updateToolbar(); - } - + } + } // if (elem != null) - + // Deal with pathedit mode togglePathEditMode(is_node, elems); updateContextPanel(); @@ -706,15 +706,15 @@ multiselected: multiselected }); }; - + // Call when part of element is in process of changing, generally // on mousemove actions like rotate, move, etc. var elementTransition = function(window,elems) { var mode = svgCanvas.getMode(); var elem = elems[0]; - + if(!elem) return; - + multiselected = (elems.length >= 2 && elems[1] != null); // Only updating fields for single elements for now if(!multiselected) { @@ -724,7 +724,7 @@ $('#angle').val(ang); $('#tool_reorient').toggleClass('disabled', ang == 0); break; - + // TODO: Update values that change on move/resize, etc // case "select": // case "resize": @@ -735,22 +735,22 @@ elems: elems }); }; - + // called when any element has changed var elementChanged = function(window,elems) { var mode = svgCanvas.getMode(); if(mode === "select") { setSelectMode(); } - + for (var i = 0; i < elems.length; ++i) { var elem = elems[i]; - + // if the element changed was the svg, then it could be a resolution change if (elem && elem.tagName === "svg") { populateLayers(); updateCanvas(); - } + } // Update selectedElement if element is no longer part of the image. // This occurs for the text elements in Firefox else if(elem && selectedElement && selectedElement.parentNode == null) { @@ -758,29 +758,29 @@ selectedElement = elem; } } - + Editor.show_save_warning = true; - + // we update the contextual panel with potentially new // positional/sizing information (we DON'T want to update the // toolbar here as that creates an infinite loop) // also this updates the history buttons - + // we tell it to skip focusing the text control if the // text element was previously in focus updateContextPanel(); - + // In the event a gradient was flipped: if(selectedElement && mode === "select") { paintBox.fill.update(); paintBox.stroke.update(); } - + svgCanvas.runExtensions("elementChanged", { elems: elems }); }; - + var zoomChanged = function(window, bbox, autoCenter) { var scrbar = 15, res = svgCanvas.getResolution(), @@ -790,29 +790,29 @@ if(!z_info) return; var zoomlevel = z_info.zoom, bb = z_info.bbox; - + if(zoomlevel < .001) { changeZoom({value: .1}); return; } - + // $('#zoom').val(Math.round(zoomlevel*100)); $('#zoom').val(zoomlevel*100); - + if(autoCenter) { updateCanvas(); } else { updateCanvas(false, {x: bb.x * zoomlevel + (bb.width * zoomlevel)/2, y: bb.y * zoomlevel + (bb.height * zoomlevel)/2}); } - + if(svgCanvas.getMode() == 'zoom' && bb.width) { // Go to select if a zoom box was drawn setSelectMode(); } - + zoomDone(); } - + $('#cur_context_panel').delegate('a', 'click', function() { var link = $(this); if(link.attr('data-root')) { @@ -822,7 +822,7 @@ } return false; }); - + var contextChanged = function(win, context) { $('#workarea,#sidepanels').css('top', context?100:75); $('#rulers').toggleClass('moved', context); @@ -832,12 +832,12 @@ } else if(!cur_context && context) { workarea[0].scrollTop += 25; } - + var link_str = ''; if(context) { var str = ''; link_str = '' + svgCanvas.getCurrentDrawing().getCurrentLayerName() + ''; - + $(context).parentsUntil('#svgcontent > g').andSelf().each(function() { if(this.id) { str += ' > ' + this.id; @@ -855,18 +855,18 @@ } $('#cur_context_panel').toggle(!!context).html(link_str); - + updateTitle(); } - + // Makes sure the current selected paint is available to work with var prepPaints = function() { paintBox.fill.prep(); paintBox.stroke.prep(); } - + var flyout_funcs = {}; - + var setupFlyouts = function(holders) { $.each(holders, function(hold_sel, btn_opts) { var buttons = $(hold_sel).children(); @@ -878,7 +878,7 @@ .each(function(i) { // Get this buttons options var opts = btn_opts[i]; - + // Remember the function that goes with this ID flyout_funcs[opts.sel] = opts.fn; @@ -889,7 +889,7 @@ var options = opts; //find the currently selected tool if comes from keystroke if (event.type === "keydown") { - var flyoutIsSelected = $(options.parent + "_show").hasClass('tool_button_current'); + var flyoutIsSelected = $(options.parent + "_show").hasClass('tool_button_current'); var currentOperation = $(options.parent + "_show").attr("data-curopt"); $.each(holders[opts.parent], function(i, tool){ if (tool.sel == currentOperation) { @@ -931,12 +931,12 @@ // Set first as default shower.attr('data-curopt', btn_opts[0].sel); } - + var timer; - + var pos = $(show_sel).position(); $(hold_sel).css({'left': pos.left+34, 'top': pos.top+77}); - + // Clicking the "show" icon should set the current mode shower.mousedown(function(evt) { if(shower.hasClass('disabled')) return false; @@ -968,22 +968,22 @@ flyout_funcs[opt](); } }); - + // $('#tools_rect').mouseleave(function(){$('#tools_rect').fadeOut();}); }); - + setFlyoutTitles(); } - + var makeFlyoutHolder = function(id, child) { var div = $('
    ',{ 'class': 'tools_flyout', id: id }).appendTo('#svg_editor').append(child); - + return div; } - + var setFlyoutPositions = function() { $('.tools_flyout').each(function() { var shower = $('#' + this.id + '_show'); @@ -992,12 +992,12 @@ $(this).css({left: (pos.left + w)*tool_scale, top: pos.top}); }); } - + var setFlyoutTitles = function() { $('.tools_flyout').each(function() { var shower = $('#' + this.id + '_show'); if(shower.data('isLibrary')) return; - + var tooltips = []; $(this).children().each(function() { tooltips.push(this.title); @@ -1006,14 +1006,14 @@ }); } - var resize_timer; - + var resize_timer; + var extAdded = function(window, ext) { - + var cb_called = false; var resize_done = false; var cb_ready = true; // Set to false to delay callback (e.g. wait for $.svgIcons) - + function prepResize() { if(resize_timer) { clearTimeout(resize_timer); @@ -1023,31 +1023,31 @@ resize_timer = setTimeout(function() { resize_done = true; setIconSize(curPrefs.iconsize); - }, 50); + }, 50); } } - + var runCallback = function() { if(ext.callback && !cb_called && cb_ready) { cb_called = true; ext.callback(); } } - + var btn_selects = []; - + if(ext.context_tools) { $.each(ext.context_tools, function(i, tool) { // Add select tool var cont_id = tool.container_id?(' id="' + tool.container_id + '"'):""; - + var panel = $('#' + tool.panel); - + // create the panel if it doesn't exist if(!panel.length) panel = $('
    ', {id: tool.panel}).appendTo("#tools_top"); - + // TODO: Allow support for other types, or adding to existing tool switch (tool.type) { case 'tool_button': @@ -1069,24 +1069,24 @@ html += ""; // Creates the tool, hides & adds it, returns the select element var sel = $(html).appendTo(panel).find('select'); - + $.each(tool.events, function(evt, func) { $(sel).bind(evt, func); }); break; - case 'button-select': + case 'button-select': var html = ''; - + var list = $('
      ').appendTo('#option_lists'); - + if(tool.colnum) { list.addClass('optcols' + tool.colnum); } - + // Creates the tool, hides & adds it, returns the select element var dropdown = $(html).appendTo(panel).children(); - + btn_selects.push({ elem: ('#' + tool.id), list: ('#' + tool.id + '_opts'), @@ -1098,51 +1098,51 @@ break; case 'input': var html = '' - + '' + + '' + tool.label + ':' + '' - + // Creates the tool, hides & adds it, returns the select element - + // Add to given tool.panel var inp = $(html).appendTo(panel).find('input'); - + if(tool.spindata) { inp.SpinButton(tool.spindata); } - + if(tool.events) { $.each(tool.events, function(evt, func) { inp.bind(evt, func); }); } break; - + default: break; } }); } - + if(ext.buttons) { var fallback_obj = {}, placement_obj = {}, svgicons = ext.svgicons; var holders = {}; - - + + // Add buttons given by extension $.each(ext.buttons, function(i, btn) { var icon; var id = btn.id; var num = i; - + // Give button a unique ID while($('#'+id).length) { id = btn.id + '_' + (++num); } - + if(!svgicons) { icon = $(''); } else { @@ -1154,9 +1154,9 @@ placement_obj['#' + id] = svgicon; } } - + var cls, parent; - + // Set button up according to its type switch ( btn.type ) { case 'mode_flyout': @@ -1176,7 +1176,7 @@ parent = '#main_menu ul'; break; } - + var button = $((btn.list || btn.type == 'app_menu')?'
    • ':'
      ') .attr("id", id) .attr("title", btn.title) @@ -1193,7 +1193,7 @@ // var opts = btn.includeWith; // // opts.button, default, position var ref_btn = $(button); - + var flyout_holder = ref_btn.parent(); // Create a flyout menu if there isn't one already if(!ref_btn.parent().hasClass('tools_flyout')) { @@ -1202,22 +1202,22 @@ var show_btn = ref_btn.clone() .attr('id',tls_id + '_show') .append($('
      ',{'class':'flyout_arrow_horiz'})); - + ref_btn.before(show_btn); - + // Create a flyout div flyout_holder = makeFlyoutHolder(tls_id, ref_btn); flyout_holder.data('isLibrary', true); show_btn.data('isLibrary', true); - } - - - + } + + + // var ref_data = Actions.getButtonData(opts.button); - + placement_obj['#' + tls_id + '_show'] = btn.id; // TODO: Find way to set the current icon using the iconloader if this is not default - + // Include data for extension button as well as ref button var cur_h = holders['#'+flyout_holder[0].id] = [{ sel: '#'+id, @@ -1226,12 +1226,12 @@ // key: btn.key, isDefault: true }, ref_data]; - // + // // // {sel:'#tool_rect', fn: clickRect, evt: 'mouseup', key: 4, parent: '#tools_rect', icon: 'rect'} - // + // // var pos = ("position" in opts)?opts.position:'last'; // var len = flyout_holder.children().length; - // + // // // Add at given position or end // if(!isNaN(pos) && pos >= 0 && pos < len) { // flyout_holder.children().eq(pos).before(button); @@ -1242,7 +1242,7 @@ } else if(btn.type == 'app_menu') { button.append('
      ').append(btn.title); } - + } else if(btn.list) { // Add button to list button.addClass('push_button'); @@ -1257,7 +1257,7 @@ var opts = btn.includeWith; // opts.button, default, position var ref_btn = $(opts.button); - + var flyout_holder = ref_btn.parent(); // Create a flyout menu if there isn't one already if(!ref_btn.parent().hasClass('tools_flyout')) { @@ -1266,20 +1266,20 @@ var show_btn = ref_btn.clone() .attr('id',tls_id + '_show') .append($('
      ',{'class':'flyout_arrow_horiz'})); - + ref_btn.before(show_btn); - + // Create a flyout div flyout_holder = makeFlyoutHolder(tls_id, ref_btn); - } - + } + var ref_data = Actions.getButtonData(opts.button); - + if(opts.isDefault) { placement_obj['#' + tls_id + '_show'] = btn.id; - } + } // TODO: Find way to set the current icon using the iconloader if this is not default - + // Include data for extension button as well as ref button var cur_h = holders['#'+flyout_holder[0].id] = [{ sel: '#'+id, @@ -1288,12 +1288,12 @@ key: btn.key, isDefault: btn.includeWith?btn.includeWith.isDefault:0 }, ref_data]; - + // {sel:'#tool_rect', fn: clickRect, evt: 'mouseup', key: 4, parent: '#tools_rect', icon: 'rect'} - + var pos = ("position" in opts)?opts.position:'last'; var len = flyout_holder.children().length; - + // Add at given position or end if(!isNaN(pos) && pos >= 0 && pos < len) { flyout_holder.children().eq(pos).before(button); @@ -1301,12 +1301,12 @@ flyout_holder.append(button); cur_h.reverse(); } - } - + } + if(!svgicons) { button.append(icon); } - + if(!btn.list) { // Add given events to button $.each(btn.events, function(name, func) { @@ -1333,14 +1333,14 @@ } }); } - + setupFlyouts(holders); }); - + $.each(btn_selects, function() { - addAltDropDown(this.elem, this.list, this.callback, {seticon: true}); + addAltDropDown(this.elem, this.list, this.callback, {seticon: true}); }); - + if (svgicons) cb_ready = false; // Delay callback @@ -1358,13 +1358,13 @@ cb_ready = true; // Ready for callback runCallback(); } - + }); } - + runCallback(); }; - + var getPaint = function(color, opac, type) { // update the editor's fill paint var opts = null; @@ -1375,10 +1375,10 @@ } else { refElem = $("#" + type + "_color defs *")[0]; } - + opts = { alpha: opac }; opts[refElem.tagName] = refElem; - } + } else if (color.indexOf("#") === 0) { opts = { alpha: opac, @@ -1392,14 +1392,14 @@ }; } return new $.jGraduate.Paint(opts); - }; - + }; + // updates the toolbar (colors, opacity, etc) based on the selected element // This function also updates the opacity and id elements that are in the context panel var updateToolbar = function() { if (selectedElement != null) { - + switch ( selectedElement.tagName ) { case 'use': case 'image': @@ -1408,47 +1408,47 @@ case 'g': case 'a': // Look for common styles - + var gWidth = null; - + var childs = selectedElement.getElementsByTagName('*'); for(var i = 0, len = childs.length; i < len; i++) { var swidth = childs[i].getAttribute("stroke-width"); - + if(i === 0) { gWidth = swidth; } else if(gWidth !== swidth) { gWidth = null; } } - + $('#stroke_width').val(gWidth === null ? "" : gWidth); - + paintBox.fill.update(true); paintBox.stroke.update(true); - + break; default: paintBox.fill.update(true); paintBox.stroke.update(true); - + $('#stroke_width').val(selectedElement.getAttribute("stroke-width") || 1); $('#stroke_style').val(selectedElement.getAttribute("stroke-dasharray")||"none"); - + var attr = selectedElement.getAttribute("stroke-linejoin") || 'miter'; - + if ($('#linejoin_' + attr).length != 0) setStrokeOpt($('#linejoin_' + attr)[0]); - + attr = selectedElement.getAttribute("stroke-linecap") || 'butt'; - + if ($('#linecap_' + attr).length != 0) setStrokeOpt($('#linecap_' + attr)[0]); } - + } - + // All elements including image and group have opacity if(selectedElement != null) { var opac_perc = ((selectedElement.getAttribute("opacity")||1.0)*100); @@ -1456,23 +1456,23 @@ $('#opac_slider').slider('option', 'value', opac_perc); $('#elem_id').val(selectedElement.id); } - + updateToolButtonState(); }; - + var setImageURL = Editor.setImageURL = function(url) { if(!url) url = default_img_url; - + svgCanvas.setImageURL(url); $('#image_url').val(url); - + if(url.indexOf('data:') === 0) { // data URI found $('#image_url').hide(); $('#change_image_url').show(); } else { // regular URL - + svgCanvas.embedImage(url, function(datauri) { if(!datauri) { // Couldn't embed, so show warning @@ -1486,12 +1486,12 @@ $('#change_image_url').hide(); } } - + var setInputWidth = function(elem) { var w = Math.min(Math.max(12 + elem.value.length * 6, 50), 300); $(elem).width(w); } - + // updates the context panel tools based on the selected element var updateContextPanel = function() { var elem = selectedElement; @@ -1500,14 +1500,14 @@ var currentLayerName = svgCanvas.getCurrentDrawing().getCurrentLayerName(); var currentMode = svgCanvas.getMode(); var unit = curConfig.baseUnit !== 'px' ? curConfig.baseUnit : null; - + var is_node = currentMode == 'pathedit'; //elem ? (elem.id && elem.id.indexOf('pathpointgrip') == 0) : false; var menu_items = $('#cmenu_canvas li'); $('#selected_panel, #multiselected_panel, #g_panel, #rect_panel, #circle_panel,\ #ellipse_panel, #line_panel, #text_panel, #image_panel, #container_panel, #use_panel, #a_panel').hide(); if (elem != null) { var elname = elem.nodeName; - + // If this is a link with no transform and one child, pretend // its child is selected // console.log('go', elem) @@ -1517,11 +1517,11 @@ var angle = svgCanvas.getRotationAngle(elem); $('#angle').val(angle); - + var blurval = svgCanvas.getBlur(elem); $('#blur').val(blurval); $('#blur_slider').slider('option', 'value', blurval); - + if(svgCanvas.addedNew) { if(elname === 'image') { // Prompt for URL if not a data URL @@ -1532,7 +1532,7 @@ // TODO: Do something here for new text }*/ } - + if(!is_node && currentMode != 'pathedit') { $('#selected_panel').show(); // Elements in this array already have coord fields @@ -1540,7 +1540,7 @@ $('#xy_panel').hide(); } else { var x,y; - + // Get BBox vals for g, polyline and path if(['g', 'polyline', 'path'].indexOf(elname) >= 0) { var bb = svgCanvas.getStrokedBBox([elem]); @@ -1552,17 +1552,17 @@ x = elem.getAttribute('x'); y = elem.getAttribute('y'); } - + if(unit) { x = svgedit.units.convertUnit(x); y = svgedit.units.convertUnit(y); - } - + } + $('#selected_x').val(x || 0); $('#selected_y').val(y || 0); $('#xy_panel').show(); } - + // Elements in this array cannot be converted to a path var no_path = ['image', 'text', 'path', 'g', 'use'].indexOf(elname) == -1; $('#tool_topath').toggle(no_path); @@ -1572,10 +1572,10 @@ var point = path.getNodePoint(); $('#tool_add_subpath').removeClass('push_button_pressed').addClass('tool_button'); $('#tool_node_delete').toggleClass('disabled', !path.canDeleteNodes); - + // Show open/close button based on selected point setIcon('#tool_openclose_path', path.closed_subpath ? 'open_path' : 'close_path'); - + if(point) { var seg_type = $('#seg_type'); if(unit) { @@ -1592,7 +1592,7 @@ } return; } - + // update contextual tools here var panels = { g: [], @@ -1601,54 +1601,54 @@ image: ['width','height'], circle: ['cx','cy','r'], ellipse: ['cx','cy','rx','ry'], - line: ['x1','y1','x2','y2'], + line: ['x1','y1','x2','y2'], text: [], 'use': [] }; - + var el_name = elem.tagName; - + // if($(elem).data('gsvg')) { // $('#g_panel').show(); // } - + var link_href = null; if (el_name === 'a') { link_href = svgCanvas.getHref(elem); $('#g_panel').show(); } - + if(elem.parentNode.tagName === 'a') { if(!$(elem).siblings().length) { $('#a_panel').show(); link_href = svgCanvas.getHref(elem.parentNode); } } - + // Hide/show the make_link buttons $('#tool_make_link, #tool_make_link').toggle(!link_href); - + if(link_href) { $('#link_url').val(link_href); } - + if(panels[el_name]) { var cur_panel = panels[el_name]; - + $('#' + el_name + '_panel').show(); - + $.each(cur_panel, function(i, item) { var attrVal = elem.getAttribute(item); if(curConfig.baseUnit !== 'px' && elem[item]) { var bv = elem[item].baseVal.value; attrVal = svgedit.units.convertUnit(bv); } - + $('#' + el_name + '_' + item).val(attrVal || 0); }); - + if(el_name == 'text') { - $('#text_panel').css("display", "inline"); + $('#text_panel').css("display", "inline"); if (svgCanvas.getItalic()) { $('#tool_italic').addClass('push_button_pressed').removeClass('tool_button'); } @@ -1699,7 +1699,7 @@ } else { menu_items.disableContextMenuItems('#delete,#cut,#copy,#group,#ungroup,#move_front,#move_up,#move_down,#move_back'); } - + // update history buttons if (undoMgr.getUndoStackSize() > 0) { $('#tool_undo').removeClass( 'disabled'); @@ -1713,13 +1713,13 @@ else { $('#tool_redo').addClass( 'disabled'); } - + svgCanvas.addedNew = false; - + if ( (elem && !is_node) || multiselected) { // update the selected elements' layer $('#selLayerNames').removeAttr('disabled').val(currentLayerName); - + // Enable regular menu options canv_menu.enableContextMenuItems('#delete,#cut,#copy,#move_front,#move_up,#move_down,#move_back'); } @@ -1727,10 +1727,10 @@ $('#selLayerNames').attr('disabled', 'disabled'); } }; - + $('#text').focus( function(){ textBeingEntered = true; } ); $('#text').blur( function(){ textBeingEntered = false; } ); - + // bind the selected event to our function that handles updates to the UI svgCanvas.bind("selected", selectedChanged); svgCanvas.bind("transition", elementTransition); @@ -1741,13 +1741,13 @@ svgCanvas.bind("contextset", contextChanged); svgCanvas.bind("extension_added", extAdded); svgCanvas.textActions.setInputElem($("#text")[0]); - + var str = '
      ' $.each(palette, function(i,item){ str += '
      '; }); $('#palette').append(str); - + // Set up editor background functionality // TODO add checkerboard as "pattern" var color_blocks = ['#FFF','#888','#000']; // ,'url(data:image/gif;base64,R0lGODlhEAAQAIAAAP%2F%2F%2F9bW1iH5BAAAAAAALAAAAAAQABAAAAIfjG%2Bgq4jM3IFLJgpswNly%2FXkcBpIiVaInlLJr9FZWAQA7)']; @@ -1765,27 +1765,27 @@ $(this).addClass(cur_bg); }); }); - + if($.pref('bkgd_color')) { setBackground($.pref('bkgd_color'), $.pref('bkgd_url')); } else if($.pref('bkgd_url')) { // No color set, only URL setBackground(defaultPrefs.bkgd_color, $.pref('bkgd_url')); } - + if($.pref('img_save')) { curPrefs.img_save = $.pref('img_save'); $('#image_save_opts input').val([curPrefs.img_save]); } - + var changeRectRadius = function(ctl) { svgCanvas.setRectRadius(ctl.value); } - + var changeFontSize = function(ctl) { svgCanvas.setFontSize(ctl.value); } - + var changeStrokeWidth = function(ctl) { var val = ctl.value; if(val == 0 && selectedElement && ['line', 'polyline'].indexOf(selectedElement.nodeName) >= 0) { @@ -1793,7 +1793,7 @@ } svgCanvas.setStrokeWidth(val); } - + var changeRotationAngle = function(ctl) { svgCanvas.setRotationAngle(ctl.value); $('#tool_reorient').toggleClass('disabled', ctl.value == 0); @@ -1806,17 +1806,17 @@ } var zoom = svgCanvas.getZoom(); var w_area = workarea; - + zoomChanged(window, { width: 0, height: 0, // center pt of scroll position - x: (w_area[0].scrollLeft + w_area.width()/2)/zoom, + x: (w_area[0].scrollLeft + w_area.width()/2)/zoom, y: (w_area[0].scrollTop + w_area.height()/2)/zoom, zoom: zoomlevel }, true); } - + var changeOpacity = function(ctl, val) { if(val == null) val = ctl.value; $('#group_opacity').val(val); @@ -1825,7 +1825,7 @@ } svgCanvas.setOpacity(val/100); } - + var changeBlur = function(ctl, val, noUndo) { if(val == null) val = ctl.value; $('#blur').val(val); @@ -1835,18 +1835,18 @@ complete = true; } if(noUndo) { - svgCanvas.setBlurNoUndo(val); + svgCanvas.setBlurNoUndo(val); } else { svgCanvas.setBlur(val, complete); } } - + var operaRepaint = function() { // Repaints canvas in Opera. Needed for stroke-dasharray change as well as fill change if(!window.opera) return; $('

      ').hide().appendTo('body').remove(); } - + $('#stroke_style').change(function(){ svgCanvas.setStrokeAttr('stroke-dasharray', $(this).val()); operaRepaint(); @@ -1857,10 +1857,10 @@ operaRepaint(); }); - + // Lose focus for select elements when changed (Allows keyboard shortcuts to work better) $('select').change(function(){$(this).blur();}); - + // fired when user wants to move elements to another layer var promptMoveLayerOnce = false; $('#selLayerNames').change(function(){ @@ -1881,23 +1881,23 @@ } } }); - + $('#font_family').change(function() { svgCanvas.setFontFamily(this.value); }); - + $('#seg_type').change(function() { svgCanvas.setSegType($(this).val()); }); - + $('#text').keyup(function(){ svgCanvas.setTextContent(this.value); }); - + $('#image_url').change(function(){ - setImageURL(this.value); + setImageURL(this.value); }); - + $('#link_url').change(function() { if(this.value.length) { svgCanvas.setLinkURL(this.value); @@ -1905,28 +1905,28 @@ svgCanvas.removeHyperlink(); } }); - + $('#g_title').change(function() { svgCanvas.setGroupTitle(this.value); }); - + $('.attr_changer').change(function() { var attr = this.getAttribute("data-attr"); var val = this.value; var valid = svgedit.units.isValidUnit(attr, val, selectedElement); - + if(!valid) { $.alert(uiStrings.notification.invalidAttrValGiven); this.value = selectedElement.getAttribute(attr); return false; } - + if (attr !== "id") { if (isNaN(val)) { val = svgCanvas.convertToNum(attr, val); } else if(curConfig.baseUnit !== 'px') { // Convert unitless value to one with given unit - + var unitData = svgedit.units.getTypeMap(); if(selectedElement[attr] || svgCanvas.getMode() === "pathedit" || attr === "x" || attr === "y") { @@ -1934,7 +1934,7 @@ } } } - + // if the user is changing the id, then de-select the element first // change the ID, then re-select it with the new ID if (attr === "id") { @@ -1948,21 +1948,21 @@ } this.blur(); }); - + // Prevent selection of elements when shift-clicking $('#palette').mouseover(function() { var inp = $(''); $(this).append(inp); inp.focus().remove(); }) - + $('.palette_item').mousedown(function(evt){ var right_click = evt.button === 2; var isStroke = evt.shiftKey || right_click; var picker = isStroke ? "stroke" : "fill"; var color = $(this).attr('data-rgb'); var paint = null; - + // Webkit-based browsers returned 'initial' here for no stroke if (color === 'transparent' || color === 'initial') { color = 'none'; @@ -1971,9 +1971,9 @@ else { paint = new $.jGraduate.Paint({alpha: 100, solidColor: color.substr(1)}); } - + paintBox[picker].setPaint(paint); - + if (isStroke) { svgCanvas.setColor('stroke', color); if (color != 'none' && svgCanvas.getStrokeOpacity() != 1) { @@ -1987,7 +1987,7 @@ } updateToolButtonState(); }).bind('contextmenu', function(e) {e.preventDefault()}); - + $("#toggle_stroke_tools").toggle(function() { $(".stroke_tool").css('display','table-cell'); $(this).text('<<'); @@ -1997,7 +1997,7 @@ $(this).text('>>'); resetScrollPos(); }); - + // This is a common function used when a tool has been clicked (chosen) // It does several common things: // - removes the tool_button_current class from whatever tool currently has it @@ -2016,20 +2016,20 @@ $(button).addClass('tool_button_current').removeClass('tool_button'); return true; }; - + (function() { - var last_x = null, last_y = null, w_area = workarea[0], + var last_x = null, last_y = null, w_area = workarea[0], panning = false, keypan = false; - + $('#svgcanvas').bind('mousemove mouseup', function(evt) { if(panning === false) return; w_area.scrollLeft -= (evt.clientX - last_x); w_area.scrollTop -= (evt.clientY - last_y); - + last_x = evt.clientX; last_y = evt.clientY; - + if(evt.type === 'mouseup') panning = false; return false; }).mousedown(function(evt) { @@ -2040,11 +2040,11 @@ return false; } }); - + $(window).mouseup(function() { panning = false; }); - + $(document).bind('keydown', 'space', function(evt) { svgCanvas.spaceKey = keypan = true; evt.preventDefault(); @@ -2061,14 +2061,14 @@ } }) }()); - - + + function setStrokeOpt(opt, changeElem) { var id = opt.id; var bits = id.split('_'); var pre = bits[0]; var val = bits[1]; - + if(changeElem) { svgCanvas.setStrokeAttr('stroke-' + pre, val); } @@ -2076,7 +2076,7 @@ setIcon('#cur_' + pre , id, 20); $(opt).addClass('current').siblings().removeClass('current'); } - + (function() { var button = $('#main_icon'); var overlay = $('#main_icon span'); @@ -2085,15 +2085,15 @@ var height = 0; var js_hover = true; var set_click = false; - + var hideMenu = function() { list.fadeOut(200); }; - + $(window).mouseup(function(evt) { if(!on_button) { button.removeClass('buttondown'); - // do not hide if it was the file input as that input needs to be visible + // do not hide if it was the file input as that input needs to be visible // for its change event to fire if (evt.target.tagName != "INPUT") { list.fadeOut(200); @@ -2108,11 +2108,11 @@ }).mousedown(function(evt) { // $(".contextMenu").hide(); // console.log('cm', $(evt.target).closest('.contextMenu')); - + var islib = $(evt.target).closest('div.tools_flyout, .contextMenu').length; if(!islib) $('.tools_flyout:visible,.contextMenu').fadeOut(250); }); - + overlay.bind('mousedown',function() { if (!button.hasClass('buttondown')) { button.addClass('buttondown').removeClass('buttonup') @@ -2136,13 +2136,13 @@ }).mouseout(function() { on_button = false; }); - + var list_items = $('#main_menu li'); - + // Check if JS method of hovering needs to be used (Webkit bug) list_items.mouseover(function() { js_hover = ($(this).css('background-color') == 'rgba(0, 0, 0, 0)'); - + list_items.unbind('mouseover'); if(js_hover) { list_items.mouseover(function() { @@ -2159,21 +2159,21 @@ Editor.addDropDown = function(elem, callback, dropUp) { if ($(elem).length == 0) return; // Quit if called on non-existant element var button = $(elem).find('button'); - + var list = $(elem).find('ul').attr('id', $(elem)[0].id + '-list'); - + if(!dropUp) { // Move list to place where it can overflow container $('#option_lists').append(list); } - + var on_button = false; if(dropUp) { $(elem).addClass('dropup'); } - + list.find('li').bind('mouseup', callback); - + $(window).mouseup(function(evt) { if(!on_button) { button.removeClass('down'); @@ -2181,11 +2181,11 @@ } on_button = false; }); - + button.bind('mousedown',function() { if (!button.hasClass('down')) { button.addClass('down'); - + if(!dropUp) { var pos = $(elem).position(); list.css({ @@ -2194,7 +2194,7 @@ }); } list.show(); - + on_button = true; } else { button.removeClass('down'); @@ -2206,7 +2206,7 @@ on_button = false; }); } - + // TODO: Combine this with addDropDown or find other way to optimize var addAltDropDown = function(elem, list, callback, opts) { var button = $(elem); @@ -2224,7 +2224,7 @@ callback.apply(this, arguments); }); - + $(window).mouseup(function(evt) { if(!on_button) { button.removeClass('down'); @@ -2233,7 +2233,7 @@ } on_button = false; }); - + var height = list.height(); $(elem).bind('mousedown',function() { var off = $(elem).offset(); @@ -2244,7 +2244,7 @@ off.top += $(elem).height(); } $(list).offset(off); - + if (!button.hasClass('down')) { button.addClass('down'); list.show(); @@ -2261,26 +2261,26 @@ }).mouseout(function() { on_button = false; }); - + if(opts.multiclick) { list.mousedown(function() { on_button = true; }); } } - + Editor.addDropDown('#font_family_dropdown', function() { var fam = $(this).text(); $('#font_family').val($(this).text()).change(); }); - + Editor.addDropDown('#opacity_dropdown', function() { if($(this).find('div').length) return; var perc = parseInt($(this).text().split('%')[0]); changeOpacity(false, perc); }, true); - - // For slider usage, see: http://jqueryui.com/demos/slider/ + + // For slider usage, see: http://jqueryui.com/demos/slider/ $("#opac_slider").slider({ start: function() { $('#opacity_dropdown li:not(.special)').hide(); @@ -2293,11 +2293,11 @@ changeOpacity(ui); } }); - + Editor.addDropDown('#blur_dropdown', $.noop); - + var slideStart = false; - + $("#blur_slider").slider({ max: 10, step: .1, @@ -2315,7 +2315,7 @@ } }); - + Editor.addDropDown('#zoom_dropdown', function() { var item = $(this); var val = item.attr('data-val'); @@ -2325,36 +2325,36 @@ changeZoom({value:parseInt(item.text())}); } }, true); - + addAltDropDown('#stroke_linecap', '#linecap_opts', function() { setStrokeOpt(this, true); }, {dropUp: true}); - + addAltDropDown('#stroke_linejoin', '#linejoin_opts', function() { setStrokeOpt(this, true); }, {dropUp: true}); - + addAltDropDown('#tool_position', '#position_opts', function() { var letter = this.id.replace('tool_pos','').charAt(0); svgCanvas.alignSelectedElements(letter, 'page'); }, {multiclick: true}); - + /* - + When a flyout icon is selected (if flyout) { - Change the icon - Make pressing the button run its stuff } - Run its stuff - + When its shortcut key is pressed - If not current in list, do as above , else: - Just run its stuff - + */ - + // Unfocus text input when workarea is mousedowned. (function() { var inp; @@ -2362,7 +2362,7 @@ var unfocus = function() { $(inp).blur(); } - + $('#svg_editor').find('button, select, input:not(#text)').focus(function() { inp = this; ui_context = 'toolbars'; @@ -2375,7 +2375,7 @@ $('#text').focus(); } }); - + }()); var clickSelect = function() { @@ -2384,87 +2384,87 @@ $('#styleoverrides').text('#svgcanvas svg *{cursor:move;pointer-events:all}, #svgcanvas svg{cursor:default}'); } }; - + var clickFHPath = function() { if (toolButtonClick('#tool_fhpath')) { svgCanvas.setMode('fhpath'); } }; - + var clickLine = function() { if (toolButtonClick('#tool_line')) { svgCanvas.setMode('line'); } }; - + var clickSquare = function(){ if (toolButtonClick('#tool_square')) { svgCanvas.setMode('square'); } }; - + var clickRect = function(){ if (toolButtonClick('#tool_rect')) { svgCanvas.setMode('rect'); } }; - + var clickFHRect = function(){ if (toolButtonClick('#tool_fhrect')) { svgCanvas.setMode('fhrect'); } }; - + var clickCircle = function(){ if (toolButtonClick('#tool_circle')) { svgCanvas.setMode('circle'); } }; - + var clickEllipse = function(){ if (toolButtonClick('#tool_ellipse')) { svgCanvas.setMode('ellipse'); } }; - + var clickFHEllipse = function(){ if (toolButtonClick('#tool_fhellipse')) { svgCanvas.setMode('fhellipse'); } }; - + var clickImage = function(){ if (toolButtonClick('#tool_image')) { svgCanvas.setMode('image'); } }; - + var clickZoom = function(){ if (toolButtonClick('#tool_zoom')) { svgCanvas.setMode('zoom'); workarea.css('cursor', zoomInIcon); } }; - + var dblclickZoom = function(){ if (toolButtonClick('#tool_zoom')) { zoomImage(); setSelectMode(); } }; - + var clickText = function(){ if (toolButtonClick('#tool_text')) { svgCanvas.setMode('text'); } }; - + var clickPath = function(){ if (toolButtonClick('#tool_path')) { svgCanvas.setMode('path'); } }; - + // Delete is a contextual tool that only appears in the ribbon if // an element has been selected var deleteSelected = function() { @@ -2472,39 +2472,39 @@ svgCanvas.deleteSelectedElements(); } }; - + var cutSelected = function() { if (selectedElement != null || multiselected) { svgCanvas.cutSelectedElements(); } }; - + var copySelected = function() { if (selectedElement != null || multiselected) { svgCanvas.copySelectedElements(); } }; - + var pasteInCenter = function() { var zoom = svgCanvas.getZoom(); - - var x = (workarea[0].scrollLeft + workarea.width()/2)/zoom - svgCanvas.contentW; + + var x = (workarea[0].scrollLeft + workarea.width()/2)/zoom - svgCanvas.contentW; var y = (workarea[0].scrollTop + workarea.height()/2)/zoom - svgCanvas.contentH; - svgCanvas.pasteElements('point', x, y); + svgCanvas.pasteElements('point', x, y); } - + var moveToTopSelected = function() { if (selectedElement != null) { svgCanvas.moveToTopSelectedElement(); } }; - + var moveToBottomSelected = function() { if (selectedElement != null) { svgCanvas.moveToBottomSelectedElement(); } }; - + var moveUpDownSelected = function(dir) { if (selectedElement != null) { svgCanvas.moveUpDownSelected(dir); @@ -2516,13 +2516,13 @@ svgCanvas.convertToPath(); } } - + var reorientPath = function() { if (selectedElement != null) { path.reorient(); } } - + var makeHyperlink = function() { if (selectedElement != null || multiselected) { $.prompt(uiStrings.notification.enterNewLinkURL, "http://", function(url) { @@ -2530,7 +2530,7 @@ }); } } - + var moveSelected = function(dx,dy) { if (selectedElement != null || multiselected) { if(curConfig.gridSnapping) { @@ -2542,29 +2542,29 @@ svgCanvas.moveSelectedElements(dx,dy); } }; - + var linkControlPoints = function() { var linked = !$('#tool_node_link').hasClass('push_button_pressed'); if (linked) $('#tool_node_link').addClass('push_button_pressed').removeClass('tool_button'); else $('#tool_node_link').removeClass('push_button_pressed').addClass('tool_button'); - + path.linkControlPoints(linked); } - + var clonePathNode = function() { if (path.getNodePoint()) { path.clonePathNode(); } }; - + var deletePathNode = function() { if (path.getNodePoint()) { path.deletePathNode(); } }; - + var addSubPath = function() { var button = $('#tool_add_subpath'); var sp = !button.hasClass('push_button_pressed'); @@ -2573,23 +2573,23 @@ } else { button.removeClass('push_button_pressed').addClass('tool_button'); } - + path.addSubPath(sp); - + }; - + var opencloseSubPath = function() { path.opencloseSubPath(); - } - + } + var selectNext = function() { svgCanvas.cycleElement(1); }; - + var selectPrev = function() { svgCanvas.cycleElement(0); }; - + var rotateSelected = function(cw,step) { if (selectedElement == null || multiselected) return; if(!cw) step *= -1; @@ -2597,7 +2597,7 @@ svgCanvas.setRotationAngle(new_angle); updateContextPanel(); }; - + var clickClear = function(){ var dims = curConfig.dimensions; $.confirm(uiStrings.notification.QwantToClear, function(ok) { @@ -2613,19 +2613,19 @@ svgCanvas.runExtensions('onNewDocument'); }); }; - + var clickBold = function(){ svgCanvas.setBold( !svgCanvas.getBold() ); updateContextPanel(); return false; }; - + var clickItalic = function(){ svgCanvas.setItalic( !svgCanvas.getItalic() ); updateContextPanel(); return false; }; - + var clickSave = function(){ // In the future, more options can be provided here var saveOpts = { @@ -2634,7 +2634,7 @@ } svgCanvas.save(saveOpts); }; - + var clickExport = function() { // Open placeholder window (prevents popup) if(!customHandlers.pngsave) { @@ -2652,30 +2652,30 @@ }); } } - + // by default, svgCanvas.open() is a no-op. - // it is up to an extension mechanism (opera widget, etc) + // it is up to an extension mechanism (opera widget, etc) // to call setCustomHandlers() which will make it do something var clickOpen = function(){ svgCanvas.open(); }; var clickImport = function(){ }; - + var clickUndo = function(){ if (undoMgr.getUndoStackSize() > 0) { undoMgr.undo(); populateLayers(); } }; - + var clickRedo = function(){ if (undoMgr.getRedoStackSize() > 0) { undoMgr.redo(); populateLayers(); } }; - + var clickGroup = function(){ // group if (multiselected) { @@ -2686,16 +2686,16 @@ svgCanvas.ungroupSelectedElement(); } }; - + var clickClone = function(){ svgCanvas.cloneSelectedElements(20,20); }; - + var clickAlign = function() { var letter = this.id.replace('tool_align','').charAt(0); svgCanvas.alignSelectedElements(letter, $('#align_relative_to').val()); }; - + var zoomImage = function(multiplier) { var res = svgCanvas.getResolution(); multiplier = multiplier?res.zoom * multiplier:1; @@ -2705,21 +2705,21 @@ zoomDone(); updateCanvas(true); }; - + var zoomDone = function() { // updateBgImage(); updateWireFrame(); //updateCanvas(); // necessary? } - + var clickWireframe = function() { var wf = !$('#tool_wireframe').hasClass('push_button_pressed'); - if (wf) + if (wf) $('#tool_wireframe').addClass('push_button_pressed').removeClass('tool_button'); else $('#tool_wireframe').removeClass('push_button_pressed').addClass('tool_button'); workarea.toggleClass('wireframe'); - + if(supportsNonSS) return; var wf_rules = $('#wireframe_rules'); if(!wf_rules.length) { @@ -2727,61 +2727,61 @@ } else { wf_rules.empty(); } - + updateWireFrame(); } - + var updateWireFrame = function() { // Test support if(supportsNonSS) return; - + var rule = "#workarea.wireframe #svgcontent * { stroke-width: " + 1/svgCanvas.getZoom() + "px; }"; $('#wireframe_rules').text(workarea.hasClass('wireframe') ? rule : ""); } - + var showSourceEditor = function(e, forSaving){ if (editingsource) return; editingsource = true; - + $('#save_output_btns').toggle(!!forSaving); $('#tool_source_back').toggle(!forSaving); - + var str = orig_source = svgCanvas.getSvgString(); $('#svg_source_textarea').val(str); $('#svg_source_editor').fadeIn(); properlySourceSizeTextArea(); $('#svg_source_textarea').focus(); }; - + $('#svg_docprops_container, #svg_prefs_container').draggable({cancel:'button,fieldset', containment: 'window'}); - + var showDocProperties = function(){ if (docprops) return; docprops = true; - + // This selects the correct radio button by using the array notation $('#image_save_opts input').val([curPrefs.img_save]); - + // update resolution option with actual resolution var res = svgCanvas.getResolution(); if(curConfig.baseUnit !== "px") { res.w = svgedit.units.convertUnit(res.w) + curConfig.baseUnit; res.h = svgedit.units.convertUnit(res.h) + curConfig.baseUnit; } - + $('#canvas_width').val(res.w); $('#canvas_height').val(res.h); $('#canvas_title').val(svgCanvas.getDocumentTitle()); - + $('#svg_docprops').show(); }; - - + + var showPreferences = function(){ if (preferences) return; preferences = true; $('#main_menu').hide(); - + // Update background color with current one var blocks = $('#bg_blocks div'); var cur_bg = 'cur_background'; @@ -2804,19 +2804,19 @@ } else { $('#grid_snapping_on').removeAttr('checked'); } - + $('#svg_prefs').show(); - }; - + }; + var properlySourceSizeTextArea = function(){ // TODO: remove magic numbers here and get values from CSS var height = $('#svg_source_container').height() - 80; $('#svg_source_textarea').css('height', height); }; - + var saveSourceEditor = function(){ if (!editingsource) return; - + var saveChanges = function() { svgCanvas.clearSelection(); hideSourceEditor(); @@ -2825,7 +2825,7 @@ updateTitle(); prepPaints(); } - + if (!svgCanvas.setSvgString($('#svg_source_textarea').val())) { $.confirm(uiStrings.notification.QerrorsRevertToSource, function(ok) { if(!ok) return false; @@ -2834,96 +2834,96 @@ } else { saveChanges(); } - setSelectMode(); + setSelectMode(); }; - + var updateTitle = function(title) { title = title || svgCanvas.getDocumentTitle(); var new_title = orig_title + (title?': ' + title:''); - + // Remove title update with current context info, isn't really necessary // if(cur_context) { // new_title = new_title + cur_context; // } $('title:first').text(new_title); } - + var saveDocProperties = function(){ // set title var new_title = $('#canvas_title').val(); updateTitle(new_title); svgCanvas.setDocumentTitle(new_title); - + // update resolution var width = $('#canvas_width'), w = width.val(); var height = $('#canvas_height'), h = height.val(); - + if(w != "fit" && !svgedit.units.isValidUnit('width', w)) { $.alert(uiStrings.notification.invalidAttrValGiven); width.parent().addClass('error'); return false; } - + width.parent().removeClass('error'); - + if(h != "fit" && !svgedit.units.isValidUnit('height', h)) { $.alert(uiStrings.notification.invalidAttrValGiven); height.parent().addClass('error'); return false; - } - + } + height.parent().removeClass('error'); - + if(!svgCanvas.setResolution(w, h)) { $.alert(uiStrings.notification.noContentToFitTo); return false; } - + // set image save option curPrefs.img_save = $('#image_save_opts :checked').val(); $.pref('img_save',curPrefs.img_save); updateCanvas(); hideDocProperties(); }; - + var savePreferences = function() { // set background var color = $('#bg_blocks div.cur_background').css('background-color') || '#FFF'; setBackground(color, $('#canvas_bg_url').val()); - + // set language var lang = $('#lang_select').val(); if(lang != curPrefs.lang) { Editor.putLocale(lang); } - + // set icon size setIconSize($('#iconsize').val()); - + // set grid setting curConfig.gridSnapping = $('#grid_snapping_on')[0].checked; curConfig.snappingStep = $('#grid_snapping_step').val(); curConfig.showRulers = $('#show_rulers')[0].checked; - + $('#rulers').toggle(curConfig.showRulers); if(curConfig.showRulers) updateRulers(); curConfig.baseUnit = $('#base_unit').val(); - + svgCanvas.setConfig(curConfig); updateCanvas(); hidePreferences(); } - + function setBackground(color, url) { // if(color == curPrefs.bkgd_color && url == curPrefs.bkgd_url) return; $.pref('bkgd_color', color); $.pref('bkgd_url', url); - + // This should be done in svgcanvas.js for the borderRect fill svgCanvas.setBackground(color, url); } - + var setIcon = Editor.setIcon = function(elem, icon_id, forcedSize) { var icon = (typeof icon_id === 'string') ? $.getSvgIcon(icon_id, true) : icon_id.clone(); if(!icon) { @@ -2933,7 +2933,7 @@ $(elem).empty().append(icon); } - + var ua_prefix; (ua_prefix = function() { var regex = /^(Moz|Webkit|Khtml|O|ms|Icab)(?=[A-Z])/; @@ -2945,34 +2945,34 @@ return prop.match(regex)[0]; } } - + // Nothing found so far? if('WebkitOpacity' in someScript.style) return 'Webkit'; if('KhtmlOpacity' in someScript.style) return 'Khtml'; - + return ''; }()); - + var scaleElements = function(elems, scale) { var prefix = '-' + ua_prefix.toLowerCase() + '-'; - + var sides = ['top', 'left', 'bottom', 'right']; - + elems.each(function() { // console.log('go', scale); // Handled in CSS // this.style[ua_prefix + 'Transform'] = 'scale(' + scale + ')'; - + var el = $(this); - + var w = el.outerWidth() * (scale - 1); var h = el.outerHeight() * (scale - 1); var margins = {}; - + for(var i = 0; i < 4; i++) { var s = sides[i]; - + var cur = el.data('orig_margin-' + s); if(cur == null) { cur = parseInt(el.css('margin-' + s)); @@ -2985,36 +2985,36 @@ } else if(s === 'bottom') { val += h; } - + el.css('margin-' + s, val); // el.css('outline', '1px solid red'); } }); } - + var setIconSize = Editor.setIconSize = function(size, force) { if(size == curPrefs.size && !force) return; // return; // var elems = $('.tool_button, .push_button, .tool_button_current, .disabled, .icon_label, #url_notice, #tool_open'); console.log('size', size); - + var sel_toscale = '#tools_top .toolset, #editor_panel > *, #history_panel > *,\ #main_button, #tools_left > *, #path_node_panel > *, #multiselected_panel > *,\ #g_panel > *, #tool_font_size > *, .tools_flyout'; - + var elems = $(sel_toscale); - + var scale = 1; - + if(typeof size == 'number') { scale = size; } else { var icon_sizes = { s:.75, m:1, l:1.25, xl:1.5 }; scale = icon_sizes[size]; } - + Editor.tool_scale = tool_scale = scale; - + setFlyoutPositions(); // $('.tools_flyout').each(function() { // var pos = $(this).position(); @@ -3024,25 +3024,25 @@ // }); // var scale = .75;//0.75; - + var hidden_ps = elems.parents(':hidden'); hidden_ps.css('visibility', 'hidden').show(); scaleElements(elems, scale); hidden_ps.css('visibility', 'visible').hide(); -// console.timeEnd('elems'); +// console.timeEnd('elems'); // return; - + $.pref('iconsize', size); $('#iconsize').val(size); - - + + // Change icon size // $('.tool_button, .push_button, .tool_button_current, .disabled, .icon_label, #url_notice, #tool_open') // .find('> svg, > img').each(function() { // this.setAttribute('width',size_num); // this.setAttribute('height',size_num); // }); -// +// // $.resizeSvgIcons({ // '.flyout_arrow_horiz > svg, .flyout_arrow_horiz > img': size_num / 5, // '#logo > svg, #logo > img': size_num * 1.3, @@ -3051,7 +3051,7 @@ // if(size != 's') { // $.resizeSvgIcons({'#layerbuttons svg, #layerbuttons img': size_num * .6}); // } - + // Note that all rules will be prefixed with '#svg_editor' when parsed var cssResizeRules = { // ".tool_button,\ @@ -3122,7 +3122,7 @@ // }, // "#tools_top > div, #tools_top": { // 'line-height': {s: '17px', l: '34px', xl: '50px'} -// }, +// }, // ".dropdown button": { // 'height': {s: '18px', l: '34px', xl: '40px'}, // 'line-height': {s: '18px', l: '34px', xl: '40px'}, @@ -3131,7 +3131,7 @@ // "#tools_top label, #tools_bottom label": { // 'font-size': {s: '1em', l: '1.5em', xl: '2em'}, // 'height': {s: '25px', l: '42px', xl: '64px'} -// }, +// }, // "div.toolset": { // 'height': {s: '25px', l: '42px', xl: '64px'} // }, @@ -3148,7 +3148,7 @@ // }, // '#layerlist': { // 'width': {l: '128px', xl: '150px'} -// }, +// }, // '.layer_button': { // 'width': {l: '19px', xl: '28px'}, // 'height': {l: '19px', xl: '28px'} @@ -3168,14 +3168,14 @@ // 'width': {all: (size_num*4) +'px'} // } }; - + var rule_elem = $('#tool_size_rules'); if(!rule_elem.length) { rule_elem = $('