Skip to content

Commit 6624745

Browse files
committed
feature(bower) add skipfirst
1 parent cb59834 commit 6624745

File tree

9 files changed

+154
-24
lines changed

9 files changed

+154
-24
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"dependencies": {
1515
"jq-console": "~2.10.0",
1616
"jquery": "~2.1.3",
17-
"load": "~1.1.0"
17+
"load": "~1.1.0",
18+
"skipfirst": "~1.0.0"
1819
}
1920
}

lib/client/console.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var $, io;
1+
var $, io, skipfirst;
22

33
(function(window) {
44
'use strict';
@@ -86,7 +86,13 @@ var $, io;
8686
}
8787

8888
function load(prefix, callback) {
89-
loadScript([prefix + '/modules/load/load.js', prefix + '/join/join.js'], function() {
89+
loadScript([
90+
'/modules/load/load.js',
91+
'/join/join.js',
92+
'/modules/skipfirst/lib/skipfirst.js'
93+
].map(function(name) {
94+
return prefix + name;
95+
}), function() {
9096
var load = window.load,
9197
join = window.join,
9298

@@ -245,7 +251,7 @@ var $, io;
245251
}
246252

247253
function addKeyWhenNoPrompt(jqconsole) {
248-
var skip = skipFirst(readNoPrompt);
254+
var skip = skipfirst(readNoPrompt);
249255

250256
jqconsole
251257
.$input_source[0]
@@ -256,7 +262,7 @@ var $, io;
256262
if (is)
257263
skip.clear();
258264
else
259-
skip(event, event.keyCode === ENTER);
265+
skip(event.keyCode === ENTER, event);
260266
});
261267
}
262268

@@ -278,22 +284,6 @@ var $, io;
278284
}
279285
}
280286

281-
function skipFirst(callback) {
282-
var first,
283-
fn = function(param, condition) {
284-
if (!first)
285-
first = condition;
286-
else
287-
callback(param);
288-
};
289-
290-
fn.clear = function() {
291-
first = null;
292-
};
293-
294-
return fn;
295-
}
296-
297287
function fromCharCode(event) {
298288
var code, hex,
299289
char = '',

modules/load/.bower.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"commit": "a888f78f5634e8b93b98863d51ab530957413fbc"
2323
},
2424
"_source": "git://github.com/coderaiser/load.js.git",
25-
"_target": "~1.1.3",
26-
"_originalSource": "load",
27-
"_direct": true
25+
"_target": "~1.1.0",
26+
"_originalSource": "load"
2827
}

modules/skipfirst/.bower.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "skipfirst",
3+
"homepage": "https://github.com/coderaiser/skipfirst",
4+
"version": "1.0.0",
5+
"_release": "1.0.0",
6+
"_resolution": {
7+
"type": "version",
8+
"tag": "v1.0.0",
9+
"commit": "220fc5004e5d3361679fb26d96dd3d187fa4a9fd"
10+
},
11+
"_source": "git://github.com/coderaiser/skipfirst.git",
12+
"_target": "~1.0.0",
13+
"_originalSource": "skipfirst",
14+
"_direct": true
15+
}

modules/skipfirst/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
npm-debug.log

modules/skipfirst/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 coderaiser
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

modules/skipfirst/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Skipfirst
2+
3+
Skip first time condition are true and call function next time.
4+
5+
## Install
6+
7+
With npm:
8+
9+
```
10+
npm i skipfirst --save
11+
```
12+
13+
or with bower:
14+
15+
```
16+
bower i skipfirst --save
17+
```
18+
19+
## How to use?
20+
21+
```js
22+
var skipfirst = require('skipfirst'),
23+
skip = skipfirst(function(identifier) {
24+
console.log('first was skiped:', identifier);
25+
});
26+
27+
/*
28+
* first enter key press would be skiped
29+
* and called next time
30+
*/
31+
document.body.addEventListener('keydown', function(event) {
32+
var key = event.keyCode,
33+
identifier = event.keyIdentifier,
34+
ENTER = 13,
35+
ESC = 27;
36+
37+
if (key === ESC)
38+
skip.clear();
39+
else
40+
skip(key === ENTER, identifier);
41+
});
42+
```
43+
44+
## License
45+
46+
MIT

modules/skipfirst/lib/skipfirst.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(function(global) {
2+
'use strict';
3+
4+
if (typeof module !== 'undefined' && module.exports)
5+
module.exports = skipfirst;
6+
else
7+
global.skipfirst = skipfirst;
8+
9+
function skipfirst(callback) {
10+
var first,
11+
fn = function(condition) {
12+
var args = [].slice.call(arguments);
13+
14+
args.shift();
15+
16+
if (!first)
17+
first = condition;
18+
else
19+
callback.apply(null, args);
20+
};
21+
22+
if (!callback)
23+
throw(Error('callback could not be empty!'));
24+
25+
fn.clear = function() {
26+
first = null;
27+
};
28+
29+
return fn;
30+
}
31+
32+
})(this);

modules/skipfirst/package.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "skipfirst",
3+
"version": "1.0.0",
4+
"description": "Skip first time condition are true and call function next time",
5+
"main": "lib/skipfirst.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git://github.com/coderaiser/skipfirst"
12+
},
13+
"keywords": [
14+
"function",
15+
"skip",
16+
"first"
17+
],
18+
"author": "coderaiser <[email protected]> (http://coderaiser.github.io/)",
19+
"license": "MIT",
20+
"bugs": {
21+
"url": "https://github.com/coderaiser/skipfirst/issues"
22+
},
23+
"homepage": "https://github.com/coderaiser/skipfirst"
24+
}

0 commit comments

Comments
 (0)