Commit afae8a6c authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Add JS Lint tool

parent b06bd370
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
<li><a class="url_list" href="#page=url_list">URL List</a></li> <li><a class="url_list" href="#page=url_list">URL List</a></li>
<li><a class="editor" href="#page=editor">Editor</a></li> <li><a class="editor" href="#page=editor">Editor</a></li>
<li><a class="save_load" href="#page=save_load">Export/Import</a></li> <li><a class="save_load" href="#page=save_load">Export/Import</a></li>
<li><a class="tools" href="#page=tools">Tools</a></li>
<li><a class="mass_remove" href="#page=mass_remove">Remove</a></li> <li><a class="mass_remove" href="#page=mass_remove">Remove</a></li>
</ul> </ul>
</div> </div>
......
...@@ -121,7 +121,7 @@ ...@@ -121,7 +121,7 @@
*/ */
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var gadget = this, var gadget = this,
page_list = ["cribjs_home", "select_site", "url_list", "editor", "save_load", "mass_remove"], page_list = ["cribjs_home", "select_site", "url_list", "editor", "save_load", "tools", "mass_remove"],
promise_list = []; promise_list = [];
gadget.stats.options = options; gadget.stats.options = options;
......
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>CribJS Header</title>
<!-- renderjs -->
<script src="../lib/rsvp.js" type="text/javascript"></script>
<script src="../lib/renderjs.js" type="text/javascript"></script>
<script src="./gadget_global.js" type="text/javascript"></script>
<script type="text/javascript" src="../lib/jshint.js"></script>
<!-- Custom -->
<script src="./gadget_cribjs_page_jslint.js" type="text/javascript"></script>
</head>
<body>
<div class="nav_content url_list container">
<form class="crib-url-list-content">
<h3>URL List</h3>
<button type="submit" name="list-contents" class="btn btn-default">Refresh</button>
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>JSLint</th>
<th>Url</th>
<th>Go</th>
</tr>
</thead>
<tfoot>
</tfoot>
<tbody>
</tbody>
</table>
<div>
<button type="submit" name="list-contents" class="btn btn-default">Refresh</button>
</div>
</form>
</div>
</body>
</html>
\ No newline at end of file
/*global window, rJS, JSHINT, RSVP, jIO, document, loopEventListener */
/*jslint nomen: true, indent: 2, maxerr: 3*/
(function (window, rJS, JSHINT, jIO, loopEventListener) {
"use strict";
function getURLContentAsText(gadget, url) {
return new RSVP.Queue()
.push(function () {
return gadget.crib_sw_get(url);
})
.push(function (data) {
var type;
type = data.type;
return jIO.util.readBlobAsText(data, type);
})
.push(function (event) {
return event.target.result;
});
}
function displayURLList(gadget, event) {
var url_list = [];
return new RSVP.Queue()
.push(function () {
return gadget.crib_sw_allDocs();
})
.push(function (data) {
var promise_list = [],
tmp_url_list = [],
url;
if (data.hasOwnProperty("urls")) {
tmp_url_list = data.urls;
} else {
tmp_url_list = data;
}
for (url in tmp_url_list) {
if (tmp_url_list.hasOwnProperty(url)) {
if (url.endsWith(".js")) {
url_list.push(url);
promise_list.push(RSVP.all([
gadget.getUrlFor({page: 'editor', url: url}),
getURLContentAsText(gadget, url)
]));
}
}
}
return RSVP.all(promise_list);
})
.push(function (result_list) {
var contentsElement = gadget.props.element.querySelector('.crib-url-list-content tbody'),
footer_element = gadget.props.element.querySelector('.crib-url-list-content tfoot'),
url_number, error_number = 0,
url, trElement, tdElement;
// Clear out the existing items from the list.
while (contentsElement.firstChild) {
contentsElement.removeChild(contentsElement.firstChild);
}
// Add each cached URL to the list, one by one.
for (url_number = 0; url_number < url_list.length; url_number++) {
url = url_list[url_number];
var element;
JSHINT(result_list[url_number][1]);
trElement = document.createElement('tr');
tdElement = document.createElement('td');
tdElement.innerHTML = (JSHINT.data().errors ? "<span>&#x274C;</span>" : "");
trElement.appendChild(tdElement);
tdElement = document.createElement('td');
element = document.createElement('a');
element.setAttribute('href', result_list[url_number][0]);
element.textContent = url;
tdElement.appendChild(element);
trElement.appendChild(tdElement);
tdElement = document.createElement('td');
element = document.createElement('a');
element.textContent = "Go";
element.setAttribute('href', url);
element.setAttribute('target', "_blank");
element.setAttribute("class", "btn btn-primary btn-xs");
tdElement.appendChild(element);
trElement.appendChild(tdElement);
contentsElement.appendChild(trElement);
error_number = JSHINT.data().errors ? error_number + 1 : error_number;
}
while (footer_element.firstChild) {
footer_element.removeChild(footer_element.firstChild);
}
trElement = document.createElement('tr');
tdElement = document.createElement('td');
tdElement.innerHTML = "<span>" + error_number + " &#x274C;</span>";
trElement.appendChild(tdElement);
tdElement = document.createElement('td');
tdElement.innerHTML = url_number + " URLs";
trElement.appendChild(tdElement);
tdElement = document.createElement('td');
trElement.appendChild(tdElement);
footer_element.appendChild(trElement);
});
}
rJS(window)
.ready(function (g) {
g.props = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
g.props.start_deferred = RSVP.defer();
});
})
.declareAcquiredMethod("crib_sw_allDocs", "crib_sw_allDocs")
.declareAcquiredMethod("crib_sw_get", "crib_sw_get")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareMethod('render', function (options) {
var gadget = this;
if (options === undefined)
options = {};
gadget.props.options = options;
return new RSVP.Queue()
.push(function () {
return displayURLList(gadget, undefined);
})
.push(function () {
return gadget.props.start_deferred.resolve();
});
})
.declareService(function () {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return gadget.props.start_deferred.promise;
})
.push(function () {
return loopEventListener(
gadget.props.element.querySelector(".crib-url-list-content"),
'submit',
false,
function (event) {displayURLList(gadget, event); }
);
});
});
}(window, rJS, JSHINT, jIO, loopEventListener));
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<!-- renderjs -->
<script src="../lib/rsvp.js" type="text/javascript"></script>
<script src="../lib/renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="./gadget_cribjs_page_tools.js" type="text/javascript"></script>
<title>CribJS Header</title>
</head>
<body>
<div class="nav_content cribjs container">
<ul>
<li>Check <a class="jslint" href="#page=jslint">JSLint</a></li>
<li><a class="mass_remove" href="#page=mass_remove">Remove</a> uncessary URLs</li>
</ul>
</div>
</body>
</html>
\ No newline at end of file
/*jslint nomen: true, indent: 2, maxerr: 3 */
/*global window, rJS, Handlebars, document, loopEventListener, RSVP */
(function (window, rJS, document, RSVP) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// ready
/////////////////////////////////////////////////////////////////
// Assign the element to a variable
.ready(function (g) {
g.props = {};
return g.getElement()
.push(function (element) {
g.props.element = element;
});
})
//////////////////////////////////////////////
// acquired methods
//////////////////////////////////////////////
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareMethod('render', function (options) {
var gadget = this,
page_list = ["jslint", "mass_remove"],
promise_list = [];
page_list.forEach(function (page) {
promise_list.push(gadget.getUrlFor({page: page}));
});
// Handle main title
return new RSVP.Queue()
.push(function () {
return RSVP.all(promise_list);
})
.push(function (link_list) {
for (var i = 0; i < link_list.length; i++) {
gadget.props.element.querySelector("." + page_list[i]).href = link_list[i];
}
});
});
}(window, rJS, document, RSVP));
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment