Source: eg.js

  1. /**
  2. * Copyright (c) 2015 NAVER Corp.
  3. * egjs projects are licensed under the MIT license
  4. */
  5. eg.module("eg", ["jQuery", eg, window, eg.Agent], function($, ns, global, Agent) {
  6. "use strict";
  7. function resultCache(scope, name, param, defaultValue) {
  8. var method = scope.hook[name];
  9. if (method) {
  10. defaultValue = method.apply(scope, param);
  11. }
  12. scope[name] = function() {
  13. var method = scope.hook[name];
  14. if (method) {
  15. return method.apply(scope, param);
  16. }
  17. return defaultValue;
  18. };
  19. return defaultValue;
  20. }
  21. /**
  22. * @namespace eg
  23. * @group egjs
  24. */
  25. /**
  26. * @name eg.VERSION
  27. * @description The version numbers of egjs.
  28. * @ko egjs 버전
  29. */
  30. ns.VERSION = "#__VERSION__#";
  31. ns.hook = {};
  32. /**
  33. * Returns the User-Agent information
  34. * @ko user-agent 정보를 반환한다.
  35. * @method eg#agent
  36. * @return {Object} agent
  37. * @return {Object} agent.os os Operating system information <ko>운영체제 정보</ko>
  38. * @return {String} agent.os.name Operating system name (android, ios, window, mac) <ko>운영체제 이름 (android, ios, window, mac)</ko>
  39. * @return {String} agent.os.version Operating system version <ko>운영체제 버전</ko>
  40. * @return {String} agent.browser Browser information <ko>브라우저 정보</ko>
  41. * @return {String} agent.browser.name Browser name (default, safari, chrome, sbrowser, ie, firefox) <ko>브라우저 이름 (default, safari, chrome, sbrowser, ie, firefox)</ko>
  42. * @return {String} agent.browser.version Browser version <ko>브라우저 버전 </ko>
  43. * @return {String} agent.browser.webview Indicates whether a WebView browser is available<ko>웹뷰 브라우저 여부</ko>
  44. * @example
  45. eg.agent();
  46. // {
  47. // os : {
  48. // name : "ios",
  49. // version : "8.2"
  50. // },
  51. // browser : {
  52. // name : "safari",
  53. // version : "8.2"
  54. // nativeVersion : "-1"
  55. // }
  56. // }
  57. eg.hook.agent = function(agent) {
  58. if(agent.os.name === "naver") {
  59. agent.browser.name = "inapp";
  60. return agent;
  61. }
  62. }
  63. */
  64. ns.agent = function() {
  65. var info = Agent.create(global.navigator.userAgent);
  66. return resultCache(this, "agent", [info], info);
  67. };
  68. /**
  69. * Returns the syntax of the translate style which is applied to CSS transition properties.
  70. *
  71. * @ko CSS 트랜지션 속성에 적용할 translate 스타일 구문을 반환한다
  72. * @method eg#translate
  73. * @param {String} x Distance to move along the X axis <ko>x축을 따라 이동할 거리</ko>
  74. * @param {String} y Distance to move along the Y axis <ko>y축을 따라 이동할 거리</ko>
  75. * @param {Boolean} [isHA] Force hardware acceleration <ko>하드웨어 가속 사용 여부</ko>
  76. * @return {String} Syntax of the translate style <ko>translate 스타일 구문</ko>
  77. * @example
  78. eg.translate('10px', '200%'); // translate(10px,200%);
  79. eg.translate('10px', '200%', true); // translate3d(10px,200%,0);
  80. */
  81. ns.translate = function(x, y, isHA) {
  82. isHA = isHA || false;
  83. return "translate" + (isHA ?
  84. "3d(" : "(") + x + "," + y + (isHA ? ",0)" :
  85. ")");
  86. };
  87. /**
  88. * Checks whether hardware acceleration is enabled.
  89. *
  90. * @ko 하드웨어 가속을 사용할 수 있는 환경인지 확인한다
  91. * @method eg#isHWAccelerable
  92. * @return {Boolean} Indicates whether hardware acceleration is enabled. <ko>하드웨어 가속 사용 가능 여부</ko>
  93. * @example
  94. eg.isHWAccelerable(); // Returns 'true' when hardware acceleration is supported
  95. // also, you can control return value
  96. eg.hook.isHWAccelerable = function(defalutVal,agent) {
  97. if(agent.os.name === "ios") {
  98. // if os is 'ios', return value is 'false'
  99. return false;
  100. } else if(agent.browser.name === "chrome" ) {
  101. // if browser is 'chrome', return value is 'true'
  102. return true;
  103. }
  104. return defaultVal;
  105. }
  106. */
  107. ns.isHWAccelerable = function() {
  108. var result = false;
  109. var agent = ns.agent();
  110. var osVersion = agent.os.version;
  111. var browser = agent.browser.name;
  112. var browserVersion = agent.browser.version;
  113. var useragent;
  114. // chrome 25- has a text blur bug (except Samsung's sbrowser)
  115. if (browser.indexOf("chrome") !== -1) {
  116. result = browserVersion >= "25";
  117. } else if (/ie|edge|firefox|safari|inapp/.test(browser)) {
  118. result = true;
  119. } else if (agent.os.name.indexOf("android") !== -1) {
  120. // for Xiaomi
  121. useragent = (Agent.ua.match(/\(.*\)/) || [null])[0];
  122. // android 4.1+ blacklist
  123. // EK-GN120 : Galaxy Camera, SM-G386F : Galaxy Core LTE
  124. // SHW-M420 : Galaxy Nexus , SHW-M200 : NexusS , GT-S7562 : Galaxy S duos
  125. result = (osVersion >= "4.1.0" && !/EK-GN120|SM-G386F/.test(useragent)) ||
  126. (osVersion >= "4.0.3" &&
  127. /SHW-|SHV-|GT-|SCH-|SGH-|SPH-|LG-F160|LG-F100|LG-F180|LG-F200|EK-|IM-A|LG-F240|LG-F260/.test(useragent) && !/SHW-M420|SHW-M200|GT-S7562/.test(useragent));
  128. }
  129. return resultCache(this, "isHWAccelerable", [result, agent], result);
  130. };
  131. /**
  132. * Checks whether CSS transition properties can be used.
  133. *
  134. * @ko CSS 트랜지션 속성을 사용할 수 있는 환경인지 확인한다.
  135. * @method eg#isTransitional
  136. * @return {Boolean} Indicates whether CSS transition properties can be used. <ko>CSS 트랜지션 속성 사용 가능 여부</ko>
  137. * @example
  138. eg.isTransitional(); // Returns 'true' when CSS transition is supported.
  139. // also, you can control return value
  140. eg.hook.isTransitional = function(defaultVal, agent) {
  141. if(agent.os.name === "ios") {
  142. // if os is 'ios', return value is 'false'
  143. return false;
  144. } else if(agent.browser.name === "chrome" ) {
  145. // if browser is 'chrome', return value is 'true'
  146. return true;
  147. }
  148. return defaultVal;
  149. }
  150. */
  151. ns.isTransitional = function() {
  152. var result = false;
  153. var agent = ns.agent();
  154. var browser = agent.browser.name;
  155. if (/chrome|firefox|sbrowser/.test(browser)) {
  156. result = true;
  157. } else {
  158. switch (agent.os.name) {
  159. case "ios" :
  160. result = /safari|inapp/.test(browser) &&
  161. parseInt(agent.os.version, 10) < 6;
  162. break;
  163. case "window" :
  164. result = /safari/.test(browser) ||
  165. (/ie/.test(browser) &&
  166. parseInt(agent.browser.nativeVersion, 10) >= 10);
  167. break;
  168. default :
  169. result = /safari/.test(browser);
  170. break;
  171. }
  172. }
  173. return resultCache(this, "isTransitional", [result, agent], result);
  174. };
  175. // 1. user press one position on screen.
  176. // 2. user moves to the other position on screen.
  177. // 3. when user releases fingers on screen, 'click' event is fired at previous position.
  178. ns._hasClickBug = function() {
  179. var agent = ns.agent();
  180. var result = agent.browser.name === "safari";
  181. return resultCache(this, "_hasClickBug", [result, agent], result);
  182. };
  183. $ && $.extend($.easing, {
  184. easeOutCubic: function(p) {
  185. return 1 - Math.pow(1 - p, 3);
  186. }
  187. });
  188. });
comments powered by Disqus