diff options
author | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-10 17:56:41 +0000 |
---|---|---|
committer | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-10 17:56:41 +0000 |
commit | d51d7f13a7261de7b9c94e77030836bec6d6a7b0 (patch) | |
tree | 0843f709bff120523a6b12fa31c39d32d078a6ba /native_client_sdk/src | |
parent | 59fee305b4eb62b3f6b710e4d5e19487fff7993d (diff) | |
download | chromium_src-d51d7f13a7261de7b9c94e77030836bec6d6a7b0.zip chromium_src-d51d7f13a7261de7b9c94e77030836bec6d6a7b0.tar.gz chromium_src-d51d7f13a7261de7b9c94e77030836bec6d6a7b0.tar.bz2 |
[NaCl SDK] Make common.js load the Release nexe/pexe by default.
This way when you run make you'll build Release, and if you navigate to the page
you'll load the Release build.
This CL also adds an "error" handler to common.js by default; this makes it easier to see when you are trying to run an example that doesn't exist.
Finally, I've also added a Debug/Release selector to the index.html landing page (served when you run "make run" from the examples directory)
BUG=327130
R=sbc@chromium.org
Review URL: https://codereview.chromium.org/110803002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239803 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk/src')
-rw-r--r-- | native_client_sdk/src/resources/common.js | 14 | ||||
-rw-r--r-- | native_client_sdk/src/resources/index.css | 15 | ||||
-rw-r--r-- | native_client_sdk/src/resources/index.html.template | 5 | ||||
-rw-r--r-- | native_client_sdk/src/resources/index.js | 35 |
4 files changed, 61 insertions, 8 deletions
diff --git a/native_client_sdk/src/resources/common.js b/native_client_sdk/src/resources/common.js index af5e5b0..a108fad 100644 --- a/native_client_sdk/src/resources/common.js +++ b/native_client_sdk/src/resources/common.js @@ -8,7 +8,7 @@ var isTest = false; // Set to true when loading a "Release" NaCl module, false when loading a // "Debug" NaCl module. -var isRelease = false; +var isRelease = true; // Javascript module pattern: // see http://en.wikipedia.org/wiki/Unobtrusive_JavaScript#Namespaces @@ -186,12 +186,24 @@ var common = (function() { var listenerDiv = document.getElementById('listener'); listenerDiv.addEventListener('load', moduleDidLoad, true); listenerDiv.addEventListener('message', handleMessage, true); + listenerDiv.addEventListener('error', handleError, true); listenerDiv.addEventListener('crash', handleCrash, true); if (typeof window.attachListeners !== 'undefined') { window.attachListeners(); } } + /** + * Called when the NaCl module fails to load. + * + * This event listener is registered in createNaClModule above. + */ + function handleError(event) { + // We can't use common.naclModule yet because the module has not been + // loaded. + var moduleEl = document.getElementById('nacl_module'); + updateStatus('ERROR [' + moduleEl.lastError + ']'); + } /** * Called when the Browser can not communicate with the Module diff --git a/native_client_sdk/src/resources/index.css b/native_client_sdk/src/resources/index.css index 93f2663..449020a 100644 --- a/native_client_sdk/src/resources/index.css +++ b/native_client_sdk/src/resources/index.css @@ -81,6 +81,21 @@ body { overflow-y: auto; -webkit-flex: auto; } +.config-group { + border-bottom: 1px solid #ccc; +} +.config-header { + font-weight: bold; + padding: 4px 0; +} +.config-item { + cursor: pointer; + font-size: 13px; + padding: 4px 0; +} +.config-item:hover { + background-color: #eee; +} iframe { border: none; width: 100%; diff --git a/native_client_sdk/src/resources/index.html.template b/native_client_sdk/src/resources/index.html.template index 207afdb..eb34e26 100644 --- a/native_client_sdk/src/resources/index.html.template +++ b/native_client_sdk/src/resources/index.html.template @@ -20,6 +20,11 @@ <div class="left-border"></div> <div class="nav-wrapper"> <div class="nav"> + <div class="config-group"> + <div class="config-header">Configuration</div> + <div class="config-item">Debug</div> + <div class="config-item selected">Release</div> + </div> [[for section in section_map:]] <div class="nav-group-header">{{section}}</div> [[ for desc in section_map[section]:]] diff --git a/native_client_sdk/src/resources/index.js b/native_client_sdk/src/resources/index.js index ab4b4ff..6c0c1cf3 100644 --- a/native_client_sdk/src/resources/index.js +++ b/native_client_sdk/src/resources/index.js @@ -3,19 +3,33 @@ // found in the LICENSE file. var iframeUpdateIntervalID; +var queryParams = ''; + +function selectConfig(el) { + deselectAllItems('.config-item'); + selectItem(el); + updateIframe(); +} function selectExample(el) { - setIframeSrc(el.dataset.href); - deselectAllNavItems(); - selectNavItem(el); + deselectAllItems('.nav-item'); + selectItem(el); + updateIframe(); } -function selectNavItem(el) { +function updateIframe() { + var exampleEl = document.querySelector('.nav-item.selected'); + var configEl = document.querySelector('.config-item.selected'); + var url = exampleEl.dataset.href + '?config=' + configEl.textContent; + setIframeSrc(url); +} + +function selectItem(el) { el.classList.add('selected'); } -function deselectAllNavItems() { - var navItemEls = document.querySelectorAll('.nav-item'); +function deselectAllItems(selector) { + var navItemEls = document.querySelectorAll(selector); for (var i = 0; i < navItemEls.length; ++i) { navItemEls[i].classList.remove('selected'); } @@ -32,8 +46,15 @@ function setIframeSrc(src) { document.addEventListener('DOMContentLoaded', function () { var iframeEl = document.querySelector('iframe'); var iframeWrapperEl = document.querySelector('.iframe-wrapper'); - var navItemEls = document.querySelectorAll('.nav-item'); + var configItemEls = document.querySelectorAll('.config-item'); + for (var i = 0; i < configItemEls.length; ++i) { + configItemEls[i].addEventListener('click', function (e) { + selectConfig(this); + }); + } + + var navItemEls = document.querySelectorAll('.nav-item'); for (var i = 0; i < navItemEls.length; ++i) { navItemEls[i].addEventListener('click', function (e) { selectExample(this); |