diff --git a/dist/extensions/route.min.js b/dist/extensions/route.min.js index 8e9aeeb..4c7e319 100644 --- a/dist/extensions/route.min.js +++ b/dist/extensions/route.min.js @@ -1 +1 @@ -(function(e){function i(e){return e instanceof Array?{latitude:e[0],longitude:e[1]}:e}var t,n,r={type:"shortest",transportMode:"car",options:"",trafficMode:"default",width:4,color:"#ff6347",marker:{text:"#",textColor:"#fff"}};n=function(n,s,o){var u,a,f;t=t||nokia.maps,n=i(n),s=i(s),o=e.extend({},r,o),f=function(n,r,i){var s,u,a,f,l,c={},h;i==="finished"?(s=n.getRoutes(),f=s[0],a=new t.map.Polyline(f&&f.shape,{pen:new t.util.Pen({lineWidth:o.width,strokeColor:o.color})}),u=new t.map.Container,u.objects.add(a),e.each(f.waypoints,e.proxy(function(t,n){var r=e.extend({},o.marker);o.marker.text==="#"&&(r.text=t+1),this.marker(n.originalPosition,r)},this)),this.map.objects.add(u),l=f.legs&&f.legs.length&&f.legs[0],c.time=l.travelTime,c.length=l.length,c.maneuvers=e.map(l.maneuvers,function(e){return{street:e.streetName,length:e.length,route:e.routeName}}),typeof o.onroute=="function"&&o.onroute.call(this.element,c),h=e.Event("jhere.route",{route:c,target:this.element}),e(this.element).trigger(h)):i==="failed"&&e.error("Failed to calcolate route")},u=new t.routing.Manager,u.addObserver("state",e.proxy(f,this)),a=new t.routing.WaypointParameterList,a.addCoordinate(n),a.addCoordinate(s),o.transportModes=[o.transportMode],u.calculateRoute(a,[o])},e.jHERE.extend("route",n)})(jQuery); \ No newline at end of file +(function(e){function i(e){return e instanceof Array?{latitude:e[0],longitude:e[1]}:e}var t,n,r={type:"shortest",transportMode:"car",options:"",trafficMode:"default",width:4,color:"#ff6347",marker:{text:"#",textColor:"#fff"}};n=function(n,s,o){var u,a,f,l;t=t||nokia.maps,n=i(n),s=i(s),o=e.extend({},r,o),f=function(n,r,i){var s,u,a,f,l,c={},h;i==="finished"?(s=n.getRoutes(),f=s[0],a=new t.map.Polyline(f&&f.shape,{pen:new t.util.Pen({lineWidth:o.width,strokeColor:o.color})}),u=new t.map.Container,u.objects.add(a),e.each(f.waypoints,e.proxy(function(t,n){var r=e.extend({},o.marker);o.marker.text==="#"&&(r.text=t+1),this.marker(n.originalPosition,r)},this)),this.map.objects.add(u),l=f.legs&&f.legs.length&&f.legs[0],c.time=l.travelTime,c.length=l.length,c.maneuvers=e.map(l.maneuvers,function(e){return{street:e.streetName,length:e.length,route:e.routeName}}),typeof o.onroute=="function"&&o.onroute.call(this.element,c),h=e.Event("jhere.route",{route:c,target:this.element}),e(this.element).trigger(h)):i==="failed"&&e.error("Failed to calcolate route")},u=new t.routing.Manager,u.addObserver("state",e.proxy(f,this)),a=new t.routing.WaypointParameterList,a.addCoordinate(n),a.addCoordinate(s),l={transportModes:[o.transportMode],type:o.type,options:o.options,trafficMode:o.trafficMode},u.calculateRoute(a,[l])},e.jHERE.extend("route",n)})(jQuery); \ No newline at end of file diff --git a/dist/jhere.min.js b/dist/jhere.min.js index 9a8cab1..0a87ab7 100644 --- a/dist/jhere.min.js +++ b/dist/jhere.min.js @@ -1 +1 @@ -(function(e,t,n){function w(t,n){this.element=t,this.options=e.extend({},i,n),this._defaults=i,this._plugin=r,this.init()}function E(){var e=this.map||{};return{center:e.center,zoom:e.zoomLevel,bbox:e.getViewBounds&&e.getViewBounds(),type:this.mtype}}function S(e,t){var n=new o.kml.Manager;n.addObserver("state",l(function(e){e.state==="finished"&&t.call(this,e)},this)),n.parseKML(e)}function x(t){var n=t.target,r=this.map.pixelToGeo(t.displayX,t.displayY);if(n!==this.map)return;t.type="map"+t.type,e(this.element).trigger(N(t,r))}function T(e){var t=e.target,n=t[e.type];C(n)&&n.call(this.element,N(e,t.coordinate))}function N(t,n){return e.Event(t.type,{originalEvent:t,geo:{latitude:n.latitude,longitude:n.longitude},target:t.target})}function C(e){return typeof e=="function"}function k(){return!!e().on}var r="jHERE",i,s,o,u,a,f,l=e.proxy,c,h="mouse",p="click",d="drag",v="touch",m="start",g="end",y="move",b=[p,"dbl"+p,h+"up",h+"down",h+y,h+"over",h+"out",h+"enter",h+"leave","longpress",d+m,d,d+g,"resize",v+m,v+g,v+y];i={appId:"69Dgg78qt4obQKxVbRA8",authToken:"Nz7ilIB_v1CRwPXxgPdvuA",zoom:12,center:[52.49,13.37],enable:["behavior","zoombar","scalebar","typeselector"],type:"map",marker:{text:"",textColor:"#333333",fill:"#ff6347",stroke:"#333333",shape:"balloon",icon:undefined},bubble:{content:"",closable:!0,onclose:e.noop},heatmap:{max:20,opacity:.8,coarseness:2}},e[r]=c={},s=w.prototype,c.defaultCredentials=function(e,t){f={appId:e,authenticationToken:t},a.load().is.done(function(){o.util.ApplicationContext.set(f)})},s.init=function(){a.load().is.done(l(this.makemap,this))},s.makemap=function(){var t=this,n=t.options,i=u.component,s=[],a=l(x,t),c={};i.Positioning=o.positioning.component.Positioning,f=f||{appId:n.appId,authenticationToken:n.authToken},o.util.ApplicationContext.set(f),e.data(t.element,r,!0),e.each(i,l(function(n,r){n=n.toLowerCase();if(~e.inArray(n,t.options.enable))return C(r)&&s.push(new r)||e.error("invalid: "+n)},t)),t.map=new u.Display(t.element,{zoomLevel:n.zoom,center:n.center,components:s}),t.type(n.type),t._mc=new u.Container,t.map.objects.add(t._mc),e.each(b,function(e,t){c[t]=[a,!1,null]}),t.map.addListeners(c)},s.center=function(e){this.map.setCenter(e)},s.zoom=function(e){this.map.set("zoomLevel",e)},s.type=function(e){var t=this.map,n={map:t.NORMAL,satellite:t.SATELLITE,smart:t.SMARTMAP,terrain:t.TERRAIN,pt:t.SMART_PT,community:t.NORMAL_COMMUNITY,satcommunity:t.SATELLITE_COMMUNITY,traffic:t.TRAFFIC};e in n?(this.mtype=e,e=n[e]):(this.mtype="map",e=n.map),t.set("baseMapType",e)},s.marker=function(t,n){var r={},s=l(T,this),o=this._mc,a="Marker";e.each(b,function(e,t){r[t]=[s,!1,null]}),n=e.extend({},i.marker,n),n.textPen=n.textPen||{strokeColor:n.textColor},n.pen=n.pen||{strokeColor:n.stroke},n.brush=n.brush||{color:n.fill},n.eventListener=r,n.icon||(a="Standard"+a),o.objects.add(new u[a](t,n))},s.nomarkers=function(){this._mc.objects.clear()},s.bubble=function(t,n){var r,s=this.map;n=e.extend({},i.bubble,n),n.content.jquery&&(n.content.css("white-space","normal"),n.content=e("
").append(n.content.clone()).html()),r=s.getComponentById("InfoBubbles")||s.addComponent(new u.component.InfoBubbles),r.openBubble(n.content,{latitude:t.latitude||t[0],longitude:t.longitude||t[1]},n.onclose,!n.closable)},s.nobubbles=function(){var e;return(e=this.map.getComponentById("InfoBubbles"))&&e.closeAll()},s.kml=function(e,t,n){C(t)&&(n=t,t=!1),S.call(this,e,l(function(e){var r=this.map,i=new o.kml.component.KMLResultSet(e.kmlDocument,r);i.addObserver("state",l(function(e){var i,s;e.state==="finished"&&(t&&(i=e.container.objects.get(0),s=i.getBoundingBox(),s&&r.zoomTo(s)),C(n)&&n.call(this,e))},this)),r.objects.add(i.create())},this))},s.heatmap=function(t,n,r){var s;n=n||"value",n.match(/^density|value$/)||(n="value"),r=r||{},r.type=n,r=e.extend({},i.heatmap,r),s=new o.heatmap.Overlay(r),s.addData(t),this.map.overlays.add(s)},s.originalMap=function(e){e.call(this.element,this.map,o)},s.destroy=function(){this.map.destroy(),e.removeData(this.element),e(this.element).empty()},a={},a.is=!1,a.load=function(){var t,r,i;return a.is&&a.is.state().match(/pending|resolved/)?this:(a.is=e.Deferred(),i=function(){o=nokia.maps,o.Features.load({map:"auto",ui:"auto",search:"auto",routing:"auto",positioning:"auto",behavior:"auto",kml:"auto",heatmap:"auto"},function(){u=o.map,a.is.resolve()})},t=n.getElementsByTagName("head")[0],r=n.createElement("script"),r.src="http://api.maps.nokia.com/2.2.3/jsl.js",r.type="text/javascript",r.charset="utf-8",r.onreadystatechange=function(){r.readyState.match(/loaded|complete/)&&i()},r.onload=i,t.appendChild(r),this)},c._JSLALoader=a,c.extend=function(e,t){typeof e=="string"&&C(t)&&(s[e]=t)},e.fn[r]=function(t){var n=arguments,i="plg_"+r,s;return k()||e.error(r+" requires Zepto or jQuery >= 1.7"),!t&&(s=e.data(this[0],i))?E.call(s):this.each(function(){var o;s=e.data(this,i),s?(typeof t!="string"&&e.error(r+" already initialized, expected method."),o=t,n=Array.prototype.slice.call(n,1),C(s[o])||e.error(r+": "+o+" does not exist"),a.load().is.done(function(){s[o].apply(s,n)})):(s=new w(this,t),e.data(this,i,s))})}})(jQuery,window,document); \ No newline at end of file +(function(e,t,n){function x(t,n){this.element=t,this.options=e.extend({},i,n),this.init()}function T(){var e=this.map||{};return{center:e.center,zoom:e.zoomLevel,bbox:e.getViewBounds&&e.getViewBounds(),type:this.mtype}}function N(e,t){var n=new u.kml.Manager;n.addObserver("state",c(function(e){e.state==="finished"&&t.call(this,e)},this)),n.parseKML(e)}function C(t){var n=t.target,r=this.map.pixelToGeo(t.displayX,t.displayY);if(n!==this.map)return;t.type="map"+t.type,e(this.element).trigger(L(t,r))}function k(e){var t=e.target,n=t[e.type];A(n)&&n.call(this.element,L(e,t.coordinate))}function L(t,n){return e.Event(t.type,{originalEvent:t,geo:{latitude:n.latitude,longitude:n.longitude},target:t.target})}function A(e){return typeof e=="function"}function O(){return!!e().on}var r="jHERE",i,s,o,u,a,f,l,c=e.proxy,h,p="mouse",d="click",v="drag",m="touch",g="start",y="end",b="move",w="appId",E="authenticationToken",S=[d,"dbl"+d,p+"up",p+"down",p+b,p+"over",p+"out",p+"enter",p+"leave","longpress",v+g,v,v+y,"resize",m+g,m+y,m+b];i={appId:"69Dgg78qt4obQKxVbRA8",authToken:"Nz7ilIB_v1CRwPXxgPdvuA",zoom:12,center:[52.49,13.37],enable:["behavior","zoombar","scalebar","typeselector"],type:"map",marker:{text:"",textColor:"#333333",fill:"#ff6347",stroke:"#333333",shape:"balloon",icon:undefined},bubble:{content:"",closable:!0,onclose:e.noop},heatmap:{max:20,opacity:.8,coarseness:2}},e[r]=h={},s=x.prototype,h.defaultCredentials=function(e,t){l={id:e,token:t},f.load().is.done(function(){o.Settings.set(w,e),o.Settings.set(E,t)})},s.init=function(){f.load().is.done(c(this.makemap,this))},s.makemap=function(){var t=this,n=t.options,i=a.component,s=[],f=c(C,t),h={};i.Positioning=u.positioning.component.Positioning,l=l||{id:n.appId,token:n.authToken},o.Settings.set(w,l.id),o.Settings.set(E,l.token),e.data(t.element,r,!0),e.each(i,c(function(n,r){n=n.toLowerCase();if(~e.inArray(n,t.options.enable))return A(r)&&s.push(new r)||e.error("invalid: "+n)},t)),t.map=new a.Display(t.element,{zoomLevel:n.zoom,center:n.center,components:s}),t.type(n.type),t._mc=new a.Container,t.map.objects.add(t._mc),e.each(S,function(e,t){h[t]=[f,!1,null]}),t.map.addListeners(h)},s.center=function(e){this.map.setCenter(e)},s.zoom=function(e){this.map.set("zoomLevel",e)},s.type=function(e){var t=this.map,n={map:t.NORMAL,satellite:t.SATELLITE,smart:t.SMARTMAP,terrain:t.TERRAIN,pt:t.SMART_PT,community:t.NORMAL_COMMUNITY,satcommunity:t.SATELLITE_COMMUNITY,traffic:t.TRAFFIC};e in n?(this.mtype=e,e=n[e]):(this.mtype="map",e=n.map),t.set("baseMapType",e)},s.marker=function(t,n){var r={},s=c(k,this),o=this._mc,u="Marker";e.each(S,function(e,t){r[t]=[s,!1,null]}),n=e.extend({},i.marker,n),n.textPen=n.textPen||{strokeColor:n.textColor},n.pen=n.pen||{strokeColor:n.stroke},n.brush=n.brush||{color:n.fill},n.eventListener=r,n.icon||(u="Standard"+u),o.objects.add(new a[u](t,n))},s.nomarkers=function(){this._mc.objects.clear()},s.bubble=function(t,n){var r,s=this.map;n=e.extend({},i.bubble,n),n.content.jquery&&(n.content.css("white-space","normal"),n.content=e("
").append(n.content.clone()).html()),r=s.getComponentById("InfoBubbles")||s.addComponent(new a.component.InfoBubbles),r.openBubble(n.content,{latitude:t.latitude||t[0],longitude:t.longitude||t[1]},n.onclose,!n.closable)},s.nobubbles=function(){var e;return(e=this.map.getComponentById("InfoBubbles"))&&e.closeAll()},s.kml=function(e,t,n){A(t)&&(n=t,t=!1),N.call(this,e,c(function(e){var r=this.map,i=new u.kml.component.KMLResultSet(e.kmlDocument,r);i.addObserver("state",c(function(e){var i,s;e.state==="finished"&&(t&&(i=e.container.objects.get(0),s=i.getBoundingBox(),s&&r.zoomTo(s)),A(n)&&n.call(this,e))},this)),r.objects.add(i.create())},this))},s.heatmap=function(t,n,r){var s;n=n||"value",n.match(/^density|value$/)||(n="value"),r=r||{},r.type=n,r=e.extend({},i.heatmap,r),s=new u.heatmap.Overlay(r),s.addData(t),this.map.overlays.add(s)},s.originalMap=function(e){e.call(this.element,this.map,u)},s.destroy=function(){this.map.destroy(),e.removeData(this.element),e(this.element).empty()},f={},f.is=!1,f.load=function(){var t,r,i;return f.is&&f.is.state().match(/pending|resolved/)?this:(f.is=e.Deferred(),i=function(){o=nokia,u=o.maps,o.Features.load({map:"auto",ui:"auto",search:"auto",routing:"auto",positioning:"auto",behavior:"auto",kml:"auto",heatmap:"auto"},function(){a=u.map,f.is.resolve()})},t=n.getElementsByTagName("head")[0],r=n.createElement("script"),r.src="http://api.maps.nokia.com/2.2.4/jsl.js",r.type="text/javascript",r.charset="utf-8",r.onreadystatechange=function(){r.readyState.match(/loaded|complete/)&&i()},r.onload=i,t.appendChild(r),this)},h._JSLALoader=f,h.extend=function(e,t){typeof e=="string"&&A(t)&&(s[e]=t)},e.fn[r]=function(t){var n=arguments,i="plg_"+r,s;return O()||e.error(r+" requires Zepto or jQuery >= 1.7"),!t&&(s=e.data(this[0],i))?T.call(s):this.each(function(){var o;s=e.data(this,i),s?(typeof t!="string"&&e.error(r+" already initialized, expected method."),o=t,n=Array.prototype.slice.call(n,1),A(s[o])||e.error(r+": "+o+" does not exist"),f.load().is.done(function(){s[o].apply(s,n)})):(s=new x(this,t),e.data(this,i,s))})}})(jQuery,window,document); \ No newline at end of file diff --git a/dist/tire.adapter.min.js b/dist/tire.adapter.min.js index aa9bf90..ef4168b 100644 --- a/dist/tire.adapter.min.js +++ b/dist/tire.adapter.min.js @@ -1 +1 @@ -(function(e){function t(){e.each(this.queue,function(e,t){typeof t=="function"&&t.call(null)})}function u(e){return e._zid||(e._zid=o++)}e.error=function(e){throw new Error(e)},e.Deferred=function(){if(!(this instanceof e.Deferred))return new e.Deferred;this.queue=[],this._state="pending"};var n=e.Deferred.prototype,r,i,s;n.resolve=function(){this._state="resolved",t.call(this)},n.state=function(){return this._state},n.done=function(e){if(this._state==="pending"){this.queue.push(e);return}e.call(null)},r=function(){this.store={},this.counter=0},i=r.prototype,i.data=function(e,t,n){if(!n)return this.store[e.__data]&&this.store[e.__data][t];e.__data||(e.__data="cache"+this.counter++),this.store[e.__data]=this.store[e.__data]||{},this.store[e.__data][t]=n},i.removeData=function(e,t){if(t){this.store[e.__data][t]=null;return}this.store[e.__data]=null},s=new r,e.data=function(){return s.data.apply(s,arguments)},e.removeData=function(){return s.removeData.apply(s,arguments)};var o=1;e.proxy=function(t,n){if(e.isFunction(t)){var r=function(){return t.apply(n,arguments)};return r._zid=u(t),r}if(typeof n=="string")return e.proxy(t[n],t);throw new TypeError("expected function")},e.inArray=function(e,t,n){return[].indexOf.call(t,e,n)},e.Event=function(t,n){typeof t!="string"&&(n=t,t=n.type);var r=document.createEvent((t.match(/click|mouse/)?"Mouse":"")+"Events"),i=!0;return n&&(e.each(n,function(e,t,n,s){s=e==="bubbles"?i=!!t:r[e]=t}),r.initEvent(t,i,!0,null,null,null,null,null,null,null,null,null,null,null,null),r.isDefaultPrevented=function(){return this.defaultPrevented}),r},window.jQuery=e})(tire); \ No newline at end of file +(function(e){function t(){e.each(this.queue,function(e,t){typeof t=="function"&&t.call(null)})}function u(e){return e._zid||(e._zid=o++)}e.error=function(e){throw new Error(e)},e.Deferred=function(){if(!(this instanceof e.Deferred))return new e.Deferred;this.queue=[],this._state="pending"};var n=e.Deferred.prototype,r,i,s;n.resolve=function(){this._state="resolved",t.call(this)},n.state=function(){return this._state},n.done=function(e){if(this._state==="pending"){this.queue.push(e);return}e.call(null)},r=function(){this.store={},this.counter=0},i=r.prototype,i.data=function(e,t,n){if(!n)return this.store[e.__data]&&this.store[e.__data][t];e.__data||(e.__data="cache"+this.counter++),this.store[e.__data]=this.store[e.__data]||{},this.store[e.__data][t]=n},i.removeData=function(e,t){if(t){this.store[e.__data][t]=null;return}this.store[e.__data]=null},s=new r,e.data=function(){return s.data.apply(s,arguments)},e.removeData=function(){return s.removeData.apply(s,arguments)};var o=1;e.proxy=function(t,n){if(e.isFunction(t)){var r=function(){return t.apply(n,arguments)};return r._zid=u(t),r}if(typeof n=="string")return e.proxy(t[n],t);throw new TypeError("expected function")},e.inArray=function(e,t,n){return[].indexOf.call(t,e,n)},e.Event=function(t,n){typeof t!="string"&&(n=t,t=n.type);var r=document.createEvent((t.match(/click|mouse/)?"Mouse":"")+"Events"),i=!0;return n&&(e.each(n,function(e,t,n,s){s=e==="bubbles"?i=!!t:r[e]=t}),r.xdata=n,r.initEvent(t,i,!0,null,null,null,null,null,null,null,null,null,null,null,null),r.isDefaultPrevented=function(){return this.defaultPrevented}),r},e.fn._trigger=e.fn.trigger,e.fn.trigger=function(){if(!arguments[0].xdata)return e.fn._trigger.apply(this,arguments);e.fn._trigger.call(this,arguments[0].type,arguments[0].xdata)},window.jQuery=e})(tire); \ No newline at end of file diff --git a/src/examples/example.tire.html b/src/examples/example.tire.html index cf0c085..a3637f3 100644 --- a/src/examples/example.tire.html +++ b/src/examples/example.tire.html @@ -287,7 +287,10 @@ click: function(e){ $(this).jHERE('bubble', [52.49, 13.39], {content: JSON.stringify(e.geo), closable: false}); }}).jHERE('heatmap', heatMapData, 'value'); - $('#map').jHERE('kml', 'resources/berlin.kml', true); + $('#map').jHERE('kml', 'resources/berlin.kml', true).jHERE('marker', {latitude: 52.5113748680947, longitude: 13.401589126700173}, {icon: 'resources/balloon.png', anchor: {x: 24, y: 48}}); + $('#map').on('maplongpress', function(){ + alert('Why you keep pressing that button?!'); + }); }); diff --git a/src/extensions/route.js b/src/extensions/route.js index 28e56a0..5b26e64 100644 --- a/src/extensions/route.js +++ b/src/extensions/route.js @@ -69,7 +69,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. //`marker` is an object containing the same options used for //`$('.selector').jHERE('marker')`. Options apply to both start and destionation markers. route = function(from, to, options){ - var router, wp, done; + var router, wp, done, cleanOptions; _ns = _ns || nokia.maps; from = normalize(from); to = normalize(to); @@ -133,8 +133,15 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. wp.addCoordinate(from); wp.addCoordinate(to); - options.transportModes = [options.transportMode]; - router.calculateRoute(wp, [options]); + /*Fix for insanity*/ + cleanOptions = { + transportModes: [options.transportMode], + type: options.type, + options: options.options, + trafficMode: options.trafficMode + }; + + router.calculateRoute(wp, [cleanOptions]); }; $.jHERE.extend('route', route); diff --git a/src/jhere.js b/src/jhere.js index 6ee6172..6397676 100644 --- a/src/jhere.js +++ b/src/jhere.js @@ -61,10 +61,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // //**Note that jHERE requires Zepto.JS, jQuery > 1.7 or Tire.js >= 1.1.1** var plugin = 'jHERE', - defaults, H, _ns, _ns_map, _JSLALoader, + defaults, H, _nokia, _ns, _ns_map, _JSLALoader, _credentials, bind = $.proxy, P, /*Map and marker supported events*/ mouse = 'mouse', click = 'click', drag = 'drag', touch = 'touch', start = 'start', end = 'end', move = 'move', + appIdKey = 'appId', authTokenKey = 'authenticationToken', supportedEvents = [ click, 'dbl' + click, @@ -162,7 +163,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. //### Map events // //It is possible to listen for events on the map in the usual jQuery way (`on`, `off`). All the event - //names start with `map`. The event passed to the callback function always has a `geo` property that + //names start with `map`. The event passed to the callback function always has a `geo` (`data.geo` for Tire users) property that //contains latitude and longitude of the point where the event originated. // //For example, to listen for clicks events: @@ -177,8 +178,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. function jHERE(element, options){ this.element = element; this.options = $.extend({}, defaults, options); - this._defaults = defaults; - this._plugin = plugin; this.init(); } @@ -192,11 +191,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. //to `$('.selector').jHERE(options);`. P.defaultCredentials = function(appId, authToken) { _credentials = { - appId: appId, - authenticationToken: authToken + id: appId, + token: authToken }; _JSLALoader.load().is.done(function(){ - _ns.util.ApplicationContext.set(_credentials); + _nokia.Settings.set(appIdKey, appId); + _nokia.Settings.set(authTokenKey, authToken); }); }; @@ -221,10 +221,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /*First of all sort out the credential thingy*/ _credentials = _credentials || { - appId: options.appId, - authenticationToken: options.authToken + id: options.appId, + token: options.authToken }; - _ns.util.ApplicationContext.set(_credentials); + _nokia.Settings.set(appIdKey, _credentials.id); + _nokia.Settings.set(authTokenKey, _credentials.token); /*and now make the map*/ $.data(self.element, plugin, true); @@ -657,15 +658,16 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. _JSLALoader.is = $.Deferred(); /*And load stuff*/ load = function(){ - _ns = nokia.maps; + _nokia = nokia; + _ns = _nokia.maps; /*TODO: make load cutomizable so we don't load unnecessary stuff.*/ - _ns.Features.load({map: 'auto', ui: 'auto', search: 'auto', routing: 'auto', + _nokia.Features.load({map: 'auto', ui: 'auto', search: 'auto', routing: 'auto', positioning: 'auto', behavior: 'auto', kml: 'auto', heatmap: 'auto'}, function(){_ns_map = _ns.map; _JSLALoader.is.resolve();}); }; head = doc.getElementsByTagName('head')[0]; jsla = doc.createElement('script'); - jsla.src = 'http://api.maps.nokia.com/2.2.3/jsl.js'; + jsla.src = 'http://api.maps.nokia.com/2.2.4/jsl.js'; jsla.type = 'text/javascript'; jsla.charset = 'utf-8'; jsla.onreadystatechange = function(){ diff --git a/src/tire.adapter.js b/src/tire.adapter.js index 05c4bcb..3e92f95 100644 --- a/src/tire.adapter.js +++ b/src/tire.adapter.js @@ -121,11 +121,21 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. $.each(props, function(name, value, a, x){ x = (name === 'bubbles') ? (bubbles = !!value) : (event[name] = value); }); + event.xdata = props; event.initEvent(type, bubbles, true, null, null, null, null, null, null, null, null, null, null, null, null); event.isDefaultPrevented = function(){ return this.defaultPrevented; }; } return event; }; + //Tire only supports text + data for trigger + //The following adds support for $.Event + $.fn._trigger = $.fn.trigger; + $.fn.trigger = function(){ + if(!arguments[0].xdata) { + return $.fn._trigger.apply(this, arguments); + } + $.fn._trigger.call(this, arguments[0].type, arguments[0].xdata); + }; //Export Tire as jQuery so there is no need //to check for it in the plugin. window.jQuery = $; diff --git a/test/lib/injectors.js b/test/lib/injectors.js index 071cf01..a7b4538 100644 --- a/test/lib/injectors.js +++ b/test/lib/injectors.js @@ -1,6 +1,7 @@ -P._injectNS = function(ns){ - _ns = ns; - _ns_map = ns.map; +P._injectNS = function(nokia){ + _nokia = nokia; + _ns = nokia.maps; + _ns_map = _ns.map; }; P._injectJSLALoader = function(loader){ _JSLALoader = loader; diff --git a/test/lib/mocks.js b/test/lib/mocks.js index b792a82..a003a8d 100644 --- a/test/lib/mocks.js +++ b/test/lib/mocks.js @@ -45,10 +45,17 @@ var resetMocks, spy, nokia = {}, SPIES = {}, _JSLALoader; }; //JSLA + nokia.Settings = { + set: spy('nokia.Settings.set') + }; + nokia.maps = { util: { ApplicationContext: { - set: spy('ApplicationContext.set') + set: function(){ + console.log('ApplicationContext.set is deprecated'); + spy('ApplicationContext.set')(); + } } } }; @@ -207,7 +214,7 @@ var resetMocks, spy, nokia = {}, SPIES = {}, _JSLALoader; this.addData = function(){ SPIES.heatmap_addData.apply(this, arguments); }; }; - $.jHERE._injectNS(nokia.maps); + $.jHERE._injectNS(nokia); $.jHERE._injectJSLALoader(_JSLALoader); }; diff --git a/test/spec/jhere.js b/test/spec/jhere.js index 43cf752..927e462 100644 --- a/test/spec/jhere.js +++ b/test/spec/jhere.js @@ -61,6 +61,12 @@ describe('jHERE', function(){ expect($('#map').data('jHERE')).toBe(true); expect($('#map').data('plg_jHERE').mtype).toBe('map'); + expect(nokia.Settings.set.callCount).toBe(2); + expect(nokia.Settings.set.argsForCall[0][0]).toBe('appId'); + expect(nokia.Settings.set.argsForCall[0][1]).toBe('monkey'); + expect(nokia.Settings.set.argsForCall[1][0]).toBe('authenticationToken'); + expect(nokia.Settings.set.argsForCall[1][1]).toBe('chimpanzee'); + expect(nokia.maps.map.component.Behavior).toHaveBeenCalled(); expect(nokia.maps.map.Display).toHaveBeenCalledWith($('#map')[0], jasmine.any(Object)); expect(nokia.maps.map.Container).toHaveBeenCalled();