ios6.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* iOS 6 Theme for FHEM */
  2. /* by Sandra Ohmayer */
  3. /* http://www.animeschatten.net */
  4. /* jQuery is required*/
  5. $(document).ready(function() {
  6. /*
  7. /* Style Config
  8. */
  9. var menuwidth = 200;
  10. var paddingwidth = 60;
  11. var mobilepaddingwidth = 20;
  12. var logowidth = 28;
  13. var switchtomobilemode = 415;
  14. var hdrheight = 44;
  15. var inputpadding = 251;
  16. /*
  17. /* Functions
  18. */
  19. // Set style height and width
  20. var recalculateStyleHeight = function() {
  21. var height = window.innerHeight;
  22. $("#menu").height(height - hdrheight);
  23. $("#content").height(height - hdrheight);
  24. $("#right").height(height - hdrheight);
  25. };
  26. var recalculateStyleWithMenu = function() {
  27. var width = $("body").width();
  28. $("body").removeClass("hideMenu");
  29. if (switchtomobilemode > width) {
  30. $("#menu").width(width);
  31. $("#content").width(0);
  32. $("#right").width(0);
  33. $("#content").hide()
  34. $("#right").hide();
  35. $("#hdr input").width(width - inputpadding + menuwidth - logowidth);
  36. } else {
  37. $("#menu").width(menuwidth);
  38. $("#content").width(width - menuwidth - paddingwidth - 1);
  39. $("#right").width(width - menuwidth - paddingwidth - 1);
  40. $("#hdr input").width(width - inputpadding);
  41. $("#content").show()
  42. $("#right").show();
  43. }
  44. };
  45. var recalculateStyleWithoutMenu = function() {
  46. var width = $("body").width();
  47. $("body").addClass("hideMenu");
  48. if (switchtomobilemode > width) {
  49. $("#hdr input").width(width - inputpadding + menuwidth - logowidth);
  50. $("#content").width(width - mobilepaddingwidth);
  51. $("#right").width(width - mobilepaddingwidth);
  52. } else {
  53. $("#hdr input").width(width - inputpadding);
  54. $("#content").width(width - paddingwidth);
  55. $("#right").width(width - paddingwidth);
  56. }
  57. $("#menu").width(0);
  58. $("#content").show()
  59. $("#right").show();
  60. };
  61. // Show / Hide menu
  62. var toggleMenuOnFHEMIcon = function() {
  63. if ($("body").hasClass("hideMenu")) {
  64. recalculateStyleWithMenu();
  65. } else {
  66. recalculateStyleWithoutMenu();
  67. }
  68. };
  69. /*
  70. /* DOM manipulation
  71. */
  72. // init viewport
  73. $('meta[name="viewport"]').remove();
  74. $('head').append('<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />');
  75. var ismobile = (/iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i.test(navigator.userAgent.toLowerCase()));
  76. var istablet = (/ipad|android|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(navigator.userAgent.toLowerCase()));
  77. var isAndroid = function() {
  78. return navigator.userAgent.match(/Android/i);
  79. };
  80. if (ismobile) {
  81. $("body").addClass("isMobile");
  82. if (isAndroid()) {
  83. $("body").addClass("isAndroidPhone");
  84. }
  85. } else if(istablet) {
  86. if (isAndroid()) {
  87. $("body").addClass("isAndroidTablet");
  88. }
  89. }
  90. // init height and width
  91. recalculateStyleHeight();
  92. // hide menu
  93. if ($("body").width() < window.innerHeight) {
  94. recalculateStyleWithoutMenu();
  95. } else {
  96. recalculateStyleWithMenu();
  97. }
  98. // Logo - add toggle link
  99. var parentLink = $("#logo").parent("a");
  100. $(parentLink).unbind("click");
  101. if (typeof(parentLink.attr("href")) == "undefined") {
  102. parentLink.attr("onclick", "#");
  103. } else {
  104. parentLink.attr("href", "#");
  105. }
  106. $("#logo").click(toggleMenuOnFHEMIcon);
  107. /*
  108. /* Event Handlers
  109. */
  110. // Resize
  111. $(window).resize(function() {
  112. recalculateStyleHeight();
  113. if ($("body").width() < window.innerHeight) {
  114. recalculateStyleWithoutMenu();
  115. } else {
  116. recalculateStyleWithMenu();
  117. }
  118. });
  119. $(window).bind('orientationchange', function(event) {
  120. $(window).trigger('resize');
  121. //alert("orientationchange width: "+window.innerWidth+" height: "+window.innerHeight);
  122. });
  123. // Touch - Color picker
  124. $(document).on('touchstart', function(e) {
  125. var container = $("#colorpicker");
  126. if (!container.is(e.target) // if the target of the click isn't the container...
  127. && container.has(e.target).length === 0 // ... nor a descendant of the container
  128. && !$("input").is(e.target) && container.length > 0) // ... is not an input
  129. {
  130. container.remove();
  131. }
  132. });
  133. });