Refactor common example script and run the linter on it
This commit is contained in:
2
build.py
2
build.py
@@ -417,7 +417,7 @@ def build_lint_src_timestamp(t):
|
|||||||
virtual('jshint', 'build/jshint-timestamp')
|
virtual('jshint', 'build/jshint-timestamp')
|
||||||
|
|
||||||
@target('build/jshint-timestamp', SRC, EXAMPLES_SRC_JS, SPEC, SPEC_RENDERING,
|
@target('build/jshint-timestamp', SRC, EXAMPLES_SRC_JS, SPEC, SPEC_RENDERING,
|
||||||
TASKS, NPM_INSTALL, precious=True)
|
'examples/resources/common.js', TASKS, NPM_INSTALL, precious=True)
|
||||||
def build_jshint_timestamp(t):
|
def build_jshint_timestamp(t):
|
||||||
t.run(variables.JSHINT, '--verbose', t.newer(t.dependencies))
|
t.run(variables.JSHINT, '--verbose', t.newer(t.dependencies))
|
||||||
t.touch()
|
t.touch()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
;(function() {
|
(function() {
|
||||||
var copyButton = document.getElementById('copy-button');
|
var copyButton = document.getElementById('copy-button');
|
||||||
if (copyButton) {
|
if (copyButton) {
|
||||||
var data = document.getElementById('example-source').textContent;
|
var data = document.getElementById('example-source').textContent;
|
||||||
@@ -13,42 +13,35 @@
|
|||||||
if (window.location.host === 'localhost:3000') {
|
if (window.location.host === 'localhost:3000') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var container = document.getElementById('navbar-inner-container'),
|
|
||||||
form = document.createElement('form'),
|
|
||||||
select = document.createElement('select'),
|
|
||||||
possibleModes = {
|
|
||||||
'raw' : 'Development',
|
|
||||||
'advanced': 'Production'
|
|
||||||
},
|
|
||||||
urlMode = window.location.href.match(/mode=([a-z0-9\-]+)\&?/i),
|
|
||||||
curMode = urlMode ? urlMode[1] : 'advanced',
|
|
||||||
option,
|
|
||||||
modeIdx,
|
|
||||||
mode,
|
|
||||||
modeTxt,
|
|
||||||
modeChangedMethod;
|
|
||||||
|
|
||||||
|
var container = document.getElementById('navbar-inner-container');
|
||||||
if (!container) {
|
if (!container) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
modeChangedMethod = function() {
|
var form = document.createElement('form');
|
||||||
var newMode = this.value,
|
var select = document.createElement('select');
|
||||||
search = window.location.search.substring(1),
|
var possibleModes = {
|
||||||
baseUrl = window.location.href.split('?')[0],
|
'raw' : 'Development',
|
||||||
chunks = search ? search.split('&') : [],
|
'advanced': 'Production'
|
||||||
pairs = [],
|
};
|
||||||
i,
|
var urlMode = window.location.href.match(/mode=([a-z0-9\-]+)\&?/i);
|
||||||
pair,
|
var curMode = urlMode ? urlMode[1] : 'advanced';
|
||||||
adjusted,
|
|
||||||
modeFound = false;
|
var modeChangedMethod = function() {
|
||||||
for (i = chunks.length - 1; i >= 0; --i) {
|
var newMode = this.value;
|
||||||
pair = chunks[i].split('=');
|
var search = window.location.search.substring(1);
|
||||||
|
var baseUrl = window.location.href.split('?')[0];
|
||||||
|
var chunks = search ? search.split('&') : [];
|
||||||
|
var pairs = [];
|
||||||
|
var modeFound = false;
|
||||||
|
for (var i = chunks.length - 1; i >= 0; --i) {
|
||||||
|
var pair = chunks[i].split('=');
|
||||||
if (pair[0].toLowerCase() === 'mode') {
|
if (pair[0].toLowerCase() === 'mode') {
|
||||||
pair[1] = newMode;
|
pair[1] = newMode;
|
||||||
modeFound = true;
|
modeFound = true;
|
||||||
}
|
}
|
||||||
adjusted = encodeURIComponent(pair[0]);
|
var adjusted = encodeURIComponent(pair[0]);
|
||||||
if (typeof pair[1] !== undefined) {
|
if (typeof pair[1] !== undefined) {
|
||||||
adjusted += '=' + encodeURIComponent(pair[1] || '');
|
adjusted += '=' + encodeURIComponent(pair[1] || '');
|
||||||
}
|
}
|
||||||
@@ -60,10 +53,10 @@
|
|||||||
location.href = baseUrl + '?' + pairs.join('&');
|
location.href = baseUrl + '?' + pairs.join('&');
|
||||||
};
|
};
|
||||||
|
|
||||||
for (mode in possibleModes) {
|
for (var mode in possibleModes) {
|
||||||
if (possibleModes.hasOwnProperty(mode)) {
|
if (possibleModes.hasOwnProperty(mode)) {
|
||||||
option = document.createElement('option');
|
var option = document.createElement('option');
|
||||||
modeTxt = possibleModes[mode];
|
var modeTxt = possibleModes[mode];
|
||||||
option.value = mode;
|
option.value = mode;
|
||||||
option.innerHTML = modeTxt;
|
option.innerHTML = modeTxt;
|
||||||
option.selected = curMode === mode;
|
option.selected = curMode === mode;
|
||||||
@@ -83,11 +76,14 @@
|
|||||||
var exampleNS = {};
|
var exampleNS = {};
|
||||||
|
|
||||||
exampleNS.getRendererFromQueryString = function() {
|
exampleNS.getRendererFromQueryString = function() {
|
||||||
var obj = {}, queryString = location.search.slice(1),
|
var obj = {};
|
||||||
re = /([^&=]+)=([^&]*)/g, m;
|
var queryString = location.search.slice(1);
|
||||||
|
var re = /([^&=]+)=([^&]*)/g;
|
||||||
|
|
||||||
while (m = re.exec(queryString)) {
|
var m = re.exec(queryString);
|
||||||
|
while (m) {
|
||||||
obj[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
|
obj[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
|
||||||
|
m = re.exec(queryString);
|
||||||
}
|
}
|
||||||
if ('renderers' in obj) {
|
if ('renderers' in obj) {
|
||||||
return obj['renderers'].split(',');
|
return obj['renderers'].split(',');
|
||||||
|
|||||||
Reference in New Issue
Block a user