From 51741745b0bb691a55b642a2ea938ac74324da2d Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 17 Apr 2018 15:48:38 -0400 Subject: don't get transform from html --- embroider_print.py | 1 - print/resources/inkstitch.js | 53 ++++++++++++++-------------------- print/templates/operator_overview.html | 2 +- print/templates/print_detail.html | 2 +- print/templates/print_overview.html | 2 +- 5 files changed, 25 insertions(+), 35 deletions(-) diff --git a/embroider_print.py b/embroider_print.py index bc96b2cd..2aa76ec6 100644 --- a/embroider_print.py +++ b/embroider_print.py @@ -343,7 +343,6 @@ class Print(InkstitchExtension): 'estimated_thread': '', # TODO }, svg_overview = overview_svg, - svg_transform = '', # Format: matrix(0.2, 0, 0, 0.2, 0, 0) color_blocks = stitch_plan.color_blocks, ) diff --git a/print/resources/inkstitch.js b/print/resources/inkstitch.js index 8c5e8fa6..825130c8 100644 --- a/print/resources/inkstitch.js +++ b/print/resources/inkstitch.js @@ -39,24 +39,14 @@ function scaleSVG(element, scale = 'fit') { var label = parseInt(scale*100); element.find('svg').css({ transform: transform }); - element.find('figcaption span').text(label); + element.find('.scale').text(label); } // set preview svg scale to fit into its box if transform is not set function scaleAllSvg() { $('.page').each(function() { - if( $(this).css('display') != 'none' ) { - if( $(this).find('.inksimulation svg').css('transform') == 'none') { - if( $(this).find('.inksimulation span').text() == '') { - scaleSVG($(this).find('.inksimulation')); - } - else { - var transform = $(this).find('.inksimulation span').text(); - var scale = transform.match(/-?[\d\.]+/g)[0]; - $(this).find('.inksimulation svg').css({ transform: transform }); - $(this).find('.inksimulation span').text(parseInt(scale*100)); - } - } + if( $(this).find('.inksimulation svg').css('transform') == 'none') { + scaleSVG($(this).find('.inksimulation'), 'fit'); } }); } @@ -64,7 +54,6 @@ function scaleAllSvg() { $(function() { setTimeout(ping, 1000); setPageNumbers(); - scaleAllSvg(); /* SCALING AND MOVING SVG */ @@ -92,7 +81,7 @@ $(function() { svg.css({ transform: 'matrix(' + transform + ')' }); // set scale caption text - $(this).find("span").text(parseInt(scale*100)); + $(this).find(".scale").text(parseInt(scale*100)); //prevent page fom scrolling return false; @@ -138,7 +127,7 @@ $(function() { var scale = transform.match(/-?[\d\.]+/g)[0]; $('.inksimulation').each(function() { $(this).find('svg').css({ transform: transform }); - $(this).find("span").text(parseInt(scale*100)); + $(this).find(".scale").text(parseInt(scale*100)); }) }); @@ -167,20 +156,22 @@ $(function() { // load up initial metadata values $.getJSON('/settings', function(settings) { - $.each(settings, function(field_name, value) { - $('[data-field-name="' + field_name + '"]').each(function(i, item) { - var item = $(item); - if (item.is(':checkbox')) { - item.prop('checked', value).trigger('change'); - } else if (item.is('img')) { - item.attr('src', value); - } else if (item.is('select')) { - item.val(value).trigger('change'); - } else { - item.text(value); - } - }); - }); + $.each(settings, function(field_name, value) { + $('[data-field-name="' + field_name + '"]').each(function(i, item) { + var item = $(item); + if (item.is(':checkbox')) { + item.prop('checked', value).trigger('change'); + } else if (item.is('img')) { + item.attr('src', value); + } else if (item.is('select')) { + item.val(value).trigger('change'); + } else { + item.text(value); + } + }); + }); + // wait until page size is set (if they've specified one) and then scale SVGs to fit + setTimeout(function() { scaleAllSvg() }, 500); }); $('[contenteditable="true"]').keypress(function(e) { @@ -229,6 +220,7 @@ $(function() { $('select#printing-size').change(function(){ var size = $(this).find(':selected').val(); $('.page').toggleClass('a4', size == 'a4'); + console.log("" + Date.now() + "paper size changed"); $.postJSON('/settings/paper-size', {value: size}); }); @@ -239,7 +231,6 @@ $(function() { $('.' + field_name).toggle(checked); setPageNumbers(); - scaleAllSvg(); $.postJSON('/settings/' + field_name, {value: checked}); }); diff --git a/print/templates/operator_overview.html b/print/templates/operator_overview.html index 38da7746..8615c42a 100644 --- a/print/templates/operator_overview.html +++ b/print/templates/operator_overview.html @@ -27,7 +27,7 @@
{{ svg_overview|safe }} -
{{ _('Scale') }} {{ svg_transform }}%
+
{{ _('Scale') }} %
diff --git a/print/templates/print_detail.html b/print/templates/print_detail.html index eddcf36f..d3b064a5 100644 --- a/print/templates/print_detail.html +++ b/print/templates/print_detail.html @@ -17,7 +17,7 @@
{{color_block.svg_preview|safe}} -
{{ _('Scale') }} {{ svg_transform }}%
+
{{ _('Scale') }} %
diff --git a/print/templates/print_overview.html b/print/templates/print_overview.html index 7a396b4a..f876ad70 100644 --- a/print/templates/print_overview.html +++ b/print/templates/print_overview.html @@ -27,7 +27,7 @@
{{ svg_overview|safe }} -
{{ _('Scale') }} {{ svg_transform }}%
+
{{ _('Scale') }} %
-- cgit v1.2.3