Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Commit

Permalink
fix(lab): remove es6 features from lab
Browse files Browse the repository at this point in the history
  • Loading branch information
mhartington committed Jul 27, 2017
1 parent 8f308ca commit 41a1335
Showing 1 changed file with 36 additions and 37 deletions.
73 changes: 36 additions & 37 deletions lab/static/js/lab.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,58 @@ var $ = document.querySelector.bind(document);

var API_ROOT = '/ionic-lab/api/v1';

var APP_CONFIG = {}
var APP_CONFIG = {};

function loadAppConfig() {
var req = new XMLHttpRequest();
req.addEventListener('load', function(e) {
setAppConfig(JSON.parse(req.response));
})
req.open('GET', API_ROOT + '/app-config', true)
});
req.open('GET', API_ROOT + '/app-config', true);
req.send(null);
}

function setAppConfig(data) {
APP_CONFIG = data;
}


function buildMenu() {
buildComponentsMenu();
const sidebar = $('#sidebar');
const topLevels = sidebar.querySelectorAll('#menu > li > a');
var sidebar = $('#sidebar');
var topLevels = sidebar.querySelectorAll('#menu > li > a');

const lastMenuConfig = window.localStorage.getItem('ionic_labmenu');
if(lastMenuConfig === 'true' || lastMenuConfig === null) {
var lastMenuConfig = window.localStorage.getItem('ionic_labmenu');
if (lastMenuConfig === 'true' || lastMenuConfig === null) {
sidebar.classList.remove('hidden');
}

Array.prototype.map.call(topLevels, a => {
if(!a.href) {
a.addEventListener('click', e => {
if(a.parentNode.classList.contains('expanded')) {
Array.prototype.map.call(topLevels, function(a) {
if (!a.href) {
a.addEventListener('click', function(e) {
if (a.parentNode.classList.contains('expanded')) {
a.parentNode.classList.remove('expanded');
} else {
a.parentNode.classList.add('expanded');
}
e.preventDefault();
});
}
})
});

$('#view-ad').addEventListener('click', (e) => {
$('#view-ad').addEventListener('click', function(e) {
var win = window.open('http://view.ionic.io/', '_blank');
win.focus();
})
});

const toggleMenu = e => {
if(sidebar.classList.contains('hidden')) {
var toggleMenu = function(e) {
if (sidebar.classList.contains('hidden')) {
sidebar.classList.remove('hidden');
window.localStorage.setItem('ionic_labmenu', 'true');
} else {
sidebar.classList.add('hidden');
window.localStorage.setItem('ionic_labmenu', 'false');
}
}
};

$('#menu-toggle').addEventListener('click', toggleMenu);
$('#sidebar .close').addEventListener('click', toggleMenu);
Expand All @@ -63,22 +62,22 @@ function buildMenu() {
function buildComponentsMenu() {
var items = [{"href":"http://ionicframework.com/docs/components/#overview","title":"Overview"},{"href":"http://ionicframework.com/docs/components/#action-sheets","title":"Action Sheets"},{"href":"http://ionicframework.com/docs/components/#alert","title":"Alerts"},{"href":"http://ionicframework.com/docs/components/#badges","title":"Badges"},{"href":"http://ionicframework.com/docs/components/#buttons","title":"Buttons"},{"href":"http://ionicframework.com/docs/components/#cards","title":"Cards"},{"href":"http://ionicframework.com/docs/components/#checkbox","title":"Checkbox"},{"href":"http://ionicframework.com/docs/components/#datetime","title":"DateTime"},{"href":"http://ionicframework.com/docs/components/#fabs","title":"FABs"},{"href":"http://ionicframework.com/docs/components/#gestures","title":"Gestures"},{"href":"http://ionicframework.com/docs/components/#grid","title":"Grid"},{"href":"http://ionicframework.com/docs/components/#icons","title":"Icons"},{"href":"http://ionicframework.com/docs/components/#inputs","title":"Inputs"},{"href":"http://ionicframework.com/docs/components/#lists","title":"Lists"},{"href":"http://ionicframework.com/docs/components/#loading","title":"Loading"},{"href":"http://ionicframework.com/docs/components/#menus","title":"Menus"},{"href":"http://ionicframework.com/docs/components/#modals","title":"Modals"},{"href":"http://ionicframework.com/docs/components/#navigation","title":"Navigation"},{"href":"http://ionicframework.com/docs/components/#popovers","title":"Popover"},{"href":"http://ionicframework.com/docs/components/#radio","title":"Radio"},{"href":"http://ionicframework.com/docs/components/#range","title":"Range"},{"href":"http://ionicframework.com/docs/components/#searchbar","title":"Searchbar"},{"href":"http://ionicframework.com/docs/components/#segment","title":"Segment"},{"href":"http://ionicframework.com/docs/components/#select","title":"Select"},{"href":"http://ionicframework.com/docs/components/#slides","title":"Slides"},{"href":"http://ionicframework.com/docs/components/#tabs","title":"Tabs"},{"href":"http://ionicframework.com/docs/components/#toast","title":"Toast"},{"href":"http://ionicframework.com/docs/components/#toggle","title":"Toggle"},{"href":"http://ionicframework.com/docs/components/#toolbar","title":"Toolbar"}];

const componentsMenu = $('#components-menu');
items.map(i => {
const l = document.createElement('li')
const a = document.createElement('a')
a.href = i.href
var componentsMenu = $('#components-menu');
items.map(function (i) {
var l = document.createElement('li');
var a = document.createElement('a');
a.href = i.href;
a.target = "_blank";
a.innerText = i.title
l.appendChild(a)
componentsMenu.appendChild(l)
})
a.innerText = i.title;
l.appendChild(a);
componentsMenu.appendChild(l);
});
}

function tryShowViewPopup() {
var view = window.localStorage.getItem('ionic_viewpop');

if(!view) {
if (!view) {
$('#view-popup').style.display = 'block';
$('#view-popup .close').addEventListener('click', function(e) {
window.localStorage.setItem('ionic_viewpop', true);
Expand All @@ -101,14 +100,14 @@ function bindToggles() {
var windows = $('#device-windows');

var devices = [iphone, android, windows];
for(i in devices) {
for(var i in devices) {
devices[i].addEventListener('change', function(e) {
var device = this.name;
console.log('Device changed', device, this.checked);

showDevice(device, this.checked);
saveLastDevices(device, this.checked);
})
});
}
}

Expand All @@ -122,11 +121,11 @@ function showDevice(device, isShowing) {
var clone = document.importNode(template, true);
$('preview').appendChild(clone.content);
//check for extra params in location.url to pass on to iframes
var params = document.location.href.split('?')
var params = document.location.href.split('?');
if (params) {
var newparams = params[params.length - 1]
var oldsrc = $('preview .frame').getAttribute('src')
$('preview .frame').setAttribute('src', oldsrc + '&' + newparams)
var newparams = params[params.length - 1];
var oldsrc = $('preview .frame').getAttribute('src');
$('preview .frame').setAttribute('src', oldsrc + '&' + newparams);
}
} else {
rendered.style.display = isShowing ? '' : 'none';
Expand Down Expand Up @@ -163,7 +162,7 @@ function showLastDevices() {
}

function setCordovaInfo(data) {
let el = $('#app-info');
var el = $('#app-info');
el.innerHTML = data.name + ' - v' + data.version;
if(data.name) {
document.title = data.name + ' - Ionic Lab';
Expand All @@ -174,8 +173,8 @@ function loadCordova() {
var req = new XMLHttpRequest();
req.addEventListener('load', function(e) {
setCordovaInfo(JSON.parse(req.response));
})
req.open('GET', API_ROOT + '/cordova', true)
});
req.open('GET', API_ROOT + '/cordova', true);
req.send(null);
}

Expand Down

0 comments on commit 41a1335

Please sign in to comment.