Git Product home page Git Product logo

json-formatter's People

Contributors

aharwood avatar andrew avatar emmasax avatar pharsadi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

json-formatter's Issues

.toggle click event needs to be "scoped" to its instance's list_id setting

Issue:
.toggle click event needs to be "scoped" to its instance's list_id setting

Description:
If more than one Instance of JSONFormatter is used then the click event gets binded {n} times.
So, if an object is toggled it will close right after it opens.

Code Reference:

$('.toggle').next().slideUp().end().text(' + ').on('click', function() {

Reproduce:

  1. touch test.html && vi test.html
<html>
    <head>
        <title>Issue x</title>
        <!-- jQuery -->
        <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
        <!-- JSONFormatter -->
        <link rel="stylesheet" href="JSONFormatter.css">
        <script type="text/javascript" src="JSONFormatter.js"></script>
    </head>
    <body>
        <div class="code">{"foo": {"foo": "bar"}}</div>
        <div class="code">{"foo": {"foo": "bar"}}</div>
        <div class="code">{"foo": {"foo": "bar"}}</div>
        
        <script type="text/javascript">
            // fancy way to setup code
            var loop = 5;
            var $els = $('.code');
            for (var i = 0; i <= $els.length - 1; i++ ) {
                $el = $els[i];
                var json = JSON.parse($el.innerText);
                var ref = '.code:eq(' + $els.index($el) + ')';
                $(ref).empty();
                JSONFormatter.format(json, {'appendTo': ref, 'collapse': true, 'list_id': 'json_' + i});
            }
        </script>
    </body>
</html>
  1. open test.html

Suggestions and Typo Fix

In the readme, you have this as the options object

{
collapse: false, // Setting to 'true' this will format the JSON into a collapsable/expandable tree
append_to: 'body', // A string of the id, class or element name to append the formatted json
list_id: 'json' // The name of the id at the root ul of the formatted JSON
}

append_to should be appendTo

It also isn't clear that when you say

JSONFormatter.format(json, {});

that json is a javascript object and not a JSON string. Initially, I did this after reading the readme.

var myObj = {"blah":"blah"};
var json = JSON.stringify(myObj);
JSONFormatter.format(json, {});

and of course that didn't work.

The other thing that might be nice is if the formatter would just return a DOM node of what you have produced.

Then I could put it wherever I want.

IE.

var node = JSONFormatter.format(json, {});
myElement.appendChild(node);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.