shims.js 976 B

123456789101112131415161718192021222324252627282930313233
  1. if (typeof String.prototype.startsWith != 'function') {
  2. String.prototype.startsWith = function (str) {
  3. return this.slice(0, str.length) == str
  4. }
  5. }
  6. function dataURItoBlob(dataURI) {
  7. // convert base64 to raw binary data held in a string
  8. // doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
  9. var byteString = atob(dataURI.split(',')[1]);
  10. // separate out the mime component
  11. var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
  12. // write the bytes of the string to an ArrayBuffer
  13. var ab = new ArrayBuffer(byteString.length);
  14. var ia = new Uint8Array(ab);
  15. for (var i = 0; i < byteString.length; i++) {
  16. ia[i] = byteString.charCodeAt(i);
  17. }
  18. // write the ArrayBuffer to a blob, and you're done
  19. return new Blob([ab], { type: mimeString });
  20. }
  21. function isiframed() {
  22. try {
  23. return window.self !== window.top;
  24. } catch (e) {
  25. return true;
  26. }
  27. }