Skip to content

Commit

Permalink
Added methods to the service for get the keyboard from a element refe…
Browse files Browse the repository at this point in the history
…rence
  • Loading branch information
antonio-spinelli committed Oct 3, 2015
1 parent 9200556 commit 2ad9105
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 69 deletions.
83 changes: 49 additions & 34 deletions dist/ng-virtual-keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,55 @@
angular.module('ng-virtual-keyboard', [])

.constant('VKI_CONFIG', {

})

.service('ngVirtualKeyboardService', ['VKI_CONFIG', function(VKI_CONFIG) {
var clone = function(obj) {
var copy;

// Handle the 3 simple types, and null or undefined
if (null == obj || "object" != typeof obj) return obj;

// Handle Date
if (obj instanceof Date) {
copy = new Date();
copy.setTime(obj.getTime());
return copy;
}

// Handle Array
if (obj instanceof Array) {
copy = [];
for (var i = 0, len = obj.length; i < len; i++) {
copy[i] = clone(obj[i]);
}
return copy;
}

// Handle Object
if (obj instanceof Object) {
copy = {};
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);
}
return copy;
}

throw new Error("Unable to copy obj! Its type isn't supported.");
var clone = function(obj){
var copy;

// Handle the 3 simple types, and null or undefined
if (null == obj || "object" != typeof obj) return obj;

// Handle Date
if (obj instanceof Date) {
copy = new Date();
copy.setTime(obj.getTime());
return copy;
}

// Handle Array
if (obj instanceof Array) {
copy = [];
for (var i = 0, len = obj.length; i < len; i++) {
copy[i] = clone(obj[i]);
}
return copy;
}

// Handle Object
if (obj instanceof Object) {
copy = {};
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);
}
return copy;
}

throw new Error("Unable to copy obj! Its type isn't supported.");
};

var executeGetKeyboard = function(elementReference){
var keyboard;
var element = $(elementReference);
if (element) {
keyboard = $(elementReference).getkeyboard();
}
return keyboard;
};

return {
attach: function(element, config, inputCallback) {
attach: function(element, config, inputCallback){
var newConfig = clone(VKI_CONFIG);

config = config || {};
Expand All @@ -62,6 +71,12 @@ angular.module('ng-virtual-keyboard', [])
newConfig.accepted = config.accepted || inputCallback;

$(element).keyboard(newConfig);
},
getKeyboard: function(elementReference){
return executeGetKeyboard(elementReference);
},
getKeyboardById: function(id){
return executeGetKeyboard('#' + id);
}
};
}])
Expand Down
2 changes: 1 addition & 1 deletion dist/ng-virtual-keyboard.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 49 additions & 34 deletions src/ng-virtual-keyboard.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,55 @@
angular.module('ng-virtual-keyboard', [])

.constant('VKI_CONFIG', {

})

.service('ngVirtualKeyboardService', ['VKI_CONFIG', function(VKI_CONFIG) {
var clone = function(obj) {
var copy;

// Handle the 3 simple types, and null or undefined
if (null == obj || "object" != typeof obj) return obj;

// Handle Date
if (obj instanceof Date) {
copy = new Date();
copy.setTime(obj.getTime());
return copy;
}

// Handle Array
if (obj instanceof Array) {
copy = [];
for (var i = 0, len = obj.length; i < len; i++) {
copy[i] = clone(obj[i]);
}
return copy;
}

// Handle Object
if (obj instanceof Object) {
copy = {};
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);
}
return copy;
}

throw new Error("Unable to copy obj! Its type isn't supported.");
var clone = function(obj){
var copy;

// Handle the 3 simple types, and null or undefined
if (null == obj || "object" != typeof obj) return obj;

// Handle Date
if (obj instanceof Date) {
copy = new Date();
copy.setTime(obj.getTime());
return copy;
}

// Handle Array
if (obj instanceof Array) {
copy = [];
for (var i = 0, len = obj.length; i < len; i++) {
copy[i] = clone(obj[i]);
}
return copy;
}

// Handle Object
if (obj instanceof Object) {
copy = {};
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);
}
return copy;
}

throw new Error("Unable to copy obj! Its type isn't supported.");
};

var executeGetKeyboard = function(elementReference){
var keyboard;
var element = $(elementReference);
if (element) {
keyboard = $(elementReference).getkeyboard();
}
return keyboard;
};

return {
attach: function(element, config, inputCallback) {
attach: function(element, config, inputCallback){
var newConfig = clone(VKI_CONFIG);

config = config || {};
Expand All @@ -52,6 +61,12 @@ angular.module('ng-virtual-keyboard', [])
newConfig.accepted = config.accepted || inputCallback;

$(element).keyboard(newConfig);
},
getKeyboard: function(elementReference){
return executeGetKeyboard(elementReference);
},
getKeyboardById: function(id){
return executeGetKeyboard('#' + id);
}
};
}])
Expand Down

0 comments on commit 2ad9105

Please sign in to comment.