All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.webjars.jquery.js.jquery.json.js Maven / Gradle / Ivy

/*!
 * jQuery Json Plugin (with Transition Definitions)
 * Examples and documentation at: http://json.cn/
 * Copyright (c) 2012-2013  China.Ren.
 * Version: 1.0.2 (19-OCT-2013)
 * Dual licensed under the MIT and GPL licenses.
 * http://jquery.malsup.com/license.html
 * Requires: jQuery v1.3.1 or later
 */
var JSONFormat = (function(){
    var _toString = Object.prototype.toString;
    var _bigNums = [];
    function format(object, indent_count){
        var html_fragment = '';
        switch(_typeof(object)){
            case 'Null' :0
                html_fragment = _format_null(object);
                break;
            case 'Boolean' :
                html_fragment = _format_boolean(object);
                break;
            case 'Number' :
                html_fragment = _format_number(object);
                break;
            case 'String' :
                html_fragment = _format_string(object);
                break;
            case 'Array' :
                html_fragment = _format_array(object, indent_count);
                break;
            case 'Object' :
                html_fragment = _format_object(object, indent_count);
                break;
        }
        return html_fragment;
    };

    function _format_null(object){
        return 'null';
    }

    function _format_boolean(object){
        return '' + object + '';
    }

    function _format_number(object){
        return '' + object + '';
    }

    function _format_string(object){
        if(!isNaN(object) && object.length>=15 && $.inArray(object, _bigNums)>-1){
            return _format_number(object);
        }
        object = object.replace(/\/g,">");
        if(0 <= object.search(/^http/)){
            object = '' + object + ''
        }
        return '"' + object + '"';
    }

    function _format_array(object, indent_count){
        var tmp_array = [];
        for(var i = 0, size = object.length; i < size; ++i){
            tmp_array.push(indent_tab(indent_count) + format(object[i], indent_count + 1));
        }
        return '[
' + tmp_array.join(',
') + '
' + indent_tab(indent_count - 1) + ']
'; } function _format_object(object, indent_count){ var tmp_array = []; for(var key in object){ tmp_array.push( indent_tab(indent_count) + '"' + key + '":' + format(object[key], indent_count + 1)); } return '{
' + tmp_array.join(',
') + '
' + indent_tab(indent_count - 1) + '}
'; } function indent_tab(indent_count){ return (new Array(indent_count + 1)).join('    '); } function _typeof(object){ var tf = typeof object, ts = _toString.call(object); return null === object ? 'Null' : 'undefined' == tf ? 'Undefined' : 'boolean' == tf ? 'Boolean' : 'number' == tf ? 'Number' : 'string' == tf ? 'String' : '[object Function]' == ts ? 'Function' : '[object Array]' == ts ? 'Array' : '[object Date]' == ts ? 'Date' : 'Object'; }; function loadCssString(){ var style = document.createElement('style'); style.type = 'text/css'; var code = Array.prototype.slice.apply(arguments).join(''); try{ style.appendChild(document.createTextNode(code)); }catch(ex){ style.styleSheet.cssText = code; } document.getElementsByTagName('head')[0].appendChild(style); } loadCssString( '.json_key{ color: #92278f;font-weight:bold;}', '.json_null{color: #f1592a;font-weight:bold;}', '.json_string{ color: #3ab54a;font-weight:bold;}', '.json_number{ color: #25aae2;font-weight:bold;}', '.json_boolean{ color: #f98280;font-weight:bold;}', '.json_link{ color: #61D2D6;font-weight:bold;}', '.json_array_brackets{}'); var _JSONFormat = function(origin_data){ //this.data = origin_data ? origin_data : //JSON && JSON.parse ? JSON.parse(origin_data) : eval('(' + origin_data + ')'); _bigNums = []; var check_data = origin_data.replace(/\s/g,''); var bigNum_regex = /[^\\][\"]([\[:]){1}(\d{16,})([,\}\]])/g; //var tmp_bigNums = check_data.match(bigNum_regex); var m; do { m = bigNum_regex.exec(check_data); if (m) { _bigNums.push(m[2]); origin_data=origin_data.replace(/([\[:])?(\d{16,})\s*([,\}\]])/, "$1\"$2\"$3"); } } while (m); this.data = JSON.parse(origin_data); }; _JSONFormat.prototype = { constructor : JSONFormat, toString : function(){ return format(this.data, 1); } } return _JSONFormat; })(); var last_html = ''; function hide(obj){ var data_type = obj.parentNode.getAttribute('data-type'); var data_size = obj.parentNode.getAttribute('data-size'); obj.parentNode.setAttribute('data-inner',obj.parentNode.innerHTML); if (data_type === 'array') { obj.parentNode.innerHTML = 'Array[' + data_size + ']'; }else{ obj.parentNode.innerHTML = 'Object{...}'; } } function show(obj){ var innerHtml = obj.parentNode.getAttribute('data-inner'); obj.parentNode.innerHTML = innerHtml; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy