Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add fullinit_ui.js, an ADsafe widget

  • Loading branch information...
commit f73d2066efa3f41d294115e552dd6c41309f5689 1 parent 523956b
Douglas Crockford authored
Showing with 159 additions and 5 deletions.
  1. +6 −3 README
  2. +151 −0 fullinit_ui.js
  3. +2 −2 fulljslint.html
9 README
View
@@ -8,11 +8,14 @@ douglas@crockford.com
fulljslint.js contains the fully commented JSLINT function.
fulljslint.html runs the JSLINT function in a web page. The page also depends
-on adsafe.js and json2.js (which are not included in this project) and
-intercept.js (which is).
+on adsafe.js [www.ADsafe.org] and json2.js [www.JSON.org] (which are not
+included in this project) and intercept.js and init_ui.js (which are).
intercept.js scripts the fulljslint.html ui by augmenting ADsafe.
-wsh.js is a sample companion script to run fulljslint.js on WSH.
+init_ui.js hooks the HTML ui components to ADsafe.
lint.html describes JSLint's usage.
+
+JSLint can be run anywhere that JavaScript (or Java) can run. See for example
+http://tech.groups.yahoo.com/group/jslint_com/database?method=reportRows&tbl=1
151 fullinit_ui.js
View
@@ -0,0 +1,151 @@
+// init_ui.js
+// 2010-11-29
+
+
+// This is the web browser companion to fulljslint.js. It is an ADsafe
+// lib file that implements a web ui by adding behavior to the widget's
+// html tags.
+
+// It stores a function in lib.init_ui. Calling that function will
+// start up the JSLint widget ui.
+
+// option = {adsafe: true, fragment: false}
+
+/*members check, cookie, each, edition, get, getTitle, getValue, indent,
+ isArray, join, jslint, lib, maxerr, maxlen, on, passfail, predef, push,
+ q, select, set, split, value, white
+*/
+
+"use strict";
+
+ADSAFE.lib("init_ui", function (lib) {
+ return function (dom) {
+ var checkboxes = dom.q('input_checkbox'),
+ goodparts = checkboxes.q('&goodpart'),
+ indent = dom.q('#JSLINT_INDENT'),
+ input = dom.q('#JSLINT_INPUT'),
+ jslintstring = dom.q('#JSLINT_JSLINTSTRING'),
+ maxerr = dom.q('#JSLINT_MAXERR'),
+ maxlen = dom.q('#JSLINT_MAXLEN'),
+ option = lib.cookie.get(),
+ output = dom.q('#JSLINT_OUTPUT'),
+ predefined = dom.q('#JSLINT_PREDEF');
+
+ function show_jslint_options() {
+
+// Build and display a jslint control comment.
+
+// The comment can be copied into a .js file.
+
+ var a = [], name;
+ for (name in option) {
+ if (typeof ADSAFE.get(option, name) === 'boolean') {
+ a.push(name + ': true');
+ }
+ }
+ if (+option.maxerr > 0) {
+ a.push('maxerr: ' + option.maxerr);
+ }
+ if (+option.maxlen > 0) {
+ a.push('maxlen: ' + option.maxlen);
+ }
+ if (+option.indent > 0) {
+ a.push('indent: ' + option.indent);
+ }
+ jslintstring.value('/*jslint ' + a.join(', ') + ' */');
+ }
+ function update_options() {
+
+// Make an object containing the current options.
+
+ var value;
+ option = {};
+ checkboxes.q(':checked').each(function (bunch) {
+ ADSAFE.set(option, bunch.getTitle(), true);
+ });
+ if (option.white) {
+ value = +indent.getValue();
+ if (value && value !== 4) {
+ option.indent = value;
+ }
+ }
+ if (!option.passfail) {
+ value = +maxerr.getValue();
+ if (value && value !== 50) {
+ option.maxerr = value;
+ }
+ }
+ value = +maxlen.getValue();
+ option.maxlen = value && value > 0 ? value : 0;
+ value = predefined.getValue();
+ if (value) {
+ option.predef = value.split(/\s*,\s*/);
+ }
+ show_jslint_options();
+ }
+
+// Restore the options from a JSON cookie.
+
+ if (!option || typeof option !== 'object') {
+ option = {};
+ } else {
+ checkboxes.each(function (bunch) {
+ bunch.check(ADSAFE.get(option, bunch.getTitle()));
+ });
+ indent.value(option.indent || '4');
+ maxlen.value(option.maxlen || '');
+ maxerr.value(option.maxerr || '50');
+ predefined.value(ADSAFE.isArray(option.predef) ?
+ option.predef.join(',') : '');
+ }
+ show_jslint_options();
+
+// Display the edition.
+
+ dom.q('#JSLINT_EDITION').value('Edition ' + lib.edition());
+
+// Add click event handlers to the [JSLint] and [clear] buttons.
+
+ dom.q('input&jslint').on('click', function (e) {
+
+// Make a JSON cookie of the option object.
+
+ lib.cookie.set(option);
+
+// Call JSLint and display the report.
+
+ lib.jslint(input.getValue(), option, output);
+ input.select();
+ return false;
+ });
+
+ dom.q('input&clear').on('click', function (e) {
+ output.value('');
+ input.value('').select();
+ });
+
+ dom.q('#JSLINT_CLEARALL').on('click', function (e) {
+ checkboxes.check(false);
+ indent.value(option.indent || '4');
+ maxlen.value(option.maxlen || '');
+ maxerr.value(option.maxerr || '50');
+ update_options();
+ });
+
+ dom.q('#JSLINT_GOODPARTS').on('click', function (e) {
+ goodparts.check(true);
+ update_options();
+ });
+
+ checkboxes.on('click', update_options);
+ indent.on('change', update_options);
+ maxerr.on('change', update_options);
+ maxlen.on('change', update_options);
+ predefined.on('change', update_options);
+ input
+ .on('change', function (e) {
+ output.value('');
+ })
+ .select();
+ };
+});
4 fulljslint.html 100644 → 100755
View
@@ -255,11 +255,11 @@
"use strict";
ADSAFE.id("JSLINT_");
</script>
-<script src="widget.js"></script>
+<script src="fullinit_ui.js"></script>
<script>
"use strict";
ADSAFE.go("JSLINT_", function (dom, lib) {
- lib.init_jslint_ui(dom);
+ lib.init_ui(dom);
});
</script>
Please sign in to comment.
Something went wrong with that request. Please try again.