mobiscroll.appframework.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*jslint eqeq: true, plusplus: true, undef: true, sloppy: true, vars: true, forin: true */
  2. if (!window.jQuery) {
  3. var jQuery = jq;
  4. (function ($) {
  5. var document = window.document,
  6. classSelectorRE = /^\.([\w-]+)$/,
  7. idSelectorRE = /^#([\w-]+)$/,
  8. tagSelectorRE = /^[\w-]+$/,
  9. rtable = /^t(?:able|d|h)$/i,
  10. rroot = /^(?:body|html)$/i,
  11. tempParent = document.createElement('div'),
  12. emptyArray = [],
  13. slice = emptyArray.slice,
  14. class2type = {},
  15. toString = class2type.toString;
  16. function type(obj) { return obj == null ? String(obj) : class2type[toString.call(obj)] || "object" }
  17. function isWindow(obj) { return obj != null && obj == obj.window }
  18. function isObject(obj) { return type(obj) == "object" }
  19. function isPlainObject(obj) { return isObject(obj) && !isWindow(obj) && obj.__proto__ == Object.prototype }
  20. function isArray(value) { return value instanceof Array }
  21. function extend(target, source, deep) {
  22. for (key in source)
  23. if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
  24. if (isPlainObject(source[key]) && !isPlainObject(target[key]))
  25. target[key] = {}
  26. if (isArray(source[key]) && !isArray(target[key]))
  27. target[key] = []
  28. extend(target[key], source[key], deep)
  29. } else if (source[key] !== undefined)
  30. target[key] = source[key]
  31. }
  32. function isNumeric(n) {
  33. return !isNaN(parseFloat(n)) && isFinite(n);
  34. }
  35. function matches(element, selector) {
  36. if (!element || element.nodeType !== 1) {
  37. return false;
  38. }
  39. var matchesSelector = element.webkitMatchesSelector || element.mozMatchesSelector ||
  40. element.oMatchesSelector || element.matchesSelector;
  41. if (matchesSelector) {
  42. return matchesSelector.call(element, selector);
  43. }
  44. // fall back to performing a selector:
  45. var match, parent = element.parentNode, temp = !parent
  46. if (temp) (parent = tempParent).appendChild(element)
  47. match = ~qsa(parent, selector).indexOf(element)
  48. temp && tempParent.removeChild(element)
  49. return match
  50. }
  51. function qsa(element, selector){
  52. var found
  53. return (element === document && idSelectorRE.test(selector)) ?
  54. ( (found = element.getElementById(RegExp.$1)) ? [found] : emptyArray ) :
  55. (element.nodeType !== 1 && element.nodeType !== 9) ? emptyArray :
  56. slice.call(
  57. classSelectorRE.test(selector) ? element.getElementsByClassName(RegExp.$1) :
  58. tagSelectorRE.test(selector) ? element.getElementsByTagName(selector) :
  59. element.querySelectorAll(selector)
  60. )
  61. }
  62. function camelize(str) {
  63. return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' });
  64. }
  65. $.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
  66. class2type[ "[object " + name + "]" ] = name.toLowerCase()
  67. });
  68. ['width', 'height'].forEach(function(dimension){
  69. $.fn[dimension] = function(value){
  70. var body = document.body,
  71. html = document.documentElement,
  72. offset, Dimension = dimension.replace(/./, function(m){return m[0].toUpperCase()})
  73. if (value === undefined) return this[0] == window ? document.documentElement['client' + Dimension] :
  74. this[0] == document ? Math.max(body['scroll' + Dimension], body['offset' + Dimension], html['client' + Dimension], html['scroll' + Dimension], html['offset' + Dimension]) : //document.documentElement['offset' + Dimension] :
  75. (offset = this.offset()) && offset[dimension]
  76. else return this.each(function(idx){
  77. var el = $(this)
  78. el.css(dimension, value)
  79. })
  80. }
  81. });
  82. ['width', 'height'].forEach(function(dimension) {
  83. var offset, Dimension = dimension.replace(/./, function(m) {return m[0].toUpperCase()});
  84. $.fn['outer' + Dimension] = function(margin) {
  85. var elem = this;
  86. if (elem) {
  87. var size = elem[0]['offset' + Dimension];
  88. var sides = {'width': ['left', 'right'], 'height': ['top', 'bottom']};
  89. sides[dimension].forEach(function(side) {
  90. if (margin) {
  91. size += parseInt(elem.css(camelize('margin-' + side)), 10);
  92. }
  93. });
  94. return size;
  95. }
  96. else {
  97. return null;
  98. }
  99. };
  100. });
  101. ['width', 'height'].forEach(function (dimension) {
  102. var offset, Dimension = dimension.replace(/./, function (m) { return m[0].toUpperCase(); });
  103. $.fn['inner' + Dimension] = function () {
  104. var elem = this;
  105. if (elem[0]['inner' + Dimension]) {
  106. return elem[0]['inner' + Dimension];
  107. } else {
  108. var size = elem[0]['offset' + Dimension],
  109. sides = {'width': ['left', 'right'], 'height': ['top', 'bottom']};
  110. sides[dimension].forEach(function (side) {
  111. size -= parseInt(elem.css(camelize('border-' + side + '-width')), 10);
  112. });
  113. return size;
  114. }
  115. };
  116. });
  117. ["Left", "Top"].forEach(function(name, i) {
  118. var method = "scroll" + name;
  119. function isWindow( obj ) {
  120. return obj && typeof obj === "object" && "setInterval" in obj;
  121. }
  122. function getWindow( elem ) {
  123. return isWindow( elem ) ? elem : elem.nodeType === 9 ? elem.defaultView || elem.parentWindow : false;
  124. }
  125. $.fn[method] = function( val ) {
  126. var elem, win;
  127. if (val === undefined) {
  128. elem = this[0];
  129. if (!elem) {
  130. return null;
  131. }
  132. win = getWindow(elem);
  133. // Return the scroll offset
  134. return win ? ("pageXOffset" in win) ? win[i ? "pageYOffset" : "pageXOffset"] :
  135. win.document.documentElement[method] ||
  136. win.document.body[method] :
  137. elem[method];
  138. }
  139. // Set the scroll offset
  140. this.each(function() {
  141. win = getWindow(this);
  142. if (win) {
  143. var xCoord = !i ? val : $(win).scrollLeft();
  144. var yCoord = i ? val : $(win).scrollTop();
  145. win.scrollTo(xCoord, yCoord);
  146. }
  147. else {
  148. this[method] = val;
  149. }
  150. });
  151. }
  152. });
  153. $.fn.focus = function (handler) {
  154. if (handler === undefined) {
  155. return $(this).trigger('focus');
  156. } else {
  157. return $(this).bind('focus', handler);
  158. }
  159. };
  160. $.fn.blur = function (handler) {
  161. if (handler === undefined) {
  162. return $(this).trigger('blur');
  163. } else {
  164. return $(this).bind('blur', handler);
  165. }
  166. };
  167. $.fn.slice = function () {
  168. return $(slice.apply(this, arguments));
  169. };
  170. $.fn.before = function (elm) {
  171. $(elm).insertBefore(this);
  172. return this;
  173. };
  174. $.fn.insertAfter = function (elm) {
  175. this.insertBefore(elm, true);
  176. return this;
  177. };
  178. $.fn.detach = $.fn.remove;
  179. $.fn.pluck = function (property) {
  180. var ret = [];
  181. this.each(function () {
  182. if (this[property] !== undefined && this[property] !== null) {
  183. ret.push(this[property]);
  184. }
  185. });
  186. return $(ret);
  187. };
  188. $.fn.prev = function (selector) {
  189. return this.pluck('previousElementSibling').filter(selector || '*');
  190. };
  191. $.fn.next = function (selector) {
  192. return this.pluck('nextElementSibling').filter(selector || '*');
  193. };
  194. $.fn.prevUntil = function (selector) {
  195. var n = this,
  196. array = [];
  197. while (n.length && !$(n).filter(selector).length) {
  198. array.push(n[0]);
  199. n = n.prev();
  200. }
  201. return $(array);
  202. };
  203. $.fn.nextUntil = function (selector) {
  204. var n = this,
  205. array = [];
  206. while (n.length && !n.filter(selector).length) {
  207. array.push(n[0]);
  208. n = n.next();
  209. }
  210. return $(array);
  211. };
  212. $.inArray = function (value, array, fromIndex) {
  213. var i = fromIndex || 0;
  214. while (i < array.length) {
  215. if (array[i++] == value) {
  216. return --i;
  217. }
  218. }
  219. return -1;
  220. };
  221. $.isPlainObject = function (v) {
  222. return $.isObject(v);
  223. };
  224. $.fn._css = $.fn.css;
  225. $.fn.css = function (attr, val, obj) {
  226. if ($.isObject(attr)) {
  227. var i;
  228. for (i in attr) {
  229. $(this)._css(i, isNumeric(attr[i]) ? attr[i] + 'px' : attr[i], obj);
  230. }
  231. return this;
  232. } else {
  233. return $(this)._css(attr, isNumeric(val) ? val + 'px' : val, obj);
  234. }
  235. };
  236. // Copy all but undefined properties from one or more
  237. // objects to the `target` object.
  238. $.extend = function (target) {
  239. arguments[0] = arguments[0] || {};
  240. var deep, args = slice.call(arguments, 1)
  241. if (typeof target == 'boolean') {
  242. deep = target
  243. target = args.shift()
  244. }
  245. args.forEach(function (arg) {
  246. extend(target, arg, deep)
  247. })
  248. return target
  249. }
  250. })(jQuery);
  251. }