WazeWrapBeta

A base library for WME script writers

当前为 2017-11-10 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/24870/229327/WazeWrapBeta.js

  1. // ==UserScript==
  2. // @name WazeWrapBeta
  3. // @namespace https://gf.qytechs.cn/users/30701-justins83-waze
  4. // @version 0.3.07
  5. // @description A base library for WME script writers
  6. // @author JustinS83/MapOMatic
  7. // @include https://beta.waze.com/*editor*
  8. // @include https://www.waze.com/*editor*
  9. // @exclude https://www.waze.com/*user/editor/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. /* global W */
  14. /* global WazeWrap */
  15.  
  16. var WazeWrap = {};
  17.  
  18. (function() {
  19.  
  20. function bootstrap(tries) {
  21. tries = tries || 1;
  22. if (window.W && window.W.map &&
  23. window.W.model && window.W.loginManager.user &&
  24. $) {
  25. init();
  26. } else if (tries < 1000) {
  27. setTimeout(function () { bootstrap(tries++); }, 200);
  28. } else {
  29. console.log('WazeWrap failed to load');
  30. }
  31. }
  32.  
  33. bootstrap();
  34.  
  35. function init(){
  36. console.log("WazeWrap initializing...");
  37. var oldLib = window.WazeWrap;
  38. var root = this;
  39.  
  40. WazeWrap.Version = "0.3.07";
  41. WazeWrap.isBetaEditor = /beta/.test(location.href);
  42.  
  43. //SetUpRequire();
  44. RestoreMissingSegmentFunctions();
  45. WazeWrap.Geometry = new Geometry;
  46. WazeWrap.Model = new Model;
  47. WazeWrap.Interface = new Interface;
  48. WazeWrap.User = new User;
  49. WazeWrap.Util = new Util;
  50. WazeWrap.Require = new Require;
  51. WazeWrap.String = new String;
  52. root.WazeWrap = WazeWrap;
  53.  
  54. console.log('WazeWrap Loaded');
  55. };
  56.  
  57. function RestoreMissingSegmentFunctions(){
  58. if(W.model.segments.getObjectArray().length > 0){
  59. Waze.map.events.unregister("moveend", this, RestoreMissingSegmentFunctions);
  60. Waze.map.events.unregister("zoomend", this, RestoreMissingSegmentFunctions);
  61. if(typeof W.model.segments.getObjectArray()[0].model.getDirection == "undefined")
  62. W.model.segments.getObjectArray()[0].__proto__.getDirection = function(){return (this.attributes.fwdDirection ? 1 : 0) + (this.attributes.revDirection ? 2 : 0);};
  63. if(typeof W.model.segments.getObjectArray()[0].model.isTollRoad == "undefined")
  64. W.model.segments.getObjectArray()[0].__proto__.isTollRoad = function(){ return (this.attributes.fwdToll || this.attributes.revToll);};
  65. }
  66. else{
  67. Waze.map.events.register("moveend", this, RestoreMissingSegmentFunctions);
  68. Waze.map.events.register("zoomend", this, RestoreMissingSegmentFunctions);
  69. }
  70. }
  71.  
  72. function SetUpRequire(){
  73. if(this.isBetaEditor || typeof window.require !== "undefined")
  74. return;
  75.  
  76. console.log("Setting d2's require fix...");
  77.  
  78. // setup one global var and put all in
  79. var WMEAPI = {};
  80.  
  81. // detect URL of WME source code
  82. WMEAPI.scripts = document.getElementsByTagName('script');
  83. WMEAPI.url=null;
  84. for (i=0;i<WMEAPI.scripts.length;i++){
  85. if (WMEAPI.scripts[i].src.indexOf('/assets-editor/js/app')!=-1)
  86. {
  87. WMEAPI.url=WMEAPI.scripts[i].src;
  88. break;
  89. }
  90. }
  91. if (WMEAPI.url==null)
  92. throw new Error("WME Hack: can't detect WME main JS");
  93.  
  94.  
  95. // setup a fake require and require.define
  96. WMEAPI.require=function (e) {
  97. if (WMEAPI.require.define.modules.hasOwnProperty(e))
  98. return WMEAPI.require.define.modules[e];
  99. else
  100. console.error('Require failed on ' + e, WMEAPI.require.define.modules);
  101. return null;
  102. };
  103.  
  104. WMEAPI.require.define=function (m) {
  105. if (WMEAPI.require.define.hasOwnProperty('modules')==false)
  106. WMEAPI.require.define.modules={};
  107. for (var p in m){
  108. WMEAPI.require.define.modules[p]=m[p];
  109. }
  110. };
  111.  
  112. // save the original webpackJsonp function
  113. WMEAPI.tmp = window.webpackJsonp;
  114.  
  115. // taken from WME code: this function is a wrapper that setup the API and may call recursively other functions
  116. WMEAPI.t = function (n) {
  117. if (WMEAPI.s[n]) return WMEAPI.s[n].exports;
  118. var r = WMEAPI.s[n] = {
  119. exports: {},
  120. id: n,
  121. loaded: !1
  122. };
  123. return WMEAPI.e[n].call(r.exports, r, r.exports, WMEAPI.t), r.loaded = !0, r.exports;
  124. };
  125.  
  126. // e is a copy of all WME funcs because function t need to access to this list
  127. WMEAPI.e=[];
  128.  
  129. // the patch
  130. window.webpackJsonp = function(a, i) {
  131. // our API but we will use it only to build the require stuffs
  132. var api={};
  133. // taken from WME code. a is [1], so...
  134. for (var o, d, u = 0, l = []; u < a.length; u++) d = a[u], WMEAPI.r[d] && l.push.apply(l, WMEAPI.r[d]), WMEAPI.r[d] = 0;
  135. var unknownCount=0;
  136. var classname, funcStr;
  137. // copy i in e and keep a link from classname to index in e
  138. for (o in i){
  139. WMEAPI.e[o] = i[o];
  140. funcStr = i[o].toString();
  141. classname = funcStr.match(/CLASS_NAME:\"([^\"]*)\"/);
  142. if (classname){
  143. // keep the link.
  144. api[classname[1].replace(/\./g,'/').replace(/^W\//, 'Waze/')]={index: o, func: WMEAPI.e[o]};
  145. }
  146. else{
  147. api['Waze/Unknown/' + unknownCount]={index: o, func: WMEAPI.e[o]};
  148. unknownCount++;
  149. }
  150. }
  151. // taken from WME code: it calls the original webpackJsonp and do something else, but I don't really know what.
  152. // removed the call to the original webpackJsonp: still works...
  153. //for (tmp && tmp(a, i); l.length;) l.shift().call(null, t);
  154. for (; l.length;) l.shift().call(null, WMEAPI.t);
  155. WMEAPI.s[0] = 0;
  156. // run the first func of WME. This first func will call recusrsively all funcs needed to setup the API.
  157. // After this call, s will contain all instanciables classes.
  158. //var ret = WMEAPI.t(0);
  159. // now, build the requires thanks to the link we've built in var api.
  160. var module={};
  161. var apiFuncName;
  162. unknownCount=0;
  163. for (o in i){
  164. funcStr = i[o].toString();
  165. classname = funcStr.match(/CLASS_NAME:\"([^\"]*)\"/);
  166. if (classname){
  167. module={};
  168. apiFuncName = classname[1].replace(/\./g,'/').replace(/^W\//, 'Waze/');
  169. module[apiFuncName]=WMEAPI.t(api[apiFuncName].index);
  170. WMEAPI.require.define(module);
  171. }
  172. else{
  173. var matches = funcStr.match(/SEGMENT:"segment",/);
  174. if (matches){
  175. module={};
  176. apiFuncName='Waze/Model/ObjectType';
  177. module[apiFuncName]=WMEAPI.t(api['Waze/Unknown/' + unknownCount].index);
  178. WMEAPI.require.define(module);
  179. }
  180. unknownCount++;
  181. }
  182. }
  183.  
  184. // restore the original func
  185. window.webpackJsonp=WMEAPI.tmp;
  186.  
  187. // set the require public if needed
  188. // if so: others scripts must wait for the window.require to be available before using it.
  189. window.require = WMEAPI.require;
  190. // all available functions are in WMEAPI.require.define.modules
  191. // console.debug this variable to read it:
  192. // console.debug('Modules: ', WMEAPI.require.define.modules);
  193. // run your script here:
  194. // setTimeout(yourscript);
  195. // again taken from WME code. Not sure about what it does.
  196. //if (i[0]) return ret;
  197. };
  198.  
  199. // some kind of global vars and init
  200. WMEAPI.s = {};
  201. WMEAPI.r = {
  202. 0: 0
  203. };
  204.  
  205. // hacking finished
  206.  
  207. // load again WME through our patched func
  208. WMEAPI.WMEHACK_Injected_script = document.createElement("script");
  209. WMEAPI.WMEHACK_Injected_script.setAttribute("type", "application/javascript");
  210. WMEAPI.WMEHACK_Injected_script.src = WMEAPI.url;
  211. document.body.appendChild(WMEAPI.WMEHACK_Injected_script);
  212. console.log("d2 fix complete");
  213. }
  214.  
  215. function Geometry(){
  216. //var geometry = WazeWrap.Geometry;
  217.  
  218. //Converts to "normal" GPS coordinates
  219. this.ConvertTo4326 = function (long, lat){
  220. var projI=new OpenLayers.Projection("EPSG:900913");
  221. var projE=new OpenLayers.Projection("EPSG:4326");
  222. return (new OpenLayers.LonLat(long, lat)).transform(projI,projE);
  223. };
  224. this.ConvertTo900913 = function (long, lat){
  225. var projI=new OpenLayers.Projection("EPSG:900913");
  226. var projE=new OpenLayers.Projection("EPSG:4326");
  227. return (new OpenLayers.LonLat(long, lat)).transform(projE,projI);
  228. };
  229.  
  230. //Converts the Longitudinal offset to an offset in 4326 gps coordinates
  231. this.CalculateLongOffsetGPS = function(longMetersOffset, long, lat)
  232. {
  233. var R= 6378137; //Earth's radius
  234. var dLon = longMetersOffset / (R * Math.cos(Math.PI * lat / 180)); //offset in radians
  235. var lon0 = dLon * (180 / Math.PI); //offset degrees
  236.  
  237. return lon0;
  238. };
  239.  
  240. //Converts the Latitudinal offset to an offset in 4326 gps coordinates
  241. this.CalculateLatOffsetGPS = function(latMetersOffset, lat)
  242. {
  243. var R= 6378137; //Earth's radius
  244. var dLat = latMetersOffset/R;
  245. var lat0 = dLat * (180 /Math.PI); //offset degrees
  246.  
  247. return lat0;
  248. };
  249. /**
  250. * Checks if the given geometry is on screen
  251. * @function WazeWrap.Geometry.isGeometryInMapExtent
  252. * @param {OpenLayers.Geometry} Geometry to check if any part of is in the current viewport
  253. */
  254. this.isLonLatInMapExtent = function (lonLat) {
  255. 'use strict';
  256. return lonLat && W.map.getExtent().containsLonLat(lonLat);
  257. };
  258. /**
  259. * Checks if the given geometry is on screen
  260. * @function WazeWrap.Geometry.isGeometryInMapExtent
  261. * @param {OpenLayers.Geometry} Geometry to check if any part of is in the current viewport
  262. */
  263. this.isGeometryInMapExtent = function (geometry) {
  264. 'use strict';
  265. return geometry && geometry.getBounds &&
  266. W.map.getExtent().intersectsBounds(geometry.getBounds());
  267. };
  268. /**
  269. * Calculates the distance between two given points, returned in meters
  270. * @function WazeWrap.Geometry.calculateDistance
  271. * @param {OpenLayers.Geometry.Point} An array of OL.Geometry.Point with which to measure the total distance. A minimum of 2 points is needed.
  272. */
  273. this.calculateDistance = function(pointArray) {
  274. if(pointArray.length < 2)
  275. return 0;
  276.  
  277. var line = new OpenLayers.Geometry.LineString(pointArray);
  278. length = line.getGeodesicLength(W.map.getProjectionObject());
  279. return length; //multiply by 3.28084 to convert to feet
  280. };
  281. this.findClosestSegment = function(mygeometry, ignorePLR, ignoreUnnamedPR){
  282. var onscreenSegments = WazeWrap.Model.getOnscreenSegments();
  283. var minDistance = Infinity;
  284. var closestSegment;
  285. for (s in onscreenSegments) {
  286. if (!onscreenSegments.hasOwnProperty(s))
  287. continue;
  288.  
  289. segmentType = onscreenSegments[s].attributes.roadType;
  290. if (segmentType === 10 || segmentType === 16 || segmentType === 18 || segmentType === 19) //10 ped boardwalk, 16 stairway, 18 railroad, 19 runway, 3 freeway
  291. continue;
  292. if(ignorePLR && segmentType === 20) //PLR
  293. continue;
  294.  
  295. if(ignoreUnnamedPR)
  296. if(segmentType === 17 && WazeWrap.Model.getStreetName(onscreenSegments[s].attributes.primaryStreetID) === null) //PR
  297. continue;
  298.  
  299.  
  300. distanceToSegment = mygeometry.distanceTo(onscreenSegments[s].geometry, {details: true});
  301.  
  302. if (distanceToSegment.distance < minDistance) {
  303. minDistance = distanceToSegment.distance;
  304. closestSegment = onscreenSegments[s];
  305. closestSegment.closestPoint = new OL.Geometry.Point(distanceToSegment.x1, distanceToSegment.y1);
  306. }
  307. }
  308. return closestSegment;
  309. };
  310. };
  311.  
  312. function Model(){
  313.  
  314. this.getPrimaryStreetID = function(segmentID){
  315. return W.model.segments.get(segmentID).attributes.primaryStreetID;
  316. };
  317.  
  318. this.getStreetName = function(primaryStreetID){
  319. return W.model.streets.get(primaryStreetID).name;
  320. };
  321.  
  322. this.getCityID = function(primaryStreetID){
  323. return W.model.streets.get(primaryStreetID).cityID;
  324. };
  325.  
  326. this.getCityName = function(primaryStreetID){
  327. return W.model.cities.get(this.getCityID(primaryStreetID)).attributes.Name;
  328. };
  329.  
  330. this.getStateName = function(primaryStreetID){
  331. return W.model.states.get(getStateID(primaryStreetID)).Name;
  332. };
  333.  
  334. this.getStateID = function(primaryStreetID){
  335. return W.model.cities.get(primaryStreetID).attributes.stateID;
  336. };
  337.  
  338. this.getCountryID = function(primaryStreetID){
  339. return W.model.cities.get(this.getCityID(primaryStreetID)).attributes.CountryID;
  340. };
  341.  
  342. this.getCountryName = function(primaryStreetID){
  343. return W.model.countries.get(getCountryID(primaryStreetID)).name;
  344. };
  345.  
  346. this.getCityNameFromSegmentObj = function(segObj){
  347. return this.getCityName(segObj.attributes.primaryStreetID);
  348. };
  349.  
  350. this.getStateNameFromSegmentObj = function(segObj){
  351. return this.getStateName(segObj.attributes.primaryStreetID);
  352. };
  353.  
  354. //returns an array of segmentIDs for all segments that are part of the same roundabout as the passed segment
  355. this.getAllRoundaboutSegmentsFromObj = function(segObj){
  356. if(segObj.model.attributes.junctionID === null)
  357. return null;
  358.  
  359. return W.model.junctions.objects[segObj.model.attributes.junctionID].attributes.segIDs;
  360. };
  361.  
  362. this.getAllRoundaboutJunctionNodesFromObj = function(segObj){
  363. var RASegs = this.getAllRoundaboutSegmentsFromObj(segObj);
  364. var RAJunctionNodes = [];
  365. for(i=0; i< RASegs.length; i++){
  366. RAJunctionNodes.push(W.model.nodes.objects[W.model.segments.get(RASegs[i]).attributes.toNodeID]);
  367.  
  368. }
  369. return RAJunctionNodes;
  370. };
  371.  
  372. this.isRoundaboutSegmentID = function(segmentID){
  373. if(W.model.segments.get(segmentID).attributes.junctionID === null)
  374. return false;
  375. else
  376. return true;
  377. };
  378.  
  379. this.isRoundaboutSegmentObj = function(segObj){
  380. if(segObj.model.attributes.junctionID === null)
  381. return false;
  382. else
  383. return true;
  384. };
  385. this.getOnscreenSegments = function(){
  386. var segments = W.model.segments.objects;
  387. var mapExtent = W.map.getExtent();
  388. var onScreenSegments = [];
  389. var seg;
  390.  
  391. for (s in segments) {
  392. if (!segments.hasOwnProperty(s))
  393. continue;
  394.  
  395. seg = W.model.segments.get(s);
  396. if (mapExtent.intersectsBounds(seg.geometry.getBounds()))
  397. onScreenSegments.push(seg);
  398. }
  399. return onScreenSegments;
  400. };
  401.  
  402. /**
  403. * Defers execution of a callback function until the WME map and data
  404. * model are ready. Call this function before calling a function that
  405. * causes a map and model reload, such as W.map.moveTo(). After the
  406. * move is completed the callback function will be executed.
  407. * @function WazeWrap.Model.onModelReady
  408. * @param {Function} callback The callback function to be executed.
  409. * @param {Boolean} now Whether or not to call the callback now if the
  410. * model is currently ready.
  411. * @param {Object} context The context in which to call the callback.
  412. */
  413. this.onModelReady = function (callback, now, context) {
  414. var deferModelReady = function () {
  415. return $.Deferred(function (dfd) {
  416. var resolve = function () {
  417. dfd.resolve();
  418. W.model.events.unregister('mergeend', null, resolve);
  419. };
  420. W.model.events.register('mergeend', null, resolve);
  421. }).promise();
  422. };
  423. var deferMapReady = function () {
  424. return $.Deferred(function (dfd) {
  425. var resolve = function () {
  426. dfd.resolve();
  427. W.vent.off('operationDone', resolve);
  428. };
  429. W.vent.on('operationDone', resolve);
  430. }).promise();
  431. };
  432.  
  433. if (typeof callback === 'function') {
  434. context = context || callback;
  435. if (now && WazeWrap.Util.mapReady() && WazeWrap.Util.modelReady()) {
  436. callback.call(context);
  437. } else {
  438. $.when(deferMapReady() && deferModelReady()).
  439. then(function () {
  440. callback.call(context);
  441. });
  442. }
  443. }
  444. };
  445. /**
  446. * Retrives a route from the Waze Live Map.
  447. * @class
  448. * @name wLib.Model.RouteSelection
  449. * @param firstSegment The segment to use as the start of the route.
  450. * @param lastSegment The segment to use as the destination for the route.
  451. * @param {Array|Function} callback A function or array of funcitons to be
  452. * executed after the route
  453. * is retrieved. 'This' in the callback functions will refer to the
  454. * RouteSelection object.
  455. * @param {Object} options A hash of options for determining route. Valid
  456. * options are:
  457. * fastest: {Boolean} Whether or not the fastest route should be used.
  458. * Default is false, which selects the shortest route.
  459. * freeways: {Boolean} Whether or not to avoid freeways. Default is false.
  460. * dirt: {Boolean} Whether or not to avoid dirt roads. Default is false.
  461. * longtrails: {Boolean} Whether or not to avoid long dirt roads. Default
  462. * is false.
  463. * uturns: {Boolean} Whether or not to allow U-turns. Default is true.
  464. * @return {wLib.Model.RouteSelection} The new RouteSelection object.
  465. * @example: // The following example will retrieve a route from the Live Map and select the segments in the route.
  466. * selection = W.selectionManager.selectedItems;
  467. * myRoute = new wLib.Model.RouteSelection(selection[0], selection[1], function(){this.selectRouteSegments();}, {fastest: true});
  468. */
  469. this.RouteSelection = function (firstSegment, lastSegment, callback, options) {
  470. var i,
  471. n,
  472. start = this.getSegmentCenterLonLat(firstSegment),
  473. end = this.getSegmentCenterLonLat(lastSegment);
  474. this.options = {
  475. fastest: options && options.fastest || false,
  476. freeways: options && options.freeways || false,
  477. dirt: options && options.dirt || false,
  478. longtrails: options && options.longtrails || false,
  479. uturns: options && options.uturns || true
  480. };
  481. this.requestData = {
  482. from: 'x:' + start.x + ' y:' + start.y + ' bd:true',
  483. to: 'x:' + end.x + ' y:' + end.y + ' bd:true',
  484. returnJSON: true,
  485. returnGeometries: true,
  486. returnInstructions: false,
  487. type: this.options.fastest ? 'HISTORIC_TIME' : 'DISTANCE',
  488. clientVersion: '4.0.0',
  489. timeout: 60000,
  490. nPaths: 3,
  491. options: this.setRequestOptions(this.options)
  492. };
  493. this.callbacks = [];
  494. if (callback) {
  495. if (!(callback instanceof Array)) {
  496. callback = [callback];
  497. }
  498. for (i = 0, n = callback.length; i < n; i++) {
  499. if ('function' === typeof callback[i]) {
  500. this.callbacks.push(callback[i]);
  501. }
  502. }
  503. }
  504. this.routeData = null;
  505. this.getRouteData();
  506. };
  507.  
  508. this.RouteSelection.prototype =
  509. /** @lends wLib.Model.RouteSelection.prototype */ {
  510. /**
  511. * Formats the routing options string for the ajax request.
  512. * @private
  513. * @param {Object} options Object containing the routing options.
  514. * @return {String} String containing routing options.
  515. */
  516. setRequestOptions: function (options) {
  517. return 'AVOID_TOLL_ROADS:' + (options.tolls ? 't' : 'f') + ',' +
  518. 'AVOID_PRIMARIES:' + (options.freeways ? 't' : 'f') + ',' +
  519. 'AVOID_TRAILS:' + (options.dirt ? 't' : 'f') + ',' +
  520. 'AVOID_LONG_TRAILS:' + (options.longtrails ? 't' : 'f') + ',' +
  521. 'ALLOW_UTURNS:' + (options.uturns ? 't' : 'f');
  522. },
  523. /**
  524. * Gets the center of a segment in LonLat form.
  525. * @private
  526. * @param segment A Waze model segment object.
  527. * @return {OpenLayers.LonLat} The LonLat object corresponding to the
  528. * center of the segment.
  529. */
  530. getSegmentCenterLonLat: function (segment) {
  531. var x, y, componentsLength, midPoint;
  532. if (segment) {
  533. componentsLength = segment.geometry.components.length;
  534. midPoint = Math.floor(componentsLength / 2);
  535. if (componentsLength % 2 === 1) {
  536. x = segment.geometry.components[midPoint].x;
  537. y = segment.geometry.components[midPoint].y;
  538. } else {
  539. x = (segment.geometry.components[midPoint - 1].x +
  540. segment.geometry.components[midPoint].x) / 2;
  541. y = (segment.geometry.components[midPoint - 1].y +
  542. segment.geometry.components[midPoint].y) / 2;
  543. }
  544. return new OL.Geometry.Point(x, y).
  545. transform(W.map.getProjectionObject(), 'EPSG:4326');
  546. }
  547.  
  548. },
  549. /**
  550. * Gets the route from Live Map and executes any callbacks upon success.
  551. * @private
  552. * @returns The ajax request object. The responseJSON property of the
  553. * returned object
  554. * contains the route information.
  555. *
  556. */
  557. getRouteData: function () {
  558. var i,
  559. n,
  560. that = this;
  561. return $.ajax({
  562. dataType: 'json',
  563. url: this.getURL(),
  564. data: this.requestData,
  565. dataFilter: function (data, dataType) {
  566. return data.replace(/NaN/g, '0');
  567. },
  568. success: function (data) {
  569. that.routeData = data;
  570. for (i = 0, n = that.callbacks.length; i < n; i++) {
  571. that.callbacks[i].call(that);
  572. }
  573. }
  574. });
  575. },
  576. /**
  577. * Extracts the IDs from all segments on the route.
  578. * @private
  579. * @return {Array} Array containing an array of segment IDs for
  580. * each route alternative.
  581. */
  582. getRouteSegmentIDs: function () {
  583. var i, j, route, len1, len2, segIDs = [],
  584. routeArray = [],
  585. data = this.routeData;
  586. if ('undefined' !== typeof data.alternatives) {
  587. for (i = 0, len1 = data.alternatives.length; i < len1; i++) {
  588. route = data.alternatives[i].response.results;
  589. for (j = 0, len2 = route.length; j < len2; j++) {
  590. routeArray.push(route[j].path.segmentId);
  591. }
  592. segIDs.push(routeArray);
  593. routeArray = [];
  594. }
  595. } else {
  596. route = data.response.results;
  597. for (i = 0, len1 = route.length; i < len1; i++) {
  598. routeArray.push(route[i].path.segmentId);
  599. }
  600. segIDs.push(routeArray);
  601. }
  602. return segIDs;
  603. },
  604. /**
  605. * Gets the URL to use for the ajax request based on country.
  606. * @private
  607. * @return {String} Relative URl to use for route ajax request.
  608. */
  609. getURL: function () {
  610. if (W.model.countries.get(235) || W.model.countries.get(40)) {
  611. return '/RoutingManager/routingRequest';
  612. } else if (W.model.countries.get(106)) {
  613. return '/il-RoutingManager/routingRequest';
  614. } else {
  615. return '/row-RoutingManager/routingRequest';
  616. }
  617. },
  618. /**
  619. * Selects all segments on the route in the editor.
  620. * @param {Integer} routeIndex The index of the alternate route.
  621. * Default route to use is the first one, which is 0.
  622. */
  623. selectRouteSegments: function (routeIndex) {
  624. var i, n, seg,
  625. segIDs = this.getRouteSegmentIDs()[Math.floor(routeIndex) || 0],
  626. segments = [];
  627. if ('undefined' === typeof segIDs) {
  628. return;
  629. }
  630. for (i = 0, n = segIDs.length; i < n; i++) {
  631. seg = W.model.segments.get(segIDs[i]);
  632. if ('undefined' !== seg) {
  633. segments.push(seg);
  634. }
  635. }
  636. return W.selectionManager.select(segments);
  637. }
  638. };
  639. };
  640. function User(){
  641. this.Rank = function(){
  642. return W.loginManager.user.normalizedLevel;
  643. };
  644.  
  645. this.Username = function(){
  646. return W.loginManager.user.userName;
  647. };
  648.  
  649. this.isCM = function(){
  650. if(W.loginManager.user.editableCountryIDs.length > 0)
  651. return true;
  652. else
  653. return false;
  654. };
  655. this.isAM = function(){
  656. return W.loginManager.user.isAreaManager;
  657. };
  658. };
  659. function Require(){
  660. this.DragElement = function(){
  661. var myDragElement = OL.Class({
  662. started: !1,
  663. stopDown: !0,
  664. dragging: !1,
  665. touch: !1,
  666. last: null ,
  667. start: null ,
  668. lastMoveEvt: null ,
  669. oldOnselectstart: null ,
  670. interval: 0,
  671. timeoutId: null ,
  672. forced: !1,
  673. active: !1,
  674. initialize: function(e) {
  675. this.map = e,
  676. this.uniqueID = myDragElement.baseID--
  677. },
  678. callback: function(e, t) {
  679. if (this[e])
  680. return this[e].apply(this, t)
  681. },
  682. dragstart: function(e) {
  683. e.xy = new OL.Pixel(e.clientX - this.map.viewPortDiv.offsets[0],e.clientY - this.map.viewPortDiv.offsets[1]);
  684. var t = !0;
  685. return this.dragging = !1,
  686. (OL.Event.isLeftClick(e) || OL.Event.isSingleTouch(e)) && (this.started = !0,
  687. this.start = e.xy,
  688. this.last = e.xy,
  689. OL.Element.addClass(this.map.viewPortDiv, "olDragDown"),
  690. this.down(e),
  691. this.callback("down", [e.xy]),
  692. OL.Event.stop(e),
  693. this.oldOnselectstart || (this.oldOnselectstart = document.onselectstart ? document.onselectstart : OL.Function.True),
  694. document.onselectstart = OL.Function.False,
  695. t = !this.stopDown),
  696. t
  697. },
  698. forceStart: function() {
  699. var e = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
  700. return this.started = !0,
  701. this.endOnMouseUp = e,
  702. this.forced = !0,
  703. this.last = {
  704. x: 0,
  705. y: 0
  706. },
  707. this.callback("force")
  708. },
  709. forceEnd: function() {
  710. if (this.forced)
  711. return this.endDrag()
  712. },
  713. dragmove: function(e) {
  714. return this.map.viewPortDiv.offsets && (e.xy = new OL.Pixel(e.clientX - this.map.viewPortDiv.offsets[0],e.clientY - this.map.viewPortDiv.offsets[1])),
  715. this.lastMoveEvt = e,
  716. !this.started || this.timeoutId || e.xy.x === this.last.x && e.xy.y === this.last.y || (this.interval > 0 && (this.timeoutId = window.setTimeout(OL.Function.bind(this.removeTimeout, this), this.interval)),
  717. this.dragging = !0,
  718. this.move(e),
  719. this.oldOnselectstart || (this.oldOnselectstart = document.onselectstart,
  720. document.onselectstart = OL.Function.False),
  721. this.last = e.xy),
  722. !0
  723. },
  724. dragend: function(e) {
  725. if (e.xy = new OL.Pixel(e.clientX - this.map.viewPortDiv.offsets[0],e.clientY - this.map.viewPortDiv.offsets[1]),
  726. this.started) {
  727. var t = this.start !== this.last;
  728. this.endDrag(),
  729. this.up(e),
  730. this.callback("up", [e.xy]),
  731. t && this.callback("done", [e.xy])
  732. }
  733. return !0
  734. },
  735. endDrag: function() {
  736. this.started = !1,
  737. this.dragging = !1,
  738. this.forced = !1,
  739. OL.Element.removeClass(this.map.viewPortDiv, "olDragDown"),
  740. document.onselectstart = this.oldOnselectstart
  741. },
  742. down: function(e) {},
  743. move: function(e) {},
  744. up: function(e) {},
  745. out: function(e) {},
  746. mousedown: function(e) {
  747. return this.dragstart(e)
  748. },
  749. touchstart: function(e) {
  750. return this.touch || (this.touch = !0,
  751. this.map.events.un({
  752. mousedown: this.mousedown,
  753. mouseup: this.mouseup,
  754. mousemove: this.mousemove,
  755. click: this.click,
  756. scope: this
  757. })),
  758. this.dragstart(e)
  759. },
  760. mousemove: function(e) {
  761. return this.dragmove(e)
  762. },
  763. touchmove: function(e) {
  764. return this.dragmove(e)
  765. },
  766. removeTimeout: function() {
  767. if (this.timeoutId = null ,
  768. this.dragging)
  769. return this.mousemove(this.lastMoveEvt)
  770. },
  771. mouseup: function(e) {
  772. if (!this.forced || this.endOnMouseUp)
  773. return this.started ? this.dragend(e) : void 0
  774. },
  775. touchend: function(e) {
  776. if (e.xy = this.last,
  777. !this.forced)
  778. return this.dragend(e)
  779. },
  780. click: function(e) {
  781. return this.start === this.last
  782. },
  783. activate: function(e) {
  784. this.$el = e,
  785. this.active = !0;
  786. var t = $(this.map.viewPortDiv);
  787. return this.$el.on("mousedown.drag-" + this.uniqueID, $.proxy(this.mousedown, this)),
  788. this.$el.on("touchstart.drag-" + this.uniqueID, $.proxy(this.touchstart, this)),
  789. $(document).on("mouseup.drag-" + this.uniqueID, $.proxy(this.mouseup, this)),
  790. t.on("mousemove.drag-" + this.uniqueID, $.proxy(this.mousemove, this)),
  791. t.on("touchmove.drag-" + this.uniqueID, $.proxy(this.touchmove, this)),
  792. t.on("touchend.drag-" + this.uniqueID, $.proxy(this.touchend, this))
  793. },
  794. deactivate: function() {
  795. return this.active = !1,
  796. this.$el.off(".drag-" + this.uniqueID),
  797. $(this.map.viewPortDiv).off(".drag-" + this.uniqueID),
  798. $(document).off(".drag-" + this.uniqueID),
  799. this.touch = !1,
  800. this.started = !1,
  801. this.forced = !1,
  802. this.dragging = !1,
  803. this.start = null ,
  804. this.last = null ,
  805. OL.Element.removeClass(this.map.viewPortDiv, "olDragDown")
  806. },
  807. adjustXY: function(e) {
  808. var t = OL.Util.pagePosition(this.map.viewPortDiv);
  809. return e.xy.x -= t[0],
  810. e.xy.y -= t[1]
  811. },
  812. CLASS_NAME: "W.Handler.DragElement"
  813. });
  814. myDragElement.baseID = 0;
  815. return myDragElement;
  816. };
  817. this.DivIcon = OpenLayers.Class({
  818. className: null ,
  819. $div: null ,
  820. events: null ,
  821. initialize: function(e, t) {
  822. this.className = e,
  823. this.moveWithTransform = !!t,
  824. this.$div = $("<div />").addClass(e),
  825. this.div = this.$div.get(0),
  826. this.imageDiv = this.$div.get(0);
  827. },
  828. destroy: function() {
  829. this.erase(),
  830. this.$div = null;
  831. },
  832. clone: function() {
  833. return new i(this.className);
  834. },
  835. draw: function(e) {
  836. return this.moveWithTransform ? (this.$div.css({
  837. transform: "translate(" + e.x + "px, " + e.y + "px)"
  838. }),
  839. this.$div.css({
  840. position: "absolute"
  841. })) : this.$div.css({
  842. position: "absolute",
  843. left: e.x,
  844. top: e.y
  845. }),
  846. this.$div.get(0);
  847. },
  848. moveTo: function(e) {
  849. null !== e && (this.px = e),
  850. null === this.px ? this.display(!1) : this.moveWithTransform ? this.$div.css({
  851. transform: "translate(" + this.px.x + "px, " + this.px.y + "px)"
  852. }) : this.$div.css({
  853. left: this.px.x,
  854. top: this.px.y
  855. });
  856. },
  857. erase: function() {
  858. this.$div.remove();
  859. },
  860. display: function(e) {
  861. this.$div.toggle(e);
  862. },
  863. isDrawn: function() {
  864. return !!this.$div.parent().length;
  865. },
  866. bringToFront: function() {
  867. if (this.isDrawn()) {
  868. var e = this.$div.parent();
  869. this.$div.detach().appendTo(e);
  870. }
  871. },
  872. forceReflow: function() {
  873. return this.$div.get(0).offsetWidth;
  874. },
  875. CLASS_NAME: "Waze.DivIcon"
  876. });
  877. };
  878. function Util(){
  879. /**
  880. * Function to defer function execution until an element is present on
  881. * the page.
  882. * @function WazeWrap.Util.waitForElement
  883. * @param {String} selector The CSS selector string or a jQuery object
  884. * to find before executing the callback.
  885. * @param {Function} callback The function to call when the page
  886. * element is detected.
  887. * @param {Object} [context] The context in which to call the callback.
  888. */
  889. this.waitForElement = function (selector, callback, context) {
  890. var jqObj;
  891.  
  892. if (!selector || typeof callback !== 'function') {
  893. return;
  894. }
  895.  
  896. jqObj = typeof selector === 'string' ?
  897. $(selector) : selector instanceof $ ? selector : null;
  898.  
  899. if (!jqObj.size()) {
  900. window.requestAnimationFrame(function () {
  901. WazeWrap.Util.waitForElement(selector, callback, context);
  902. });
  903. } else {
  904. callback.call(context || callback);
  905. }
  906. };
  907.  
  908. /**
  909. * Function to track the ready state of the map.
  910. * @function WazeWrap.Util.mapReady
  911. * @return {Boolean} Whether or not a map operation is pending or
  912. * undefined if the function has not yet seen a map ready event fired.
  913. */
  914. this.mapReady = function () {
  915. var mapReady = true;
  916. W.vent.on('operationPending', function () {
  917. mapReady = false;
  918. });
  919. W.vent.on('operationDone', function () {
  920. mapReady = true;
  921. });
  922. return function () {
  923. return mapReady;
  924. };
  925. } ();
  926.  
  927. /**
  928. * Function to track the ready state of the model.
  929. * @function WazeWrap.Util.modelReady
  930. * @return {Boolean} Whether or not the model has loaded objects or
  931. * undefined if the function has not yet seen a model ready event fired.
  932. */
  933. this.modelReady = function () {
  934. var modelReady = true;
  935. W.model.events.register('mergestart', null, function () {
  936. modelReady = false;
  937. });
  938. W.model.events.register('mergeend', null, function () {
  939. modelReady = true;
  940. });
  941. return function () {
  942. return modelReady;
  943. };
  944. } ();
  945. };
  946.  
  947. function Interface() {
  948. /**
  949. * Generates id for message bars.
  950. * @private
  951. */
  952. var getNextID = function () {
  953. var id = 1;
  954. return function () {
  955. return id++;
  956. };
  957. } ();
  958. this.Shortcut = OL.Class(this, /** @lends WazeWrap.Interface.Shortcut.prototype */ {
  959. name: null,
  960. desc: null,
  961. group: null,
  962. title: null,
  963. shortcut: {},
  964. callback: null,
  965. scope: null,
  966. groupExists: false,
  967. actionExists: false,
  968. eventExists: false,
  969. defaults: {
  970. group: 'default'
  971. },
  972. /**
  973. * Creates a new {WazeWrap.Interface.Shortcut}.
  974. * @class
  975. * @name WazeWrap.Interface.Shortcut
  976. * @param name {String} The name of the shortcut.
  977. * @param desc {String} The description to display for the shortcut
  978. * @param group {String} The name of the shortcut group.
  979. * @param title {String} The title to display for this group in the Keyboard shortcuts list
  980. * @param shortcut {String} The shortcut key(s). The shortcut
  981. * should be of the form 'i' where i is the keyboard shortuct or
  982. * include modifier keys such as 'CSA+i', where C = the control
  983. * key, S = the shift key, A = the alt key, and i = the desired
  984. * keyboard shortcut. The modifier keys are optional.
  985. * @param callback {Function} The function to be called by the
  986. * shortcut.
  987. * @param scope {Object} The object to be used as this by the
  988. * callback.
  989. * @return {WazeWrap.Interface.Shortcut} The new shortcut object.
  990. * @example //Creates new shortcut and adds it to the map.
  991. * shortcut = new WazeWrap.Interface.Shortcut('myName', 'myGroup', 'C+p', callbackFunc, null).add();
  992. */
  993. initialize: function (name, desc, group, title, shortcut, callback, scope) {
  994. if ('string' === typeof name && name.length > 0 &&
  995. 'string' === typeof shortcut &&
  996. 'function' === typeof callback) {
  997. this.name = name;
  998. this.desc = desc;
  999. this.group = group || this.defaults.group;
  1000. this.title = title;
  1001. this.callback = callback;
  1002. this.shortcut[shortcut] = name;
  1003. if ('object' !== typeof scope) {
  1004. this.scope = null;
  1005. } else {
  1006. this.scope = scope;
  1007. }
  1008. return this;
  1009. }
  1010. },
  1011. /**
  1012. * Determines if the shortcut's group already exists.
  1013. * @private
  1014. */
  1015. doesGroupExist: function () {
  1016. this.groupExists = 'undefined' !== typeof W.accelerators.Groups[this.group] &&
  1017. undefined !== typeof W.accelerators.Groups[this.group].members;
  1018. return this.groupExists;
  1019. },
  1020. /**
  1021. * Determines if the shortcut's action already exists.
  1022. * @private
  1023. */
  1024. doesActionExist: function () {
  1025. this.actionExists = 'undefined' !== typeof W.accelerators.Actions[this.name];
  1026. return this.actionExists;
  1027. },
  1028. /**
  1029. * Determines if the shortcut's event already exists.
  1030. * @private
  1031. */
  1032. doesEventExist: function () {
  1033. this.eventExists = 'undefined' !== typeof W.accelerators.events.listeners[this.name] &&
  1034. W.accelerators.events.listeners[this.name].length > 0 &&
  1035. this.callback === W.accelerators.events.listeners[this.name][0].func &&
  1036. this.scope === W.accelerators.events.listeners[this.name][0].obj;
  1037. return this.eventExists;
  1038. },
  1039. /**
  1040. * Creates the shortcut's group.
  1041. * @private
  1042. */
  1043. createGroup: function () {
  1044. W.accelerators.Groups[this.group] = [];
  1045. W.accelerators.Groups[this.group].members = [];
  1046.  
  1047. if(this.title && !I18n.translations[I18n.currentLocale()].keyboard_shortcuts.groups[this.group]){
  1048. I18n.translations[I18n.currentLocale()].keyboard_shortcuts.groups[this.group] = [];
  1049. I18n.translations[I18n.currentLocale()].keyboard_shortcuts.groups[this.group].description = this.title;
  1050. I18n.translations[I18n.currentLocale()].keyboard_shortcuts.groups[this.group].members = [];
  1051. }
  1052. },
  1053. /**
  1054. * Registers the shortcut's action.
  1055. * @private
  1056. */
  1057. addAction: function () {
  1058. if(this.title)
  1059. I18n.translations[I18n.currentLocale()].keyboard_shortcuts.groups[this.group].members[this.name] = this.desc;
  1060. W.accelerators.addAction(this.name, { group: this.group });
  1061. },
  1062. /**
  1063. * Registers the shortcut's event.
  1064. * @private
  1065. */
  1066. addEvent: function () {
  1067. W.accelerators.events.register(this.name, this.scope, this.callback);
  1068. },
  1069. /**
  1070. * Registers the shortcut's keyboard shortcut.
  1071. * @private
  1072. */
  1073. registerShortcut: function () {
  1074. W.accelerators._registerShortcuts(this.shortcut);
  1075. },
  1076. /**
  1077. * Adds the keyboard shortcut to the map.
  1078. * @return {WazeWrap.Interface.Shortcut} The keyboard shortcut.
  1079. */
  1080. add: function () {
  1081. /* If the group is not already defined, initialize the group. */
  1082. if (!this.doesGroupExist()) {
  1083. this.createGroup();
  1084. }
  1085.  
  1086. /* Clear existing actions with same name */
  1087. if (this.doesActionExist()) {
  1088. W.accelerators.Actions[this.name] = null;
  1089. }
  1090. this.addAction();
  1091.  
  1092. /* Register event only if it's not already registered */
  1093. if (!this.doesEventExist()) {
  1094. this.addEvent();
  1095. }
  1096.  
  1097. /* Finally, register the shortcut. */
  1098. this.registerShortcut();
  1099. return this;
  1100. },
  1101. /**
  1102. * Removes the keyboard shortcut from the map.
  1103. * @return {WazeWrap.Interface.Shortcut} The keyboard shortcut.
  1104. */
  1105. remove: function () {
  1106. if (this.doesEventExist()) {
  1107. W.accelerators.events.unregister(this.name, this.scope, this.callback);
  1108. }
  1109. if (this.doesActionExist()) {
  1110. delete W.accelerators.Actions[this.name];
  1111. }
  1112. //remove shortcut?
  1113. return this;
  1114. },
  1115. /**
  1116. * Changes the keyboard shortcut and applies changes to the map.
  1117. * @return {WazeWrap.Interface.Shortcut} The keyboard shortcut.
  1118. */
  1119. change: function (shortcut) {
  1120. if (shortcut) {
  1121. this.shortcut = {};
  1122. this.shortcut[shortcut] = this.name;
  1123. this.registerShortcut();
  1124. }
  1125. return this;
  1126. }
  1127. }),
  1128.  
  1129. this.Tab = OL.Class(this, {
  1130. /** @lends WazeWrap.Interface.Tab */
  1131. TAB_SELECTOR: '#user-tabs ul.nav-tabs',
  1132. CONTENT_SELECTOR: '#user-info div.tab-content',
  1133. callback: null,
  1134. $content: null,
  1135. context: null,
  1136. $tab: null
  1137. /**
  1138. * Creates a new WazeWrap.Interface.Tab. The tab is appended to the WME
  1139. * editor sidebar and contains the passed HTML content.
  1140. * @class
  1141. * @name WazeWrap.Interface.Tab
  1142. * @param {String} name The name of the tab. Should not contain any
  1143. * special characters.
  1144. * @param {String} content The HTML content of the tab.
  1145. * @param {Function} [callback] A function to call upon successfully
  1146. * appending the tab.
  1147. * @param {Object} [context] The context in which to call the callback
  1148. * function.
  1149. * @return {WazeWrap.Interface.Tab} The new tab object.
  1150. * @example //Creates new tab and adds it to the page.
  1151. * new WazeWrap.Interface.Tab('thebestscriptever', '<div>Hello World!</div>');
  1152. */
  1153. initialize: function (name, content, callback, context) {
  1154. var idName, i = 0;
  1155. if (name && 'string' === typeof name &&
  1156. content && 'string' === typeof content) {
  1157. if (callback && 'function' === typeof callback) {
  1158. this.callback = callback;
  1159. this.context = context || callback;
  1160. }
  1161. /* Sanitize name for html id attribute */
  1162. idName = name.toLowerCase().replace(/[^a-z-_]/g, '');
  1163. /* Make sure id will be unique on page */
  1164. while (
  1165. $('#sidepanel-' + (i ? idName + i : idName)).length > 0) {
  1166. i++;
  1167. }
  1168. if (i) {
  1169. idName = idName + i;
  1170. }
  1171. /* Create tab and content */
  1172. this.$tab = $('<li/>')
  1173. .append($('<a/>')
  1174. .attr({
  1175. 'href': '#sidepanel-' + idName,
  1176. 'data-toggle': 'tab',
  1177. })
  1178. .text(name));
  1179. this.$content = $('<div/>')
  1180. .addClass('tab-pane')
  1181. .attr('id', 'sidepanel-' + idName)
  1182. .html(content);
  1183.  
  1184. this.appendTab();
  1185. var that = this;
  1186. if (Waze.prefs) {
  1187. Waze.prefs.on('change:isImperial', function(){that.appendTab(that);});
  1188. }
  1189. Waze.app.modeController.model.bind('change:mode', that.appendTab);
  1190. }
  1191. },
  1192.  
  1193. append: function (content) {
  1194. this.$content.append(content);
  1195. },
  1196.  
  1197. appendTab: function (self) {
  1198. if(self == null)
  1199. self = this;
  1200. WazeWrap.Util.waitForElement(
  1201. self.TAB_SELECTOR + ',' + self.CONTENT_SELECTOR,
  1202. function () {
  1203. $(self.TAB_SELECTOR).append(self.$tab);
  1204. $(self.CONTENT_SELECTOR).first().append(self.$content);
  1205. if (self.callback) {
  1206. self.callback.call(self.context);
  1207. }
  1208. }, self);
  1209. },
  1210.  
  1211. clearContent: function () {
  1212. this.$content.empty();
  1213. },
  1214.  
  1215. destroy: function () {
  1216. this.$tab.remove();
  1217. this.$content.remove();
  1218. }
  1219. });
  1220.  
  1221. this.AddLayerCheckbox = function(group, checkboxText, checked, callback){
  1222. group = group.toLowerCase();
  1223. var normalizedText = checkboxText.toLowerCase().replace(/\s/g, '_');
  1224. var checkboxID = "layer-switcher-item_" + normalizedText;
  1225. var groupPrefix = 'layer-switcher-group_';
  1226. var groupClass = groupPrefix + group.toLowerCase();
  1227. sessionStorage[normalizedText] = checked;
  1228.  
  1229. var CreateParentGroup = function(groupChecked){
  1230. var groupList = $('.layer-switcher').find('.list-unstyled.togglers');
  1231. var checkboxText = group.charAt(0).toUpperCase() + group.substr(1);
  1232. var newLI = $('<li class="group">');
  1233. newLI.html([
  1234. '<div class="controls-container toggler">',
  1235. '<input class="' + groupClass + '" id="' + groupClass + '" type="checkbox" ' + (groupChecked ? 'checked' : '') +'>',
  1236. '<label for="' + groupClass + '">',
  1237. '<span class="label-text">'+ checkboxText + '</span>',
  1238. '</label></div>',
  1239. '<ul class="children"></ul>'
  1240. ].join(' '));
  1241.  
  1242. groupList.append(newLI);
  1243. $('#' + groupClass).change(function(){sessionStorage[groupClass] = this.checked;});
  1244. };
  1245.  
  1246. if(group !== "issues" && group !== "places" && group !== "road" && group !== "display") //"non-standard" group, check its existence
  1247. if($('.'+groupClass).length === 0){ //Group doesn't exist yet, create it
  1248. var isParentChecked = (typeof sessionStorage[groupClass] == "undefined" ? true : sessionStorage[groupClass]=='true');
  1249. CreateParentGroup(isParentChecked); //create the group
  1250. sessionStorage[groupClass] = isParentChecked;
  1251.  
  1252. Waze.app.modeController.model.bind('change:mode', function(model, modeId, context){ //make it reappear after changing modes
  1253. CreateParentGroup((sessionStorage[groupClass]=='true'));
  1254. });
  1255. }
  1256.  
  1257. var buildLayerItem = function(isChecked){
  1258. var groupChildren = $("."+groupClass).parent().parent().find('.children').not('.extended');
  1259. $li = $('<li>');
  1260. $li.html([
  1261. '<div class="controls-container toggler">',
  1262. '<input type="checkbox" id="' + checkboxID + '" class="' + checkboxID + ' toggle">',
  1263. '<label for="' + checkboxID + '"><span class="label-text">' + checkboxText + '</span></label>',
  1264. '</div>',
  1265. ].join(' '));
  1266.  
  1267. groupChildren.append($li);
  1268. $('#' + checkboxID).prop('checked', isChecked);
  1269. $('#' + checkboxID).change(function(){callback(this.checked); sessionStorage[normalizedText] = this.checked;});
  1270. if(!$('#' + groupClass).is(':checked')){
  1271. $('#' + checkboxID).prop('disabled', true);
  1272. callback(false);
  1273. }
  1274.  
  1275. $('#' + groupClass).change(function(){$('#' + checkboxID).prop('disabled', !this.checked); callback(this.checked);});
  1276. };
  1277.  
  1278.  
  1279. Waze.app.modeController.model.bind('change:mode', function(model, modeId, context){
  1280. buildLayerItem((sessionStorage[normalizedText]=='true'));
  1281. });
  1282.  
  1283. buildLayerItem(checked);
  1284. };
  1285. };
  1286.  
  1287. function String(){
  1288. this.toTitleCase = function(str){
  1289. return str.replace(/(?:^|\s)\w/g, function(match) {
  1290. return match.toUpperCase();
  1291. });
  1292. };
  1293. };
  1294. }.call(this));

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址