You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

613 regels
20 KiB

  1. /**
  2. * <div id="app" class="mui-views">
  3. <div class="mui-view">
  4. <div class="mui-navbar">
  5. </div>
  6. <div class="mui-pages">
  7. </div>
  8. </div>
  9. </div>
  10. * @param {Object} $
  11. * @param {Object} window
  12. */
  13. (function($, window) {
  14. var CLASS_LEFT = $.className('left');
  15. var CLASS_CENTER = $.className('center');
  16. var CLASS_RIGHT = $.className('right');
  17. var CLASS_PAGE = $.className('page');
  18. var CLASS_PAGE_LEFT = $.className('page-left');
  19. var CLASS_PAGE_CENTER = $.className('page-center');
  20. var CLASS_NAVBAR_LEFT = $.className('navbar-left');
  21. var CLASS_NAVBAR_CENTER = $.className('navbar-center');
  22. var CLASS_PAGE_SHADOW = $.className('page-shadow');
  23. var CLASS_TRANSITIONING = $.className('transitioning');
  24. var SELECTOR_LEFT = '.' + CLASS_LEFT;
  25. var SELECTOR_CENTER = '.' + CLASS_CENTER;
  26. var SELECTOR_RIGHT = '.' + CLASS_RIGHT;
  27. var SELECTOR_ICON = $.classSelector('.icon');
  28. var SELECTOR_NAVBAR = $.classSelector('.navbar');
  29. var SELECTOR_NAVBAR_INNER = $.classSelector('.navbar-inner');
  30. var SELECTOR_PAGES = $.classSelector('.pages');
  31. var SELECTOR_BTN_NAV = $.classSelector('.btn-nav');
  32. var SELECTOR_PAGE_LEFT = '.' + CLASS_PAGE_LEFT;
  33. var SELECTOR_PAGE_CENTER = '.' + CLASS_PAGE_CENTER;
  34. var SELECTOR_NAVBAR_LEFT = '.' + CLASS_NAVBAR_LEFT;
  35. var SELECTOR_NAVBAR_CENTER = '.' + CLASS_NAVBAR_CENTER;
  36. var View = $.Class.extend({
  37. init: function(element, options) {
  38. this.view = this.element = element;
  39. this.options = $.extend({
  40. animateNavbar: true,
  41. swipeBackPageActiveArea: 30,
  42. hardwareAccelerated: true
  43. }, options);
  44. this.navbars = this.view.querySelector(SELECTOR_NAVBAR);
  45. this.pages = this.view.querySelector(SELECTOR_PAGES);
  46. this.history = []; //history
  47. this.maxScrollX = this.view.offsetWidth;
  48. this.x = this.y = 0;
  49. this.translateZ = this.options.hardwareAccelerated ? ' translateZ(0)' : '';
  50. this.ratio = 0;
  51. this.isBack = true;
  52. this.moved = this.dragging = false;
  53. this.activeNavbar = this.previousNavbar = null;
  54. this.activePage = this.previousPage = null;
  55. this._initPageEventMethod();
  56. this._initDefaultPage();
  57. this._initNavBar();
  58. this.initEvent();
  59. },
  60. _initPageEventMethod: function() {
  61. var self = this;
  62. $.each(['onPageBeforeShow', 'onPageShow', 'onPageBeforeBack', 'onPageBack'], function(index, event) {
  63. self[event + 'Callbacks'] = {};
  64. self[event] = function(page, callback) {
  65. var eventCallbacks = event + 'Callbacks';
  66. if (!self[eventCallbacks].hasOwnProperty(page)) {
  67. self[eventCallbacks][page] = [callback];
  68. } else {
  69. self[eventCallbacks][page].push(callback);
  70. }
  71. };
  72. });
  73. },
  74. _initDefaultPage: function() {
  75. var defaultPage = document.querySelector(this.options.defaultPage);
  76. if (defaultPage) {
  77. this._appendPage(defaultPage);
  78. } else {
  79. throw new Error('defaultPage[' + this.options.defaultPage + '] does not exist');
  80. }
  81. },
  82. initEvent: function() {
  83. this.view.addEventListener('click', this);
  84. this.view.addEventListener('tap', this);
  85. this.pages.addEventListener('drag', this);
  86. this.pages.addEventListener('dragend', this);
  87. this.pages.addEventListener('webkitTransitionEnd', this);
  88. },
  89. handleEvent: function(event) {
  90. switch (event.type) {
  91. case 'click':
  92. this._click(event);
  93. break;
  94. case 'tap':
  95. this._tap(event);
  96. break;
  97. case 'drag':
  98. this._drag(event);
  99. break;
  100. case 'dragend':
  101. this._dragend(event);
  102. break;
  103. case 'webkitTransitionEnd':
  104. this._webkitTransitionEnd(event);
  105. break;
  106. }
  107. },
  108. shadow: function() {
  109. var shadow = document.createElement('div');
  110. shadow.className = CLASS_PAGE_SHADOW;
  111. return shadow;
  112. }(),
  113. _removePage: function(page, navbar) {
  114. this._removeNavbar(page, navbar);
  115. document.body.appendChild(page);
  116. this._cleanPageClass(page);
  117. },
  118. _prependPage: function(page) {
  119. var navbar = page.querySelector(SELECTOR_NAVBAR_INNER);
  120. this._prependNavbar(navbar);
  121. page.classList.add(CLASS_PAGE_LEFT);
  122. this.pages.insertBefore(page, this.pages.firstElementChild);
  123. },
  124. _appendPage: function(page) {
  125. var navbar = page.querySelector(SELECTOR_NAVBAR_INNER);
  126. this._appendNavbar(navbar);
  127. page.classList.add(CLASS_PAGE_CENTER);
  128. this.pages.appendChild(page);
  129. },
  130. _removeNavbar: function(page, navbar) {
  131. page.insertBefore(navbar, page.firstElementChild);
  132. this._cleanNavbarClass(navbar);
  133. },
  134. _prependNavbar: function(navbar) {
  135. navbar.classList.add(CLASS_NAVBAR_LEFT);
  136. this.navbars.insertBefore(navbar, this.navbars.firstElementChild);
  137. },
  138. _appendNavbar: function(navbar) {
  139. navbar.classList.add(CLASS_NAVBAR_CENTER);
  140. this.navbars.appendChild(navbar);
  141. },
  142. _cleanPageClass: function(page) {
  143. page.classList.remove(CLASS_PAGE_CENTER);
  144. page.classList.remove(CLASS_PAGE_LEFT);
  145. },
  146. _cleanNavbarClass: function(navbar) {
  147. navbar.classList.remove(CLASS_NAVBAR_CENTER);
  148. navbar.classList.remove(CLASS_NAVBAR_LEFT);
  149. },
  150. _tap: function(event) {
  151. var target = event.target;
  152. for (; target && target !== document; target = target.parentNode) {
  153. if (target.tagName === 'A' && target.hash) {
  154. var page = document.getElementById(target.hash.replace('#', ''));
  155. if (page && page.classList.contains(CLASS_PAGE)) {
  156. event.stopPropagation();
  157. event.detail.gesture.preventDefault();
  158. this.go(target.hash);
  159. break;
  160. }
  161. }
  162. }
  163. },
  164. _click: function(event) {
  165. var target = event.target;
  166. for (; target && target !== document; target = target.parentNode) {
  167. if (target.tagName === 'A' && target.hash) {
  168. var page = document.getElementById(target.hash.replace('#', ''));
  169. if (page && page.classList.contains(CLASS_PAGE)) {
  170. event.preventDefault();
  171. break;
  172. }
  173. }
  174. }
  175. },
  176. _cleanStyle: function(el) {
  177. if (el) {
  178. el.style.webkitTransform = '';
  179. el.style.opacity = '';
  180. }
  181. },
  182. _webkitTransitionEnd: function(event) {
  183. this.dragging = this.moved = false;
  184. if (this.activePage !== event.target) {
  185. return;
  186. }
  187. this.isInTransition = false;
  188. this.shadow.parentNode === this.activePage && this.activePage.removeChild(this.shadow);
  189. this.previousPageClassList.remove(CLASS_TRANSITIONING);
  190. this.activePageClassList.remove(CLASS_TRANSITIONING);
  191. var self = this;
  192. if ($.os.ios && this.options.animateNavbar && this.previousNavElements && this.activeNavElements) {
  193. var isBack = this.isBack;
  194. $.each(this.previousNavElements, function(i, el) {
  195. el.classList.remove(CLASS_TRANSITIONING);
  196. isBack && self._cleanStyle(el);
  197. });
  198. $.each(this.activeNavElements, function(i, el) {
  199. el.classList.remove(CLASS_TRANSITIONING);
  200. self._cleanStyle(el);
  201. });
  202. if (this.previousNavBackIcon) {
  203. this.previousNavBackIcon.classList.remove(CLASS_TRANSITIONING);
  204. isBack && this._cleanStyle(this.previousNavBackIcon);
  205. }
  206. if (this.activeNavBackIcon) {
  207. this.activeNavBackIcon.classList.remove(CLASS_TRANSITIONING);
  208. this._cleanStyle(this.activeNavBackIcon);
  209. }
  210. } else {
  211. this.previousNavbar.classList.remove(CLASS_TRANSITIONING);
  212. this.activeNavbar.classList.remove(CLASS_TRANSITIONING);
  213. this._cleanStyle(this.previousNavbar);
  214. this._cleanStyle(this.activeNavbar);
  215. }
  216. this._cleanStyle(this.previousPage);
  217. this._cleanStyle(this.activePage);
  218. if (this.ratio <= 0.5) {
  219. return;
  220. }
  221. if (this.isBack) {
  222. this._removePage(this.activePage, this.activeNavbar);
  223. this.previousPageClassList.remove(CLASS_PAGE_LEFT);
  224. this.previousPageClassList.add(CLASS_PAGE_CENTER);
  225. this.previousNavbar.classList.remove(CLASS_NAVBAR_LEFT);
  226. this.previousNavbar.classList.add(CLASS_NAVBAR_CENTER);
  227. if (this.history.length > 0) {
  228. this._prependPage(this.history.pop());
  229. }
  230. this._initNavBar();
  231. this._trigger('pageBack', this.activePage);
  232. this._trigger('pageShow', this.previousPage);
  233. } else {
  234. this.previousPageClassList.add(CLASS_PAGE_LEFT);
  235. this.activePageClassList.add(CLASS_PAGE_CENTER);
  236. this._trigger('pageShow', this.activePage);
  237. }
  238. },
  239. _trigger: function(eventType, page) {
  240. var eventCallbacks = 'on' + eventType.charAt(0).toUpperCase() + eventType.slice(1) + 'Callbacks';
  241. if (this[eventCallbacks].hasOwnProperty(page.id)) {
  242. var callbacks = this[eventCallbacks][page.id];
  243. var event = new CustomEvent(eventType, {
  244. detail: {
  245. page: page
  246. },
  247. bubbles: true,
  248. cancelable: true
  249. });
  250. for (var len = callbacks.length; len--;) {
  251. callbacks[len].apply(this, event);
  252. }
  253. }
  254. $.trigger(this.view, eventType, {
  255. page: page
  256. });
  257. },
  258. _initPageTransform: function() {
  259. this.previousPage = this.pages.querySelector(SELECTOR_PAGE_LEFT);
  260. this.activePage = this.pages.querySelector(SELECTOR_PAGE_CENTER);
  261. if (this.previousPage && this.activePage) {
  262. this.activePage.appendChild(this.shadow);
  263. this.previousPageClassList = this.previousPage.classList;
  264. this.activePageClassList = this.activePage.classList;
  265. this.previousPageStyle = this.previousPage.style;
  266. this.activePageStyle = this.activePage.style;
  267. this.previousPageClassList.remove(CLASS_TRANSITIONING);
  268. this.activePageClassList.remove(CLASS_TRANSITIONING);
  269. if (this.options.animateNavbar && this.navbars) {
  270. this.previousNavbar = this.navbars.querySelector(SELECTOR_NAVBAR_LEFT);
  271. this.activeNavbar = this.navbars.querySelector(SELECTOR_NAVBAR_CENTER);
  272. if (this.previousNavbar && this.activeNavbar) {
  273. this.previousNavElements = this.previousNavbar.querySelectorAll(SELECTOR_LEFT + ',' + SELECTOR_CENTER + ',' + SELECTOR_RIGHT);
  274. this.activeNavElements = this.activeNavbar.querySelectorAll(SELECTOR_LEFT + ',' + SELECTOR_CENTER + ',' + SELECTOR_RIGHT);
  275. this.previousNavBackIcon = this.previousNavbar.querySelector(SELECTOR_LEFT + SELECTOR_BTN_NAV + ' ' + SELECTOR_ICON);
  276. this.activeNavBackIcon = this.activeNavbar.querySelector(SELECTOR_LEFT + SELECTOR_BTN_NAV + ' ' + SELECTOR_ICON);
  277. }
  278. }
  279. this.x = 0;
  280. this.dragging = true;
  281. return true;
  282. }
  283. return false;
  284. },
  285. _initNavBar: function() {
  286. if (this.options.animateNavbar && this.navbars) {
  287. var inners = this.navbars.querySelectorAll(SELECTOR_NAVBAR_INNER);
  288. var inner, left, right, center, leftWidth, rightWidth, centerWidth, noLeft, onRight, currLeft, diff, navbarWidth;
  289. for (var i = 0, len = inners.length; i < len; i++) {
  290. inner = inners[i];
  291. left = inner.querySelector(SELECTOR_LEFT);
  292. right = inner.querySelector(SELECTOR_RIGHT);
  293. center = inner.querySelector(SELECTOR_CENTER);
  294. noLeft = !left;
  295. noRight = !right;
  296. leftWidth = noLeft ? 0 : left.offsetWidth;
  297. rightWidth = noRight ? 0 : right.offsetWidth;
  298. centerWidth = center ? center.offsetWidth : 0;
  299. navbarWidth = this.maxScrollX;
  300. onLeft = inner.classList.contains('navbar-left');
  301. if (noRight) {
  302. currLeft = navbarWidth - centerWidth;
  303. }
  304. if (noLeft) {
  305. currLeft = 0;
  306. }
  307. if (!noLeft && !noRight) {
  308. currLeft = (navbarWidth - rightWidth - centerWidth + leftWidth) / 2;
  309. }
  310. var requiredLeft = (navbarWidth - centerWidth) / 2;
  311. if (navbarWidth - leftWidth - rightWidth > centerWidth) {
  312. if (requiredLeft < leftWidth) {
  313. requiredLeft = leftWidth;
  314. }
  315. if (requiredLeft + centerWidth > navbarWidth - rightWidth) {
  316. requiredLeft = navbarWidth - rightWidth - centerWidth;
  317. }
  318. diff = requiredLeft - currLeft;
  319. } else {
  320. diff = 0;
  321. }
  322. var centerLeft = diff;
  323. if (center) {
  324. center.style.marginLeft = -leftWidth + 'px';
  325. center.mNavbarLeftOffset = -(currLeft + diff) + 30; //这个30是测出来的。后续要实际计算一下
  326. center.mNavbarRightOffset = navbarWidth - currLeft - diff - centerWidth;
  327. }
  328. if (onLeft) center.style.webkitTransform = ('translate3d(' + center.mNavbarLeftOffset + 'px, 0, 0)');
  329. if (!noLeft) {
  330. left.mNavbarLeftOffset = -leftWidth;
  331. left.mNavbarRightOffset = (navbarWidth - leftWidth) / 2;
  332. if (onLeft) left.style.webkitTransform = ('translate3d(' + left[0].mNavbarLeftOffset + 'px, 0, 0)');
  333. }
  334. if (!noRight) {
  335. right.mNavbarLeftOffset = -(navbarWidth - rightWidth) / 2;
  336. right.mNavbarRightOffset = rightWidth;
  337. if (onLeft) right.style.webkitTransform = ('translate3d(' + right[0].mNavbarLeftOffset + 'px, 0, 0)');
  338. }
  339. }
  340. }
  341. },
  342. _drag: function(event) {
  343. if (this.isInTransition) {
  344. return;
  345. }
  346. var detail = event.detail;
  347. if (!this.dragging) {
  348. if ((detail.start.x - this.view.offsetLeft) < this.options.swipeBackPageActiveArea) {
  349. this.isBack = true;
  350. this._initPageTransform();
  351. }
  352. }
  353. if (this.dragging) {
  354. var deltaX = 0;
  355. if (!this.moved) { //start
  356. deltaX = detail.deltaX;
  357. $.gestures.touch.lockDirection = true; //锁定方向
  358. $.gestures.touch.startDirection = detail.direction;
  359. } else { //move
  360. deltaX = detail.deltaX - detail.lastDeltaX;
  361. }
  362. var newX = this.x + deltaX;
  363. if (newX < 0 || newX > this.maxScrollX) {
  364. newX = newX < 0 ? 0 : this.maxScrollX;
  365. }
  366. event.stopPropagation();
  367. detail.gesture.preventDefault();
  368. if (!this.requestAnimationFrame) {
  369. this._updateTranslate();
  370. }
  371. this.moved = true;
  372. this.x = newX;
  373. this.y = 0;
  374. }
  375. },
  376. _dragend: function(event) {
  377. if (!this.moved) {
  378. return;
  379. }
  380. event.stopPropagation();
  381. var detail = event.detail;
  382. this._clearRequestAnimationFrame();
  383. this._prepareTransition();
  384. this.ratio = this.x / this.maxScrollX;
  385. if (this.ratio === 1 || this.ratio === 0) {
  386. $.trigger(this.activePage, 'webkitTransitionEnd');
  387. return;
  388. }
  389. if (this.ratio > 0.5) {
  390. this.setTranslate(this.maxScrollX, 0);
  391. } else {
  392. this._cleanStyle(this.previousPage);
  393. this._cleanStyle(this.activePage);
  394. }
  395. },
  396. _prepareTransition: function() {
  397. this.isInTransition = true;
  398. this.previousPageClassList.add(CLASS_TRANSITIONING);
  399. this.activePageClassList.add(CLASS_TRANSITIONING);
  400. var self = this;
  401. if (this.options.animateNavbar && this.previousNavElements && this.activeNavElements) {
  402. this.previousNavbar.classList.add(CLASS_TRANSITIONING);
  403. this.activeNavbar.classList.add(CLASS_TRANSITIONING);
  404. $.each(this.previousNavElements, function(i, el) {
  405. el.classList.add(CLASS_TRANSITIONING);
  406. self._cleanStyle(el);
  407. });
  408. $.each(this.activeNavElements, function(i, el) {
  409. el.classList.add(CLASS_TRANSITIONING);
  410. self._cleanStyle(el);
  411. });
  412. if (this.previousNavBackIcon) {
  413. this._cleanStyle(this.previousNavBackIcon);
  414. this.previousNavBackIcon.classList.add(CLASS_TRANSITIONING);
  415. }
  416. if (this.activeNavBackIcon) {
  417. this._cleanStyle(this.activeNavBackIcon);
  418. this.activeNavBackIcon.classList.add(CLASS_TRANSITIONING);
  419. }
  420. }
  421. },
  422. _clearRequestAnimationFrame: function() {
  423. if (this.requestAnimationFrame) {
  424. cancelAnimationFrame(this.requestAnimationFrame);
  425. this.requestAnimationFrame = null;
  426. }
  427. },
  428. _getTranslateStr: function(x, y) {
  429. if (this.options.hardwareAccelerated) {
  430. return 'translate3d(' + x + 'px,' + y + 'px,0px) ' + this.translateZ;
  431. }
  432. return 'translate(' + x + 'px,' + y + 'px) ';
  433. },
  434. _updateTranslate: function() {
  435. var self = this;
  436. if (self.x !== self.lastX || self.y !== self.lastY) {
  437. self.setTranslate(self.x, self.y);
  438. }
  439. self.requestAnimationFrame = requestAnimationFrame(function() {
  440. self._updateTranslate();
  441. });
  442. },
  443. _setNavbarTranslate: function(x, y) {
  444. var percentage = x / this.maxScrollX;
  445. //only for ios
  446. if ($.os.ios && this.options.animateNavbar && this.previousNavElements && this.activeNavElements) {
  447. var i, len, style, el;
  448. for (i = 0, len = this.activeNavElements.length; i < len; i++) {
  449. el = this.activeNavElements[i];
  450. style = el.style;
  451. style.opacity = (1 - percentage * (el.classList.contains(CLASS_LEFT) ? 3.5 : 1.3));
  452. if (!el.classList.contains(CLASS_RIGHT)) {
  453. var activeNavTranslate = percentage * el.mNavbarRightOffset;
  454. el.style.webkitTransform = ('translate3d(' + activeNavTranslate + 'px,0,0)');
  455. if (el.classList.contains(CLASS_LEFT) && this.activeNavBackIcon) {
  456. this.activeNavBackIcon.style.webkitTransform = ('translate3d(' + -activeNavTranslate + 'px,0,0)');
  457. }
  458. }
  459. }
  460. for (i = 0, len = this.previousNavElements.length; i < len; i++) {
  461. el = this.previousNavElements[i];
  462. style = el.style;
  463. style.opacity = percentage * 1.3 - 0.3;
  464. if (!el.classList.contains(CLASS_RIGHT)) {
  465. var previousNavTranslate = el.mNavbarLeftOffset * (1 - percentage);
  466. el.style.webkitTransform = ('translate3d(' + previousNavTranslate + 'px,0,0)');
  467. if (el.classList.contains(CLASS_LEFT) && this.previousNavBackIcon) {
  468. this.previousNavBackIcon.style.webkitTransform = ('translate3d(' + -previousNavTranslate + 'px,0,0)');
  469. }
  470. }
  471. }
  472. } else {
  473. this.activeNavbar.style.opacity = 1 - percentage * 1.3;
  474. this.previousNavbar.style.opacity = percentage * 1.3 - 0.3;
  475. }
  476. },
  477. setTranslate: function(x, y) {
  478. this.x = x;
  479. this.y = y;
  480. this.previousPage.style.opacity = 0.9 + 0.1 * x / this.maxScrollX;
  481. if ($.os.ios) { //only for ios
  482. this.previousPage.style['webkitTransform'] = this._getTranslateStr((x / 5 - this.maxScrollX / 5), y);
  483. }
  484. this.activePage.style['webkitTransform'] = this._getTranslateStr(x, y);
  485. if (this.options.animateNavbar) {
  486. this._setNavbarTranslate(x, y);
  487. }
  488. this.lastX = this.x;
  489. this.lastY = this.y;
  490. },
  491. canBack: function() {
  492. return this.pages.querySelector(SELECTOR_PAGE_LEFT);
  493. },
  494. back: function() {
  495. if (this.isInTransition) {
  496. return;
  497. }
  498. this.isBack = true;
  499. this.ratio = 1;
  500. if (this._initPageTransform()) {
  501. this._trigger('pageBeforeBack', this.activePage);
  502. this._trigger('pageBeforeShow', this.previousPage);
  503. this._prepareTransition();
  504. this.previousPage.offsetHeight;
  505. this.activePage.offsetHeight;
  506. this.setTranslate(this.maxScrollX, 0);
  507. }
  508. },
  509. go: function(pageSelector) {
  510. if (this.isInTransition) {
  511. return;
  512. }
  513. var nextPage = document.querySelector(pageSelector);
  514. if (nextPage) {
  515. var nextNavbar = nextPage.querySelector(SELECTOR_NAVBAR_INNER);
  516. var previousNavbar = this.navbars.querySelector(SELECTOR_NAVBAR_LEFT);
  517. var activeNavbar = this.navbars.querySelector(SELECTOR_NAVBAR_CENTER);
  518. var previousPage = this.pages.querySelector(SELECTOR_PAGE_LEFT);
  519. var activePage = this.pages.querySelector(SELECTOR_PAGE_CENTER);
  520. if (previousNavbar && previousPage) {
  521. this._removePage(previousPage, previousNavbar);
  522. this.history.push(previousPage); //add to history
  523. }
  524. if (activeNavbar) {
  525. activeNavbar.classList.remove(CLASS_NAVBAR_CENTER);
  526. activeNavbar.classList.add(CLASS_NAVBAR_LEFT);
  527. }
  528. if (activePage) {
  529. activePage.classList.remove(CLASS_PAGE_CENTER);
  530. activePage.style.webkitTransform = 'translate3d(0,0,0)';
  531. activePage.classList.add(CLASS_PAGE_LEFT);
  532. }
  533. nextPage.style.webkitTransform = 'translate3d(100%,0,0)';
  534. this._appendPage(nextPage);
  535. nextPage.appendChild(this.shadow); //shadow
  536. nextPage.offsetHeight; //force
  537. this.isBack = false;
  538. this.ratio = 1;
  539. this._initPageTransform();
  540. this._initNavBar();
  541. this._setNavbarTranslate(this.maxScrollX, 0);
  542. //force
  543. this.previousPage.offsetHeight;
  544. this.activePage.offsetHeight;
  545. this.previousNavbar.offsetHeight;
  546. this.activeNavbar.offsetHeight;
  547. this._trigger('pageBeforeShow', this.activePage);
  548. this._prepareTransition();
  549. this.setTranslate(0, 0);
  550. }
  551. }
  552. });
  553. $.fn.view = function(options) {
  554. var self = this[0];
  555. var viewApi = null;
  556. var id = self.getAttribute('data-view');
  557. if (!id) {
  558. id = ++$.uuid;
  559. $.data[id] = viewApi = new View(self, options);
  560. } else {
  561. viewApi = $.data[id];
  562. }
  563. return viewApi;
  564. }
  565. })(mui, window);