国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

292 行
7.8KB

  1. /*
  2. * jQuery UI @VERSION
  3. *
  4. * Copyright (c) 2008 Paul Bakaus (ui.jquery.com)
  5. * Dual licensed under the MIT (MIT-LICENSE.txt)
  6. * and GPL (GPL-LICENSE.txt) licenses.
  7. *
  8. * http://docs.jquery.com/UI
  9. */
  10. ;(function($) {
  11. $.ui = {
  12. plugin: {
  13. add: function(module, option, set) {
  14. var proto = $.ui[module].prototype;
  15. for(var i in set) {
  16. proto.plugins[i] = proto.plugins[i] || [];
  17. proto.plugins[i].push([option, set[i]]);
  18. }
  19. },
  20. call: function(instance, name, args) {
  21. var set = instance.plugins[name];
  22. if(!set) { return; }
  23. for (var i = 0; i < set.length; i++) {
  24. if (instance.options[set[i][0]]) {
  25. set[i][1].apply(instance.element, args);
  26. }
  27. }
  28. }
  29. },
  30. cssCache: {},
  31. css: function(name) {
  32. if ($.ui.cssCache[name]) { return $.ui.cssCache[name]; }
  33. var tmp = $('<div class="ui-gen">').addClass(name).css({position:'absolute', top:'-5000px', left:'-5000px', display:'block'}).appendTo('body');
  34. //if (!$.browser.safari)
  35. //tmp.appendTo('body');
  36. //Opera and Safari set width and height to 0px instead of auto
  37. //Safari returns rgba(0,0,0,0) when bgcolor is not set
  38. $.ui.cssCache[name] = !!(
  39. (!(/auto|default/).test(tmp.css('cursor')) || (/^[1-9]/).test(tmp.css('height')) || (/^[1-9]/).test(tmp.css('width')) ||
  40. !(/none/).test(tmp.css('backgroundImage')) || !(/transparent|rgba\(0, 0, 0, 0\)/).test(tmp.css('backgroundColor')))
  41. );
  42. try { $('body').get(0).removeChild(tmp.get(0)); } catch(e){}
  43. return $.ui.cssCache[name];
  44. },
  45. disableSelection: function(el) {
  46. $(el).attr('unselectable', 'on').css('MozUserSelect', 'none');
  47. },
  48. enableSelection: function(el) {
  49. $(el).attr('unselectable', 'off').css('MozUserSelect', '');
  50. },
  51. hasScroll: function(e, a) {
  52. var scroll = /top/.test(a||"top") ? 'scrollTop' : 'scrollLeft', has = false;
  53. if (e[scroll] > 0) return true; e[scroll] = 1;
  54. has = e[scroll] > 0 ? true : false; e[scroll] = 0;
  55. return has;
  56. }
  57. };
  58. /** jQuery core modifications and additions **/
  59. var _remove = $.fn.remove;
  60. $.fn.remove = function() {
  61. $("*", this).add(this).triggerHandler("remove");
  62. return _remove.apply(this, arguments );
  63. };
  64. // $.widget is a factory to create jQuery plugins
  65. // taking some boilerplate code out of the plugin code
  66. // created by Scott González and J?rn Zaefferer
  67. function getter(namespace, plugin, method) {
  68. var methods = $[namespace][plugin].getter || [];
  69. methods = (typeof methods == "string" ? methods.split(/,?\s+/) : methods);
  70. return ($.inArray(method, methods) != -1);
  71. }
  72. $.widget = function(name, prototype) {
  73. var namespace = name.split(".")[0];
  74. name = name.split(".")[1];
  75. // create plugin method
  76. $.fn[name] = function(options) {
  77. var isMethodCall = (typeof options == 'string'),
  78. args = Array.prototype.slice.call(arguments, 1);
  79. if (isMethodCall && getter(namespace, name, options)) {
  80. var instance = $.data(this[0], name);
  81. return (instance ? instance[options].apply(instance, args)
  82. : undefined);
  83. }
  84. return this.each(function() {
  85. var instance = $.data(this, name);
  86. if (isMethodCall && instance && $.isFunction(instance[options])) {
  87. instance[options].apply(instance, args);
  88. } else if (!isMethodCall) {
  89. $.data(this, name, new $[namespace][name](this, options));
  90. }
  91. });
  92. };
  93. // create widget constructor
  94. $[namespace][name] = function(element, options) {
  95. var self = this;
  96. this.widgetName = name;
  97. this.widgetBaseClass = namespace + '-' + name;
  98. this.options = $.extend({}, $.widget.defaults, $[namespace][name].defaults, options);
  99. this.element = $(element)
  100. .bind('setData.' + name, function(e, key, value) {
  101. return self.setData(key, value);
  102. })
  103. .bind('getData.' + name, function(e, key) {
  104. return self.getData(key);
  105. })
  106. .bind('remove', function() {
  107. return self.destroy();
  108. });
  109. this.init();
  110. };
  111. // add widget prototype
  112. $[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype);
  113. };
  114. $.widget.prototype = {
  115. init: function() {},
  116. destroy: function() {
  117. this.element.removeData(this.widgetName);
  118. },
  119. getData: function(key) {
  120. return this.options[key];
  121. },
  122. setData: function(key, value) {
  123. this.options[key] = value;
  124. if (key == 'disabled') {
  125. this.element[value ? 'addClass' : 'removeClass'](
  126. this.widgetBaseClass + '-disabled');
  127. }
  128. },
  129. enable: function() {
  130. this.setData('disabled', false);
  131. },
  132. disable: function() {
  133. this.setData('disabled', true);
  134. }
  135. };
  136. $.widget.defaults = {
  137. disabled: false
  138. };
  139. /** Mouse Interaction Plugin **/
  140. $.ui.mouse = {
  141. mouseInit: function() {
  142. var self = this;
  143. this.element.bind('mousedown.'+this.widgetName, function(e) {
  144. return self.mouseDown(e);
  145. });
  146. // Prevent text selection in IE
  147. if ($.browser.msie) {
  148. this._mouseUnselectable = this.element.attr('unselectable');
  149. this.element.attr('unselectable', 'on');
  150. }
  151. this.started = false;
  152. },
  153. // TODO: make sure destroying one instance of mouse doesn't mess with
  154. // other instances of mouse
  155. mouseDestroy: function() {
  156. this.element.unbind('.'+this.widgetName);
  157. // Restore text selection in IE
  158. ($.browser.msie
  159. && this.element.attr('unselectable', this._mouseUnselectable));
  160. },
  161. mouseDown: function(e) {
  162. // we may have missed mouseup (out of window)
  163. (this._mouseStarted && this.mouseUp(e));
  164. this._mouseDownEvent = e;
  165. var self = this,
  166. btnIsLeft = (e.which == 1),
  167. elIsCancel = (typeof this.options.cancel == "string" ? $(e.target).parents().add(e.target).filter(this.options.cancel).length : false);
  168. if (!btnIsLeft || elIsCancel || !this.mouseCapture(e)) {
  169. return true;
  170. }
  171. this._mouseDelayMet = !this.options.delay;
  172. if (!this._mouseDelayMet) {
  173. this._mouseDelayTimer = setTimeout(function() {
  174. self._mouseDelayMet = true;
  175. }, this.options.delay);
  176. }
  177. if (this.mouseDistanceMet(e) && this.mouseDelayMet(e)) {
  178. this._mouseStarted = (this.mouseStart(e) !== false);
  179. if (!this._mouseStarted) {
  180. e.preventDefault();
  181. return true;
  182. }
  183. }
  184. // these delegates are required to keep context
  185. this._mouseMoveDelegate = function(e) {
  186. return self.mouseMove(e);
  187. };
  188. this._mouseUpDelegate = function(e) {
  189. return self.mouseUp(e);
  190. };
  191. $(document)
  192. .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  193. .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  194. return false;
  195. },
  196. mouseMove: function(e) {
  197. // IE mouseup check - mouseup happened when mouse was out of window
  198. if ($.browser.msie && !e.button) {
  199. return this.mouseUp(e);
  200. }
  201. if (this._mouseStarted) {
  202. this.mouseDrag(e);
  203. return false;
  204. }
  205. if (this.mouseDistanceMet(e) && this.mouseDelayMet(e)) {
  206. this._mouseStarted =
  207. (this.mouseStart(this._mouseDownEvent, e) !== false);
  208. (this._mouseStarted ? this.mouseDrag(e) : this.mouseUp(e));
  209. }
  210. return !this._mouseStarted;
  211. },
  212. mouseUp: function(e) {
  213. $(document)
  214. .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  215. .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  216. if (this._mouseStarted) {
  217. this._mouseStarted = false;
  218. this.mouseStop(e);
  219. }
  220. return false;
  221. },
  222. mouseDistanceMet: function(e) {
  223. return (Math.max(
  224. Math.abs(this._mouseDownEvent.pageX - e.pageX),
  225. Math.abs(this._mouseDownEvent.pageY - e.pageY)
  226. ) >= this.options.distance
  227. );
  228. },
  229. mouseDelayMet: function(e) {
  230. return this._mouseDelayMet;
  231. },
  232. // These are placeholder methods, to be overriden by extending plugin
  233. mouseStart: function(e) {},
  234. mouseDrag: function(e) {},
  235. mouseStop: function(e) {},
  236. mouseCapture: function(e) { return true; }
  237. };
  238. $.ui.mouse.defaults = {
  239. cancel: null,
  240. distance: 1,
  241. delay: 0
  242. };
  243. })(jQuery);