jQuery UI widget源码解析,价值2000元的学习资源泄露

这篇具有很好参考价值的文章主要介绍了jQuery UI widget源码解析,价值2000元的学习资源泄露。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

  1. * @param base 需要继承的ui组件

  2. * @param prototype 插件的实际代码

  3. * @returns {Function}

  4. */

  5. $.widget = function(name, base, prototype) {

  6. var fullName, //插件全称

  7. existingConstructor, //原有的构造函数

  8. constructor, //当前构造函数

  9. basePrototype, //父类的Prototype

  10. // proxiedPrototype allows the provided prototype to remain unmodified

  11. // so that it can be used as a mixin for multiple widgets (#8876)

  12. proxiedPrototype = {},

  13. //可调用父类方法_spuer的prototype对象,扩展于prototype

  14. namespace = name.split(“.”)[0];

  15. name = name.split(“.”)[1];

  16. fullName = namespace + “-” + name;

  17. //如果只有2个参数  base默认为Widget类,组件默认会继承base类的所有方法

  18. if (!prototype) {

  19. prototype = base;

  20. base = $.Widget;

  21. }

  22. //    console.log(base, $.Widget)

  23. // create selector for plugin

  24. //创建一个自定义的伪类选择器

  25. //如 $(‘:ui-menu’) 则表示选择定义了ui-menu插件的元素

  26. $.expr[“:”][fullName.toLowerCase()] = function(elem) {

  27. return !!$.data(elem, fullName);

  28. };

  29. // 判定命名空间对象是否存在,没有的话 则创建一个空对象

  30. KaTeX parse error: Undefined control sequence: \[ at position 1: \̲[̲namespace\] = [namespace] || {};

  31. //这里存一份旧版的插件,如果这个插件已经被使用或者定义了

  32. existingConstructor = $[namespace][name];

  33. //这个是插件实例化的主要部分

  34. //constructor存储了插件的实例,同时也创建了基于命名空间的对象

  35. //如$.ui.menu

  36. constructor = $[namespace][name] = function(options, element) {

  37. // allow instantiation without “new” keyword

  38. //允许直接调用命名空间上的方法来创建组件

  39. //比如:$.ui.menu({},‘#id’) 这种方式创建的话,默认没有new 实例化。因为_createWidget是prototype上的方法,需要new关键字来实例化

  40. //通过 调用 $.ui.menu 来实例化插件

  41. if (!this._createWidget) {

  42. console.info(this)

  43. return new constructor(options, element);

  44. }

  45. // allow instantiation without initializing for simple inheritance

  46. // must use “new” keyword (the code above always passes args)

  47. //如果存在参数,则说明是正常调用插件

  48. //_createWidget是创建插件的核心方法

  49. if (arguments.length) {

  50. this._createWidget(options, element);

  51. }

  52. };

  53. // extend with the existing constructor to carry over any static properties

  54. //合并对象,将旧插件实例,及版本号、prototype合并到constructor

  55. $.extend(constructor, existingConstructor, {

  56. version: prototype.version,

  57. // copy the object used to create the prototype in case we need to

  58. // redefine the widget later

  59. //创建一个新的插件对象

  60. //将插件实例暴露给外部,可用户修改及覆盖

  61. _proto: $.extend({}, prototype),

  62. // track widgets that inherit from this widget in case this widget is

  63. // redefined after a widget inherits from it

  64. _childConstructors: []

  65. });

  66. //实例化父类 获取父类的  prototype

  67. basePrototype = new base();

  68. // we need to make the options hash a property directly on the new instance

  69. // otherwise we’ll modify the options hash on the prototype that we’re

  70. // inheriting from

  71. //这里深复制一份options

  72. basePrototype.options = $.widget.extend({}, basePrototype.options);

  73. //在传入的ui原型中有方法调用this._super 和this.__superApply会调用到base上(最基类上)的方法

  74. $.each(prototype, function(prop, value) {

  75. //如果val不是function 则直接给对象赋值字符串

  76. if (!$.isFunction(value)) {

  77. proxiedPrototype[prop] = value;

  78. return;

  79. }

  80. //如果val是function

  81. proxiedPrototype[prop] = (function() {

  82. //两种调用父类函数的方法

  83. var _super = function() {

  84. //将当期实例调用父类的方法

  85. return base.prototype[prop].apply(this, arguments);

  86. },

  87. _superApply = function(args) {

  88. return base.prototype[prop].apply(this, args);

  89. };

  90. return function() {

  91. var __super = this._super,

  92. __superApply = this._superApply,

  93. returnValue;

  94. //                console.log(prop, value,this,this._super,‘===’)

  95. //                debugger;

  96. //在这里调用父类的函数

  97. this._super = _super;

  98. this._superApply = _superApply;

  99. returnValue = value.apply(this, arguments);

  100. this._super = __super;

  101. this._superApply = __superApply;

  102. //                console.log(this,value,returnValue,prop,‘===’)

  103. return returnValue;

  104. };

  105. })();

  106. });

  107. //    console.info(proxiedPrototype)

  108. //    debugger;

  109. //这里是实例化获取的内容

  110. constructor.prototype = $.widget.extend(basePrototype, {

  111. // TODO: remove support for widgetEventPrefix

  112. // always use the name + a colon as the prefix, e.g., draggable:start

  113. // don’t prefix for widgets that aren’t DOM-based

  114. widgetEventPrefix: existingConstructor ? (basePrototype.widgetEventPrefix || name) : name

  115. }, proxiedPrototype, {

  116. //重新把constructor指向 constructor 变量

  117. constructor: constructor,

  118. namespace: namespace,

  119. widgetName: name,

  120. widgetFullName: fullName

  121. });

  122. // If this widget is being redefined then we need to find all widgets that

  123. // are inheriting from it and redefine all of them so that they inherit from

  124. // the new version of this widget. We’re essentially trying to replace one

  125. // level in the prototype chain.

  126. //这里判定插件是否被使用了。一般来说,都不会被使用的。

  127. //因为插件的开发者都是我们自己,呵呵

  128. if (existingConstructor) {

  129. $.each(existingConstructor._childConstructors, function(i, child) {

  130. var childPrototype = child.prototype;

  131. // redefine the child widget using the same prototype that was

  132. // originally used, but inherit from the new version of the base

  133. $.widget(childPrototype.namespace + “.” + childPrototype.widgetName, constructor, child._proto);

  134. });

  135. // remove the list of existing child constructors from the old constructor

  136. // so the old child constructors can be garbage collected

  137. delete existingConstructor._childConstructors;

  138. } else {

  139. //父类添加当前插件的实例 主要用于作用域链查找 不至于断层

  140. base._childConstructors.push(constructor);

  141. }

  142. //将此方法挂在jQuery对象上

  143. $.widget.bridge(name, constructor);

  144. return constructor;

  145. };

  146. //扩展jq的extend方法,实际上类似$.extend(true,…) 深复制

  147. $.widget.extend = function(target) {

  148. var input = widget_slice.call(arguments, 1),

  149. inputIndex = 0,

  150. inputLength = input.length,

  151. key, value;

  152. for (; inputIndex < inputLength; inputIndex++) {

  153. for (key in input[inputIndex]) {

  154. value = input[inputIndex][key];

  155. if (input[inputIndex].hasOwnProperty(key) && value !== undefined) {

  156. // Clone objects

  157. if ($.isPlainObject(value)) {

  158. target[key] = KaTeX parse error: Undefined control sequence: \[ at position 22: …inObject(target\̲[̲key\]) ? .widget.extend({}, target[key], value) :

  159. // Don’t extend strings, arrays, etc. with objects

  160. $.widget.extend({}, value);

  161. // Copy everything else by reference

  162. } else {

  163. target[key] = value;

  164. }

  165. }

  166. }

  167. }

  168. return target;

  169. };

  170. //bridge 是设计模式的一种,这里将对象转为插件调用

  171. $.widget.bridge = function(name, object) {

  172. var fullName = object.prototype.widgetFullName || name;

  173. //这里就是插件了

  174. //这部分的实现主要做了几个工作,也是制作一个优雅的插件的主要代码

  175. //1、初次实例化时将插件对象缓存在dom上,后续则可直接调用,避免在相同元素下widget的多实例化。简单的说,就是一个单例方法。

  176. //2、合并用户提供的默认设置选项options

  177. //3、可以通过调用插件时传递字符串来调用插件内的方法。如:$(‘#id’).menu(‘hide’) 实际就是实例插件并调用hide()方法。

  178. //4、同时限制外部调用“_”下划线的私有方法

  179. $.fn[name] = function(options) {

  180. var isMethodCall = typeof options === “string”,

  181. args = widget_slice.call(arguments, 1),

  182. returnValue = this;

  183. // allow multiple hashes to be passed on init.

  184. //可以简单认为是$.extend(true,options,args[0],…),args可以是一个参数或是数组

  185. options = !isMethodCall && args.length ? $.widget.extend.apply(null, [options].concat(args)) : options;

  186. //这里对字符串和对象分别作处理

  187. if (isMethodCall) {

  188. this.each(function() {

  189. var methodValue, instance = $.data(this, fullName);

  190. //如果传递的是instance则将this返回。

  191. if (options === “instance”) {

  192. returnValue = instance;

  193. return false;

  194. }

  195. if (!instance) {

  196. return $.error("cannot call methods on " + name + " prior to initialization; " + “attempted to call method '” + options + “'”);

  197. }

  198. //这里对私有方法的调用做了限制,直接调用会抛出异常事件

  199. if (!$.isFunction(instance[options]) || options.charAt(0) === “_”) {

  200. return $.error(“no such method '” + options + “’ for " + name + " widget instance”);

  201. }

  202. //这里是如果传递的是字符串,则调用字符串方法,并传递对应的参数.

  203. //比如插件有个方法hide(a,b); 有2个参数:a,b

  204. //则调用时$(‘#id’).menu(‘hide’,1,2);//1和2 分别就是参数a和b了。

  205. methodValue = instance[options].apply(instance, args);

  206. if (methodValue !== instance && methodValue !== undefined) {

  207. returnValue = methodValue && methodValue.jquery ? returnValue.pushStack(methodValue.get()) : methodValue;

  208. return false;

  209. }

  210. });

  211. } else {

  212. this.each(function() {

  213. var instance = $.data(this, fullName);

  214. if (instance) {

  215. instance.option(options || {});

  216. //这里每次都调用init方法

  217. if (instance._init) {

  218. instance._init();

  219. }

  220. } else {

  221. //缓存插件实例

  222. $.data(this, fullName, new object(options, this));

  223. }

  224. });

  225. }

  226. return returnValue;

  227. };

  228. };

  229. //这里是真正的widget基类

  230. $.Widget = function( /* options, element */ ) {};

  231. $.Widget._childConstructors = [];

  232. $.Widget.prototype = {

  233. widgetName: “widget”,

  234. //用来决定事件的名称和插件提供的callbacks的关联。

  235. // 比如dialog有一个close的callback,当close的callback被执行的时候,一个dialogclose的事件被触发。

  236. // 事件的名称和事件的prefix+callback的名称。widgetEventPrefix 默认就是控件的名称,但是如果事件需要不同的名称也可以被重写。

  237. // 比如一个用户开始拖拽一个元素,我们不想使用draggablestart作为事件的名称,我们想使用dragstart,所以我们可以重写事件的prefix。

  238. // 如果callback的名称和事件的prefix相同,事件的名称将不会是prefix。

  239. // 它阻止像dragdrag一样的事件名称。

  240. widgetEventPrefix: “”,

  241. defaultElement: “

    ”,
  242. //属性会在创建模块时被覆盖

  243. options: {

  244. disabled: false,

  245. // callbacks

  246. create: null

  247. },

  248. _createWidget: function(options, element) {

  249. element = $(element || this.defaultElement || this)[0];

  250. this.element = $(element);

  251. this.uuid = widget_uuid++;

  252. this.eventNamespace = “.” + this.widgetName + this.uuid;

  253. this.options = $.widget.extend({}, this.options, this._getCreateOptions(), options);

  254. this.bindings = $();

  255. this.hoverable = $();

  256. this.focusable = $();

  257. if (element !== this) {

  258. //            debugger

  259. $.data(element, this.widgetFullName, this);

  260. this._on(true, this.element, {

  261. remove: function(event) {

  262. if (event.target === element) {

  263. this.destroy();

  264. }

  265. }

  266. });

  267. this.document = $(element.style ?

  268. // element within the document

  269. element.ownerDocument :

  270. // element is window or document

  271. element.document || element);

  272. this.window = $(this.document[0].defaultView || this.document[0].parentWindow);

  273. }

  274. this._create();

  275. //创建插件时,有个create的回调

  276. this._trigger(“create”, null, this._getCreateEventData());

  277. this._init();

  278. },

  279. _getCreateOptions: $.noop,

  280. _getCreateEventData: $.noop,

  281. _create: $.noop,

  282. _init: $.noop,

  283. //销毁模块:去除绑定事件、去除数据、去除样式、属性

  284. destroy: function() {

  285. this._destroy();

  286. // we can probably remove the unbind calls in 2.0

  287. // all event bindings should go through this._on()

  288. this.element.unbind(this.eventNamespace).removeData(this.widgetFullName)

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
jQuery UI widget源码解析,价值2000元的学习资源泄露,2024年程序员学习,jquery,ui,学习
jQuery UI widget源码解析,价值2000元的学习资源泄露,2024年程序员学习,jquery,ui,学习
jQuery UI widget源码解析,价值2000元的学习资源泄露,2024年程序员学习,jquery,ui,学习
jQuery UI widget源码解析,价值2000元的学习资源泄露,2024年程序员学习,jquery,ui,学习
jQuery UI widget源码解析,价值2000元的学习资源泄露,2024年程序员学习,jquery,ui,学习

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!

jQuery UI widget源码解析,价值2000元的学习资源泄露,2024年程序员学习,jquery,ui,学习
jQuery UI widget源码解析,价值2000元的学习资源泄露,2024年程序员学习,jquery,ui,学习

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V:vip1024c 备注前端获取(资料价值较高,非无偿)
jQuery UI widget源码解析,价值2000元的学习资源泄露,2024年程序员学习,jquery,ui,学习

ES6

  • 列举常用的ES6特性:

  • 箭头函数需要注意哪些地方?

  • let、const、var

  • 拓展:var方式定义的变量有什么样的bug?

  • Set数据结构

  • 拓展:数组去重的方法

  • 箭头函数this的指向。

  • 手写ES6 class继承。

jQuery UI widget源码解析,价值2000元的学习资源泄露,2024年程序员学习,jquery,ui,学习

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

微信小程序

  • 简单描述一下微信小程序的相关文件类型?

  • 你是怎么封装微信小程序的数据请求?

  • 有哪些参数传值的方法?

  • 你使用过哪些方法,来提高微信小程序的应用速度?

  • 小程序和原生App哪个好?

  • 简述微信小程序原理?

  • 分析微信小程序的优劣势

  • 怎么解决小程序的异步请求问题?

]

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V:vip1024c 备注前端获取(资料价值较高,非无偿)
[外链图片转存中…(img-9QGTCNWL-1711561934574)]

ES6

  • 列举常用的ES6特性:

  • 箭头函数需要注意哪些地方?

  • let、const、var

  • 拓展:var方式定义的变量有什么样的bug?

  • Set数据结构

  • 拓展:数组去重的方法

  • 箭头函数this的指向。

  • 手写ES6 class继承。

jQuery UI widget源码解析,价值2000元的学习资源泄露,2024年程序员学习,jquery,ui,学习

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

微信小程序

  • 简单描述一下微信小程序的相关文件类型?

  • 你是怎么封装微信小程序的数据请求?

  • 有哪些参数传值的方法?

  • 你使用过哪些方法,来提高微信小程序的应用速度?

  • 小程序和原生App哪个好?

  • 简述微信小程序原理?

  • 分析微信小程序的优劣势

  • 怎么解决小程序的异步请求问题?

jQuery UI widget源码解析,价值2000元的学习资源泄露,2024年程序员学习,jquery,ui,学习文章来源地址https://www.toymoban.com/news/detail-846105.html

到了这里,关于jQuery UI widget源码解析,价值2000元的学习资源泄露的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • element-ui 打包流程源码解析(上)

    分析版本为 element-ui,v2.15.9。 打包目录,包括所有的打包配置 webpack 等 js 文件。 element-ui 官网的源代码,是一个独立的 vue2 项目。通过脚本 build/webpack.demo.js 打包。 每个组件都是一个单独的文件夹。 组件对应的样式没有写在 .vue 文件中,而是统一在 packages/theme-chalk 目录,该

    2024年01月19日
    浏览(22)
  • element-ui 打包流程源码解析(下)

    接上文:element-ui 打包流程源码解析(上) 文章中提到的【上文】都指它 ↑ 我们从使用方式来分析,为什么要打包成上面的目录结构。 每个模块都有 package.json 文件,其中的 main 字段表示模块的入口文件。 1.1,完整引入 样式引入不必多说。 完整引入对应的是上文中 第2.3节

    2024年01月20日
    浏览(27)
  • ​【UI界面】Foobar2000 FlatLite 整合版

      Foobar2000 是一款本地音乐播放器,这里我就不再做介绍了,不懂的请自行了解。此 Foobar2000 FlatLite 主题包为整合版本,下载既可用。主题界面是模块化的 JS 面板,每个面板都是独立的,面板里的图标也是由 JS 脚本绘制,可以实现颜色的自由变换等。   主题介绍: 本主题是

    2024年02月14日
    浏览(24)
  • element ui el-avatar 源码解析零基础逐行解析

    快捷配置头像的样式 属性 说明 参数 size 尺寸 type string 类型 (‘large’,‘medium’,‘small’)number类型 validator 校验 shape 形状 circle (原型) square(方形) icon 传入的icon src 传入的图片 string类型 可以是本地图片(本地图片需要在js中requir导入,不可直接使用相对路劲引用) 也可

    2024年02月03日
    浏览(24)
  • Kendo UI for jQuery,一个现代的jQuery UI组件!

    Kendo UI for jQuery是什么? Kendo UI for jQuery是完整的jQuery UI组件库,可快速构建出色的高性能响应式Web应用程序。Kendo UI for jQuery提供在短时间内构建现代Web应用程序所需要的工具,从多个UI组件中选择,并轻松地将它们组合起来,创建出酷炫响应式的应用程序,同时将开发时间加

    2024年02月13日
    浏览(26)
  • Flutter源码分析笔记:Widget类源码分析

    Flutter源码分析笔记 Widget类源码分析 - 文章信息 - Author: 李俊才 (jcLee95) Visit me at: https://jclee95.blog.csdn.net Email: 291148484@163.com. Shenzhen China Address of this article: https://blog.csdn.net/qq_28550263/article/details/132259681 【介绍】:本文记录阅读与分析Flutter源码 - Widget类源码分析。 Widget类是Flu

    2024年02月12日
    浏览(28)
  • 在QT的UI界面,让Widget可以跟随窗体大小而改变

    可以使用布局(Layout)机制让Widget(QWidget)随窗口一起缩放和移动。 Qt提供以下几种布局: QHBoxLayout:将QWidget按照水平方向依次排列 QVBoxLayout:将QWidget按照垂直方向依次排列 QGridLayout:将QWidget按照行列划分为多个网格,根据网格位置排列 QFormLayout:将QWidget按照表单样式排

    2024年02月07日
    浏览(29)
  • 官方项目《内容示例》中Common UI部分笔记: 1.1 Activatable Widgets

    本文主要面向UMG以及Common UI的初学者 这个例子非常简单,定义了1+3个 Common Activatable Widget CommonUI_ActivatableWidgets 相当于一个容器包含了其它3个 Common Activatable Widget , CommonUI_ActivatableWidgets 里没有什么逻辑,窗口弹出/切换的逻辑在 CommonUI_BaseLayer 里, CommonUI_BaseLayer 通过变量引用

    2024年02月11日
    浏览(23)
  • jQuery UI简单的讲解

    我们先进入一下问答时间,你都知道多少呢? (1)什么是jQuery UI 呢?   解答:jQuery UI 是以 jQuery 为基础的开源 JavaScript 网页用户界面代码库。包含底层用户交互、动画、特效和可更换主题的可视控件。我们可以直接用它来构建具有很好交互性的web应用程序。所有插件测试

    2024年04月10日
    浏览(36)
  • jQuery UI -- 日历选择器

    现在,这个demo中,其实我们已经实现了一个日期选择器的功能。 但我们知道 jQuery UI 的文件包是一系列部件的合集,,所以说,如果我们只希望借助 jQuery UI 来 实现一个日期选择器,我们没必要引入整个的 jQuery UI ,而只需要引入 datepicker 相关的文件即可。 1、关于CSS的部分

    2024年04月09日
    浏览(25)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包