File tree 9 files changed +69
-32
lines changed
9 files changed +69
-32
lines changed Original file line number Diff line number Diff line change 21
21
"es6": true,
22
22
"node": true,
23
23
"browser": true,
24
+ "jquery": true,
24
25
"mocha": true
25
26
},
26
27
"ecmaFeatures": {
Original file line number Diff line number Diff line change 1
- # jQueryのPlugin Pattern
1
+ # jQueryのPlugin
2
2
3
- !CODEFILE "../../src/jQuery/jquery.js"
3
+ jQueryでは ` $.fn ` を拡張する事で、 ` $() ` の返り値であるjQueryオブジェクトにメソッドを追加することが出来ます。
4
4
5
- ``` js
6
- var jQuery = require (" jquery" );
7
- jQuery (document .body );
8
- ```
5
+ 次の` greenify ` プラグインでは、` $(document.body).greenify(); ` というメソッド呼び出しが可能になります。
6
+
7
+ !CODEFILE "../../src/jQuery/greenify.js"
8
+
9
+ 実際に利用するためには、` jquery.js ` を読み込んだ後に` greenify.js ` を読み込ませる必要があります。
10
+
11
+ ``` html
12
+ <script src =" jquery.js" ></script >
13
+ <script src =" greenify.js" ></script >
14
+ ```
15
+
16
+ ## どういう仕組み?
Original file line number Diff line number Diff line change 24
24
"eslint" : " eslint src/**/*.js" ,
25
25
"eslint:md" : " eslint --ext .md ja/**/*.md" ,
26
26
"textlint" : " summary-to-path | xargs textlint --rule spellcheck-tech-word" ,
27
- "test" : " npm run textlint && npm run eslint:md && npm run eslint && npm run build"
27
+ "test" : " mocha --recursive && npm run textlint && npm run eslint:md && npm run eslint && npm run build"
28
28
},
29
29
"keywords" : [
30
30
" plugin" ,
33
33
"devDependencies" : {
34
34
"eslint" : " ^1.3.0" ,
35
35
"eslint-plugin-markdown" : " git://github.com/eslint/eslint-plugin-markdown.git" ,
36
+ "espower-babel" : " ^3.3.0" ,
36
37
"gitbook-cli" : " ^0.3.4" ,
37
38
"gitbook-summary-to-path" : " ^1.0.1" ,
39
+ "jsdom" : " ^3.0.0" ,
40
+ "mocha" : " ^2.2.5" ,
41
+ "power-assert" : " ^1.0.0" ,
38
42
"textlint" : " ^3.2.0" ,
39
43
"textlint-rule-spellcheck-tech-word" : " ^4.0.1"
44
+ },
45
+ "dependencies" : {
46
+ "jquery" : " ^2.1.4"
40
47
}
41
48
}
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+ ( function ( $ ) {
3
+ $ . fn . greenify = function ( ) {
4
+ this . css ( "color" , "green" ) ;
5
+ return this ;
6
+ } ;
7
+ } ) ( jQuery ) ;
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > </ title >
6
+ </ head >
7
+ < body >
8
+
9
+ </ body >
10
+ </ html >
Original file line number Diff line number Diff line change
1
+ // LICENSE : MIT
2
+ "use strict" ;
3
+ import jsdom from "jsdom" ;
4
+ import assert from "power-assert" ;
5
+ import fs from "fs" ;
6
+ const testbed = fs . readFileSync ( __dirname + "/fixtures/testbed.html" , "utf-8" ) ;
7
+ const jquery = fs . readFileSync ( __dirname + "/../../node_modules/jquery/dist/jquery.js" , "utf-8" ) ;
8
+ const greenify = fs . readFileSync ( __dirname + "/../../src/jQuery/greenify.js" , "utf-8" ) ;
9
+ describe ( "greenify" , function ( ) {
10
+ var $ , document ;
11
+ before ( done => {
12
+ jsdom . env ( {
13
+ html : testbed ,
14
+ src : [ jquery , greenify ] ,
15
+ done : function ( err , window ) {
16
+ document = window . document ;
17
+ $ = window . $ ;
18
+ done ( ) ;
19
+ }
20
+ } ) ;
21
+ } ) ;
22
+ it ( "should extend $.prototype with greenify" , function ( ) {
23
+ assert ( typeof $ !== "undefined" ) ;
24
+ assert ( $ . fn . greenify != null ) ;
25
+ assert ( $ ( document . body ) . greenify != null ) ;
26
+ assert ( $ ( document . body ) . greenify ( ) instanceof $ ) ;
27
+ } ) ;
28
+ } ) ;
Original file line number Diff line number Diff line change
1
+ --compilers js:espower-babel/guess
You can’t perform that action at this time.
0 commit comments