Comparing version 1.0.4 to 1.0.5
40
index.js
@@ -11,3 +11,3 @@ 'use strict'; | ||
openFileDialog: function(filter, multiple, callback) { | ||
openFileDialog: function(filter, multiple, workdir, callback) { | ||
@@ -24,6 +24,6 @@ var fn = callback; | ||
node.setAttribute('accept', filter); | ||
} else if (typeof filter === 'boolean' && filter === true) { | ||
node.setAttribute('multiple', ''); | ||
} else if (this.isArray(filter)) { | ||
node.setAttribute('accept', filter.join(',')); | ||
} else if (typeof filter === 'boolean' && filter === true) { | ||
node.setAttribute('multiple', ''); | ||
} | ||
@@ -33,12 +33,16 @@ | ||
fn = multiple; | ||
} else if (typeof multiple === 'string') { | ||
node.setAttribute('nwworkingdir', multiple); | ||
} else if (typeof multiple === 'boolean' && multiple === true) { | ||
node.setAttribute('multiple', ''); | ||
} else if (typeof multiple === 'string') { | ||
node.setAttribute('nwdirectory', ''); // not work in 0.13 | ||
} | ||
this._context.body.appendChild(node); | ||
node.addEventListener('change', function() { | ||
if (typeof workdir === 'function') { | ||
fn = workdir; | ||
} else if (typeof workdir === 'string') { | ||
node.setAttribute('nwworkingdir', workdir); | ||
} | ||
node.addEventListener('change', function(e) { | ||
fn(node.value); | ||
node.remove(); | ||
}); | ||
@@ -75,9 +79,7 @@ node.click(); | ||
} else if (typeof directory === 'string') { | ||
node.setAttribute('nwdirectory', directory); //not work in 0.13 | ||
node.setAttribute('nwworkingdir', directory); | ||
} | ||
this._context.body.appendChild(node); | ||
node.addEventListener('change', function() { | ||
fn(node.value); | ||
node.remove(); | ||
}); | ||
@@ -88,3 +90,4 @@ node.click(); | ||
folderBrowserDialog: function(callback) { | ||
folderBrowserDialog: function(workdir, callback) { | ||
var fn = callback; | ||
var node = this._context.createElement('input'); | ||
@@ -96,6 +99,10 @@ node.type = 'file'; | ||
this._context.body.appendChild(node); | ||
if (typeof workdir === 'function') { | ||
fn = workdir | ||
} else if (typeof workdir === 'string') { | ||
node.setAttribute('nwworkingdir', workdir); | ||
} | ||
node.addEventListener('change', function() { | ||
callback(node.value); | ||
node.remove(); | ||
fn(node.value); | ||
}); | ||
@@ -112,5 +119,6 @@ node.click(); | ||
if (typeof exports == 'undefined') { | ||
nw.Dialog = window.Dialog = nwdialog; | ||
nw.Dialog = nwdialog; | ||
window.dialog = nwdialog; | ||
} else { | ||
module.exports = nwdialog; | ||
} |
{ | ||
"name": "nw-dialog", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Node Webkit Dialog", | ||
@@ -13,12 +13,9 @@ "main": "index.js", | ||
"keywords": [ | ||
"nwjs", | ||
"dialog", | ||
"nwjs dialog", | ||
"node webkit dialog", | ||
"node", | ||
"webkit", | ||
"dialog", | ||
"dialog", | ||
"nwjs", | ||
"node", | ||
"webkit" | ||
"dialog" | ||
] | ||
} |
@@ -10,3 +10,3 @@ # nw-dialog | ||
``` | ||
```JavaScript | ||
var dialog = require('nw-dialog') | ||
@@ -19,7 +19,7 @@ dialog.setContext(document) // work in client | ||
``` | ||
```JavaScript | ||
<script src="nw-dialog/index.js"></script> | ||
nw.Dialog.openFileDialog( ... ) | ||
// or | ||
Dialog.openFileDialog( ... ) | ||
window.dialog.openFileDialog( ... ) | ||
``` | ||
@@ -31,3 +31,3 @@ | ||
``` | ||
```JavaScript | ||
dialog.openFileDialog(function(result) { | ||
@@ -40,9 +40,10 @@ alert(result) | ||
``` | ||
```JavaScript | ||
dialog.openFileDialog('.zip,.rar', function(result) { | ||
alert(result) | ||
}) | ||
``` | ||
or | ||
// or | ||
```JavaScript | ||
dialog.openFileDialog(['.zip', '.rar'], function(result) { | ||
@@ -53,12 +54,13 @@ alert(result) | ||
Multiple select | ||
``` | ||
```JavaScript | ||
dialog.openFileDialog(true, function(result) { | ||
alert(result) | ||
}) | ||
``` | ||
// with file type | ||
File type + Multiple select | ||
```JavaScript | ||
dialog.openFileDialog('.zip,.rar', true, function(result) { | ||
@@ -69,6 +71,22 @@ alert(result) | ||
File type + Working directory | ||
```JavaScript | ||
dialog.openFileDialog('.zip,.rar', '/Users/didanurwanda', function(result) { | ||
alert(result) | ||
}) | ||
``` | ||
File type + Multiple select + Working directory | ||
```JavaScript | ||
dialog.openFileDialog('.zip,.rar', true, '/Users/didanurwanda', function(result) { | ||
alert(result) | ||
}) | ||
``` | ||
### SaveFileDialog | ||
Simple | ||
``` | ||
```JavaScript | ||
dialog.saveFileDialog(function(result) { | ||
@@ -81,3 +99,3 @@ alert(result) | ||
``` | ||
```JavaScript | ||
dialog.saveFileDialog('name.txt', function(result) { | ||
@@ -90,17 +108,18 @@ alert(result) | ||
```JavaScript | ||
dialog.saveFileDialog('name', '.txt,.srt', function(result) { | ||
alert(result) | ||
}) | ||
``` | ||
dialog.saveFileDialog('name', '.txt', function(result) { | ||
alert(result) | ||
}) | ||
or | ||
// or | ||
```JavaScript | ||
dialog.saveFileDialog('name', ['.txt', '.srt'], function(result) { | ||
alert(result) | ||
alert(result) | ||
}) | ||
``` | ||
Default directory | ||
Working directory | ||
``` | ||
```JavaScript | ||
dialog.saveFileDialog('name', '.txt', '/Users/didanurwanda', function(result) { | ||
@@ -114,3 +133,3 @@ alert(result) | ||
``` | ||
```JavaScript | ||
dialog.folderBrowseDialog(function(result) { | ||
@@ -120,1 +139,9 @@ alert(result) | ||
``` | ||
Default Directory | ||
```JavaScript | ||
dialog.folderBrowseDialog('/Users/didanurwanda', function(result) { | ||
alert(result) | ||
}) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5939
94
137