update
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
/* --------------------------------------------------------------
|
||||
|
||||
css-classes.css
|
||||
* Classes for CSS development
|
||||
|
||||
See the Readme file in this directory
|
||||
for further instructions.
|
||||
|
||||
-------------------------------------------------------------- */
|
||||
|
||||
.left { float:left; }
|
||||
.right { float:right; }
|
||||
|
||||
.hide { display:none; }
|
||||
|
||||
.reset-margin { margin:0; }
|
||||
.reset-padding { padding:0; }
|
||||
.reset { margin:0; padding:0; }
|
||||
|
||||
.align-justify { text-align:justify; }
|
||||
.align-left { text-align:left; }
|
||||
.align-center { text-align:center; }
|
||||
.align-right { text-align:right; }
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* jQuery Lined Textarea Plugin
|
||||
* http://alan.blog-city.com/jquerylinedtextarea.htm
|
||||
*
|
||||
* Copyright (c) 2010 Alan Williamson
|
||||
*
|
||||
* Contribution done by Ryan Zielke (neoalchemy@gmail.com)
|
||||
*
|
||||
* Released under the MIT License:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* Usage:
|
||||
* Displays a line number count column to the left of the textarea
|
||||
*
|
||||
* Class up your textarea with a given class, or target it directly
|
||||
* with JQuery Selectors
|
||||
*
|
||||
* $(".lined").linedtextarea({
|
||||
* selectedLine: 10,
|
||||
* selectedClass: 'lineselect'
|
||||
* });
|
||||
*
|
||||
*/
|
||||
|
||||
textarea { resize:both; }
|
||||
|
||||
.linedwrap {
|
||||
border: 1px solid #c0c0c0;
|
||||
padding: 3px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.linedtextarea {
|
||||
padding: 0px;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.linedtextarea textarea, .linedwrap .codelines .lineno {
|
||||
font-size: 10pt;
|
||||
font-family: monospace;
|
||||
line-height: normal !important;
|
||||
}
|
||||
|
||||
.linedtextarea textarea {
|
||||
padding-right:0.3em;
|
||||
padding-top:0.3em;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.linedwrap .lines {
|
||||
margin-top: 0px;
|
||||
width: 50px;
|
||||
float: left;
|
||||
overflow: hidden;
|
||||
border-right: 1px solid #c0c0c0;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.linedwrap .codelines {
|
||||
padding-top: 5px;
|
||||
}
|
||||
|
||||
.linedwrap .codelines .lineno {
|
||||
color:#AAAAAA;
|
||||
padding-right: 0.5em;
|
||||
padding-top: 0.0em;
|
||||
text-align: right;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.linedwrap .codelines .lineselect {
|
||||
color: red;
|
||||
}
|
||||
136
ebpm-process-manage/webapp/resource/js/plugins/jsonfommat/js/jquery-linedtextarea.js
vendored
Normal file
136
ebpm-process-manage/webapp/resource/js/plugins/jsonfommat/js/jquery-linedtextarea.js
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* jQuery Lined Textarea Plugin
|
||||
* http://alan.blog-city.com/jquerylinedtextarea.htm
|
||||
*
|
||||
* Copyright (c) 2010 Alan Williamson
|
||||
*
|
||||
* Contributions done by Ryan Zielke (NeoAlchemy@gmail.com)
|
||||
*
|
||||
* Version:
|
||||
* $Id: jquery-linedtextarea.js 464 2010-01-08 10:36:33Z alan $
|
||||
*
|
||||
* Released under the MIT License:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* Usage:
|
||||
* Displays a line number count column to the left of the textarea
|
||||
*
|
||||
* Class up your textarea with a given class, or target it directly
|
||||
* with JQuery Selectors
|
||||
*
|
||||
* $(".lined").linedtextarea({
|
||||
* selectedLine: 10,
|
||||
* selectedClass: 'lineselect'
|
||||
* });
|
||||
*
|
||||
* History:
|
||||
* - 2011.12.08: Changes to allow resizing and not affect styling of the outer div
|
||||
* - 2010.01.08: Fixed a Google Chrome layout problem
|
||||
* - 2010.01.07: Refactored code for speed/readability; Fixed horizontal sizing
|
||||
* - 2010.01.06: Initial Release
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
|
||||
$.fn.linedtextarea = function(options) {
|
||||
|
||||
// Get the Options
|
||||
var opts = $.extend({}, $.fn.linedtextarea.defaults, options);
|
||||
|
||||
|
||||
/*
|
||||
* Helper function to make sure the line numbers are always
|
||||
* kept up to the current system
|
||||
*/
|
||||
var fillOutLines = function(codeLines, h, lineNo){
|
||||
while ( (codeLines.height() - h ) <= 0 ){
|
||||
if ( lineNo == opts.selectedLine )
|
||||
codeLines.append("<div class='lineno lineselect'>" + lineNo + "</div>");
|
||||
else
|
||||
codeLines.append("<div class='lineno'>" + lineNo + "</div>");
|
||||
|
||||
lineNo++;
|
||||
}
|
||||
return lineNo;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Iterate through each of the elements are to be applied to
|
||||
*/
|
||||
return this.each(function() {
|
||||
var lineNo = 1;
|
||||
var textarea = $(this);
|
||||
|
||||
/* Turn off the wrapping of as we don't want to screw up the line numbers */
|
||||
textarea.attr("wrap", "off");
|
||||
textarea.css({resize:'both'});
|
||||
var originalTextAreaWidth = textarea.outerWidth();
|
||||
|
||||
/* Wrap the text area in the elements we need */
|
||||
var linedTextAreaDiv = textarea.wrap("<div class='linedwrap'></div>");
|
||||
var linedWrapDiv = linedTextAreaDiv.parent();
|
||||
|
||||
linedWrapDiv.prepend("<div class='lines' style='width:50px'></div>");
|
||||
|
||||
var linesDiv = linedWrapDiv.find(".lines");
|
||||
|
||||
|
||||
/* Draw the number bar; filling it out where necessary */
|
||||
linesDiv.append( "<div class='codelines'></div>" );
|
||||
var codeLinesDiv = linesDiv.find(".codelines");
|
||||
lineNo = fillOutLines( codeLinesDiv, linesDiv.height(), 1 );
|
||||
|
||||
/* Move the textarea to the selected line */
|
||||
if ( opts.selectedLine != -1 && !isNaN(opts.selectedLine) ){
|
||||
var fontSize = parseInt( textarea.height() / (lineNo-2) );
|
||||
var position = parseInt( fontSize * opts.selectedLine ) - (textarea.height()/2);
|
||||
textarea[0].scrollTop = position;
|
||||
}
|
||||
|
||||
|
||||
/* Set the width */
|
||||
var sidebarWidth = linesDiv.outerWidth(true);
|
||||
var paddingHorizontal = parseInt( linedWrapDiv.css("border-left-width") ) + parseInt( linedWrapDiv.css("border-right-width") ) + parseInt( linedWrapDiv.css("padding-left") ) + parseInt( linedWrapDiv.css("padding-right") );
|
||||
var linedWrapDivNewWidth = originalTextAreaWidth - paddingHorizontal;
|
||||
var textareaNewWidth = originalTextAreaWidth - sidebarWidth - paddingHorizontal;
|
||||
|
||||
textarea.width( textareaNewWidth);
|
||||
textarea.css({maxWidth: textareaNewWidth - 6}); //TODO make this calculated
|
||||
|
||||
|
||||
|
||||
/* React to the scroll event */
|
||||
textarea.scroll( function(tn){
|
||||
var domTextArea = $(this)[0];
|
||||
var scrollTop = domTextArea.scrollTop;
|
||||
var clientHeight = domTextArea.clientHeight;
|
||||
codeLinesDiv.css( {'margin-top': (-1*scrollTop) + "px"} );
|
||||
lineNo = fillOutLines( codeLinesDiv, scrollTop + clientHeight, lineNo );
|
||||
});
|
||||
|
||||
|
||||
/* Should the textarea get resized outside of our control */
|
||||
textarea.resize( function(tn){
|
||||
var domTextArea = $(this)[0];
|
||||
linesDiv.height( domTextArea.clientHeight + 6 );
|
||||
});
|
||||
|
||||
|
||||
window.setInterval( function(tn) {
|
||||
linesDiv.height(textarea.height());
|
||||
var scrollTop = textarea[0].scrollTop;
|
||||
var clientHeight = textarea[0].clientHeight;
|
||||
codeLinesDiv.css( {'margin-top': (-1*scrollTop) + "px"} );
|
||||
lineNo = fillOutLines( codeLinesDiv, scrollTop + clientHeight, lineNo );
|
||||
},10);
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
// default options
|
||||
$.fn.linedtextarea.defaults = {
|
||||
selectedLine: -1,
|
||||
selectedClass: 'lineselect'
|
||||
};
|
||||
})(jQuery);
|
||||
@@ -0,0 +1,83 @@
|
||||
/*jslint white: true, devel: true, onevar: true, browser: true, undef: true, nomen: true, regexp: true, plusplus: false, bitwise: true, newcap: true, maxerr: 50, indent: 4 */
|
||||
var jsl = typeof jsl === 'undefined' ? {} : jsl;
|
||||
|
||||
/**
|
||||
* jsl.format - Provide json reformatting in a character-by-character approach, so that even invalid JSON may be reformatted (to the best of its ability).
|
||||
*
|
||||
**/
|
||||
jsl.format = (function () {
|
||||
|
||||
function repeat(s, count) {
|
||||
return new Array(count + 1).join(s);
|
||||
}
|
||||
|
||||
function formatJson(json) {
|
||||
var i = 0,
|
||||
il = 0,
|
||||
tab = " ",
|
||||
newJson = "",
|
||||
indentLevel = 0,
|
||||
inString = false,
|
||||
currentChar = null;
|
||||
|
||||
for (i = 0, il = json.length; i < il; i += 1) {
|
||||
currentChar = json.charAt(i);
|
||||
|
||||
switch (currentChar) {
|
||||
case '{':
|
||||
case '[':
|
||||
if (!inString) {
|
||||
newJson += currentChar + "\n" + repeat(tab, indentLevel + 1);
|
||||
indentLevel += 1;
|
||||
} else {
|
||||
newJson += currentChar;
|
||||
}
|
||||
break;
|
||||
case '}':
|
||||
case ']':
|
||||
if (!inString) {
|
||||
indentLevel -= 1;
|
||||
newJson += "\n" + repeat(tab, indentLevel) + currentChar;
|
||||
} else {
|
||||
newJson += currentChar;
|
||||
}
|
||||
break;
|
||||
case ',':
|
||||
if (!inString) {
|
||||
newJson += ",\n" + repeat(tab, indentLevel);
|
||||
} else {
|
||||
newJson += currentChar;
|
||||
}
|
||||
break;
|
||||
case ':':
|
||||
if (!inString) {
|
||||
newJson += ": ";
|
||||
} else {
|
||||
newJson += currentChar;
|
||||
}
|
||||
break;
|
||||
case ' ':
|
||||
case "\n":
|
||||
case "\t":
|
||||
if (inString) {
|
||||
newJson += currentChar;
|
||||
}
|
||||
break;
|
||||
case '"':
|
||||
if (i > 0 && json.charAt(i - 1) !== '\\') {
|
||||
inString = !inString;
|
||||
}
|
||||
newJson += currentChar;
|
||||
break;
|
||||
default:
|
||||
newJson += currentChar;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return newJson;
|
||||
}
|
||||
|
||||
return { "formatJson": formatJson };
|
||||
|
||||
}());
|
||||
@@ -0,0 +1,241 @@
|
||||
/*jslint white: true, devel: true, onevar: true, browser: true, undef: true, nomen: true, regexp: true, plusplus: false, bitwise: true, newcap: true, maxerr: 50, indent: 4 */
|
||||
var jsl = typeof jsl === 'undefined' ? {} : jsl;
|
||||
|
||||
/**
|
||||
* Helper Function for Caret positioning
|
||||
* Gratefully borrowed from the Masked Input Plugin by Josh Bush
|
||||
* http://digitalbush.com/projects/masked-input-plugin
|
||||
**/
|
||||
$.fn.caret = function (begin, end) {
|
||||
if (this.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (typeof begin === 'number') {
|
||||
end = (typeof end === 'number') ? end : begin;
|
||||
return this.each(function () {
|
||||
if (this.setSelectionRange) {
|
||||
this.focus();
|
||||
this.setSelectionRange(begin, end);
|
||||
} else if (this.createTextRange) {
|
||||
var range = this.createTextRange();
|
||||
range.collapse(true);
|
||||
range.moveEnd('character', end);
|
||||
range.moveStart('character', begin);
|
||||
range.select();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (this[0].setSelectionRange) {
|
||||
begin = this[0].selectionStart;
|
||||
end = this[0].selectionEnd;
|
||||
} else if (document.selection && document.selection.createRange) {
|
||||
var range = document.selection.createRange();
|
||||
begin = -range.duplicate().moveStart('character', -100000);
|
||||
end = begin + range.text.length;
|
||||
}
|
||||
return {"begin": begin, "end": end};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* jsl.interactions - provides support for interactions within JSON Lint.
|
||||
*
|
||||
**/
|
||||
jsl.interactions = (function () {
|
||||
var reformatParam,
|
||||
reformat,
|
||||
compress;
|
||||
|
||||
|
||||
/******* UTILITY METHODS *******/
|
||||
|
||||
/**
|
||||
* Get the Nth position of a character in a string
|
||||
* @searchStr the string to search through
|
||||
* @char the character to find
|
||||
* @pos int the nth character to find, 1 based.
|
||||
*
|
||||
* @return int the position of the character found
|
||||
**/
|
||||
function getNthPos(searchStr, char, pos) {
|
||||
var i,
|
||||
charCount = 0,
|
||||
strArr = searchStr.split(char);
|
||||
|
||||
if (pos === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < pos; i++) {
|
||||
if (i >= strArr.length) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// +1 because we split out some characters
|
||||
charCount += strArr[i].length + char.length;
|
||||
}
|
||||
|
||||
return charCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a URL parameter from the current windows URL.
|
||||
* Courtesy Paul Oppenheim: http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery
|
||||
* @param name the parameter to retrieve
|
||||
* @return string the url parameter's value, if any
|
||||
**/
|
||||
function getURLParameter(name) {
|
||||
param = (new RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || ['', null])[1];
|
||||
if (param) {
|
||||
return decodeURIComponent(param);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/******* INTERACTION METHODS *******/
|
||||
|
||||
/**
|
||||
* Validate the JSON we've been given, displaying an error or success message.
|
||||
* @return void
|
||||
**/
|
||||
function validate() {
|
||||
var lineNum,
|
||||
lineMatches,
|
||||
lineStart,
|
||||
lineEnd,
|
||||
jsonVal,
|
||||
result;
|
||||
|
||||
jsonVal = $('#json_input').val();
|
||||
|
||||
try {
|
||||
result = jsl.parser.parse(jsonVal);
|
||||
|
||||
if (result) {
|
||||
$('#results').removeClass('error').addClass('success');
|
||||
$('div.linedwrap').removeClass('redBorder').addClass('greenBorder');
|
||||
$('#results').text('Valid JSON');
|
||||
|
||||
if (reformat) {
|
||||
$('#json_input').val(JSON.stringify(JSON.parse(jsonVal), null, " "));
|
||||
}
|
||||
|
||||
if (compress) {
|
||||
$('#json_input').val(JSON.stringify(JSON.parse(jsonVal), null, ""));
|
||||
}
|
||||
} else {
|
||||
alert("An unknown error occurred. Please contact Arc90.");
|
||||
}
|
||||
} catch (parseException) {
|
||||
|
||||
/**
|
||||
* If we failed to validate, run our manual formatter and then re-validate so that we
|
||||
* can get a better line number. On a successful validate, we don't want to run our
|
||||
* manual formatter because the automatic one is faster and probably more reliable.
|
||||
**/
|
||||
try {
|
||||
if (reformat) {
|
||||
jsonVal = jsl.format.formatJson($('#json_input').val());
|
||||
$('#json_input').val(jsonVal);
|
||||
result = jsl.parser.parse($('#json_input').val());
|
||||
}
|
||||
} catch(e) {
|
||||
parseException = e;
|
||||
}
|
||||
|
||||
lineMatches = parseException.message.match(/line ([0-9]*)/);
|
||||
if (lineMatches && typeof lineMatches === "object" && lineMatches.length > 1) {
|
||||
lineNum = parseInt(lineMatches[1], 10);
|
||||
|
||||
if (lineNum === 1) {
|
||||
lineStart = 0;
|
||||
} else {
|
||||
lineStart = getNthPos(jsonVal, "\n", lineNum - 1);
|
||||
}
|
||||
|
||||
lineEnd = jsonVal.indexOf("\n", lineStart);
|
||||
if (lineEnd < 0) {
|
||||
lineEnd = jsonVal.length;
|
||||
}
|
||||
|
||||
$('#json_input').focus().caret(lineStart, lineEnd);
|
||||
}
|
||||
|
||||
$('#results').text(parseException.message);
|
||||
|
||||
$('#results').removeClass('success').addClass('error');
|
||||
$('div.linedwrap').removeClass('greenBorder').addClass('redBorder');
|
||||
}
|
||||
|
||||
$('#loadSpinner').hide();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize variables, add event listeners, etc.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function init() {
|
||||
reformatParam = getURLParameter('reformat');
|
||||
reformat = reformatParam !== '0' && reformatParam !== 'no';
|
||||
compress = reformatParam === 'compress',
|
||||
jsonParam = getURLParameter('json');
|
||||
|
||||
if (compress) {
|
||||
$('#headerText').html('JSONLint<span class="light">Compressor</span>');
|
||||
}
|
||||
|
||||
if (!reformat) {
|
||||
$('#headerText').html('JSONLint<span class="light">Lite</span>');
|
||||
}
|
||||
|
||||
//页面加载后执行校验方法
|
||||
validate();
|
||||
|
||||
$('#validate').click(function () {
|
||||
$('#results_header, #loadSpinner').show();
|
||||
|
||||
var jsonVal = $.trim($('#json_input').val());
|
||||
|
||||
if (jsonVal.substring(0, 4).toLowerCase() === "http") {
|
||||
$.post("proxy.php", {"url": jsonVal}, function (responseObj) {
|
||||
$('#json_input').val(responseObj.content);
|
||||
validate();
|
||||
}, 'json');
|
||||
} else {
|
||||
validate();
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#json_input').keyup(function () {
|
||||
$('div.linedwrap').removeClass('greenBorder').removeClass('redBorder');
|
||||
}).linedtextarea({
|
||||
selectedClass: 'lineselect'
|
||||
}).focus();
|
||||
|
||||
$('#reset').click(function () {
|
||||
$('#json_input').val('').focus();
|
||||
});
|
||||
|
||||
$('#faqButton').click(function () {
|
||||
$('#faq').slideToggle();
|
||||
});
|
||||
|
||||
if (jsonParam) {
|
||||
$('#json_input').val(jsonParam);
|
||||
$('#validate').click();
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
'init': init
|
||||
};
|
||||
}());
|
||||
|
||||
$(function () {
|
||||
jsl.interactions.init();
|
||||
});
|
||||
@@ -0,0 +1,241 @@
|
||||
/*jslint white: true, devel: true, onevar: true, browser: true, undef: true, nomen: true, regexp: true, plusplus: false, bitwise: true, newcap: true, maxerr: 50, indent: 4 */
|
||||
var jsl = typeof jsl === 'undefined' ? {} : jsl;
|
||||
|
||||
/**
|
||||
* Helper Function for Caret positioning
|
||||
* Gratefully borrowed from the Masked Input Plugin by Josh Bush
|
||||
* http://digitalbush.com/projects/masked-input-plugin
|
||||
**/
|
||||
$.fn.caret = function (begin, end) {
|
||||
if (this.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (typeof begin === 'number') {
|
||||
end = (typeof end === 'number') ? end : begin;
|
||||
return this.each(function () {
|
||||
if (this.setSelectionRange) {
|
||||
this.focus();
|
||||
this.setSelectionRange(begin, end);
|
||||
} else if (this.createTextRange) {
|
||||
var range = this.createTextRange();
|
||||
range.collapse(true);
|
||||
range.moveEnd('character', end);
|
||||
range.moveStart('character', begin);
|
||||
range.select();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (this[0].setSelectionRange) {
|
||||
begin = this[0].selectionStart;
|
||||
end = this[0].selectionEnd;
|
||||
} else if (document.selection && document.selection.createRange) {
|
||||
var range = document.selection.createRange();
|
||||
begin = -range.duplicate().moveStart('character', -100000);
|
||||
end = begin + range.text.length;
|
||||
}
|
||||
return {"begin": begin, "end": end};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* jsl.interactions - provides support for interactions within JSON Lint.
|
||||
*
|
||||
**/
|
||||
jsl.interactions_ext = (function () {
|
||||
var reformatParam,
|
||||
reformat,
|
||||
compress;
|
||||
|
||||
|
||||
/******* UTILITY METHODS *******/
|
||||
|
||||
/**
|
||||
* Get the Nth position of a character in a string
|
||||
* @searchStr the string to search through
|
||||
* @char the character to find
|
||||
* @pos int the nth character to find, 1 based.
|
||||
*
|
||||
* @return int the position of the character found
|
||||
**/
|
||||
function getNthPos(searchStr, char, pos) {
|
||||
var i,
|
||||
charCount = 0,
|
||||
strArr = searchStr.split(char);
|
||||
|
||||
if (pos === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < pos; i++) {
|
||||
if (i >= strArr.length) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// +1 because we split out some characters
|
||||
charCount += strArr[i].length + char.length;
|
||||
}
|
||||
|
||||
return charCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a URL parameter from the current windows URL.
|
||||
* Courtesy Paul Oppenheim: http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery
|
||||
* @param name the parameter to retrieve
|
||||
* @return string the url parameter's value, if any
|
||||
**/
|
||||
function getURLParameter(name) {
|
||||
param = (new RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || ['', null])[1];
|
||||
if (param) {
|
||||
return decodeURIComponent(param);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/******* INTERACTION METHODS *******/
|
||||
|
||||
/**
|
||||
* Validate the JSON we've been given, displaying an error or success message.
|
||||
* @return void
|
||||
**/
|
||||
function validate() {
|
||||
var lineNum,
|
||||
lineMatches,
|
||||
lineStart,
|
||||
lineEnd,
|
||||
jsonVal,
|
||||
result;
|
||||
|
||||
jsonVal = $('#json_input_ext').val();
|
||||
|
||||
try {
|
||||
result = jsl.parser.parse(jsonVal);
|
||||
|
||||
if (result) {
|
||||
$('#results').removeClass('error').addClass('success');
|
||||
$('div.linedwrap').removeClass('redBorder').addClass('greenBorder');
|
||||
$('#results').text('Valid JSON');
|
||||
|
||||
if (reformat) {
|
||||
$('#json_input_ext').val(JSON.stringify(JSON.parse(jsonVal), null, " "));
|
||||
}
|
||||
|
||||
if (compress) {
|
||||
$('#json_input_ext').val(JSON.stringify(JSON.parse(jsonVal), null, ""));
|
||||
}
|
||||
} else {
|
||||
alert("An unknown error occurred. Please contact Arc90.");
|
||||
}
|
||||
} catch (parseException) {
|
||||
|
||||
/**
|
||||
* If we failed to validate, run our manual formatter and then re-validate so that we
|
||||
* can get a better line number. On a successful validate, we don't want to run our
|
||||
* manual formatter because the automatic one is faster and probably more reliable.
|
||||
**/
|
||||
try {
|
||||
if (reformat) {
|
||||
jsonVal = jsl.format.formatJson($('#json_input_ext').val());
|
||||
$('#json_input_ext').val(jsonVal);
|
||||
result = jsl.parser.parse($('#json_input_ext').val());
|
||||
}
|
||||
} catch(e) {
|
||||
parseException = e;
|
||||
}
|
||||
|
||||
lineMatches = parseException.message.match(/line ([0-9]*)/);
|
||||
if (lineMatches && typeof lineMatches === "object" && lineMatches.length > 1) {
|
||||
lineNum = parseInt(lineMatches[1], 10);
|
||||
|
||||
if (lineNum === 1) {
|
||||
lineStart = 0;
|
||||
} else {
|
||||
lineStart = getNthPos(jsonVal, "\n", lineNum - 1);
|
||||
}
|
||||
|
||||
lineEnd = jsonVal.indexOf("\n", lineStart);
|
||||
if (lineEnd < 0) {
|
||||
lineEnd = jsonVal.length;
|
||||
}
|
||||
|
||||
$('#json_input_ext').focus().caret(lineStart, lineEnd);
|
||||
}
|
||||
|
||||
$('#results').text(parseException.message);
|
||||
|
||||
$('#results').removeClass('success').addClass('error');
|
||||
$('div.linedwrap').removeClass('greenBorder').addClass('redBorder');
|
||||
}
|
||||
|
||||
$('#loadSpinner').hide();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize variables, add event listeners, etc.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function init() {
|
||||
reformatParam = getURLParameter('reformat');
|
||||
reformat = reformatParam !== '0' && reformatParam !== 'no';
|
||||
compress = reformatParam === 'compress',
|
||||
jsonParam = getURLParameter('json');
|
||||
|
||||
if (compress) {
|
||||
$('#headerText').html('JSONLint<span class="light">Compressor</span>');
|
||||
}
|
||||
|
||||
if (!reformat) {
|
||||
$('#headerText').html('JSONLint<span class="light">Lite</span>');
|
||||
}
|
||||
|
||||
//页面加载后执行校验方法
|
||||
validate();
|
||||
|
||||
$('#validate').click(function () {
|
||||
$('#results_header, #loadSpinner').show();
|
||||
|
||||
var jsonVal = $.trim($('#json_input_ext').val());
|
||||
|
||||
if (jsonVal.substring(0, 4).toLowerCase() === "http") {
|
||||
$.post("proxy.php", {"url": jsonVal}, function (responseObj) {
|
||||
$('#json_input_ext').val(responseObj.content);
|
||||
validate();
|
||||
}, 'json');
|
||||
} else {
|
||||
validate();
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#json_input_ext').keyup(function () {
|
||||
$('div.linedwrap').removeClass('greenBorder').removeClass('redBorder');
|
||||
}).linedtextarea({
|
||||
selectedClass: 'lineselect'
|
||||
}).focus();
|
||||
|
||||
$('#reset').click(function () {
|
||||
$('#json_input_ext').val('').focus();
|
||||
});
|
||||
|
||||
$('#faqButton').click(function () {
|
||||
$('#faq').slideToggle();
|
||||
});
|
||||
|
||||
if (jsonParam) {
|
||||
$('#json_input_ext').val(jsonParam);
|
||||
$('#validate').click();
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
'init': init
|
||||
};
|
||||
}());
|
||||
|
||||
$(function () {
|
||||
jsl.interactions_ext.init();
|
||||
});
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user