Created
July 26, 2012 06:02
-
-
Save kmdsbng/3180499 to your computer and use it in GitHub Desktop.
ルート要素以下しか検索しないjQueryオブジェクトを作るメソッド
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ルート要素以下しか検索しないjQueryオブジェクトを作る | |
| // | |
| // 使い方: | |
| // var $part = $.partJQuery('#dialog'); | |
| // $part('#hogehoge'); // #dialogの子孫要素しか検索しない | |
| // | |
| // jQuery.fn.sub() の実装をほぼパクった。 | |
| jQuery.partJQuery = function(root) { | |
| function PartJQuery( selector, context ) { | |
| return new PartJQuery.fn.init( selector, context ); | |
| } | |
| jQuery.extend( true, PartJQuery, this ); | |
| PartJQuery.superclass = this; | |
| PartJQuery.fn = PartJQuery.prototype = this(); | |
| PartJQuery.fn.constructor = PartJQuery; | |
| PartJQuery.sub = this.sub; | |
| PartJQuery.fn.init = function init( selector, context ) { | |
| if ( context && context instanceof jQuery && !(context instanceof PartJQuery) ) { | |
| context = PartJQuery( context ); | |
| } | |
| if (!context) { | |
| context = root; | |
| } | |
| return jQuery.fn.init.call( this, selector, context, rootPartJQuery ); | |
| }; | |
| PartJQuery.fn.init.prototype = PartJQuery.fn; | |
| var rootPartJQuery = PartJQuery(document); | |
| return PartJQuery; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment