WazeWrap Beta

A base library for WME script writers

目前為 2016-11-17 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/24870/158442/WazeWrap%20Beta.js

  1. // ==UserScript==
  2. // @name WazeWrap Beta
  3. // @namespace https://greasyfork.org/users/30701-justins83-waze
  4. // @version 0.1.4
  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. (function() {
  17.  
  18. function bootstrap(tries) {
  19. tries = tries || 1;
  20. if (W &&
  21. W.map &&
  22. W.model &&
  23. W.loginManager &&
  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. //extendModel();
  37. //extendGeometry();
  38.  
  39. var oldLib = window.WazeWrap;
  40.  
  41. var root = this;
  42. var WazeWrap = {};
  43.  
  44. WazeWrap.Version = "0.1.4";
  45.  
  46. SetUpRequire();
  47.  
  48. WazeWrap.isBetaEditor = /beta/.test(location.href);
  49. WazeWrap.test = "test";
  50. WazeWrap.Geometry = new Geometry;
  51. WazeWrap.Model = new Model;
  52. WazeWrap.Interface = new Interface;
  53. WazeWrap.User = new User;
  54. WazeWrap.Util = new Util;
  55. root.WazeWrap = WazeWrap;
  56.  
  57. console.log('WazeWrap Loaded');
  58. };
  59.  
  60.  
  61. function SetUpRequire(){
  62. if(require)
  63. return;
  64.  
  65. // setup one global var and put all in
  66. var WMEAPI = {};
  67.  
  68. // detect URL of WME source code
  69. WMEAPI.scripts = document.getElementsByTagName('script');
  70. WMEAPI.url=null;
  71. for (i=0;i<WMEAPI.scripts.length;i++){
  72. if (WMEAPI.scripts[i].src.indexOf('/assets-editor/js/app')!=-1)
  73. {
  74. WMEAPI.url=WMEAPI.scripts[i].src;
  75. break;
  76. }
  77. }
  78. if (WMEAPI.url==null)
  79. throw new Error("WME Hack: can't detect WME main JS");
  80.  
  81.  
  82. // setup a fake require and require.define
  83. WMEAPI.require=function (e) {
  84. if (WMEAPI.require.define.modules.hasOwnProperty(e))
  85. return WMEAPI.require.define.modules[e];
  86. else
  87. console.error('Require failed on ' + e, WMEAPI.require.define.modules);
  88. return null;
  89. };
  90.  
  91. WMEAPI.require.define=function (m) {
  92. if (WMEAPI.require.define.hasOwnProperty('modules')==false)
  93. WMEAPI.require.define.modules={};
  94. for (var p in m){
  95. WMEAPI.require.define.modules[p]=m[p];
  96. }
  97. };
  98.  
  99. // save the original webpackJsonp function
  100. WMEAPI.tmp = window.webpackJsonp;
  101.  
  102. // taken from WME code: this function is a wrapper that setup the API and may call recursively other functions
  103. WMEAPI.t = function (n) {
  104. if (WMEAPI.s[n]) return WMEAPI.s[n].exports;
  105. var r = WMEAPI.s[n] = {
  106. exports: {},
  107. id: n,
  108. loaded: !1
  109. };
  110. return WMEAPI.e[n].call(r.exports, r, r.exports, WMEAPI.t), r.loaded = !0, r.exports;
  111. };
  112.  
  113. // e is a copy of all WME funcs because function t need to access to this list
  114. WMEAPI.e=[];
  115.  
  116. // the patch
  117. window.webpackJsonp = function(a, i) {
  118. // our API but we will use it only to build the require stuffs
  119. var api={};
  120. // taken from WME code. a is [1], so...
  121. 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;
  122. var unknownCount=0;
  123. var classname, funcStr;
  124. // copy i in e and keep a link from classname to index in e
  125. for (o in i){
  126. WMEAPI.e[o] = i[o];
  127. funcStr = i[o].toString();
  128. classname = funcStr.match(/CLASS_NAME:\"([^\"]*)\"/);
  129. if (classname){
  130. // keep the link.
  131. api[classname[1].replace(/\./g,'/').replace(/^W\//, 'Waze/')]={index: o, func: WMEAPI.e[o]};
  132. }
  133. else{
  134. api['Waze/Unknown/' + unknownCount]={index: o, func: WMEAPI.e[o]};
  135. unknownCount++;
  136. }
  137. }
  138. // taken from WME code: it calls the original webpackJsonp and do something else, but I don't really know what.
  139. // removed the call to the original webpackJsonp: still works...
  140. //for (tmp && tmp(a, i); l.length;) l.shift().call(null, t);
  141. for (; l.length;) l.shift().call(null, WMEAPI.t);
  142. WMEAPI.s[0] = 0;
  143. // run the first func of WME. This first func will call recusrsively all funcs needed to setup the API.
  144. // After this call, s will contain all instanciables classes.
  145. //var ret = WMEAPI.t(0);
  146. // now, build the requires thanks to the link we've built in var api.
  147. var module={};
  148. var apiFuncName;
  149. unknownCount=0;
  150. for (o in i){
  151. funcStr = i[o].toString();
  152. classname = funcStr.match(/CLASS_NAME:\"([^\"]*)\"/);
  153. if (classname){
  154. module={};
  155. apiFuncName = classname[1].replace(/\./g,'/').replace(/^W\//, 'Waze/');
  156. module[apiFuncName]=WMEAPI.t(api[apiFuncName].index);
  157. WMEAPI.require.define(module);
  158. }
  159. else{
  160. var matches = funcStr.match(/SEGMENT:"segment",/);
  161. if (matches){
  162. module={};
  163. apiFuncName='Waze/Model/ObjectType';
  164. module[apiFuncName]=WMEAPI.t(api['Waze/Unknown/' + unknownCount].index);
  165. WMEAPI.require.define(module);
  166. }
  167. unknownCount++;
  168. }
  169. }
  170.  
  171. // restore the original func
  172. window.webpackJsonp=WMEAPI.tmp;
  173.  
  174. // set the require public if needed
  175. // if so: others scripts must wait for the window.require to be available before using it.
  176. window.require = WMEAPI.require;
  177. // all available functions are in WMEAPI.require.define.modules
  178. // console.debug this variable to read it:
  179. // console.debug('Modules: ', WMEAPI.require.define.modules);
  180. // run your script here:
  181. // setTimeout(yourscript);
  182. // again taken from WME code. Not sure about what it does.
  183. //if (i[0]) return ret;
  184. };
  185.  
  186. // some kind of global vars and init
  187. WMEAPI.s = {};
  188. WMEAPI.r = {
  189. 0: 0
  190. };
  191.  
  192. // hacking finished
  193.  
  194. // load again WME through our patched func
  195. WMEAPI.WMEHACK_Injected_script = document.createElement("script");
  196. WMEAPI.WMEHACK_Injected_script.setAttribute("type", "application/javascript");
  197. WMEAPI.WMEHACK_Injected_script.src = WMEAPI.url;
  198. document.body.appendChild(WMEAPI.WMEHACK_Injected_script);
  199. }
  200.  
  201. function Geometry(){
  202. //var geometry = WazeWrap.Geometry;
  203.  
  204. //Converts to "normal" GPS coordinates
  205. this.ConvertTo4326 = function (long, lat){
  206. var projI=new OpenLayers.Projection("EPSG:900913");
  207. var projE=new OpenLayers.Projection("EPSG:4326");
  208. return (new OpenLayers.LonLat(long, lat)).transform(projI,projE);
  209. };
  210. this.ConvertTo900913 = function (long, lat){
  211. var projI=new OpenLayers.Projection("EPSG:900913");
  212. var projE=new OpenLayers.Projection("EPSG:4326");
  213. return (new OpenLayers.LonLat(long, lat)).transform(projE,projI);
  214. };
  215.  
  216. //Converts the Longitudinal offset to an offset in 4326 gps coordinates
  217. this.CalculateLongOffsetGPS = function(longMetersOffset, long, lat)
  218. {
  219. var R= 6378137; //Earth's radius
  220. var dLon = longMetersOffset / (R * Math.cos(Math.PI * lat / 180)); //offset in radians
  221. var lon0 = dLon * (180 / Math.PI); //offset degrees
  222.  
  223. return lon0;
  224. };
  225.  
  226. //Converts the Latitudinal offset to an offset in 4326 gps coordinates
  227. this.CalculateLatOffsetGPS = function(latMetersOffset, lat)
  228. {
  229. var R= 6378137; //Earth's radius
  230. var dLat = latMetersOffset/R;
  231. var lat0 = dLat * (180 /Math.PI); //offset degrees
  232.  
  233. return lat0;
  234. };
  235. this.isLonLatInMapExtent = function (lonLat) {
  236. 'use strict';
  237. return lonLat && W.map.getExtent().containsLonLat(lonLat);
  238. };
  239. this.isGeometryInMapExtent = function (geometry) {
  240. 'use strict';
  241. return geometry && geometry.getBounds &&
  242. W.map.getExtent().intersectsBounds(geometry.getBounds());
  243. };
  244. };
  245.  
  246. function Model(){
  247. //var model = WazeWrap.Model;
  248.  
  249. this.getPrimaryStreetID = function(segmentID){
  250. return W.model.segments.get(segmentID).attributes.primaryStreetID;
  251. };
  252.  
  253. this.getStreetName = function(primaryStreetID){
  254. return W.model.streets.get(PrimaryStreetID).name;
  255. };
  256.  
  257. this.getCityID = function(primaryStreetID){
  258. return W.model.streets.get(primaryStreetID).cityID;
  259. };
  260.  
  261. this.getCityName = function(primaryStreetID){
  262. return W.model.cities.get(this.getCityID(primaryStreetID)).attributes.Name;
  263. };
  264.  
  265. this.getStateName = function(primaryStreetID){
  266. return W.model.states.get(getStateID(primaryStreetID)).Name;
  267. };
  268.  
  269. this.getStateID = function(primaryStreetID){
  270. return W.model.cities.get(primaryStreetID).attributes.stateID;
  271. };
  272.  
  273. this.getCountryID = function(primaryStreetID){
  274. return W.model.cities.get(this.getCityID(primaryStreetID)).attributes.CountryID;
  275. };
  276.  
  277. this.getCountryName = function(primaryStreetID){
  278. return W.model.countries.get(getCountryID(primaryStreetID)).name;
  279. };
  280.  
  281. this.getCityNameFromSegmentObj = function(segObj){
  282. return this.getCityName(segObj.attributes.primaryStreetID);
  283. };
  284.  
  285. this.getStateNameFromSegmentObj = function(segObj){
  286. return this.getStateName(segObj.attributes.primaryStreetID);
  287. };
  288.  
  289. //returns an array of segmentIDs for all segments that are part of the same roundabout as the passed segment
  290. this.getAllRoundaboutSegmentsFromObj = function(segObj){
  291. if(segObj.model.attributes.junctionID === null)
  292. return null;
  293.  
  294. return W.model.junctions.objects[segObj.model.attributes.junctionID].segIDs;
  295. };
  296.  
  297. this.getAllRoundaboutJunctionNodesFromObj = function(segObj){
  298. var RASegs = this.getAllRoundaboutSegmentsFromObj(segObj);
  299. var RAJunctionNodes = [];
  300. for(i=0; i< RASegs.length; i++){
  301. RAJunctionNodes.push(W.model.nodes.objects[W.model.segments.get(RASegs[i]).attributes.toNodeID]);
  302.  
  303. }
  304. return RAJunctionNodes;
  305. };
  306.  
  307. this.isRoundaboutSegmentID = function(segmentID){
  308. if(W.model.segments.get(segmentID).attributes.junctionID === null)
  309. return false;
  310. else
  311. return true;
  312. };
  313.  
  314. this.isRoundaboutSegmentObj = function(segObj){
  315. if(segObj.model.attributes.junctionID === null)
  316. return false;
  317. else
  318. return true;
  319. };
  320.  
  321. /**
  322. * Defers execution of a callback function until the WME map and data
  323. * model are ready. Call this function before calling a function that
  324. * causes a map and model reload, such as W.map.moveTo(). After the
  325. * move is completed the callback function will be executed.
  326. * @function WazeWrap.Model.onModelReady
  327. * @param {Function} callback The callback function to be executed.
  328. * @param {Boolean} now Whether or not to call the callback now if the
  329. * model is currently ready.
  330. * @param {Object} context The context in which to call the callback.
  331. */
  332. this.onModelReady = function (callback, now, context) {
  333. var deferModelReady = function () {
  334. return $.Deferred(function (dfd) {
  335. var resolve = function () {
  336. dfd.resolve();
  337. W.model.events.unregister('mergeend', null, resolve);
  338. };
  339. W.model.events.register('mergeend', null, resolve);
  340. }).promise();
  341. };
  342. var deferMapReady = function () {
  343. return $.Deferred(function (dfd) {
  344. var resolve = function () {
  345. dfd.resolve();
  346. W.vent.off('operationDone', resolve);
  347. };
  348. W.vent.on('operationDone', resolve);
  349. }).promise();
  350. };
  351.  
  352. if (typeof callback === 'function') {
  353. context = context || callback;
  354. if (now && WazeWrap.Util.mapReady() && WazeWrap.Util.modelReady()) {
  355. callback.call(context);
  356. } else {
  357. $.when(deferMapReady() && deferModelReady()).
  358. then(function () {
  359. callback.call(context);
  360. });
  361. }
  362. }
  363. };
  364. };
  365. function User(){
  366. this.Rank = function(){
  367. return W.loginManager.user.normalizedLevel;
  368. };
  369.  
  370. this.Username = function(){
  371. return W.loginManager.user.userName;
  372. };
  373.  
  374. this.isCM = function(){
  375. if(W.loginManager.user.editableCountryIDs.length > 0)
  376. return true;
  377. else
  378. return false;
  379. };
  380. this.isAM = function(){
  381. return W.loginManager.user.isAreaManager;
  382. };
  383. };
  384. function Util(){
  385. /**
  386. * Function to defer function execution until an element is present on
  387. * the page.
  388. * @function WazeWrap.Util.waitForElement
  389. * @param {String} selector The CSS selector string or a jQuery object
  390. * to find before executing the callback.
  391. * @param {Function} callback The function to call when the page
  392. * element is detected.
  393. * @param {Object} [context] The context in which to call the callback.
  394. */
  395. this.waitForElement = function (selector, callback, context) {
  396. var jqObj;
  397.  
  398. if (!selector || typeof callback !== 'function') {
  399. return;
  400. }
  401.  
  402. jqObj = typeof selector === 'string' ?
  403. $(selector) : selector instanceof $ ? selector : null;
  404.  
  405. if (!jqObj.size()) {
  406. window.requestAnimationFrame(function () {
  407. WazeWrap.Util.waitForElement(selector, callback, context);
  408. });
  409. } else {
  410. callback.call(context || callback);
  411. }
  412. };
  413.  
  414. /**
  415. * Function to track the ready state of the map.
  416. * @function WazeWrap.Util.mapReady
  417. * @return {Boolean} Whether or not a map operation is pending or
  418. * undefined if the function has not yet seen a map ready event fired.
  419. */
  420. this.mapReady = function () {
  421. var mapReady = true;
  422. W.vent.on('operationPending', function () {
  423. mapReady = false;
  424. });
  425. W.vent.on('operationDone', function () {
  426. mapReady = true;
  427. });
  428. return function () {
  429. return mapReady;
  430. };
  431. } ();
  432.  
  433. /**
  434. * Function to track the ready state of the model.
  435. * @function WazeWrap.Util.modelReady
  436. * @return {Boolean} Whether or not the model has loaded objects or
  437. * undefined if the function has not yet seen a model ready event fired.
  438. */
  439. this.modelReady = function () {
  440. var modelReady = true;
  441. W.model.events.register('mergestart', null, function () {
  442. modelReady = false;
  443. });
  444. W.model.events.register('mergeend', null, function () {
  445. modelReady = true;
  446. });
  447. return function () {
  448. return modelReady;
  449. };
  450. } ();
  451. };
  452.  
  453. function Interface() {
  454. /**
  455. * Generates id for message bars.
  456. * @private
  457. */
  458. var getNextID = function () {
  459. var id = 1;
  460. return function () {
  461. return id++;
  462. };
  463. } ();
  464. this.Shortcut = OL.Class(this, /** @lends WazeWrap.Interface.Shortcut.prototype */ {
  465. name: null,
  466. group: null,
  467. shortcut: {},
  468. callback: null,
  469. scope: null,
  470. groupExists: false,
  471. actionExists: false,
  472. eventExists: false,
  473. defaults: {
  474. group: 'default'
  475. },
  476. /**
  477. * Creates a new {WazeWrap.Interface.Shortcut}.
  478. * @class
  479. * @name WazeWrap.Interface.Shortcut
  480. * @param name {String} The name of the shortcut.
  481. * @param group {String} The name of the shortcut group.
  482. * @param shortcut {String} The shortcut key(s). The shortcut
  483. * should be of the form 'i' where i is the keyboard shortuct or
  484. * include modifier keys such as 'CSA+i', where C = the control
  485. * key, S = the shift key, A = the alt key, and i = the desired
  486. * keyboard shortcut. The modifier keys are optional.
  487. * @param callback {Function} The function to be called by the
  488. * shortcut.
  489. * @param scope {Object} The object to be used as this by the
  490. * callback.
  491. * @return {WazeWrap.Interface.Shortcut} The new shortcut object.
  492. * @example //Creates new shortcut and adds it to the map.
  493. * shortcut = new WazeWrap.Interface.Shortcut('myName', 'myGroup', 'C+p', callbackFunc, null).add();
  494. */
  495. initialize: function (name, group, shortcut, callback, scope) {
  496. if ('string' === typeof name && name.length > 0 &&
  497. 'string' === typeof shortcut && shortcut.length > 0 &&
  498. 'function' === typeof callback) {
  499. this.name = name;
  500. this.group = group || this.defaults.group;
  501. this.callback = callback;
  502. this.shortcut[shortcut] = name;
  503. if ('object' !== typeof scope) {
  504. this.scope = null;
  505. } else {
  506. this.scope = scope;
  507. }
  508. return this;
  509. }
  510. },
  511. /**
  512. * Determines if the shortcut's group already exists.
  513. * @private
  514. */
  515. doesGroupExist: function () {
  516. this.groupExists = 'undefined' !== typeof W.accelerators.Groups[this.group] &&
  517. undefined !== typeof W.accelerators.Groups[this.group].members &&
  518. W.accelerators.Groups[this.group].length > 0;
  519. return this.groupExists;
  520. },
  521. /**
  522. * Determines if the shortcut's action already exists.
  523. * @private
  524. */
  525. doesActionExist: function () {
  526. this.actionExists = 'undefined' !== typeof W.accelerators.Actions[this.name];
  527. return this.actionExists;
  528. },
  529. /**
  530. * Determines if the shortcut's event already exists.
  531. * @private
  532. */
  533. doesEventExist: function () {
  534. this.eventExists = 'undefined' !== typeof W.accelerators.events.listeners[this.name] &&
  535. W.accelerators.events.listeners[this.name].length > 0 &&
  536. this.callback === W.accelerators.events.listeners[this.name][0].func &&
  537. this.scope === W.accelerators.events.listeners[this.name][0].obj;
  538. return this.eventExists;
  539. },
  540. /**
  541. * Creates the shortcut's group.
  542. * @private
  543. */
  544. createGroup: function () {
  545. W.accelerators.Groups[this.group] = [];
  546. W.accelerators.Groups[this.group].members = [];
  547. },
  548. /**
  549. * Registers the shortcut's action.
  550. * @private
  551. */
  552. addAction: function () {
  553. W.accelerators.addAction(this.name, { group: this.group });
  554. },
  555. /**
  556. * Registers the shortcut's event.
  557. * @private
  558. */
  559. addEvent: function () {
  560. W.accelerators.events.register(this.name, this.scope, this.callback);
  561. },
  562. /**
  563. * Registers the shortcut's keyboard shortcut.
  564. * @private
  565. */
  566. registerShortcut: function () {
  567. W.accelerators._registerShortcuts(this.shortcut);
  568. },
  569. /**
  570. * Adds the keyboard shortcut to the map.
  571. * @return {WazeWrap.Interface.Shortcut} The keyboard shortcut.
  572. */
  573. add: function () {
  574. /* If the group is not already defined, initialize the group. */
  575. if (!this.doesGroupExist()) {
  576. this.createGroup();
  577. }
  578.  
  579. /* Clear existing actions with same name */
  580. if (this.doesActionExist()) {
  581. W.accelerators.Actions[this.name] = null;
  582. }
  583. this.addAction();
  584.  
  585. /* Register event only if it's not already registered */
  586. if (!this.doesEventExist()) {
  587. this.addEvent();
  588. }
  589.  
  590. /* Finally, register the shortcut. */
  591. this.registerShortcut();
  592. return this;
  593. },
  594. /**
  595. * Removes the keyboard shortcut from the map.
  596. * @return {WazeWrap.Interface.Shortcut} The keyboard shortcut.
  597. */
  598. remove: function () {
  599. if (this.doesEventExist()) {
  600. W.accelerators.events.unregister(this.name, this.scope, this.callback);
  601. }
  602. if (this.doesActionExist()) {
  603. delete W.accelerators.Actions[this.name];
  604. }
  605. //remove shortcut?
  606. return this;
  607. },
  608. /**
  609. * Changes the keyboard shortcut and applies changes to the map.
  610. * @return {WazeWrap.Interface.Shortcut} The keyboard shortcut.
  611. */
  612. change: function (shortcut) {
  613. if (shortcut) {
  614. this.shortcut = {};
  615. this.shortcut[shortcut] = this.name;
  616. this.registerShortcut();
  617. }
  618. return this;
  619. }
  620. }),
  621.  
  622. this.Tab = OL.Class(this, {
  623. /** @lends WazeWrap.Interface.Tab */
  624. TAB_SELECTOR: '#user-tabs ul.nav-tabs',
  625. CONTENT_SELECTOR: '#user-info div.tab-content',
  626. callback: null,
  627. $content: null,
  628. context: null,
  629. $tab: null,
  630. /**
  631. * Creates a new WazeWrap.Interface.Tab. The tab is appended to the WME
  632. * editor sidebar and contains the passed HTML content.
  633. * @class
  634. * @name WazeWrap.Interface.Tab
  635. * @param {String} name The name of the tab. Should not contain any
  636. * special characters.
  637. * @param {String} content The HTML content of the tab.
  638. * @param {Function} [callback] A function to call upon successfully
  639. * appending the tab.
  640. * @param {Object} [context] The context in which to call the callback
  641. * function.
  642. * @return {WazeWrap.Interface.Tab} The new tab object.
  643. * @example //Creates new tab and adds it to the page.
  644. * new WazeWrap.Interface.Tab('thebestscriptever', '<div>Hello World!</div>');
  645. */
  646. initialize: function (name, content, callback, context) {
  647. var idName, i = 0;
  648. if (name && 'string' === typeof name &&
  649. content && 'string' === typeof content) {
  650. if (callback && 'function' === typeof callback) {
  651. this.callback = callback;
  652. this.context = context || callback;
  653. }
  654. /* Sanitize name for html id attribute */
  655. idName = name.toLowerCase().replace(/[^a-z-_]/g, '');
  656. /* Make sure id will be unique on page */
  657. while (
  658. $('#sidepanel-' + (i ? idName + i : idName)).length > 0) {
  659. i++;
  660. }
  661. if (i) {
  662. idName = idName + i;
  663. }
  664. /* Create tab and content */
  665. this.$tab = $('<li/>')
  666. .append($('<a/>')
  667. .attr({
  668. 'href': '#sidepanel-' + idName,
  669. 'data-toggle': 'tab',
  670. })
  671. .text(name));
  672. this.$content = $('<div/>')
  673. .addClass('tab-pane')
  674. .attr('id', 'sidepanel-' + idName)
  675. .html(content);
  676.  
  677. this.appendTab();
  678. }
  679. },
  680.  
  681. append: function (content) {
  682. this.$content.append(content);
  683. },
  684.  
  685. appendTab: function () {
  686. WazeWrap.Util.waitForElement(
  687. this.TAB_SELECTOR + ',' + this.CONTENT_SELECTOR,
  688. function () {
  689. $(this.TAB_SELECTOR).append(this.$tab);
  690. $(this.CONTENT_SELECTOR).first().append(this.$content);
  691. if (this.callback) {
  692. this.callback.call(this.context);
  693. }
  694. }, this);
  695. },
  696.  
  697. clearContent: function () {
  698. this.$content.empty();
  699. },
  700.  
  701. destroy: function () {
  702. this.$tab.remove();
  703. this.$content.remove();
  704. }
  705. });
  706. };
  707.  
  708. }.call(this));