hulk

所属分类:JavaScript/JQuery
开发工具:JavaScript
文件大小:147KB
下载次数:0
上传日期:2019-10-13 07:38:53
上 传 者sh-1993
说明:  浏览器内JSON编辑器
(In-browser JSON editor)

文件列表:
AUTHORS.md (123, 2015-08-12)
CHANGES.md (199, 2015-08-12)
Gruntfile.js (1546, 2015-08-12)
LICENSE (1078, 2015-08-12)
Makefile (241, 2015-08-12)
css (0, 2015-08-12)
css\hulk-all.css (2741, 2015-08-12)
css\hulk-colors.css (2004, 2015-08-12)
css\hulk.css (736, 2015-08-12)
example (0, 2015-08-12)
example\bootstrap-responsive.min.css (16849, 2015-08-12)
example\bootstrap.min.css (105939, 2015-08-12)
example\codemirror-compressed.js (114888, 2015-08-12)
example\codemirror.css (6025, 2015-08-12)
example\index.html (4236, 2015-08-12)
hulk.js (17295, 2015-08-12)
hulk.min.js (5441, 2015-08-12)
scss (0, 2015-08-12)
scss\hulk-all.scss (50, 2015-08-12)
scss\hulk-colors.scss (2372, 2015-08-12)
scss\hulk.scss (893, 2015-08-12)
tests (0, 2015-08-12)
tests\jquery.min.js (93868, 2015-08-12)
tests\qunit-1.11.0.css (4668, 2015-08-12)
tests\qunit-1.11.0.js (56908, 2015-08-12)
tests\qunit.js (58796, 2015-08-12)
tests\test.html (436, 2015-08-12)
tests\tests.js (5398, 2015-08-12)

# Hulk Hulk is an in-browser JSON editor. [View an example][example] [example]: http://kevinburke.github.io/hulk/example/ ## Usage ```javascript $.hulk('#selector', {foo: "bar"}, function(data) { console.log("Here's the updated data: " + data); }); ``` Will insert the JSON editor into the div with id "selector". Generally ID's are preferred. The third argument is a callback that will execute when the user presses "Save". Alternatively, you can retrieve the state of the world at any point by calling: ```javascript $.hulkSmash('#selector'); ``` There are two CSS files, `hulk.css` and `hulk-colors.css`, which make the layout much more readable. Of course, you are happy to style the inputs however you desire. ## Argument documentation The `$.hulk` function takes the following arguments in this order: - **selector (string)** - Any valid jQuery selector. The input nodes will be inserted into the DOM based on the selector you give. This argument is required. - **data (object)** - Any valid JSON object. This will be serialized and splayed into the DOM. This argument is required. - **callback (function)** - When the user presses "Save" hulk will re-serialize the data and pass it as an argument to the function you provide. This argument is optional. - **options (object)** - A dictionary of optional settings for hulk. The possible options are outlined below. This argument is optional. The `$.hulkSmash` function takes the following arguments in this order: - **selector (string)** - Any valid jQuery selector. The input nodes will be inserted into the DOM based on the selector you give. This argument is required. - **options (object)** - A dictionary of optional settings for hulk. The possible options are outlined below. This argument is optional. ### Optional settings These are options that you can pass to either `$.hulk` or `$.hulkSmash`. - **separator (string)** - Define a custom separator between keys and values. By default, the separator is "=>". - **emptyString (string)** - Serialize an empty text input field back into JSON using the empty string (`""`) instead of `null`. Defaults to `false`. - **depth (int)** - Collapse all dictionaries and lists that are nested deeper than `depth`. `depth=0` will collapse everything. `depth=-1` will expand everything. The default is to show all JSON. - **smartParsing (boolean)** - Try to parse text inputs into matching data types, eg turn the string "5.53" into the number 5.53 when serializing into JSON, and turn "true" into true. If set to `false`, all objects will be serialized as strings. The default is ``true``. - **showSaveButton (boolean)** - Whether to show the "Save" button. The default is to show the button. - **permissions (array of strings)** - Define how customizable and editable the custom JSON dictionary is. For example, you may only want to update existing values, not add new objects. This takes a few different values - "all" - allow the user to edit everything. This is the default. - "values-only" - only allow the user to edit the leaf nodes. Keys cannot be added or modified. - "no-append" - User can edit keys and values, but can't add or delete nodes from the object. ### Why? Editing raw JSON is error-prone and not friendly to non-technical people. This makes it easy to edit and serialize JSON. This also makes it easy for a programmer and a non-technical user to collaborate. We also use this tool internally at [Twilio][twilio] to edit configuration files. [twilio]: https://www.twilio.com ### Notes - Javascript objects do not maintain a sorted order. This means, when serializing an object from HTML to JSON, the keys will not be sorted. To maintain some semblance of order, keys are presented on the page in alphabetical order when serializing from JSON to HTML (this is something we can control). Consider sorting keys once they are received on the server or whichever sane language is dealing with your new JSON object. - There is inherent uncertainty in using text inputs for data entry. Does the entry "5.5" represent the number 5.5 or the string "5.5"? In this case we do some basic parsing. - if the value looks like a number, it's converted to a number - if the value looks like a boolean ("true" or "false"), it's converted to a boolean - if the value is empty, or the word "null", it's converted to the null value. That said, if you set the `smartParsing` option to `false`, all inputs will be serialized and returned as strings. ## Installation 1. Include the jQuery source on your page 2. Include the `hulk` plugin. 3. Call away

近期下载者

相关文件


收藏者