File tree 6 files changed +76
-0
lines changed
6 files changed +76
-0
lines changed Original file line number Diff line number Diff line change 1
1
node_modules
2
2
config /local.js
3
3
assets
4
+ pnpm-lock.yaml
5
+ browser-demo /wikibase-edit.js
4
6
Original file line number Diff line number Diff line change
1
+ # wikibase-edit browser demo
2
+
3
+ To run wikibase-edit in the browser, you need a bundler. In this demo we use ` esbuild ` (see [ ` build.sh ` ] ( ./build.sh ) ).
4
+ ``` sh
5
+ cd browser-demo
6
+ ./build.sh
7
+ ```
8
+
9
+ You can then use a file server to serve the files in this directory and test wikibase-edit in the browser. Note that the edit will only work if the page is served under HTTPS.
Original file line number Diff line number Diff line change
1
+ esbuild ../lib/index.js --bundle --outfile=./wikibase-edit.js --format=esm
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < meta charset ="utf-8 " />
5
+ < title > Test wikibase-edit in the browser</ title >
6
+ < script type ="module " src ="./main.js " async > </ script >
7
+ < style >
8
+ input , button {
9
+ padding : 0.5em ;
10
+ margin : 0.5em 0 ;
11
+ }
12
+ </ style >
13
+ </ head >
14
+ < body >
15
+ < h1 > Test wikibase-edit in the browser</ h1 >
16
+ < label >
17
+ Add an English Alias to < a href ="https://www.wikidata.org/entity/Q112795079 "> Wikidata Sandbox 4 : Q112795079</ a >
18
+ < br >
19
+ < input id ="text " type ="text " placeholder ="foo " />
20
+ </ label >
21
+ < button > Add</ button >
22
+ < pre id ="response "> </ pre >
23
+ </ body >
24
+ </ html >
Original file line number Diff line number Diff line change
1
+ import WbEdit from './wikibase-edit.js'
2
+
3
+ console . log ( 'hillo' )
4
+
5
+ const wbEdit = WbEdit ( {
6
+ instance : 'https://www.wikidata.org' ,
7
+ credentials : {
8
+ browserSession : true ,
9
+ } ,
10
+ } )
11
+
12
+ document . addEventListener ( 'click' , async e => {
13
+ if ( e . target . tagName === 'BUTTON' && document . getElementById ( 'text' ) . value ) {
14
+ try {
15
+ const res = await wbEdit . alias . add ( {
16
+ id : 'Q112795079' ,
17
+ language : 'fr' ,
18
+ value : document . getElementById ( 'text' ) . value ,
19
+ } )
20
+ document . getElementById ( 'response' ) . innerText = JSON . stringify ( res , null , 2 )
21
+ } catch ( err ) {
22
+ document . getElementById ( 'response' ) . innerText = err . stack || err . toString ( )
23
+ }
24
+ }
25
+ } )
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " browser-demo" ,
3
+ "version" : " 1.0.0" ,
4
+ "description" : " " ,
5
+ "main" : " main.js" ,
6
+ "scripts" : {
7
+ "test" : " echo \" Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords" : [],
10
+ "author" : " " ,
11
+ "license" : " ISC" ,
12
+ "devDependencies" : {
13
+ "esbuild" : " ^0.20.1"
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments