Skip to content

Commit ae508ba

Browse files
add old versions of scannerdetection
1 parent b70a10f commit ae508ba

14 files changed

+701
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* jQuery Scanner Detection
3+
*
4+
* Copyright (c) 2013 Julien Maurel
5+
*
6+
* Licensed under the MIT license:
7+
* http://www.opensource.org/licenses/mit-license.php
8+
*
9+
* Project home:
10+
* https://github.com/julien-maurel/jQuery-Scanner-Detection
11+
*
12+
* Version: 1.0.0
13+
*
14+
*/
15+
(function($){
16+
$.fn.scannerDetection=function(options){
17+
18+
// If string given, call onComplete callback
19+
if(typeof options==="string"){
20+
this.each(function(){
21+
$(this).data('scannerDetection').options.onComplete.call(this,options);
22+
});
23+
return this;
24+
}
25+
26+
var defaults={
27+
onComplete:function(){}, // Callback after detection of a successfull scanning (scanned string in parameter)
28+
onError:false, // Callback after detection of a unsuccessfull scanning (scanned string in parameter)
29+
onReceive:false, // Callback after receive a char (scanned char in parameter)
30+
timeBeforeScanTest:100, // Wait duration (ms) after keypress event to check if scanning is finished
31+
avgTimeByChar:30, // Average time (ms) between 2 chars. Used to do difference between keyboard typing and scanning
32+
minLength:6, // Minimum length for a scanning
33+
endChar:[9,13], // Chars to remove and means end of scanning
34+
stopPropagation:false, // Stop immediate propagation on keypress event
35+
preventDefault:false, // Prevent default action on keypress event
36+
};
37+
if(typeof options==="function"){
38+
options={onComplete:options}
39+
}
40+
options=$.extend({},defaults,options);
41+
42+
this.each(function(){
43+
var self=this, $self=$(self), firstCharTime=0, lastCharTime=0, stringWriting='', callIsScanner=false, testTimer=false;
44+
var initScannerDetection=function(){
45+
firstCharTime=0;
46+
stringWriting='';
47+
};
48+
var isScanner=function(){
49+
// If all condition are good (length, time...), call the callback and re-initialize the plugin for next scanning
50+
// Else, just re-initialize
51+
if(stringWriting.length>=options.minLength && lastCharTime-firstCharTime<stringWriting.length*options.avgTimeByChar){
52+
options.onComplete.call(self,stringWriting);
53+
initScannerDetection();
54+
return true;
55+
}else{
56+
if(options.onError) options.onError.call(self,stringWriting);
57+
initScannerDetection();
58+
return false;
59+
}
60+
}
61+
$self.data('scannerDetection',{options:options}).unbind('.scannerDetection').bind('keypress.scannerDetection',function(e){
62+
if(options.stopPropagation) e.stopImmediatePropagation();
63+
if(options.preventDefault) e.preventDefault();
64+
65+
if(firstCharTime && options.endChar.indexOf(e.which)!==-1){
66+
e.preventDefault();
67+
e.stopImmediatePropagation();
68+
callIsScanner=true;
69+
}else{
70+
stringWriting+=String.fromCharCode(e.which);
71+
callIsScanner=false;
72+
}
73+
74+
if(!firstCharTime){
75+
firstCharTime=e.timeStamp;
76+
}
77+
lastCharTime=e.timeStamp;
78+
79+
if(testTimer) clearTimeout(testTimer);
80+
if(callIsScanner){
81+
isScanner();
82+
testTimer=false;
83+
}else{
84+
testTimer=setTimeout(isScanner,options.timeBeforeScanTest);
85+
}
86+
87+
if(options.onReceive) options.onReceive.call(self,e.which);
88+
});
89+
});
90+
return this;
91+
}
92+
})(jQuery);

ajax/libs/scannerdetection/1.0.0/jquery.scannerdetection.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* jQuery Scanner Detection
3+
*
4+
* Copyright (c) 2013 Julien Maurel
5+
*
6+
* Licensed under the MIT license:
7+
* http://www.opensource.org/licenses/mit-license.php
8+
*
9+
* Project home:
10+
* https://github.com/julien-maurel/jQuery-Scanner-Detection
11+
*
12+
* Version: 1.1.0
13+
*
14+
*/
15+
(function($){
16+
$.fn.scannerDetection=function(options){
17+
18+
// If string given, call onComplete callback
19+
if(typeof options==="string"){
20+
this.each(function(){
21+
$(this).data('scannerDetection').options.onComplete.call(this,options);
22+
});
23+
return this;
24+
}
25+
26+
var defaults={
27+
onComplete:false, // Callback after detection of a successfull scanning (scanned string in parameter)
28+
onError:false, // Callback after detection of a unsuccessfull scanning (scanned string in parameter)
29+
onReceive:false, // Callback after receive a char (scanned char in parameter)
30+
timeBeforeScanTest:100, // Wait duration (ms) after keypress event to check if scanning is finished
31+
avgTimeByChar:30, // Average time (ms) between 2 chars. Used to do difference between keyboard typing and scanning
32+
minLength:6, // Minimum length for a scanning
33+
endChar:[9,13], // Chars to remove and means end of scanning
34+
stopPropagation:false, // Stop immediate propagation on keypress event
35+
preventDefault:false // Prevent default action on keypress event
36+
};
37+
if(typeof options==="function"){
38+
options={onComplete:options}
39+
}
40+
if(typeof options!=="object"){
41+
options=$.extend({},defaults);
42+
}else{
43+
options=$.extend({},defaults,options);
44+
}
45+
46+
this.each(function(){
47+
var self=this, $self=$(self), firstCharTime=0, lastCharTime=0, stringWriting='', callIsScanner=false, testTimer=false;
48+
var initScannerDetection=function(){
49+
firstCharTime=0;
50+
stringWriting='';
51+
};
52+
var isScanner=function(){
53+
// If all condition are good (length, time...), call the callback and re-initialize the plugin for next scanning
54+
// Else, just re-initialize
55+
if(stringWriting.length>=options.minLength && lastCharTime-firstCharTime<stringWriting.length*options.avgTimeByChar){
56+
if(options.onComplete) options.onComplete.call(self,stringWriting);
57+
$self.trigger('scannerDetectionComplete',{string:stringWriting});
58+
initScannerDetection();
59+
return true;
60+
}else{
61+
if(options.onError) options.onError.call(self,stringWriting);
62+
$self.trigger('scannerDetectionError',{string:stringWriting});
63+
initScannerDetection();
64+
return false;
65+
}
66+
}
67+
$self.data('scannerDetection',{options:options}).unbind('.scannerDetection').bind('keypress.scannerDetection',function(e){
68+
if(options.stopPropagation) e.stopImmediatePropagation();
69+
if(options.preventDefault) e.preventDefault();
70+
71+
if(firstCharTime && options.endChar.indexOf(e.which)!==-1){
72+
e.preventDefault();
73+
e.stopImmediatePropagation();
74+
callIsScanner=true;
75+
}else{
76+
stringWriting+=String.fromCharCode(e.which);
77+
callIsScanner=false;
78+
}
79+
80+
if(!firstCharTime){
81+
firstCharTime=e.timeStamp;
82+
}
83+
lastCharTime=e.timeStamp;
84+
85+
if(testTimer) clearTimeout(testTimer);
86+
if(callIsScanner){
87+
isScanner();
88+
testTimer=false;
89+
}else{
90+
testTimer=setTimeout(isScanner,options.timeBeforeScanTest);
91+
}
92+
93+
if(options.onReceive) options.onReceive.call(self,e);
94+
$self.trigger('scannerDetectionReceive',{evt:e});
95+
});
96+
});
97+
return this;
98+
}
99+
})(jQuery);

ajax/libs/scannerdetection/1.1.0/jquery.scannerdetection.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* jQuery Scanner Detection
3+
*
4+
* Copyright (c) 2013 Julien Maurel
5+
*
6+
* Licensed under the MIT license:
7+
* http://www.opensource.org/licenses/mit-license.php
8+
*
9+
* Project home:
10+
* https://github.com/julien-maurel/jQuery-Scanner-Detection
11+
*
12+
* Version: 1.1.1
13+
*
14+
*/
15+
(function($){
16+
$.fn.scannerDetection=function(options){
17+
18+
// If string given, call onComplete callback
19+
if(typeof options==="string"){
20+
this.each(function(){
21+
this.scannerDetectionTest(options);
22+
});
23+
return this;
24+
}
25+
26+
var defaults={
27+
onComplete:false, // Callback after detection of a successfull scanning (scanned string in parameter)
28+
onError:false, // Callback after detection of a unsuccessfull scanning (scanned string in parameter)
29+
onReceive:false, // Callback after receive a char (scanned char in parameter)
30+
timeBeforeScanTest:100, // Wait duration (ms) after keypress event to check if scanning is finished
31+
avgTimeByChar:30, // Average time (ms) between 2 chars. Used to do difference between keyboard typing and scanning
32+
minLength:6, // Minimum length for a scanning
33+
endChar:[9,13], // Chars to remove and means end of scanning
34+
stopPropagation:false, // Stop immediate propagation on keypress event
35+
preventDefault:false // Prevent default action on keypress event
36+
};
37+
if(typeof options==="function"){
38+
options={onComplete:options}
39+
}
40+
if(typeof options!=="object"){
41+
options=$.extend({},defaults);
42+
}else{
43+
options=$.extend({},defaults,options);
44+
}
45+
46+
this.each(function(){
47+
var self=this, $self=$(self), firstCharTime=0, lastCharTime=0, stringWriting='', callIsScanner=false, testTimer=false;
48+
var initScannerDetection=function(){
49+
firstCharTime=0;
50+
stringWriting='';
51+
};
52+
self.scannerDetectionTest=function(s){
53+
// If string is given, test it
54+
if(s){
55+
firstCharTime=lastCharTime=0;
56+
stringWriting=s;
57+
}
58+
// If all condition are good (length, time...), call the callback and re-initialize the plugin for next scanning
59+
// Else, just re-initialize
60+
if(stringWriting.length>=options.minLength && lastCharTime-firstCharTime<stringWriting.length*options.avgTimeByChar){
61+
if(options.onComplete) options.onComplete.call(self,stringWriting);
62+
$self.trigger('scannerDetectionComplete',{string:stringWriting});
63+
initScannerDetection();
64+
return true;
65+
}else{
66+
if(options.onError) options.onError.call(self,stringWriting);
67+
$self.trigger('scannerDetectionError',{string:stringWriting});
68+
initScannerDetection();
69+
return false;
70+
}
71+
}
72+
$self.data('scannerDetection',{options:options}).unbind('.scannerDetection').bind('keypress.scannerDetection',function(e){
73+
if(options.stopPropagation) e.stopImmediatePropagation();
74+
if(options.preventDefault) e.preventDefault();
75+
76+
if(firstCharTime && options.endChar.indexOf(e.which)!==-1){
77+
e.preventDefault();
78+
e.stopImmediatePropagation();
79+
callIsScanner=true;
80+
}else{
81+
stringWriting+=String.fromCharCode(e.which);
82+
callIsScanner=false;
83+
}
84+
85+
if(!firstCharTime){
86+
firstCharTime=e.timeStamp;
87+
}
88+
lastCharTime=e.timeStamp;
89+
90+
if(testTimer) clearTimeout(testTimer);
91+
if(callIsScanner){
92+
self.scannerDetectionTest();
93+
testTimer=false;
94+
}else{
95+
testTimer=setTimeout(self.scannerDetectionTest,options.timeBeforeScanTest);
96+
}
97+
98+
if(options.onReceive) options.onReceive.call(self,e);
99+
$self.trigger('scannerDetectionReceive',{evt:e});
100+
});
101+
});
102+
return this;
103+
}
104+
})(jQuery);

ajax/libs/scannerdetection/1.1.1/jquery.scannerdetection.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)