Skip to content

Commit ec66da6

Browse files
committed
More convenience: Allow for SVG border as a standard container
+ Allow drop file multiple times before choosing
1 parent 581895b commit ec66da6

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

index.html

+27-5
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@
5757
if(splash){
5858
splash.remove();
5959
}
60-
document.removeEventListener('dragover', FileDragHover, false);
61-
document.removeEventListener('dragleave', FileDragHover, false);
62-
document.removeEventListener('drop', FileDrop, false);
6360
svgnest.setAttribute('style','display: block');
6461
}
6562

@@ -146,6 +143,11 @@
146143
};
147144

148145
function startnest(){
146+
// Once started, don't allow this anymore
147+
document.removeEventListener('dragover', FileDragHover, false);
148+
document.removeEventListener('dragleave', FileDragHover, false);
149+
document.removeEventListener('drop', FileDrop, false);
150+
149151
SvgNest.start(progress, renderSvg);
150152
startlabel.innerHTML = 'Stop Nest';
151153
start.className = 'button spinner';
@@ -334,7 +336,22 @@
334336
if(reader.result){
335337
try{
336338
var svg = window.SvgNest.parsesvg(reader.result);
339+
{
340+
var wholeSVG = document.createElementNS("http://www.w3.org/2000/svg", "svg");
341+
// Copy relevant scaling info
342+
wholeSVG.setAttribute('width',svg.getAttribute('width'));
343+
wholeSVG.setAttribute('height',svg.getAttribute('height'));
344+
wholeSVG.setAttribute('viewBox',svg.getAttribute('viewBox'));
345+
var rect = document.createElementNS(wholeSVG.namespaceURI,'rect');
346+
rect.setAttribute('x', wholeSVG.viewBox.baseVal.x);
347+
rect.setAttribute('y', wholeSVG.viewBox.baseVal.x);
348+
rect.setAttribute('width', wholeSVG.viewBox.baseVal.width);
349+
rect.setAttribute('height', wholeSVG.viewBox.baseVal.height);
350+
rect.setAttribute('class', 'fullRect');
351+
wholeSVG.appendChild(rect);
352+
}
337353
display.innerHTML = '';
354+
display.appendChild(wholeSVG); // As a default bin in background
338355
display.appendChild(svg);
339356
}
340357
catch(e){
@@ -349,6 +366,7 @@
349366
start.className = 'button start disabled';
350367

351368
attachSvgListeners(svg);
369+
attachSvgListeners(wholeSVG);
352370
}
353371
}
354372

@@ -366,11 +384,15 @@
366384
}
367385
var currentbin = document.querySelector('#select .active');
368386
if(currentbin){
369-
currentbin.removeAttribute('class');
387+
var className = currentbin.getAttribute('class').replace('active', '').trim();
388+
if(!className)
389+
currentbin.removeAttribute('class');
390+
else
391+
currentbin.setAttribute('class', className);
370392
}
371393

372394
window.SvgNest.setbin(this);
373-
this.setAttribute('class','active');
395+
this.setAttribute('class',(this.getAttribute('class') ? this.getAttribute('class')+' ' : '') + 'active');
374396

375397
start.className = 'button start animated bounce';
376398
message.className = '';

style.css

+14
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,18 @@ margin-top: 2em;
403403
#select, #bins{
404404
float: left;
405405
width: 69%;
406+
position: relative;
406407
}
407408

408409
#select svg, #bins svg{
409410
width: 100%;
410411
height: auto;
412+
position: absolute;
413+
top: 0;
411414
margin: 0;
412415
display: block;
413416
overflow: visible;
417+
pointer-events: none;
414418
}
415419

416420
#select svg *{
@@ -420,6 +424,16 @@ stroke: #3bb34a !important;
420424
stroke-width: 2px !important;
421425
vector-effect: non-scaling-stroke !important;
422426
stroke-linejoin: round !important;
427+
pointer-events: fill;
428+
}
429+
430+
#select svg *.fullRect{
431+
fill: #eee !important;
432+
fill-opacity: 1 !important;
433+
stroke: #eee !important;
434+
stroke-width: 2px !important;
435+
vector-effect: non-scaling-stroke !important;
436+
stroke-linejoin: round !important;
423437
}
424438

425439
#select svg *:hover{

0 commit comments

Comments
 (0)