define([], function () { var pageContainerCount; var animationDuration = 500; function loadView(options) { return new Promise(function (resolve, reject) { var animatedPages = document.querySelector('.mainAnimatedPages'); if (options.cancel) { return; } var selected = getSelectedIndex(animatedPages); var pageIndex = selected + 1; if (pageIndex >= pageContainerCount) { pageIndex = 0; } var newViewInfo = normalizeNewView(options); var newView = newViewInfo.elem; var dependencies = typeof (newView) == 'string' ? null : newView.getAttribute('data-require'); dependencies = dependencies ? dependencies.split(',') : []; var isPluginpage = options.url.toLowerCase().indexOf('/configurationpage?') != -1; if (isPluginpage) { dependencies.push('jqmpopup'); dependencies.push('jqmcollapsible'); dependencies.push('jqmcheckbox'); dependencies.push('legacy/dashboard'); } if (isPluginpage || (newView.classList && newView.classList.contains('type-interior'))) { dependencies.push('jqmcontrolgroup'); dependencies.push('jqmlistview'); dependencies.push('scripts/notifications'); } require(dependencies, function () { var allPages = animatedPages.querySelectorAll('.mainAnimatedPage'); var animatable = allPages[pageIndex]; var currentPage = animatable.querySelector('.page-view'); if (currentPage) { triggerDestroy(currentPage); } for (var i = 0, length = allPages.length; i < length; i++) { if (pageIndex == i) { allPages[i].classList.remove('hide'); } else { allPages[i].classList.add('hide'); } } if (typeof (newView) == 'string') { animatable.innerHTML = newView; } else { animatable.innerHTML = ''; if (newViewInfo.hasScript) { // TODO: figure this out without jQuery $(newView).appendTo(animatable); } else { animatable.appendChild(newView); } enhanceNewView(dependencies, newView); } var view = animatable.querySelector('.page-view'); if (onBeforeChange) { onBeforeChange(view, false, options); } $.mobile = $.mobile || {}; $.mobile.activePage = view; resolve(view); }); }); } function enhanceNewView(dependencies, newView) { var hasJqm = false; for (var i = 0, length = dependencies.length; i < length; i++) { if (dependencies[i].indexOf('jqm') == 0) { hasJqm = true; break; } } if (hasJqm) { $(newView).trigger('create'); } } function parseHtml(html) { var wrapper = document.createElement('div'); wrapper.innerHTML = html; return wrapper.querySelector('div[data-role="page"]'); } function normalizeNewView(options) { if (options.view.indexOf('data-role="page"') == -1) { var html = '
'; html += options.view; html += '
'; return html; } var elem = parseHtml(options.view); elem.classList.add('page-view'); elem.setAttribute('data-type', options.type || ''); elem.setAttribute('data-url', options.url); return { elem: elem, hasScript: options.view.indexOf('