-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.min.js
1 lines (1 loc) · 15.5 KB
/
main.min.js
1
!function(t){function e(r){if(n[r])return n[r][i];var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o[i],o,o[i],e),o.loaded=!0,o[i]}var i="exports",n={};return e.modules=t,e.cache=n,e.p="",e(0)}([function(t,e,i){t.exports=i(7)},function(t,e,i){var n,r,o,s=function(t,e){return function(){return t.apply(e,arguments)}},c=[].slice;r=i(8).Plugin,o=i(2).XMLParser,e.Communicator=n=function(){"use strict";function t(){}var e,n,u;return n=null,u=null,t.get=function(t){return t&&(n=t),u||(u=new e(n))},t.destroy=function(){u=null},e=function(){function t(t){this.devices=s(this.devices,this),this.configuration=t,this.plugin=new r,this.pluginIsInstalled=this.plugin.pluginIsInstalled(),this.pluginProxy=this.plugin.el}return t.prototype.pluginIsInstalled=null,t.prototype.invoke=function(){var t,e,i;if(i=arguments[0],t=2<=arguments.length?c.call(arguments,1):[],e=this.pluginProxy[i],null!=e&&"function"==typeof e)return e.apply(this.pluginProxy,t);throw new Error("'"+i+"' function does not exist!")},t.prototype.write=function(t,e){return this.pluginProxy.hasOwnProperty(t)?(this.pluginProxy[t]=e,!0):!1},t.prototype.read=function(t){return this.pluginProxy.hasOwnProperty(t)?this.pluginProxy[t]:!1},t.prototype.busy=function(t){return null!=t&&(this._busy=t),this._busy||!1},t.prototype.isLocked=function(){return this.pluginProxy.Locked},t.prototype.unlock=function(t){var e,i=this;return this.isLocked()?(e=!1,_(t).map(function(t,n){return e||(e=i.invoke("Unlock",n,t))}),e):void 0},t.prototype.devices=function(){var t,e=this;return this.busy()?void 0:(this.busy(!0),this.unlock(),t=Q.defer(),t.promise["finally"](function(){return e.busy(!1)}),this._findDevices(t),t.promise)},t.prototype._findDevices=function(t){return this.invoke("StartFindDevices"),this._loopUntilFinishedFindingDevices(t)},t.prototype._loopUntilFinishedFindingDevices=function(t){var e=this;return this.invoke("FinishFindDevices")?t.resolve(this._parseDeviceXml()):setTimeout(function(){return e._loopUntilFinishedFindingDevices(t)},100)},t.prototype._parseDeviceXml=function(){var t,e;return t=i(5).Device,e=o.parse(this.invoke("DevicesXmlString")),_(e.getElementsByTagName("Device")).map(function(e){var i,n;return i=e.getAttribute("DisplayName"),n=parseInt(e.getAttribute("Number"),10),new t(n,i)})},t}(),t}.call(this)},function(t,e){var i;e.XMLParser=i=function(){"use strict";function t(){}return t.parse=function(t){if(null==this._parser&&this._getParser(),"string"!=typeof t)throw new Error("XML is not a string!");return this._parser(t)},t._getParser=function(){return this._parser=function(){if(this._domParserAvailable())return this._domParser;if(this._xmlDomAvailable())return this._xmlDomParser;throw new Error("No XML parser found, can't parse XML")}.call(this)},t._domParserAvailable=function(){return null!=window.DOMParser},t._xmlDomAvailable=function(){return null!=window.ActiveXObject&&("function"==typeof window.ActiveXObject?window.ActiveXObject("Microsoft.XMLDOM"):void 0)},t._domParser=function(t){return(new window.DOMParser).parseFromString(t,"text/xml")},t._xmlDomParser=function(t){var e;return e=new window.ActiveXObject("Microsoft.XMLDOM"),e.async="false",e.loadXML(t)},t}()},function(t,e,i){var n,r,o,s,c,u,a={}.hasOwnProperty,p=function(t,e){function i(){this.constructor=t}for(var n in e)a.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};r=i(1).Communicator,n=i(6).Accessor,o=i(10).FitWorkoutFactory,c=i(12).TcxWorkoutFactory,e.Reader=s=function(t){function e(){return u=e.__super__.constructor.apply(this,arguments)}return p(e,t),e.prototype.ACTION="Read",e.prototype.perform=function(){return this.clearDeviceXmlBuffers(),e.__super__.perform.apply(this,arguments),this.deferred.promise},e.prototype.clearDeviceXmlBuffers=function(){return this.communicator.write("TcdXml",""),this.communicator.write("DirectoryListingXml","")},e.prototype._onFinished=function(t){return t.notify({percent:100}),t.resolve(this.handleFinishedReading())},e.prototype.handleFinishedReading=function(){switch(this.pluginMethod){case"FITDirectory":return this.handleReadFITDirectory();case"FitnessDirectory":return this.handleReadFitnessDirectory();case"FitnessDetail":return this.handleReadFitnessDetail()}},e.prototype.handleReadFITDirectory=function(){var t;return t=this.communicator.read("DirectoryListingXml"),new o(this.device).produce(t)},e.prototype.handleReadFitnessDirectory=function(){var t;return t=this.communicator.read("TcdXml"),new c(this.device).produce(t)},e.prototype.handleReadFitnessDetail=function(){return this.communicator.read("TcdXml")},e}(n)},function(t,e){var i;e.WorkoutFactory=i=function(){"use strict";function t(t){this.device=t}return t.prototype.FITFILE_TYPES={activities:4,goals:11,locations:8,monitoring:9,profiles:2,schedules:7,sports:3,totals:10},t.prototype._parseISODateString=function(t){var e;return this.REPLACE_DATE_DASHES_REGEX||(this.REPLACE_DATE_DASHES_REGEX=/-/g),this.REPLACE_DATE_TZ_REGEX||(this.REPLACE_DATE_TZ_REGEX=/[TZ]/g),e=t.replace(this.REPLACE_DATE_DASHES_REGEX,"/").replace(this.REPLACE_DATE_TZ_REGEX," "),new Date(e)},t}()},function(t,e,i){var n,r,o,s;n=i(1).Communicator,o=i(3).Reader,s=i(2).XMLParser,e.Device=r=function(){"use strict";function t(t,e){this.number=t,this.name=e,this.communicator=n.get(),this.deviceDescriptionXml=this._getDeviceDescriptionXml(),this._setDeviceInfo(),this._setDeviceCapabilities(),this._createDeviceAccessors()}return t.prototype.ACTIONS={Activities:["FitnessHistory","FitnessDirectory"],Workouts:["FitnessWorkouts","FitnessData"],Courses:["FitnessCourses","FitnessData"],Goals:["FitnessActivityGoals","FitnessData"],Profile:["FitnessUserProfile","FitnessData"],FITActivities:["FIT_TYPE_4","FITDirectory"]},t.prototype.activities=function(){return this.canReadFITActivities?this.readFITActivities():this.readActivities()},t.prototype._setDeviceCapabilities=function(){return _.each(this.ACTIONS,function(t,e){return this["canRead"+e]=this._canXY("Output",t[0]),this["canWrite"+e]=this._canXY("Input",t[0])},this)},t.prototype._createDeviceAccessors=function(){return _.each(this.ACTIONS,function(t,e){return this["read"+e]=this._reader(e,t[0],t[1]),this["write"+e]=this._writer()},this)},t.prototype._reader=function(t,e,i){return function(){var n;if(!this["canRead"+t])throw new Error("read"+t+" is not supported on this device");return n=new o(this,e,i),n.perform()}},t.prototype._writer=function(){return function(){throw new Error("Not implemented")}},t.prototype._canXY=function(t,e){var i,n,r;return i=null!=(n=this._getDataTypeNodeForDataTypeName(e))?null!=(r=n.getElementsByTagName("File")[0])?r.getElementsByTagName("TransferDirection")[0].textContent:void 0:void 0,null!=i&&new RegExp(t).test(i)},t.prototype._getDataTypeNodeForDataTypeName=function(t){var e;return e=this._getDeviceDataTypesXml(),e?_.filter(e,function(e){return t===e.getElementsByTagName("Name")[0].textContent})[0]:void 0},t.prototype._getDeviceDataTypesXml=function(){var t,e;return this._deviceDataTypes||(this._deviceDataTypes=null!=(t=this.deviceDescriptionXml)?null!=(e=t.getElementsByTagName("MassStorageMode")[0])?e.getElementsByTagName("DataType"):void 0:void 0)},t.prototype._setDeviceInfo=function(){return this.id=this._deviceId(),this.name=this._deviceDisplayName(),this.partNumber=this._devicePartNumber(),this.softwareVersion=this._softwareVersion()},t.prototype._getDeviceDescriptionXml=function(){var t;return t=this.communicator.invoke("DeviceDescription",this.number),s.parse(t)},t.prototype._deviceId=function(){return this.deviceDescriptionXml.getElementsByTagName("Id")[0].textContent},t.prototype._deviceDisplayName=function(){var t;return t=this.deviceDescriptionXml.getElementsByTagName("Model")[0],t.getElementsByTagName("DisplayName").length?t.getElementsByTagName("DisplayName")[0].textContent:t.getElementsByTagName("Description")[0].textContent},t.prototype._devicePartNumber=function(){return this.deviceDescriptionXml.getElementsByTagName("Model")[0].getElementsByTagName("PartNumber")[0].textContent},t.prototype._softwareVersion=function(){return this.deviceDescriptionXml.getElementsByTagName("Model")[0].getElementsByTagName("SoftwareVersion")[0].textContent},t}()},function(t,e,i){var n,r,o,s=function(t,e){return function(){return t.apply(e,arguments)}};r=i(1).Communicator,o=i(2).XMLParser,e.Accessor=n=function(){"use strict";function t(t,e,i){this.device=t,this.dataType=e,this.pluginMethod=i,this._checkFinished=s(this._checkFinished,this),this.communicator=r.get(),this.pluginAction=""+this.ACTION+this.pluginMethod}return t.prototype.PERCENT_REGEX=/^[0-9]+%/,t.prototype.STATUS_CODES={idle:0,working:1,waiting:2,finished:3},t.prototype.perform=function(){var t,e;if(this.deferred=Q.defer(),this.communicator.busy())throw new Error("Plugin is busy");return e=Array.prototype.slice.call(arguments,0),t=[this._startPluginAction(),this.device.number,this.dataType].concat(e),this.communicator.invoke.apply(this.communicator,t),this._checkFinished(this.deferred),this.deferred.promise},t.prototype._startPluginAction=function(){return"Start"+this.pluginAction},t.prototype._finishPluginAction=function(){return"Finish"+this.pluginAction},t.prototype._checkFinished=function(t){switch(this.communicator.invoke(this._finishPluginAction())){case this.STATUS_CODES.working:return this._onWorking(t);case this.STATUS_CODES.finished:return this._onFinished(t);case this.STATUS_CODES.waiting:return this._onWaiting(t);case this.STATUS_CODES.idle:return this._onIdle(t);default:throw new Error("Unexpected Velociraptor.")}},t.prototype._onWorking=function(t){var e=this;return t.notify(this._progress()),setTimeout(function(){return e._checkFinished(t)},100)},t.prototype._onWaiting=function(t){var e=this;return setTimeout(function(){return e._checkFinished(t)},150)},t.prototype._onIdle=function(t){return t.reject()},t.prototype._onFinished=function(){throw new Error("Abstract method: Not Implemented")},t.prototype._progress=function(){var t,e,i,n=this;return t={content:[],percent:0},e=this._getProgressXml().getElementsByTagName("ProgressWidget")[0],t.message=null!=(i=e.getElementsByTagName("Title")[0])?i.textContent:void 0,_.each(e.getElementsByTagName("Text"),function(e){return e.textContent.match(n.PERCENT_REGEX)?t.percent=parseInt(e.textContent,10):t.content.push(e.textContent),e}),t},t.prototype._getProgressXml=function(){var t;return t=this.communicator.read("ProgressXml"),o.parse(t)},t}()},function(t,e,i){var n,r;n=i(1).Communicator,window.Garmin=r=function(){"use strict";function t(t){null==t&&(t={}),this.configuration=_(t).defaults({unlockCodes:this.mergeUnlockCodes(t.unlockCodes),testMode:!1}),this.communicator=n.get(this.configuration),this.unlock()}return t.prototype.DEFAULT_UNLOCK_CODES={"file:///":"cb1492ae040612408d87cc53e3f7ff3c","http://localhost":"45517b532362fc3149e4211ade14c9b2","http://127.0.0.1":"40cd4860f7988c53b15b8491693de133"},t.prototype.mergeUnlockCodes=function(t){return null==t&&(t={}),_(this.DEFAULT_UNLOCK_CODES).defaults(t)},t.prototype.isInstalled=function(){return this.isInstalled=this.communicator.pluginIsInstalled||this.configuration.testMode},t.prototype.unlock=function(){return this.configuration.testMode?void 0:this.communicator.unlock(this.configuration.unlockCodes)},t.prototype.devices=function(){return this.communicator.devices()},t}()},function(t,e){var i;e.Plugin=i=function(){"use strict";function t(){this.el||(this.el=this._createPluginEl())}return t.prototype.softwareVersion=function(){return this.el.getPluginVersion()},t.prototype._createPluginEl=function(){return this._smellsLikeIE()?this._createIEPlugin():this._createVanillaPlugin()},t.prototype.pluginIsInstalled=function(){return null!=this.el.Unlock?!0:!1},t.prototype._smellsLikeIE=function(){return null!=window.ActiveXObject},t.prototype._createVanillaPlugin=function(){var t,e;return e=document.createElement("div"),e.style.width=0,e.style.height=0,t=document.createElement("object"),t.id="GarminNetscapePlugin",t.height=0,t.width=0,t.setAttribute("type","application/vnd-garmin.mygarmin"),e.appendChild(t),document.body.appendChild(e),t},t.prototype._createIEPlugin=function(){var t;return t=document.createElement("object"),t.id="GarminActiveXControl",t.style.width=0,t.style.height=0,t.style.visibility="hidden",t.height=0,t.width=0,t.setAttribute("classid","CLSID:099B5A62-DE20-48C6-BF9E-290A9D1D8CB5"),document.body.appendChild(t),t},t}()},function(t,e,i){var n,r;n=i(1).Communicator,e.FitWorkout=r=function(){"use strict";function t(t,e,i,r,o){this.id=e,this.device=t,this.type=i,this.date=r,this.path=o,this.communicator=n.get()}return t.prototype.getData=function(){var t;return t=Q.defer(),t.resolve(this._getBinaryFile()),t.promise},t.prototype._getBinaryFile=function(){return this.communicator.invoke("GetBinaryFile",this.device.number,this.path,!1)},t}()},function(t,e,i){var n,r,o,s,c,u=function(t,e){return function(){return t.apply(e,arguments)}},a={}.hasOwnProperty,p=function(t,e){function i(){this.constructor=t}for(var n in e)a.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};s=i(2).XMLParser,o=i(4).WorkoutFactory,n=i(9).FitWorkout,e.FitWorkoutFactory=r=function(t){function e(){return this._filterFitFileXmlType=u(this._filterFitFileXmlType,this),this._objectForFileNode=u(this._objectForFileNode,this),c=e.__super__.constructor.apply(this,arguments)}return p(e,t),e.prototype.produce=function(t){var e;return e=s.parse(t),_.chain(e.getElementsByTagName("File")).filter(this._filterFitFileXmlType).map(this._objectForFileNode).value()},e.prototype._objectForFileNode=function(t){var e,i,r,o;return i=this._getIdForFileNode(t),o=this._getFileTypeForFileNode(t),e=this._getCreationTimeFileNode(t),r=this._getPathForFileNode(t),new n(this.device,i,o,e,r)},e.prototype._getCreationTimeFileNode=function(t){var e;return e=t.getElementsByTagName("CreationTime")[0].textContent,this._parseISODateString(e)},e.prototype._filterFitFileXmlType=function(t){return this._getFileTypeForFileNode(t)===this.FITFILE_TYPES.activities},e.prototype._getIdForFileNode=function(t){return parseInt(t.getElementsByTagName("FitId")[0].getElementsByTagName("Id")[0].textContent,10)},e.prototype._getFileTypeForFileNode=function(t){return parseInt(t.getElementsByTagName("FitId")[0].getElementsByTagName("FileType")[0].textContent,10)},e.prototype._getPathForFileNode=function(t){return t.getAttribute("Path")},e}(o)},function(t,e,i){var n;e.TcxWorkout=n=function(){"use strict";function t(t,e,n){var r;r=i(3).Reader,this.device=t,this.id=e,this.date=n,this.detailReader=new r(this.device,"FitnessHistory","FitnessDetail")}return t.prototype.getData=function(){return this.detailReader.perform(this.id)},t}()},function(t,e,i){var n,r,o,s,c,u=function(t,e){return function(){return t.apply(e,arguments)}},a={}.hasOwnProperty,p=function(t,e){function i(){this.constructor=t}for(var n in e)a.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};s=i(2).XMLParser,o=i(4).WorkoutFactory,n=i(11).TcxWorkout,e.TcxWorkoutFactory=r=function(t){function e(){return this._getFirstLapStartTime=u(this._getFirstLapStartTime,this),this._objectForActivityNode=u(this._objectForActivityNode,this),c=e.__super__.constructor.apply(this,arguments)}return p(e,t),e.prototype.produce=function(t){var e;return e=s.parse(t),_.chain(e.getElementsByTagName("Activity")).map(this._objectForActivityNode).value()},e.prototype._objectForActivityNode=function(t){var e,i;return i=this._getIdForActivityNode(t),e=this._getFirstLapStartTime(t),new n(this.device,i,e)},e.prototype._getFirstLapStartTime=function(t){var e;return e=t.getElementsByTagName("Lap")[0].getAttribute("StartTime"),this._parseISODateString(e)},e.prototype._getIdForActivityNode=function(t){return t.getElementsByTagName("Id")[0].textContent},e}(o)}]);