qzind / qz-print

Archive for legacy qz-print versions (1.8, 1.9). See https://github.com/qzind/tray for modern versions.
Other
141 stars 101 forks source link

Support for relative file paths #137

Closed tresf closed 8 years ago

tresf commented 8 years ago

Investigate the possibility of supporting relative file paths in 2.0

var printData = [
   {
      type: 'image',
      data: '/relative/path/to/img/image_sample.png'
// HERE ------^
   }
];

Currently, data must be a full path requiring all of our code examples to use a getPath() function which our clients won't necessarily have.

tresf commented 8 years ago

@bberenz I found a painfully simply way to resolve URLs... It constructs an <a href="..."/> tag with the specified URL and reads the value right back out. It works with IE7 and higher.

I've also placed in a small portion of browser-detection, not sure if it's warranted.

Question... how can we assume when a URL is being supplied to the data element? Can we determine that in js, or is the logic all Java-side?

function makeAbsolute(url) {
    if (document && typeof (document.createElement == 'function')) {
        var a = document.createElement('a');
        a.href = url;
        return a.href;
    }
    return url;
}
akberenz commented 8 years ago

The logic for that check is all Java-side, unless they specify the type as file. Would it be enough to just provide that method as part of QZ?

akberenz commented 8 years ago

Implemented via 52ef9f550f1280693a5e45af96f20d0a6572389e