Advertisement
Guest User

Untitled

a guest
May 29th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. /*
  2. * iOS Launch Image Loader v1.1.1 @ GDibble
  3. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  4. * Browser downloads all meta-tagged images, thus only append 1 meta tag to
  5. * save download time and provide the fastest loading mobile experience.
  6. *
  7. * Files must live in '/img/ios/' and named:
  8. * startup-2048x1496.png Landscape Retina iPads
  9. * startup-1536x2008.png Portrait Retina iPads
  10. * startup-1024x748.png Landscape iPad 1 & 2
  11. * startup-768x1004.png Portrait iPad 1 & 2
  12. * startup-1242x2148.png Portrait Retina iPhone 6+
  13. * startup-750x1294.png Portrait Retina iPhone 6
  14. * startup-640x1096.png Portrait Retina iPhone 5
  15. * startup-640x920.png Portrait Retina iPhone 4
  16. * startup-320x460.png Portrait iPhone & iPod Touch
  17. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  18.  
  19. (function () {
  20. function dynamicLaunchImage(prefix, extension) {
  21. var resolution;
  22. if (navigator.platform === 'iPad') {
  23. if (window.devicePixelRatio === 2) {
  24. //Retina iPads
  25. if (window.orientation === 90 || window.orientation === -90) {
  26. resolution = '2048x1496';
  27. } else {
  28. resolution = '1536x2008';
  29. }
  30. } else {
  31. //iPad 1 & 2
  32. if (window.orientation === 90 || window.orientation === -90) {
  33. resolution = '1024x748';
  34. } else {
  35. resolution = '768x1004';
  36. }
  37. }
  38. } else if (window.devicePixelRatio === 3) {
  39. //Retina iPhone 6+
  40. resolution = '1242x2148';
  41. } else if (window.devicePixelRatio === 2) {
  42. if (window.screen.height === 667) {
  43. //Retina iPhone 6
  44. resolution = '750x1294';
  45. } else if (window.screen.height === 568) {
  46. //Retina iPhone 5
  47. resolution = '640x1096';
  48. } else {
  49. //Retina iPhone 4
  50. resolution = '640x920';
  51. }
  52. } else {
  53. //iPhone & iPod Touch
  54. resolution = '320x460';
  55. }
  56. return prefix + resolution + '.' + extension;
  57. }
  58.  
  59. var head = 'head';
  60. var headTag = document.getElementsByTagName(head);
  61. var linkTag = document.createElement('link');
  62. linkTag.setAttribute('rel', 'apple-touch-startup-image');
  63. linkTag.href = '/img/ios/' + dynamicLaunchImage('startup-', 'png');
  64. if (!headTag.length) { //check if head tag exists, create otherwise
  65. headTag = [ document.createElement(head) ];
  66. document.body.appendChild(headTag[0]);
  67. }
  68. headTag[0].appendChild(linkTag);
  69. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement