Jquery widget source code analysis

Source: Internet
Author: User

Recently, the project needs to modify the dialog source code of jquery ui. Therefore, let's take a closer look at the dialog source code of jquery ui and make a summary.


Dialog_obj (alias ):




<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + PGJyPgo8L3A + CjxoMT5XaWRnZXRfb2JqKLHww/spOjwvaDE + signature + Signature = "http://www.2cto.com/uploadfile/Collfiles/20140609/20140609091508380.jpg" alt = "\">





Call the widget Method


$. Widget ("ui. dialog", dialog_obj); // The jquery. ui. dialog. js file contains row 27th. // The widget method is located in row 27th of the jquery. ui. widget. js file.


Variable assignment:

prototype=dialog_obj
base=Widget_obj



Define Constructors


$ [Namespace] [name] = function (options, element) {// allow instantiation without initializing for simple inheritanceif (arguments. length) {this. _ createWidget (options, element );}};//
// The above code is located in row 44th of the jquery. ui. widget. js file.

The above code functions:

JQuery. ui. dialog = function () {}; // defines a constructor named dialog class

Create an Instance Object of the Widget_obj class


var basePrototype = new base();


Set the prototype object of the dialog class


$[ namespace ][ name ].prototype = $.extend( true, basePrototype, {namespace: namespace,widgetName: name,widgetEventPrefix: $[ namespace ][ name ].prototype.widgetEventPrefix || name,widgetBaseClass: fullName}, prototype );

Use the extern method to merge basePrototype and prototype. The two objects contain attributes with the same name,

The latter overwrites the former and assigns the basePrototype as the return value to the prototype object of the dialog class,

For example:

In Widget_obj, _ init, _ create, and destroy are overwritten by _ init, _ create, and destroy of dialog_obj.


Create a dialog plug-in


$.widget.bridge( name, $[ namespace ][ name ] );//name="dialog" ,jQuery.ui.dialog
$. Fn [name] = function () {}; // defines the dialog plug-in

Call


/* When we call $ ("# showDiv") in js on the page "). dialog ({width: 500px; heigh: 200px ;...}); $. fn [name] = function (options) {} highlights: In the bridge method, there is the following section $. data (this, name, new object (options, this); // this is the div object whose id is showDiv, and options is the json object passed in on the page, name = "dialog", object = jQuery. ui. dialog, use the closure new object // to create jQuery. ui. instance constructor of the dialog class: $ [namespace] [name] = function (options, element) {// allow instantiation without initializing for simple inheritanceif (arguments. length) {this. _ createWidget (options, element) ;}; // call this. _ createWidget, code: _ createWidget: function (options, element) {// $. widget. bridge stores the plugin instance, but we do it anyway // so that it's stored even before the _ create function runsthis. element = $ (element ). data (this. widgetName, this); this. options = $. extend (true, {}, this. options, $. metadata & $. metadata. get (element) [this. widgetName], options); var self = this; this. element. bind ("remove. "+ this. widgetName, function () {self. destroy () ;}); this. _ create (); this. _ init ();}*/





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.