ng-cordova
Version:
[ngCordova](http://ngcordova.com/) ==========
1 lines • 16.2 kB
JavaScript
!function(){var r=angular.module("ngCordovaMocks",[]);r.factory("$cordovaBarcodeScanner",["$q",function(r){var e=!1,t="",i="",n=!1;return{throwsError:e,scannedText:t,scannedFormat:i,wasCancelled:n,scan:function(){var e=r.defer();return this.throwsError?e.reject("There was an error scanning."):e.resolve({text:this.scannedText,format:this.scannedFormat,cancelled:this.wasCancelled}),e.promise},encode:function(e,t){this.scannedFormat=e,this.scannedText=t;var i=r.defer();return this.throwsError?i.reject("There was an error encoding the data."):i.resolve(),i.promise}}}]),r.factory("$cordovaCamera",["$q",function(r){var e=!1;return{throwsError:e,getPicture:function(e){var t=r.defer();return this.throwsError?t.reject("There was an error getting the picture."):(e&&(e=e),t.resolve()),t.promise}}}]),r.factory("$cordovaCapture",["$q",function(r){var e=!1;return{throwsError:e,captureAudio:function(){var e=r.defer();return this.throwsError?e.reject("There was an error capturing the audio."):e.resolve(),e.promise},captureImage:function(){var e=r.defer();return this.throwsError?e.reject("There was an error capturing the image."):e.resolve(),e.promise},captureVideo:function(){var e=r.defer();return this.throwsError?e.reject("There was an error capturing the video."):e.resolve(),e.promise}}}]),r.factory("$cordovaContacts",["$q",function(r){var e=!1,t=[];return{throwsError:e,contacts:t,save:function(e){var t=r.defer();if(this.throwsError)t.reject("There was an error saving the contact.");else{for(var i=null,n=0;n<this.contacts.length;n++)if(this.contacts[n].id===e.id){i=n;break}null===i?(this.contacts.push(e),t.resolve()):t.reject("Contact already exists.")}return t.promise},remove:function(e){var t=r.defer();if(this.throwsError)t.reject("There was an error saving the contact.");else{for(var i=null,n=0;n<this.contacts.length;n++)if(this.contacts[n].id===e.id){i=n;break}null===i?t.reject("Unable to find contact."):(this.contacts.splice(i,1),t.resolve())}return t.promise},find:function(e){var t=r.defer();if(this.throwsError)t.reject("There was an error finding the contact.");else{var i=e.fields||["id","displayName"];if(delete e.fields,i)if("*"===i)t.resolve(this.contacts);else{for(var n=[],a=0;a<this.contacts.length;a++)for(var o in this.contacts[a])var s=this.contacts[a][o];t.resolve(n)}else t.reject("ContactError.INVALID_ARGUMENT_ERROR")}return t.promise}}}]),r.factory("$cordovaDatePicker",function(){return{show:function(r){return r.date}}}),r.factory("$cordovaDevice",function(){var r="",e="",t="",i="",n="",a="";return{device:r,cordova:e,model:t,platform:i,uuid:n,version:a,getDevice:function(){return this.device},getCordova:function(){return this.cordova},getModel:function(){return this.model},getPlatform:function(){return this.platform},getUUID:function(){return this.uuid},getVersion:function(){return this.version}}}),r.factory("$cordovaDeviceMotion",["$interval","$q",function(r,e){var t=null,i=!1,n=[],a=[];return{currentAcceleration:t,throwsError:i,positions:n,watchIntervals:a,getCurrentAcceleration:function(){var r=e.defer();return this.throwsError?r.reject("There was an error getting the current acceleration."):r.resolve(this.currentAcceleration),r.promise},watchAcceleration:function(t){var i=e.defer(),n=Math.floor(1e6*Math.random()+1);if(this.positions=[],self=this,this.throwsError)i.reject("There was an error watching the current acceleration.");else{var a=1e4;t&&t.frequency&&(a=t.frequency),this.watchIntervals.push(r(function(){self.throwsError&&i.reject("There was an error watching the acceleration.");var r=Math.floor(100*Math.random()+1),e=Math.floor(100*Math.random()+1),t=Math.floor(100*Math.random()+1),n={x:r,y:e,z:t,timestamp:Date.now()};self.positions.push(n),i.notify(n)},a))}return{watchId:n,promise:i.promise}},clearWatch:function(t){var i=e.defer();if(t)if(this.throwsError)i.reject("Unable to clear watch.");else{for(var n=-1,o=0;o<this.watchIntervals.length;o++)if(this.watchIntervals[o].watchId===t){r.cancel(a[o].interval),n=o;break}-1!==n&&this.watchIntervals.splice(n,1)}else i.reject("Unable to clear watch. No watch ID provided.");return i.promise}}}]),r.factory("$cordovaDeviceOrientation",["$interval","$q",function(r,e){var t=null,i=!1,n=[],a=[];return{currentHeading:t,throwsError:i,readings:n,watchIntervals:a,getCurrentHeading:function(){var r=e.defer();return this.throwsError?r.reject("There was an error getting the current heading."):r.resolve(this.currentHeading),r.promise},watchHeading:function(t){var i=e.defer(),n=Math.floor(1e6*Math.random()+1),o=this;if(o.readings=[],o.throwsError)i.reject("There was an error getting the compass heading.");else{var s=100;t&&t.frequency&&(s=t.frequency),o.watchIntervals.push({watchID:n,interval:r(function(){o.throwsError&&i.reject("There was an error watching the acceleration.");var r=359.99*Math.random()+1,e=359.99*Math.random()+1,t=Math.floor(360*Math.random()+1),n={magneticHeading:r,trueHeading:e,headingAccuracy:t,timestamp:Date.now()};o.readings.push(n),i.notify(n)},s)})}var c=function(e){for(var t=-1,i=0;i<o.watchIntervals.length;i++)if(o.watchIntervals[i].watchID===e){r.cancel(a[i].interval),t=i;break}-1!==t&&o.watchIntervals.splice(t,1)};return i.promise.cancel=function(){c(n)},i.promise.clearWatch=function(r){c(r||n)},i.promise.watchID=n,i.promise},clearWatch:function(t){var i=e.defer();if(t)if(this.throwsError)i.reject("Unable to clear watch.");else{for(var n=-1,o=0;o<this.watchIntervals.length;o++)if(this.watchIntervals[o].watchId===t){r.cancel(a[o].interval),n=o;break}-1!==n&&this.watchIntervals.splice(n,1)}else i.reject("Unable to clear watch. No watch ID provided.");return i.promise}}}]),r.factory("$cordovaDialogs",["$q",function(r){var e=!1,t="",i="",n="",a=0,o=!0;return{dialogText:e,dialogTitle:t,defaultValue:i,promptResponse:n,buttonLabels:[],beepCount:a,useHostAbilities:o,alert:function(e,t,i){var n=r.defer();return this.useHostAbilities?(alert(e),n.resolve()):(this.dialogText=e,this.dialogTitle=t,this.buttonLabels.push(i),n.resolve()),n.promise},confirm:function(e,t,i){var n=r.defer();if(this.useHostAbilities){var a=confirm(e);n.resolve(a?2:1)}else this.dialogText=e,this.dialogTitle=t,this.buttonLabels.push(i),n.resolve(0);return n.promise},prompt:function(e,t,i,n){var a=r.defer();if(this.useHostAbilities){var o=prompt(e,n);a.resolve(o)}else{this.dialogText=e,this.dialogTitle=t,this.defaultValue=n;for(var s=0;s<i.length;s++)this.buttonLabels.push(i[s]);a.resolve(this.promptResponse)}return a.promise},beep:function(r){this.beepCount=r}}}]),r.factory("$cordovaFile",["$q",function(r){var e=!1,t={},i=function(e){var t=r.defer();return this.throwsError?t.reject(e):t.resolve(),t.promise};return{throwsError:e,fileSystem:t,checkDir:function(){return i.call(this,"There was an error checking the directory.")},createDir:function(){return i.call(this,"There was an error creating the directory.")},listDir:function(){return i.call(this,"There was an error listing the directory")},checkFile:function(){return i.call(this,"There was an error checking for the file.")},createFile:function(){return i.call(this,"There was an error creating the file.")},removeFile:function(){return i.call(this,"There was an error removng the file.")},writeFile:function(){return i.call(this,"There was an error writing the file.")},readFile:function(){return i.call(this,"There was an error reading the file.")},readAsText:function(){return i.call(this,"There was an error reading the file as text.")},readAsDataURL:function(){return i.call(this,"There was an error reading the file as a data url.")},readAsBinaryString:function(){return i.call(this,"There was an error reading the file as a binary string.")},readAsArrayBuffer:function(){return i.call(this,"There was an error reading the file as an array buffer.")},readFileMetadata:function(){return i.call(this,"There was an error reading the file metadata")},readFileAbsolute:function(){return i.call(this,"There was an error reading the file from the absolute path")},readFileMetadataAbsolute:function(){return i.call(this,"There was an error reading the file metadta from the absolute path")},downloadFile:function(){return i.call(this,"There was an error downloading the file.")},uploadFile:function(){return i.call(this,"There was an error uploading the file.")}}}]),r.factory("$cordovaGeolocation",["$interval","$q",function(r,e){var t=!1,i=!0,n=[],a=[],o=null,s=null;return{throwsError:t,watchIntervals:n,locations:a,currentPosition:o,nextPosition:s,useHostAbilities:i,getCurrentPosition:function(r){var t=e.defer();return this.throwsError?t.reject("There was an error getting the location."):(r&&(r=r),this.useHostAbilities?navigator.geolocation?navigator.geolocation.getCurrentPosition(function(r){this.currentPosition=r,t.resolve(this.currentPosition)},function(r){t.reject(r)}):t.reject("Geolocation is not supported by this browser."):t.resolve(this.currentPosition)),t.promise},watchPosition:function(t){var i=e.defer(),a=Math.floor(1e6*Math.random()+1),o=this;if(o.locations=[],o.throwsError)i.reject("There was an error getting the geolocation.");else{var s=1e3;t&&t.timeout&&(s=t.timeout),o.watchIntervals.push({watchID:a,interval:r(function(){o.throwsError&&i.reject("There was an error watching the geolocation.");var r=o.nextPosition;null===r&&(o.useHostAbilities?navigator.geolocation?navigator.geolocation.getCurrentPosition(function(r){o.currentPosition=r,o.locations.push(r),i.resolve(r)},function(r){i.reject(r)}):i.reject("Geolocation is not supported by this browser."):(r={coords:{latitude:180*Math.random()+1-90,longitude:360*Math.random()+1-180,altitude:100*Math.random()+1,accuracy:10*Math.random()+1,altitudeAccuracy:10*Math.random()+1,heading:360*Math.random()+1,speed:100*Math.random()+1},timestamp:Date.now()},o.currentPosition=r,o.locations.push(r),i.notify(r)))},s)})}var c=function(e){for(var t=-1,i=0;i<o.watchIntervals.length;i++)if(o.watchIntervals[i].watchID===e){r.cancel(n[i].interval),t=i;break}-1!==t&&o.watchIntervals.splice(t,1)};return i.promise.cancel=function(){c(a)},i.promise.clearWatch=function(r){c(r||a)},i.promise.watchID=a,i.promise},clearWatch:function(t){var i=e.defer();if(t)if(this.throwsError)i.reject("Unable to clear watch.");else{for(var a=-1,o=0;o<this.watchIntervals.length;o++)if(this.watchIntervals[o].watchID===t){r.cancel(n[o].interval),a=o;break}-1!==a&&this.watchIntervals.splice(a,1)}else i.reject("Unable to clear watch. No watch ID provided.");return i.promise}}}]),r.factory("$cordovaGlobalization",["$q",function(r){var e=!1,t="en",i="Sunday",n="";return{throwsError:e,preferredLanguage:t,localeName:n,firstDayOfWeek:i,getPreferredLanguage:function(){var e=r.defer();return this.throwsError?e.reject("There was an error getting the preferred language."):e.resolve(this.preferredLanguage),e.promise},getLocaleName:function(){var e=r.defer();return this.throwsError?e.reject("There was an error getting the locale name."):e.resolve(this.localeName),e.promise},getFirstDayOfWeek:function(){var e=r.defer();return this.throwsError?e.reject("There was an error getting the first day of week."):e.resolve(this.firstDayOfWeek),e.promise},dateToString:function(e,t){var i=r.defer();if(this.throwsError)i.reject("There was an error getting the string from the date.");else{var n="";e=e,t=t,i.resolve(n)}return i.promise},stringToDate:function(e,t){var i=r.defer();if(this.throwsError)i.reject("There was an error getting the date from the string.");else{var n="";e=e,t=t,i.resolve(n)}return i.promise},getDatePattern:function(e){var t=r.defer();if(this.throwsError)t.reject("There was an error getting the date pattern.");else{var i="";e=e,t.resolve(i)}return t.promise},getDateNames:function(e){var t=r.defer();if(this.throwsError)t.reject("There was an error getting the date names.");else{var i="";e=e,t.resolve(i)}return t.promise},isDayLightSavingsTime:function(e){var t=r.defer();if(this.throwsError)t.reject("There was an error getting if this is in daylight savings time mode.");else{var i="";e=e,t.resolve(i)}return t.promise},numberToString:function(e,t){var i=r.defer();if(this.throwsError)i.reject("There was an error convertng the number to a string.");else{var n="";e=e,t=t,i.resolve(n)}return i.promise},stringToNumber:function(e,t){var i=r.defer();if(this.throwsError)i.reject("There was an error convertng the string to a number.");else{var n="";t=t,i.resolve(n)}return i.promise},getNumberPattern:function(e){var t=r.defer();if(this.throwsError)t.reject("There was an error convertng the string to a number.");else{var i="";e=e,t.resolve(i)}return t.promise},getCurrencyPattern:function(e){var t=r.defer();if(this.throwsError)t.reject("There was an error convertng the string to a number.");else{var i="";e=e,t.resolve(i)}return t.promise}}}]),r.factory("$cordovaKeyboard",function(){var r=!1;return{hideAccessoryBar:function(){},close:function(){r=!1},show:function(){r=!0},disableScroll:function(){},isVisible:function(){return r}}}),r.factory("$cordovaNetwork",function(){var r="WiFi connection",e=!0;return{connectionType:r,isConnected:e,getNetwork:function(){return this.connectionType},isOnline:function(){return this.isConnected},isOffline:function(){return!this.isConnected}}}),r.factory("$cordovaSocialSharing",["$q",function(r){var e=!1,t="",i="",n="",a="",o="",s="",c=[],h=[],l=[];return{throwsError:e,message:t,image:i,link:n,number:a,subject:s,toAddresses:c,bccAddresses:h,socialService:o,attachments:l,shareViaTwitter:function(e,t,i){var n=r.defer();return this.throwsError?n.reject("There was an error sharing via Twitter."):(this.message=e,this.image=t,this.link=i,n.resolve()),n.promise},shareViaWhatsApp:function(e,t,i){var n=r.defer();return this.throwsError?n.reject("There was an error sharing via WhatsApp."):(this.message=e,this.image=t,this.link=i,n.resolve()),n.promise},shareViaFacebook:function(e,t,i){var n=r.defer();return this.throwsError?n.reject("There was an error sharing via Facebook."):(this.message=e,this.image=t,this.link=i,n.resolve()),n.promise},shareViaSMS:function(e,t){var i=r.defer();return this.throwsError?i.reject("There was an error sharing via SMS."):(this.message=e,this.number=t,i.resolve()),i.promise},shareViaEmail:function(e,t,i,n,a){var o=r.defer();return this.throwsError?o.reject("There was an error sharing via SMS."):(this.message=e,this.subject=t,this.toAddresses=i,this.bccAddressesc=n,this.attachments=a,o.resolve()),o.promise},canShareViaEmail:function(){var e=r.defer();return this.throwsError?e.reject(!1):e.resolve(!0),e.promise},canShareVia:function(e,t,i,n,a){var o=r.defer();return this.throwsError?o.reject("There was an error sharing via SMS."):(this.message=t,this.socialService=e,this.subject=i,this.attachments=n,this.link=a,o.resolve()),o.promise},shareVia:function(e,t,i,n,a){var o=r.defer();return this.throwsError?o.reject("There was an error sharing via SMS."):(this.socialService=e,this.message=t,this.subject=i,this.attachments=n,this.link=a,o.resolve()),o.promise},share:function(e,t,i,n){var a=r.defer();return this.throwsError?a.reject("There was an error sharing via SMS."):(this.message=e,this.subject=t,this.attachments=i,this.link=n,a.resolve()),a.promise}}}]),r.factory("$cordovaSplashscreen",function(){var r=!1;return{isVisible:r,hide:function(){return this.isVisible=!1,!0},show:function(){return this.isVisible=!0,!0}}}),r.factory("$cordovaStatusbar",function(){var r=!0,e=!0;return{isStatusBarVisible:r,canOverlayWebView:e,overlaysWebView:function(r){this.canOverlayWebView=r},style:function(r){return r},styleHex:function(r){return r},styleColor:function(r){return r},hide:function(){this.isStatusBarVisible=!1},show:function(){this.isStatusBarVisible=!0},isVisible:function(){return this.isStatusBarVisible}}}),r.factory("$cordovaVibration",["$timeout",function(r){var e=!1,t=null;return{vibrateTimer:t,isVibrating:e,vibrate:function(e){e>0&&(this.isVibrating=!0,self=this,this.vibrateTimer=e instanceof Array?r(function(){self.isVibrating=!1,self.vibrateTimer=null},e[0]):r(function(){self.isVibrating=!1,self.vibrateTimer=null},e))},vibrateWithPattern:function(){},cancelVibration:function(){null!==this.vibrateTimer&&this.isVibrating===!0&&(r.cancel(this.vibrateTimer),this.isVibrating=!1)}}}])}();