diff --git a/README.md b/README.md index 3fc67e34fec..3df737df4f7 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,24 @@ The theme will adapt to screen size and works on tablets and mobile phones. [![Swagger Theme example](dist/images/Swagger_explorer_min.png)](http://ecs.bobbytech.dk/api) +A JSON editor for the request body (disabled by default). + +![Swagger JSON editor example](dist/images/json_editor_integration.png) + +JSON editor configuration example: + +```javascript + jsonEditor: true, + jsonEditorOptions: { + disableProperties:false, + disableEditJson:false, + removeEmptyProperties:true, + noDefaultProperties:true + }, + docExpansion: "none", + sorter: "alpha", +``` + Give it a [try](http://swaggerui.herokuapp.com/) and enter your own swagger definition. diff --git a/dist/css/api-explorer.css b/dist/css/api-explorer.css index c2b4cf2a9e7..ef3abd4e97c 100644 --- a/dist/css/api-explorer.css +++ b/dist/css/api-explorer.css @@ -205,7 +205,7 @@ background: #ff9a57 } -.swagger-section .form-control.error { +.swagger-section .ui-form-control.error { border-color: #fd8888; border-width: 2px } @@ -346,17 +346,17 @@ } } -.swagger-section .parameter-item .form-control { +.swagger-section .parameter-item .ui-form-control { width: auto; max-width: 100% } -.swagger-section .parameter-item .form-control.body-textarea { +.swagger-section .parameter-item .ui-form-control.body-textarea { min-height: 100px; width: 100% } -.swagger-section .parameter-item select.form-control { +.swagger-section .parameter-item select.ui-form-control { width: auto } diff --git a/dist/css/index.css b/dist/css/index.css index c352d986441..96e7585f1b1 100644 --- a/dist/css/index.css +++ b/dist/css/index.css @@ -1657,6 +1657,21 @@ pre code { margin-right: -15px; margin-left: -15px; } + +.row { + margin-right: -15px; + margin-left: -15px; +} + +.editor_holder .row { + margin-right: 0 !important; + margin-left: 0 !important; +} + +.editor_holder .row { + margin-right: 0 !important; + margin-left: 0 !important; +} .col-xs-1, .col-sm-1, .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2, .col-md-2, .col-lg-2, .col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, .col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, .col-xs-5, .col-sm-5, .col-md-5, .col-lg-5, .col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, .col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, .col-xs-8, .col-sm-8, .col-md-8, .col-lg-8, .col-xs-9, .col-sm-9, .col-md-9, .col-lg-9, .col-xs-10, .col-sm-10, .col-md-10, .col-lg-10, .col-xs-11, .col-sm-11, .col-md-11, .col-lg-11, .col-xs-12, .col-sm-12, .col-md-12, .col-lg-12 { position: relative; min-height: 1px; @@ -2592,7 +2607,7 @@ output { line-height: 1.42857143; color: #555; } -.form-control { +.ui-form-control { display: block; width: 100%; height: 34px; @@ -2610,33 +2625,33 @@ output { -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; } -.form-control:focus { +.ui-form-control:focus { border-color: #66afe9; outline: 0; -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6); box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6); } -.form-control::-moz-placeholder { +.ui-form-control::-moz-placeholder { color: #999; opacity: 1; } -.form-control:-ms-input-placeholder { +.ui-form-control:-ms-input-placeholder { color: #999; } -.form-control::-webkit-input-placeholder { +.ui-form-control::-webkit-input-placeholder { color: #999; } -.form-control[disabled], -.form-control[readonly], -fieldset[disabled] .form-control { +.ui-form-control[disabled], +.ui-form-control[readonly], +fieldset[disabled] .ui-form-control { background-color: #eee; opacity: 1; } -.form-control[disabled], -fieldset[disabled] .form-control { +.ui-form-control[disabled], +fieldset[disabled] .ui-form-control { cursor: not-allowed; } -textarea.form-control { +textarea.ui-form-control { height: auto; } input[type="search"] { @@ -2735,14 +2750,14 @@ fieldset[disabled] .radio label, fieldset[disabled] .checkbox label { cursor: not-allowed; } -.form-control-static { +.ui-form-control-static { min-height: 34px; padding-top: 7px; padding-bottom: 7px; margin-bottom: 0; } -.form-control-static.input-lg, -.form-control-static.input-sm { +.ui-form-control-static.input-lg, +.ui-form-control-static.input-sm { padding-right: 0; padding-left: 0; } @@ -2761,22 +2776,22 @@ textarea.input-sm, select[multiple].input-sm { height: auto; } -.form-group-sm .form-control { +.form-group-sm .ui-form-control { height: 30px; padding: 5px 10px; font-size: 12px; line-height: 1.5; border-radius: 3px; } -select.form-group-sm .form-control { +select.form-group-sm .ui-form-control { height: 30px; line-height: 30px; } -textarea.form-group-sm .form-control, -select[multiple].form-group-sm .form-control { +textarea.form-group-sm .ui-form-control, +select[multiple].form-group-sm .ui-form-control { height: auto; } -.form-group-sm .form-control-static { +.form-group-sm .ui-form-control-static { height: 30px; min-height: 32px; padding: 5px 10px; @@ -2798,22 +2813,22 @@ textarea.input-lg, select[multiple].input-lg { height: auto; } -.form-group-lg .form-control { +.form-group-lg .ui-form-control { height: 46px; padding: 10px 16px; font-size: 18px; line-height: 1.3333333; border-radius: 6px; } -select.form-group-lg .form-control { +select.form-group-lg .ui-form-control { height: 46px; line-height: 46px; } -textarea.form-group-lg .form-control, -select[multiple].form-group-lg .form-control { +textarea.form-group-lg .ui-form-control, +select[multiple].form-group-lg .ui-form-control { height: auto; } -.form-group-lg .form-control-static { +.form-group-lg .ui-form-control-static { height: 46px; min-height: 38px; padding: 10px 16px; @@ -2823,10 +2838,10 @@ select[multiple].form-group-lg .form-control { .has-feedback { position: relative; } -.has-feedback .form-control { +.has-feedback .ui-form-control { padding-right: 42.5px; } -.form-control-feedback { +.ui-form-control-feedback { position: absolute; top: 0; right: 0; @@ -2838,12 +2853,12 @@ select[multiple].form-group-lg .form-control { text-align: center; pointer-events: none; } -.input-lg + .form-control-feedback { +.input-lg + .ui-form-control-feedback { width: 46px; height: 46px; line-height: 46px; } -.input-sm + .form-control-feedback { +.input-sm + .ui-form-control-feedback { width: 30px; height: 30px; line-height: 30px; @@ -2860,12 +2875,12 @@ select[multiple].form-group-lg .form-control { .has-success.checkbox-inline label { color: #3c763d; } -.has-success .form-control { +.has-success .ui-form-control { border-color: #3c763d; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); } -.has-success .form-control:focus { +.has-success .ui-form-control:focus { border-color: #2b542c; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #67b168; box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #67b168; @@ -2875,7 +2890,7 @@ select[multiple].form-group-lg .form-control { background-color: #dff0d8; border-color: #3c763d; } -.has-success .form-control-feedback { +.has-success .ui-form-control-feedback { color: #3c763d; } .has-warning .help-block, @@ -2890,12 +2905,12 @@ select[multiple].form-group-lg .form-control { .has-warning.checkbox-inline label { color: #8a6d3b; } -.has-warning .form-control { +.has-warning .ui-form-control { border-color: #8a6d3b; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); } -.has-warning .form-control:focus { +.has-warning .ui-form-control:focus { border-color: #66512c; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #c0a16b; box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #c0a16b; @@ -2905,7 +2920,7 @@ select[multiple].form-group-lg .form-control { background-color: #fcf8e3; border-color: #8a6d3b; } -.has-warning .form-control-feedback { +.has-warning .ui-form-control-feedback { color: #8a6d3b; } .has-error .help-block, @@ -2920,12 +2935,12 @@ select[multiple].form-group-lg .form-control { .has-error.checkbox-inline label { color: #a94442; } -.has-error .form-control { +.has-error .ui-form-control { border-color: #a94442; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); } -.has-error .form-control:focus { +.has-error .ui-form-control:focus { border-color: #843534; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #ce8483; box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #ce8483; @@ -2935,13 +2950,13 @@ select[multiple].form-group-lg .form-control { background-color: #f2dede; border-color: #a94442; } -.has-error .form-control-feedback { +.has-error .ui-form-control-feedback { color: #a94442; } -.has-feedback label ~ .form-control-feedback { +.has-feedback label ~ .ui-form-control-feedback { top: 25px; } -.has-feedback label.sr-only ~ .form-control-feedback { +.has-feedback label.sr-only ~ .ui-form-control-feedback { top: 0; } .help-block { @@ -2956,12 +2971,12 @@ select[multiple].form-group-lg .form-control { margin-bottom: 0; vertical-align: middle; } - .form-inline .form-control { + .form-inline .ui-form-control { display: inline-block; width: auto; vertical-align: middle; } - .form-inline .form-control-static { + .form-inline .ui-form-control-static { display: inline-block; } .form-inline .input-group { @@ -2970,10 +2985,10 @@ select[multiple].form-group-lg .form-control { } .form-inline .input-group .input-group-addon, .form-inline .input-group .input-group-btn, - .form-inline .input-group .form-control { + .form-inline .input-group .ui-form-control { width: auto; } - .form-inline .input-group > .form-control { + .form-inline .input-group > .ui-form-control { width: 100%; } .form-inline .control-label { @@ -2996,7 +3011,7 @@ select[multiple].form-group-lg .form-control { position: relative; margin-left: 0; } - .form-inline .has-feedback .form-control-feedback { + .form-inline .has-feedback .ui-form-control-feedback { top: 0; } } @@ -3023,7 +3038,7 @@ select[multiple].form-group-lg .form-control { text-align: right; } } -.form-horizontal .has-feedback .form-control-feedback { +.form-horizontal .has-feedback .ui-form-control-feedback { right: 15px; } @media (min-width: 768px) { @@ -3780,14 +3795,14 @@ tbody.collapse.in { padding-right: 0; padding-left: 0; } -.input-group .form-control { +.input-group .ui-form-control { position: relative; z-index: 2; float: left; width: 100%; margin-bottom: 0; } -.input-group-lg > .form-control, +.input-group-lg > .ui-form-control, .input-group-lg > .input-group-addon, .input-group-lg > .input-group-btn > .btn { height: 46px; @@ -3796,21 +3811,21 @@ tbody.collapse.in { line-height: 1.3333333; border-radius: 6px; } -select.input-group-lg > .form-control, +select.input-group-lg > .ui-form-control, select.input-group-lg > .input-group-addon, select.input-group-lg > .input-group-btn > .btn { height: 46px; line-height: 46px; } -textarea.input-group-lg > .form-control, +textarea.input-group-lg > .ui-form-control, textarea.input-group-lg > .input-group-addon, textarea.input-group-lg > .input-group-btn > .btn, -select[multiple].input-group-lg > .form-control, +select[multiple].input-group-lg > .ui-form-control, select[multiple].input-group-lg > .input-group-addon, select[multiple].input-group-lg > .input-group-btn > .btn { height: auto; } -.input-group-sm > .form-control, +.input-group-sm > .ui-form-control, .input-group-sm > .input-group-addon, .input-group-sm > .input-group-btn > .btn { height: 30px; @@ -3819,28 +3834,28 @@ select[multiple].input-group-lg > .input-group-btn > .btn { line-height: 1.5; border-radius: 3px; } -select.input-group-sm > .form-control, +select.input-group-sm > .ui-form-control, select.input-group-sm > .input-group-addon, select.input-group-sm > .input-group-btn > .btn { height: 30px; line-height: 30px; } -textarea.input-group-sm > .form-control, +textarea.input-group-sm > .ui-form-control, textarea.input-group-sm > .input-group-addon, textarea.input-group-sm > .input-group-btn > .btn, -select[multiple].input-group-sm > .form-control, +select[multiple].input-group-sm > .ui-form-control, select[multiple].input-group-sm > .input-group-addon, select[multiple].input-group-sm > .input-group-btn > .btn { height: auto; } .input-group-addon, .input-group-btn, -.input-group .form-control { +.input-group .ui-form-control { display: table-cell; } .input-group-addon:not(:first-child):not(:last-child), .input-group-btn:not(:first-child):not(:last-child), -.input-group .form-control:not(:first-child):not(:last-child) { +.input-group .ui-form-control:not(:first-child):not(:last-child) { border-radius: 0; } .input-group-addon, @@ -3874,7 +3889,7 @@ select[multiple].input-group-sm > .input-group-btn > .btn { .input-group-addon input[type="checkbox"] { margin-top: 0; } -.input-group .form-control:first-child, +.input-group .ui-form-control:first-child, .input-group-addon:first-child, .input-group-btn:first-child > .btn, .input-group-btn:first-child > .btn-group > .btn, @@ -3887,7 +3902,7 @@ select[multiple].input-group-sm > .input-group-btn > .btn { .input-group-addon:first-child { border-right: 0; } -.input-group .form-control:last-child, +.input-group .ui-form-control:last-child, .input-group-addon:last-child, .input-group-btn:last-child > .btn, .input-group-btn:last-child > .btn-group > .btn, @@ -4334,12 +4349,12 @@ select[multiple].input-group-sm > .input-group-btn > .btn { margin-bottom: 0; vertical-align: middle; } - .navbar-form .form-control { + .navbar-form .ui-form-control { display: inline-block; width: auto; vertical-align: middle; } - .navbar-form .form-control-static { + .navbar-form .ui-form-control-static { display: inline-block; } .navbar-form .input-group { @@ -4348,10 +4363,10 @@ select[multiple].input-group-sm > .input-group-btn > .btn { } .navbar-form .input-group .input-group-addon, .navbar-form .input-group .input-group-btn, - .navbar-form .input-group .form-control { + .navbar-form .input-group .ui-form-control { width: auto; } - .navbar-form .input-group > .form-control { + .navbar-form .input-group > .ui-form-control { width: 100%; } .navbar-form .control-label { @@ -4374,7 +4389,7 @@ select[multiple].input-group-sm > .input-group-btn > .btn { position: relative; margin-left: 0; } - .navbar-form .has-feedback .form-control-feedback { + .navbar-form .has-feedback .ui-form-control-feedback { top: 0; } } diff --git a/dist/css/print.css b/dist/css/print.css index b4fc18036ef..32764df8378 100644 --- a/dist/css/print.css +++ b/dist/css/print.css @@ -82,7 +82,7 @@ .swagger-section pre .vhdl .attribute, .swagger-section pre .clojure .attribute, .swagger-section pre .coffeescript .property { - color: #8888ff; + color: #88F; } .swagger-section pre .keyword, .swagger-section pre .id, @@ -126,6 +126,7 @@ max-width: 960px; margin-left: auto; margin-right: auto; + /* JSONEditor specific styling */ } .swagger-section .swagger-ui-wrap b, .swagger-section .swagger-ui-wrap strong { @@ -456,6 +457,17 @@ font-family: "Droid Sans", sans-serif; font-weight: bold; } +.swagger-section .swagger-ui-wrap .editor_holder { + font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace; + font-size: 0.9em; +} +.swagger-section .swagger-ui-wrap .editor_holder label { + font-weight: normal!important; + /* JSONEditor uses bold by default for all labels, we revert that back to normal to not give the impression that by default fields are required */ +} +.swagger-section .swagger-ui-wrap .editor_holder label.required { + font-weight: bold!important; +} .swagger-section .swagger-ui-wrap .heading_with_menu { float: none; clear: both; diff --git a/dist/css/screen.css b/dist/css/screen.css index 32b199b17b6..12ec0c57d5b 100644 --- a/dist/css/screen.css +++ b/dist/css/screen.css @@ -1,1256 +1,9 @@ -/* Original style from softwaremaniacs.org (c) Ivan Sagalaev */ -.swagger-section pre code { - display: block; - padding: 0.5em; - background: #F0F0F0; +.swagger-section .swagger-collapse:before { + content: "-"; } -.swagger-section pre code, -.swagger-section pre .subst, -.swagger-section pre .tag .title, -.swagger-section pre .lisp .title, -.swagger-section pre .clojure .built_in, -.swagger-section pre .nginx .title { - color: black; +.swagger-section .swagger-expand:before { + content: "+"; } -.swagger-section pre .string, -.swagger-section pre .title, -.swagger-section pre .constant, -.swagger-section pre .parent, -.swagger-section pre .tag .value, -.swagger-section pre .rules .value, -.swagger-section pre .rules .value .number, -.swagger-section pre .preprocessor, -.swagger-section pre .ruby .symbol, -.swagger-section pre .ruby .symbol .string, -.swagger-section pre .aggregate, -.swagger-section pre .template_tag, -.swagger-section pre .django .variable, -.swagger-section pre .smalltalk .class, -.swagger-section pre .addition, -.swagger-section pre .flow, -.swagger-section pre .stream, -.swagger-section pre .bash .variable, -.swagger-section pre .apache .tag, -.swagger-section pre .apache .cbracket, -.swagger-section pre .tex .command, -.swagger-section pre .tex .special, -.swagger-section pre .erlang_repl .function_or_atom, -.swagger-section pre .markdown .header { - color: #800; -} -.swagger-section pre .comment, -.swagger-section pre .annotation, -.swagger-section pre .template_comment, -.swagger-section pre .diff .header, -.swagger-section pre .chunk, -.swagger-section pre .markdown .blockquote { - color: #888; -} -.swagger-section pre .number, -.swagger-section pre .date, -.swagger-section pre .regexp, -.swagger-section pre .literal, -.swagger-section pre .smalltalk .symbol, -.swagger-section pre .smalltalk .char, -.swagger-section pre .go .constant, -.swagger-section pre .change, -.swagger-section pre .markdown .bullet, -.swagger-section pre .markdown .link_url { - color: #080; -} -.swagger-section pre .label, -.swagger-section pre .javadoc, -.swagger-section pre .ruby .string, -.swagger-section pre .decorator, -.swagger-section pre .filter .argument, -.swagger-section pre .localvars, -.swagger-section pre .array, -.swagger-section pre .attr_selector, -.swagger-section pre .important, -.swagger-section pre .pseudo, -.swagger-section pre .pi, -.swagger-section pre .doctype, -.swagger-section pre .deletion, -.swagger-section pre .envvar, -.swagger-section pre .shebang, -.swagger-section pre .apache .sqbracket, -.swagger-section pre .nginx .built_in, -.swagger-section pre .tex .formula, -.swagger-section pre .erlang_repl .reserved, -.swagger-section pre .prompt, -.swagger-section pre .markdown .link_label, -.swagger-section pre .vhdl .attribute, -.swagger-section pre .clojure .attribute, -.swagger-section pre .coffeescript .property { - color: #8888ff; -} -.swagger-section pre .keyword, -.swagger-section pre .id, -.swagger-section pre .phpdoc, -.swagger-section pre .title, -.swagger-section pre .built_in, -.swagger-section pre .aggregate, -.swagger-section pre .css .tag, -.swagger-section pre .javadoctag, -.swagger-section pre .phpdoc, -.swagger-section pre .yardoctag, -.swagger-section pre .smalltalk .class, -.swagger-section pre .winutils, -.swagger-section pre .bash .variable, -.swagger-section pre .apache .tag, -.swagger-section pre .go .typename, -.swagger-section pre .tex .command, -.swagger-section pre .markdown .strong, -.swagger-section pre .request, -.swagger-section pre .status { - font-weight: bold; -} -.swagger-section pre .markdown .emphasis { - font-style: italic; -} -.swagger-section pre .nginx .built_in { - font-weight: normal; -} -.swagger-section pre .coffeescript .javascript, -.swagger-section pre .javascript .xml, -.swagger-section pre .tex .formula, -.swagger-section pre .xml .javascript, -.swagger-section pre .xml .vbscript, -.swagger-section pre .xml .css, -.swagger-section pre .xml .cdata { - opacity: 0.5; -} -.swagger-section .swagger-ui-wrap { - line-height: 1; - font-family: "Droid Sans", sans-serif; - max-width: 960px; - margin-left: auto; - margin-right: auto; -} -.swagger-section .swagger-ui-wrap b, -.swagger-section .swagger-ui-wrap strong { - font-family: "Droid Sans", sans-serif; - font-weight: bold; -} -.swagger-section .swagger-ui-wrap q, -.swagger-section .swagger-ui-wrap blockquote { - quotes: none; -} -.swagger-section .swagger-ui-wrap p { - line-height: 1.4em; - padding: 0 0 10px; - color: #333333; -} -.swagger-section .swagger-ui-wrap q:before, -.swagger-section .swagger-ui-wrap q:after, -.swagger-section .swagger-ui-wrap blockquote:before, -.swagger-section .swagger-ui-wrap blockquote:after { - content: none; -} -.swagger-section .swagger-ui-wrap .heading_with_menu h1, -.swagger-section .swagger-ui-wrap .heading_with_menu h2, -.swagger-section .swagger-ui-wrap .heading_with_menu h3, -.swagger-section .swagger-ui-wrap .heading_with_menu h4, -.swagger-section .swagger-ui-wrap .heading_with_menu h5, -.swagger-section .swagger-ui-wrap .heading_with_menu h6 { - display: block; - clear: none; - float: left; - -moz-box-sizing: border-box; - -webkit-box-sizing: border-box; - -ms-box-sizing: border-box; - box-sizing: border-box; - width: 60%; -} -.swagger-section .swagger-ui-wrap table { - border-collapse: collapse; - border-spacing: 0; -} -.swagger-section .swagger-ui-wrap table thead tr th { - padding: 5px; - font-size: 0.9em; - color: #666666; - border-bottom: 1px solid #999999; -} -.swagger-section .swagger-ui-wrap table tbody tr:last-child td { - border-bottom: none; -} -.swagger-section .swagger-ui-wrap table tbody tr.offset { - background-color: #f0f0f0; -} -.swagger-section .swagger-ui-wrap table tbody tr td { - padding: 6px; - font-size: 0.9em; - border-bottom: 1px solid #cccccc; - vertical-align: top; - line-height: 1.3em; -} -.swagger-section .swagger-ui-wrap ol { - margin: 0px 0 10px; - padding: 0 0 0 18px; - list-style-type: decimal; -} -.swagger-section .swagger-ui-wrap ol li { - padding: 5px 0px; - font-size: 0.9em; - color: #333333; -} -.swagger-section .swagger-ui-wrap ol, -.swagger-section .swagger-ui-wrap ul { - list-style: none; -} -.swagger-section .swagger-ui-wrap h1 a, -.swagger-section .swagger-ui-wrap h2 a, -.swagger-section .swagger-ui-wrap h3 a, -.swagger-section .swagger-ui-wrap h4 a, -.swagger-section .swagger-ui-wrap h5 a, -.swagger-section .swagger-ui-wrap h6 a { - text-decoration: none; -} -.swagger-section .swagger-ui-wrap h1 a:hover, -.swagger-section .swagger-ui-wrap h2 a:hover, -.swagger-section .swagger-ui-wrap h3 a:hover, -.swagger-section .swagger-ui-wrap h4 a:hover, -.swagger-section .swagger-ui-wrap h5 a:hover, -.swagger-section .swagger-ui-wrap h6 a:hover { - text-decoration: underline; -} -.swagger-section .swagger-ui-wrap h1 span.divider, -.swagger-section .swagger-ui-wrap h2 span.divider, -.swagger-section .swagger-ui-wrap h3 span.divider, -.swagger-section .swagger-ui-wrap h4 span.divider, -.swagger-section .swagger-ui-wrap h5 span.divider, -.swagger-section .swagger-ui-wrap h6 span.divider { - color: #aaaaaa; -} -.swagger-section .swagger-ui-wrap a { - color: #547f00; -} -.swagger-section .swagger-ui-wrap a img { - border: none; -} -.swagger-section .swagger-ui-wrap article, -.swagger-section .swagger-ui-wrap aside, -.swagger-section .swagger-ui-wrap details, -.swagger-section .swagger-ui-wrap figcaption, -.swagger-section .swagger-ui-wrap figure, -.swagger-section .swagger-ui-wrap footer, -.swagger-section .swagger-ui-wrap header, -.swagger-section .swagger-ui-wrap hgroup, -.swagger-section .swagger-ui-wrap menu, -.swagger-section .swagger-ui-wrap nav, -.swagger-section .swagger-ui-wrap section, -.swagger-section .swagger-ui-wrap summary { - display: block; -} -.swagger-section .swagger-ui-wrap pre { - font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace; - background-color: #fcf6db; - border: 1px solid #e5e0c6; - padding: 10px; -} -.swagger-section .swagger-ui-wrap pre code { - line-height: 1.6em; - background: none; -} -.swagger-section .swagger-ui-wrap .content > .content-type > div > label { - clear: both; - display: block; - color: #0F6AB4; - font-size: 1.1em; - margin: 0; - padding: 15px 0 5px; -} -.swagger-section .swagger-ui-wrap .content pre { - font-size: 12px; - margin-top: 5px; - padding: 5px; -} -.swagger-section .swagger-ui-wrap .icon-btn { - cursor: pointer; -} -.swagger-section .swagger-ui-wrap .info_title { - padding-bottom: 10px; - font-weight: bold; - font-size: 25px; -} -.swagger-section .swagger-ui-wrap p.big, -.swagger-section .swagger-ui-wrap div.big p { - font-size: 1em; - margin-bottom: 10px; -} -.swagger-section .swagger-ui-wrap form.fullwidth ol li.string input, -.swagger-section .swagger-ui-wrap form.fullwidth ol li.url input, -.swagger-section .swagger-ui-wrap form.fullwidth ol li.text textarea, -.swagger-section .swagger-ui-wrap form.fullwidth ol li.numeric input { - width: 500px !important; -} -.swagger-section .swagger-ui-wrap .info_license { - padding-bottom: 5px; -} -.swagger-section .swagger-ui-wrap .info_tos { - padding-bottom: 5px; -} -.swagger-section .swagger-ui-wrap .message-fail { - color: #cc0000; -} -.swagger-section .swagger-ui-wrap .info_url { - padding-bottom: 5px; -} -.swagger-section .swagger-ui-wrap .info_email { - padding-bottom: 5px; -} -.swagger-section .swagger-ui-wrap .info_name { - padding-bottom: 5px; -} -.swagger-section .swagger-ui-wrap .info_description { - padding-bottom: 10px; - font-size: 15px; -} -.swagger-section .swagger-ui-wrap .markdown ol li, -.swagger-section .swagger-ui-wrap .markdown ul li { - padding: 3px 0px; - line-height: 1.4em; - color: #333333; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.string input, -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.url input, -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.numeric input { - display: block; - padding: 4px; - width: auto; - clear: both; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.string input.title, -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.url input.title, -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.numeric input.title { - font-size: 1.3em; -} -.swagger-section .swagger-ui-wrap table.fullwidth { - width: 100%; -} -.swagger-section .swagger-ui-wrap .model-signature { - font-family: "Droid Sans", sans-serif; - font-size: 1em; - line-height: 1.5em; -} -.swagger-section .swagger-ui-wrap .model-signature .signature-nav a { - text-decoration: none; - color: #AAA; -} -.swagger-section .swagger-ui-wrap .model-signature .signature-nav a:hover { - text-decoration: underline; - color: black; -} -.swagger-section .swagger-ui-wrap .model-signature .signature-nav .selected { - color: black; - text-decoration: none; -} -.swagger-section .swagger-ui-wrap .model-signature .propType { - color: #5555aa; -} -.swagger-section .swagger-ui-wrap .model-signature pre:hover { - background-color: #ffffdd; -} -.swagger-section .swagger-ui-wrap .model-signature pre { - font-size: .85em; - line-height: 1.2em; - overflow: auto; - max-height: 200px; - cursor: pointer; -} -.swagger-section .swagger-ui-wrap .model-signature ul.signature-nav { - display: block; - margin: 0; - padding: 0; -} -.swagger-section .swagger-ui-wrap .model-signature ul.signature-nav li:last-child { - padding-right: 0; - border-right: none; -} -.swagger-section .swagger-ui-wrap .model-signature ul.signature-nav li { - float: left; - margin: 0 5px 5px 0; - padding: 2px 5px 2px 0; - border-right: 1px solid #ddd; -} -.swagger-section .swagger-ui-wrap .model-signature .propOpt { - color: #555; -} -.swagger-section .swagger-ui-wrap .model-signature .snippet small { - font-size: 0.75em; -} -.swagger-section .swagger-ui-wrap .model-signature .propOptKey { - font-style: italic; -} -.swagger-section .swagger-ui-wrap .model-signature .description .strong { - font-weight: bold; - color: #000; - font-size: .9em; -} -.swagger-section .swagger-ui-wrap .model-signature .description div { - font-size: 0.9em; - line-height: 1.5em; - margin-left: 1em; -} -.swagger-section .swagger-ui-wrap .model-signature .description .stronger { - font-weight: bold; - color: #000; -} -.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper { - border-spacing: 0; - position: absolute; - background-color: #ffffff; - border: 1px solid #bbbbbb; - display: none; - font-size: 11px; - max-width: 400px; - line-height: 30px; - color: black; - padding: 5px; - margin-left: 10px; -} -.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper th { - text-align: center; - background-color: #eeeeee; - border: 1px solid #bbbbbb; - font-size: 11px; - color: #666666; - font-weight: bold; - padding: 5px; - line-height: 15px; -} -.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper .optionName { - font-weight: bold; -} -.swagger-section .swagger-ui-wrap .model-signature .propName { - font-weight: bold; -} -.swagger-section .swagger-ui-wrap .model-signature .signature-container { - clear: both; -} -.swagger-section .swagger-ui-wrap .body-textarea { - width: 300px; - height: 100px; - border: 1px solid #aaa; -} -.swagger-section .swagger-ui-wrap .markdown p code, -.swagger-section .swagger-ui-wrap .markdown li code { - font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace; - background-color: #f0f0f0; - color: black; - padding: 1px 3px; -} -.swagger-section .swagger-ui-wrap .required { - font-weight: bold; -} -.swagger-section .swagger-ui-wrap input.parameter { - width: 300px; - border: 1px solid #aaa; -} -.swagger-section .swagger-ui-wrap h1 { - color: black; - font-size: 1.5em; - line-height: 1.3em; - padding: 10px 0 10px 0; - font-family: "Droid Sans", sans-serif; - font-weight: bold; -} -.swagger-section .swagger-ui-wrap .heading_with_menu { - float: none; - clear: both; - overflow: hidden; - display: block; -} -.swagger-section .swagger-ui-wrap .heading_with_menu ul { - display: block; - clear: none; - float: right; - -moz-box-sizing: border-box; - -webkit-box-sizing: border-box; - -ms-box-sizing: border-box; - box-sizing: border-box; - margin-top: 10px; -} -.swagger-section .swagger-ui-wrap h2 { - color: black; - font-size: 1.3em; - padding: 10px 0 10px 0; -} -.swagger-section .swagger-ui-wrap h2 a { - color: black; -} -.swagger-section .swagger-ui-wrap h2 span.sub { - font-size: 0.7em; - color: #999999; - font-style: italic; -} -.swagger-section .swagger-ui-wrap h2 span.sub a { - color: #777777; -} -.swagger-section .swagger-ui-wrap span.weak { - color: #666666; -} -.swagger-section .swagger-ui-wrap .message-success { - color: #89BF04; -} -.swagger-section .swagger-ui-wrap caption, -.swagger-section .swagger-ui-wrap th, -.swagger-section .swagger-ui-wrap td { - text-align: left; - font-weight: normal; - vertical-align: middle; -} -.swagger-section .swagger-ui-wrap .code { - font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.text textarea { - font-family: "Droid Sans", sans-serif; - height: 250px; - padding: 4px; - display: block; - clear: both; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.select select { - display: block; - clear: both; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.boolean { - float: none; - clear: both; - overflow: hidden; - display: block; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.boolean label { - display: block; - float: left; - clear: none; - margin: 0; - padding: 0; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.boolean input { - display: block; - float: left; - clear: none; - margin: 0 5px 0 0; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.required label { - color: black; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li label { - display: block; - clear: both; - width: auto; - padding: 0 0 3px; - color: #666666; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li label abbr { - padding-left: 3px; - color: #888888; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li p.inline-hints { - margin-left: 0; - font-style: italic; - font-size: 0.9em; - margin: 0; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.buttons { - margin: 0; - padding: 0; -} -.swagger-section .swagger-ui-wrap span.blank, -.swagger-section .swagger-ui-wrap span.empty { - color: #888888; - font-style: italic; -} -.swagger-section .swagger-ui-wrap .markdown h3 { - color: #547f00; -} -.swagger-section .swagger-ui-wrap .markdown h4 { - color: #666666; -} -.swagger-section .swagger-ui-wrap .markdown pre { - font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace; - background-color: #fcf6db; - border: 1px solid #e5e0c6; - padding: 10px; - margin: 0 0 10px 0; -} -.swagger-section .swagger-ui-wrap .markdown pre code { - line-height: 1.6em; -} -.swagger-section .swagger-ui-wrap div.gist { - margin: 20px 0 25px 0 !important; -} -.swagger-section .swagger-ui-wrap ul#resources { - font-family: "Droid Sans", sans-serif; - font-size: 0.9em; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource { - border-bottom: 1px solid #dddddd; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource:hover div.heading h2 a, -.swagger-section .swagger-ui-wrap ul#resources li.resource.active div.heading h2 a { - color: black; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource:hover div.heading ul.options li a, -.swagger-section .swagger-ui-wrap ul#resources li.resource.active div.heading ul.options li a { - color: #555555; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource:last-child { - border-bottom: none; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading { - border: 1px solid transparent; - float: none; - clear: both; - overflow: hidden; - display: block; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options { - overflow: hidden; - padding: 0; - display: block; - clear: none; - float: right; - margin: 14px 10px 0 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li { - float: left; - clear: none; - margin: 0; - padding: 2px 10px; - border-right: 1px solid #dddddd; - color: #666666; - font-size: 0.9em; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a { - color: #aaaaaa; - text-decoration: none; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a:hover { - text-decoration: underline; - color: black; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a:hover, -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a:active, -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a.active { - text-decoration: underline; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li:first-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li.first { - padding-left: 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li:last-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li.last { - padding-right: 0; - border-right: none; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options:first-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options.first { - padding-left: 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 { - color: #999999; - padding-left: 0; - display: block; - clear: none; - float: left; - font-family: "Droid Sans", sans-serif; - font-weight: bold; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 a { - color: #999999; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 a:hover { - color: black; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation { - float: none; - clear: both; - overflow: hidden; - display: block; - margin: 0 0 10px; - padding: 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading { - float: none; - clear: both; - overflow: hidden; - display: block; - margin: 0; - padding: 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 { - display: block; - clear: none; - float: left; - width: auto; - margin: 0; - padding: 0; - line-height: 1.1em; - color: black; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.path { - padding-left: 10px; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.path a { - color: black; - text-decoration: none; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.path a:hover { - text-decoration: underline; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.http_method a { - text-transform: uppercase; - text-decoration: none; - color: white; - display: inline-block; - width: 50px; - font-size: 0.7em; - text-align: center; - padding: 7px 0 4px; - -moz-border-radius: 2px; - -webkit-border-radius: 2px; - -o-border-radius: 2px; - -ms-border-radius: 2px; - -khtml-border-radius: 2px; - border-radius: 2px; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span { - margin: 0; - padding: 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options { - overflow: hidden; - padding: 0; - display: block; - clear: none; - float: right; - margin: 6px 10px 0 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li { - float: left; - clear: none; - margin: 0; - padding: 2px 10px; - font-size: 0.9em; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li a { - text-decoration: none; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li.access { - color: black; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content { - border-top: none; - padding: 10px; - -moz-border-radius-bottomleft: 6px; - -webkit-border-bottom-left-radius: 6px; - -o-border-bottom-left-radius: 6px; - -ms-border-bottom-left-radius: 6px; - -khtml-border-bottom-left-radius: 6px; - border-bottom-left-radius: 6px; - -moz-border-radius-bottomright: 6px; - -webkit-border-bottom-right-radius: 6px; - -o-border-bottom-right-radius: 6px; - -ms-border-bottom-right-radius: 6px; - -khtml-border-bottom-right-radius: 6px; - border-bottom-right-radius: 6px; - margin: 0 0 20px; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content h4 { - font-size: 1.1em; - margin: 0; - padding: 15px 0 5px; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header { - float: none; - clear: both; - overflow: hidden; - display: block; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header a { - padding: 4px 0 0 10px; - display: inline-block; - font-size: 0.9em; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header input.submit { - display: block; - clear: none; - float: left; - padding: 6px 8px; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header span.response_throbber { - background-image: url('../images/throbber.gif'); - width: 128px; - height: 16px; - display: block; - clear: none; - float: right; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content form input[type='text'].error { - outline: 2px solid black; - outline-color: #cc0000; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.response div.block pre { - font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace; - padding: 10px; - font-size: 0.9em; - max-height: 400px; - overflow-y: auto; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading { - background-color: #f9f2e9; - border: 1px solid #f0e0ca; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading h3 span.http_method a { - background-color: #c5862b; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li { - border-right: 1px solid #dddddd; - border-right-color: #f0e0ca; - color: #c5862b; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li a { - color: #c5862b; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content { - background-color: #faf5ee; - border: 1px solid #f0e0ca; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content h4 { - color: #c5862b; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content div.sandbox_header a { - color: #dcb67f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading { - background-color: #fcffcd; - border: 1px solid black; - border-color: #ffd20f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading h3 span.http_method a { - text-transform: uppercase; - background-color: #ffd20f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li { - border-right: 1px solid #dddddd; - border-right-color: #ffd20f; - color: #ffd20f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li a { - color: #ffd20f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content { - background-color: #fcffcd; - border: 1px solid black; - border-color: #ffd20f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content h4 { - color: #ffd20f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content div.sandbox_header a { - color: #6fc992; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading { - background-color: #f5e8e8; - border: 1px solid #e8c6c7; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading h3 span.http_method a { - text-transform: uppercase; - background-color: #a41e22; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li { - border-right: 1px solid #dddddd; - border-right-color: #e8c6c7; - color: #a41e22; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li a { - color: #a41e22; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content { - background-color: #f7eded; - border: 1px solid #e8c6c7; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content h4 { - color: #a41e22; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content div.sandbox_header a { - color: #c8787a; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading { - background-color: #e7f6ec; - border: 1px solid #c3e8d1; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading h3 span.http_method a { - background-color: #10a54a; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li { - border-right: 1px solid #dddddd; - border-right-color: #c3e8d1; - color: #10a54a; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li a { - color: #10a54a; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content { - background-color: #ebf7f0; - border: 1px solid #c3e8d1; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content h4 { - color: #10a54a; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content div.sandbox_header a { - color: #6fc992; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading { - background-color: #FCE9E3; - border: 1px solid #F5D5C3; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading h3 span.http_method a { - background-color: #D38042; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li { - border-right: 1px solid #dddddd; - border-right-color: #f0cecb; - color: #D38042; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li a { - color: #D38042; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content { - background-color: #faf0ef; - border: 1px solid #f0cecb; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content h4 { - color: #D38042; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content div.sandbox_header a { - color: #dcb67f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading { - background-color: #e7f0f7; - border: 1px solid #c3d9ec; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading h3 span.http_method a { - background-color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li { - border-right: 1px solid #dddddd; - border-right-color: #c3d9ec; - color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li a { - color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content { - background-color: #ebf3f9; - border: 1px solid #c3d9ec; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content h4 { - color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content div.sandbox_header a { - color: #6fa5d2; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading { - background-color: #e7f0f7; - border: 1px solid #c3d9ec; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading h3 span.http_method a { - background-color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading ul.options li { - border-right: 1px solid #dddddd; - border-right-color: #c3d9ec; - color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading ul.options li a { - color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.content { - background-color: #ebf3f9; - border: 1px solid #c3d9ec; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.content h4 { - color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.content div.sandbox_header a { - color: #6fa5d2; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content { - border-top: none; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li:last-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li:last-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li:last-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li:last-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li:last-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li:last-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li.last, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li.last, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li.last, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li.last, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li.last, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li.last { - padding-right: 0; - border-right: none; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li a:hover, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li a:active, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li a.active { - text-decoration: underline; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li:first-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li.first { - padding-left: 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations:first-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations.first { - padding-left: 0; -} -.swagger-section .swagger-ui-wrap p#colophon { - margin: 0 15px 40px 15px; - padding: 10px 0; - font-size: 0.8em; - border-top: 1px solid #dddddd; - font-family: "Droid Sans", sans-serif; - color: #999999; - font-style: italic; -} -.swagger-section .swagger-ui-wrap p#colophon a { - text-decoration: none; - color: #547f00; -} -.swagger-section .swagger-ui-wrap h3 { - color: black; - font-size: 1.1em; - padding: 10px 0 10px 0; -} -.swagger-section .swagger-ui-wrap .markdown ol, -.swagger-section .swagger-ui-wrap .markdown ul { - font-family: "Droid Sans", sans-serif; - margin: 5px 0 10px; - padding: 0 0 0 18px; - list-style-type: disc; -} -.swagger-section .swagger-ui-wrap form.form_box { - background-color: #ebf3f9; - border: 1px solid #c3d9ec; - padding: 10px; -} -.swagger-section .swagger-ui-wrap form.form_box label { - color: #0f6ab4 !important; -} -.swagger-section .swagger-ui-wrap form.form_box input[type=submit] { - display: block; - padding: 10px; -} -.swagger-section .swagger-ui-wrap form.form_box p.weak { - font-size: 0.8em; -} -.swagger-section .swagger-ui-wrap form.form_box p { - font-size: 0.9em; - padding: 0 0 15px; - color: #7e7b6d; -} -.swagger-section .swagger-ui-wrap form.form_box p a { - color: #646257; -} -.swagger-section .swagger-ui-wrap form.form_box p strong { - color: black; -} -.swagger-section .title { - font-style: bold; -} -.swagger-section .secondary_form { - display: none; -} -.swagger-section .main_image { - display: block; - margin-left: auto; - margin-right: auto; -} -.swagger-section .oauth_body { - margin-left: 100px; - margin-right: 100px; -} -.swagger-section .oauth_submit { - text-align: center; -} -.swagger-section .api-popup-dialog { - z-index: 10000; - position: absolute; - width: 500px; - background: #FFF; - padding: 20px; - border: 1px solid #ccc; - border-radius: 5px; - display: none; - font-size: 13px; - color: #777; -} -.swagger-section .api-popup-dialog .api-popup-title { - font-size: 24px; - padding: 10px 0; -} -.swagger-section .api-popup-dialog .api-popup-title { - font-size: 24px; - padding: 10px 0; -} -.swagger-section .api-popup-dialog p.error-msg { - padding-left: 5px; - padding-bottom: 5px; -} -.swagger-section .api-popup-dialog button.api-popup-authbtn { - height: 30px; -} -.swagger-section .api-popup-dialog button.api-popup-cancel { - height: 30px; -} -.swagger-section .api-popup-scopes { - padding: 10px 20px; -} -.swagger-section .api-popup-scopes li { - padding: 5px 0; - line-height: 20px; -} -.swagger-section .api-popup-scopes .api-scope-desc { - padding-left: 20px; - font-style: italic; -} -.swagger-section .api-popup-scopes li input { - position: relative; - top: 2px; -} -.swagger-section .api-popup-actions { - padding-top: 10px; -} -.swagger-section .access { - float: right; -} -.swagger-section .auth { - float: right; -} -.swagger-section #api_information_panel { - position: absolute; - background: #FFF; - border: 1px solid #ccc; - border-radius: 5px; - display: none; - font-size: 13px; - max-width: 300px; - line-height: 30px; - color: black; - padding: 5px; -} -.swagger-section #api_information_panel p .api-msg-enabled { - color: green; -} -.swagger-section #api_information_panel p .api-msg-disabled { - color: red; -} -.swagger-section .api-ic { - height: 18px; - vertical-align: middle; - display: inline-block; - background: url(../images/explorer_icons.png) no-repeat; -} -.swagger-section .ic-info { - background-position: 0 0; - width: 18px; - margin-top: -7px; - margin-left: 4px; -} -.swagger-section .ic-warning { - background-position: -60px 0; - width: 18px; - margin-top: -7px; - margin-left: 4px; -} -.swagger-section .ic-error { - background-position: -30px 0; - width: 18px; - margin-top: -7px; - margin-left: 4px; -} -.swagger-section .ic-off { - background-position: -90px 0; - width: 58px; - margin-top: -4px; - cursor: pointer; -} -.swagger-section .ic-on { - background-position: -160px 0; - width: 58px; - margin-top: -4px; - cursor: pointer; -} -.swagger-section #header { - background-color: #89bf04; - padding: 14px; -} -.swagger-section #header a#logo { - font-size: 1.5em; - font-weight: bold; - text-decoration: none; - background: transparent url(../images/logo_small.png) no-repeat left center; - padding: 20px 0 20px 40px; - color: white; -} -.swagger-section #header form#api_selector { - display: block; - clear: none; - float: right; -} -.swagger-section #header form#api_selector .input { - display: block; - clear: none; - float: left; - margin: 0 10px 0 0; -} -.swagger-section #header form#api_selector .input input#input_apiKey { - width: 200px; -} -.swagger-section #header form#api_selector .input input#input_baseUrl { - width: 400px; -} -.swagger-section #header form#api_selector .input a#explore { - display: block; - text-decoration: none; - font-weight: bold; - padding: 6px 8px; - font-size: 0.9em; - color: white; - background-color: #547f00; - -moz-border-radius: 4px; - -webkit-border-radius: 4px; - -o-border-radius: 4px; - -ms-border-radius: 4px; - -khtml-border-radius: 4px; - border-radius: 4px; -} -.swagger-section #header form#api_selector .input a#explore:hover { - background-color: #547f00; -} -.swagger-section #header form#api_selector .input input { - font-size: 0.9em; - padding: 3px; - margin: 0; -} -.swagger-section #content_message { - margin: 10px 15px; - font-style: italic; - color: #999999; -} -.swagger-section #message-bar { - min-height: 30px; - text-align: center; - padding-top: 10px; +.swagger-section .property-selector input[type="checkbox"] { + margin: 3px; } diff --git a/dist/images/json_editor_integration.png b/dist/images/json_editor_integration.png new file mode 100644 index 00000000000..faa85602bb3 Binary files /dev/null and b/dist/images/json_editor_integration.png differ diff --git a/dist/index.html b/dist/index.html index 06c35c17658..6eb256e8b3b 100644 --- a/dist/index.html +++ b/dist/index.html @@ -12,6 +12,7 @@ + @@ -21,6 +22,7 @@ + @@ -81,7 +83,7 @@ log("Unable to Load SwaggerUI"); }, docExpansion: "none", - sorter: "alpha" + sorter: "alpha", }); function addApiKeyAuthorization() { diff --git a/dist/lib/jsoneditor.js b/dist/lib/jsoneditor.js new file mode 100644 index 00000000000..feea6f75b04 --- /dev/null +++ b/dist/lib/jsoneditor.js @@ -0,0 +1,7287 @@ +/*! JSON Editor v0.7.22 - JSON Schema -> HTML Editor + * By Jeremy Dorn - https://github.com/jdorn/json-editor/ + * Released under the MIT license + * + * Date: 2015-08-12 + */ + +/** + * See README.md for requirements and usage info + */ + +(function() { + +/*jshint loopfunc: true */ +/* Simple JavaScript Inheritance + * By John Resig http://ejohn.org/ + * MIT Licensed. + */ +// Inspired by base2 and Prototype +var Class; +(function(){ + var initializing = false, fnTest = /xyz/.test(function(){window.postMessage("xyz");}) ? /\b_super\b/ : /.*/; + + // The base Class implementation (does nothing) + Class = function(){}; + + // Create a new Class that inherits from this class + Class.extend = function(prop) { + var _super = this.prototype; + + // Instantiate a base class (but only create the instance, + // don't run the init constructor) + initializing = true; + var prototype = new this(); + initializing = false; + + // Copy the properties over onto the new prototype + for (var name in prop) { + // Check if we're overwriting an existing function + prototype[name] = typeof prop[name] == "function" && + typeof _super[name] == "function" && fnTest.test(prop[name]) ? + (function(name, fn){ + return function() { + var tmp = this._super; + + // Add a new ._super() method that is the same method + // but on the super-class + this._super = _super[name]; + + // The method only need to be bound temporarily, so we + // remove it when we're done executing + var ret = fn.apply(this, arguments); + this._super = tmp; + + return ret; + }; + })(name, prop[name]) : + prop[name]; + } + + // The dummy class constructor + function Class() { + // All construction is actually done in the init method + if ( !initializing && this.init ) + this.init.apply(this, arguments); + } + + // Populate our constructed prototype object + Class.prototype = prototype; + + // Enforce the constructor to be what we expect + Class.prototype.constructor = Class; + + // And make this class extendable + Class.extend = arguments.callee; + + return Class; + }; + + return Class; +})(); + +// CustomEvent constructor polyfill +// From MDN +(function () { + function CustomEvent ( event, params ) { + params = params || { bubbles: false, cancelable: false, detail: undefined }; + var evt = document.createEvent( 'CustomEvent' ); + evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail ); + return evt; + } + + CustomEvent.prototype = window.Event.prototype; + + window.CustomEvent = CustomEvent; +})(); + +// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel +// MIT license +(function() { + var lastTime = 0; + var vendors = ['ms', 'moz', 'webkit', 'o']; + for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { + window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; + window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || + window[vendors[x]+'CancelRequestAnimationFrame']; + } + + if (!window.requestAnimationFrame) + window.requestAnimationFrame = function(callback, element) { + var currTime = new Date().getTime(); + var timeToCall = Math.max(0, 16 - (currTime - lastTime)); + var id = window.setTimeout(function() { callback(currTime + timeToCall); }, + timeToCall); + lastTime = currTime + timeToCall; + return id; + }; + + if (!window.cancelAnimationFrame) + window.cancelAnimationFrame = function(id) { + clearTimeout(id); + }; +}()); + +// Array.isArray polyfill +// From MDN +(function() { + if(!Array.isArray) { + Array.isArray = function(arg) { + return Object.prototype.toString.call(arg) === '[object Array]'; + }; + } +}()); +/** + * Taken from jQuery 2.1.3 + * + * @param obj + * @returns {boolean} + */ +var $isplainobject = function( obj ) { + // Not plain objects: + // - Any object or value whose internal [[Class]] property is not "[object Object]" + // - DOM nodes + // - window + if (typeof obj !== "object" || obj.nodeType || (obj !== null && obj === obj.window)) { + return false; + } + + if (obj.constructor && !Object.prototype.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf")) { + return false; + } + + // If the function hasn't returned already, we're confident that + // |obj| is a plain object, created by {} or constructed with new Object + return true; +}; + +var $extend = function(destination) { + var source, i,property; + for(i=1; i 0 && (obj.length - 1) in obj)) { + for(i=0; i= waiting && !callback_fired) { + callback_fired = true; + callback(); + } + }); + } + // Request failed + else { + window.console.log(r); + throw "Failed to fetch ref via ajax- "+url; + } + }; + r.send(); + }); + + if(!waiting) { + callback(); + } + }, + expandRefs: function(schema) { + schema = $extend({},schema); + + while (schema.$ref) { + var ref = schema.$ref; + delete schema.$ref; + + if(!this.refs[ref]) ref = decodeURIComponent(ref); + + schema = this.extendSchemas(schema,this.refs[ref]); + } + return schema; + }, + expandSchema: function(schema) { + var self = this; + var extended = $extend({},schema); + var i; + + // Version 3 `type` + if(typeof schema.type === 'object') { + // Array of types + if(Array.isArray(schema.type)) { + $each(schema.type, function(key,value) { + // Schema + if(typeof value === 'object') { + schema.type[key] = self.expandSchema(value); + } + }); + } + // Schema + else { + schema.type = self.expandSchema(schema.type); + } + } + // Version 3 `disallow` + if(typeof schema.disallow === 'object') { + // Array of types + if(Array.isArray(schema.disallow)) { + $each(schema.disallow, function(key,value) { + // Schema + if(typeof value === 'object') { + schema.disallow[key] = self.expandSchema(value); + } + }); + } + // Schema + else { + schema.disallow = self.expandSchema(schema.disallow); + } + } + // Version 4 `anyOf` + if(schema.anyOf) { + $each(schema.anyOf, function(key,value) { + schema.anyOf[key] = self.expandSchema(value); + }); + } + // Version 4 `dependencies` (schema dependencies) + if(schema.dependencies) { + $each(schema.dependencies,function(key,value) { + if(typeof value === "object" && !(Array.isArray(value))) { + schema.dependencies[key] = self.expandSchema(value); + } + }); + } + // Version 4 `not` + if(schema.not) { + schema.not = this.expandSchema(schema.not); + } + + // allOf schemas should be merged into the parent + if(schema.allOf) { + for(i=0; i= schema.maximum) { + errors.push({ + path: path, + property: 'maximum', + message: this.translate('error_maximum_excl', [schema.maximum]) + }); + } + else if(!schema.exclusiveMaximum && value > schema.maximum) { + errors.push({ + path: path, + property: 'maximum', + message: this.translate('error_maximum_incl', [schema.maximum]) + }); + } + } + + // `minimum` + if(schema.hasOwnProperty('minimum')) { + if(schema.exclusiveMinimum && value <= schema.minimum) { + errors.push({ + path: path, + property: 'minimum', + message: this.translate('error_minimum_excl', [schema.minimum]) + }); + } + else if(!schema.exclusiveMinimum && value < schema.minimum) { + errors.push({ + path: path, + property: 'minimum', + message: this.translate('error_minimum_incl', [schema.minimum]) + }); + } + } + } + // String specific validation + else if(typeof value === "string") { + // `maxLength` + if(schema.maxLength) { + if((value+"").length > schema.maxLength) { + errors.push({ + path: path, + property: 'maxLength', + message: this.translate('error_maxLength', [schema.maxLength]) + }); + } + } + + // `minLength` + if(schema.minLength) { + if((value+"").length < schema.minLength) { + errors.push({ + path: path, + property: 'minLength', + message: this.translate((schema.minLength===1?'error_notempty':'error_minLength'), [schema.minLength]) + }); + } + } + + // `pattern` + if(schema.pattern) { + if(!(new RegExp(schema.pattern)).test(value)) { + errors.push({ + path: path, + property: 'pattern', + message: this.translate('error_pattern') + }); + } + } + } + // Array specific validation + else if(typeof value === "object" && value !== null && Array.isArray(value)) { + // `items` and `additionalItems` + if(schema.items) { + // `items` is an array + if(Array.isArray(schema.items)) { + for(i=0; i schema.maxItems) { + errors.push({ + path: path, + property: 'maxItems', + message: this.translate('error_maxItems', [schema.maxItems]) + }); + } + } + + // `minItems` + if(schema.minItems) { + if(value.length < schema.minItems) { + errors.push({ + path: path, + property: 'minItems', + message: this.translate('error_minItems', [schema.minItems]) + }); + } + } + + // `uniqueItems` + if(schema.uniqueItems) { + var seen = {}; + for(i=0; i schema.maxProperties) { + errors.push({ + path: path, + property: 'maxProperties', + message: this.translate('error_maxProperties', [schema.maxProperties]) + }); + } + } + + // `minProperties` + if(schema.minProperties) { + valid = 0; + for(i in value) { + if(!value.hasOwnProperty(i)) continue; + valid++; + } + if(valid < schema.minProperties) { + errors.push({ + path: path, + property: 'minProperties', + message: this.translate('error_minProperties', [schema.minProperties]) + }); + } + } + // [TODO] find why defaultProperties is not functioning. + // Version 4 `required` + //if(schema.required && Array.isArray(schema.required)) { + // for(i=0; i=0) { + holder = this.theme.getBlockLinkHolder(); + + link = this.theme.getBlockLink(); + link.setAttribute('target','_blank'); + + var media = document.createElement(type); + media.setAttribute('controls','controls'); + + this.theme.createMediaLink(holder,link,media); + + // When a watched field changes, update the url + this.link_watchers.push(function(vars) { + var url = href(vars); + link.setAttribute('href',url); + link.textContent = data.rel || url; + media.setAttribute('src',url); + }); + } + // Text links + else { + holder = this.theme.getBlockLink(); + holder.setAttribute('target','_blank'); + holder.textContent = data.rel; + + // When a watched field changes, update the url + this.link_watchers.push(function(vars) { + var url = href(vars); + holder.setAttribute('href',url); + holder.textContent = data.rel || url; + }); + } + + return holder; + }, + refreshWatchedFieldValues: function() { + if(!this.watched_values) return; + var watched = {}; + var changed = false; + var self = this; + + if(this.watched) { + var val,editor; + for(var name in this.watched) { + if(!this.watched.hasOwnProperty(name)) continue; + editor = self.jsoneditor.getEditor(this.watched[name]); + val = editor? editor.getValue() : null; + if(self.watched_values[name] !== val) changed = true; + watched[name] = val; + } + } + + watched.self = this.getValue(); + if(this.watched_values.self !== watched.self) changed = true; + + this.watched_values = watched; + + return changed; + }, + getWatchedFieldValues: function() { + return this.watched_values; + }, + updateHeaderText: function() { + if(this.header) { + // If the header has children, only update the text node's value + if(this.header.children.length) { + for(var i=0; i -1; + else if(this.jsoneditor.options.required_by_default) return true; + else return false; + }, + getDisplayText: function(arr) { + var disp = []; + var used = {}; + + // Determine how many times each attribute name is used. + // This helps us pick the most distinct display text for the schemas. + $each(arr,function(i,el) { + if(el.title) { + used[el.title] = used[el.title] || 0; + used[el.title]++; + } + if(el.description) { + used[el.description] = used[el.description] || 0; + used[el.description]++; + } + if(el.format) { + used[el.format] = used[el.format] || 0; + used[el.format]++; + } + if(el.type) { + used[el.type] = used[el.type] || 0; + used[el.type]++; + } + }); + + // Determine display text for each element of the array + $each(arr,function(i,el) { + var name; + + // If it's a simple string + if(typeof el === "string") name = el; + // Object + else if(el.title && used[el.title]<=1) name = el.title; + else if(el.format && used[el.format]<=1) name = el.format; + else if(el.type && used[el.type]<=1) name = el.type; + else if(el.description && used[el.description]<=1) name = el.descripton; + else if(el.title) name = el.title; + else if(el.format) name = el.format; + else if(el.type) name = el.type; + else if(el.description) name = el.description; + else if(JSON.stringify(el).length < 50) name = JSON.stringify(el); + else name = "type"; + + disp.push(name); + }); + + // Replace identical display text with "text 1", "text 2", etc. + var inc = {}; + $each(disp,function(i,name) { + inc[name] = inc[name] || 0; + inc[name]++; + + if(used[name] > 1) disp[i] = name + " " + inc[name]; + }); + + return disp; + }, + getOption: function(key) { + try { + throw "getOption is deprecated"; + } + catch(e) { + window.console.error(e); + } + + return this.options[key]; + }, + showValidationErrors: function(errors) { + + } +}); + +JSONEditor.defaults.editors["null"] = JSONEditor.AbstractEditor.extend({ + getValue: function() { + return null; + }, + setValue: function() { + this.onChange(); + }, + getNumColumns: function() { + return 2; + } +}); + +JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({ + register: function() { + this._super(); + if(!this.input) return; + this.input.setAttribute('name',this.formname); + }, + unregister: function() { + this._super(); + if(!this.input) return; + this.input.removeAttribute('name'); + }, + setValue: function(value,initial,from_template) { + var self = this; + + if(this.template && !from_template) { + return; + } + + if(value === null || typeof value === 'undefined') value = ""; + else if(typeof value === "object") value = JSON.stringify(value); + else if(typeof value !== "string") value = ""+value; + + if(value === this.serialized) return; + + // Sanitize value before setting it + var sanitized = this.sanitize(value); + + if(this.input.value === sanitized) { + return; + } + + this.input.value = sanitized; + + // If using SCEditor, update the WYSIWYG + if(this.sceditor_instance) { + this.sceditor_instance.val(sanitized); + } + else if(this.epiceditor) { + this.epiceditor.importFile(null,sanitized); + } + else if(this.ace_editor) { + this.ace_editor.setValue(sanitized); + } + + var changed = from_template || this.getValue() !== value; + + this.refreshValue(); + + if(initial) this.is_dirty = false; + else if(this.jsoneditor.options.show_errors === "change") this.is_dirty = true; + + if(this.adjust_height) this.adjust_height(this.input); + + // Bubble this setValue to parents if the value changed + this.onChange(changed); + }, + getNumColumns: function() { + var min = Math.ceil(Math.max(this.getTitle().length,this.schema.maxLength||0,this.schema.minLength||0)/5); + var num; + + if(this.input_type === 'textarea') num = 6; + else if(['text','email'].indexOf(this.input_type) >= 0) num = 4; + else num = 2; + + return Math.min(12,Math.max(min,num)); + }, + build: function() { + var self = this, i; + if(!this.options.compact) this.header = this.label = this.theme.getFormInputLabel(this.getTitle()); + if(this.schema.description) this.description = this.theme.getFormInputDescription(this.schema.description); + + this.format = this.schema.format; + if(!this.format && this.schema.media && this.schema.media.type) { + this.format = this.schema.media.type.replace(/(^(application|text)\/(x-)?(script\.)?)|(-source$)/g,''); + } + if(!this.format && this.options.default_format) { + this.format = this.options.default_format; + } + if(this.options.format) { + this.format = this.options.format; + } + + // Specific format + if(this.format) { + // Text Area + if(this.format === 'textarea') { + this.input_type = 'textarea'; + this.input = this.theme.getTextareaInput(); + } + // Range Input + else if(this.format === 'range') { + this.input_type = 'range'; + var min = this.schema.minimum || 0; + var max = this.schema.maximum || Math.max(100,min+1); + var step = 1; + if(this.schema.multipleOf) { + if(min%this.schema.multipleOf) min = Math.ceil(min/this.schema.multipleOf)*this.schema.multipleOf; + if(max%this.schema.multipleOf) max = Math.floor(max/this.schema.multipleOf)*this.schema.multipleOf; + step = this.schema.multipleOf; + } + + this.input = this.theme.getRangeInput(min,max,step); + } + // Source Code + else if([ + 'actionscript', + 'batchfile', + 'bbcode', + 'c', + 'c++', + 'cpp', + 'coffee', + 'csharp', + 'css', + 'dart', + 'django', + 'ejs', + 'erlang', + 'golang', + 'handlebars', + 'haskell', + 'haxe', + 'html', + 'ini', + 'jade', + 'java', + 'javascript', + 'json', + 'less', + 'lisp', + 'lua', + 'makefile', + 'markdown', + 'matlab', + 'mysql', + 'objectivec', + 'pascal', + 'perl', + 'pgsql', + 'php', + 'python', + 'r', + 'ruby', + 'sass', + 'scala', + 'scss', + 'smarty', + 'sql', + 'stylus', + 'svg', + 'twig', + 'vbscript', + 'xml', + 'yaml' + ].indexOf(this.format) >= 0 + ) { + this.input_type = this.format; + this.source_code = true; + + this.input = this.theme.getTextareaInput(); + } + // HTML5 Input type + else { + this.input_type = this.format; + this.input = this.theme.getFormInputField(this.input_type); + } + } + // Normal text input + else { + this.input_type = 'text'; + this.input = this.theme.getFormInputField(this.input_type); + } + + // minLength, maxLength, and pattern + if(typeof this.schema.maxLength !== "undefined") this.input.setAttribute('maxlength',this.schema.maxLength); + if(typeof this.schema.pattern !== "undefined") this.input.setAttribute('pattern',this.schema.pattern); + else if(typeof this.schema.minLength !== "undefined") this.input.setAttribute('pattern','.{'+this.schema.minLength+',}'); + + if(this.options.compact) { + this.container.className += ' compact'; + } + else { + if(this.options.input_width) this.input.style.width = this.options.input_width; + } + + if(this.schema.readOnly || this.schema.readonly || this.schema.template) { + this.always_disabled = true; + this.input.disabled = true; + } + + this.input + .addEventListener('change',function(e) { + e.preventDefault(); + e.stopPropagation(); + + // Don't allow changing if this field is a template + if(self.schema.template) { + this.value = self.value; + return; + } + + var val = this.value; + + // sanitize value + var sanitized = self.sanitize(val); + if(val !== sanitized) { + this.value = sanitized; + } + + self.is_dirty = true; + + self.refreshValue(); + self.onChange(true); + }); + + if(this.options.input_height) this.input.style.height = this.options.input_height; + if(this.options.expand_height) { + this.adjust_height = function(el) { + if(!el) return; + var i, ch=el.offsetHeight; + // Input too short + if(el.offsetHeight < el.scrollHeight) { + i=0; + while(el.offsetHeight < el.scrollHeight+3) { + if(i>100) break; + i++; + ch++; + el.style.height = ch+'px'; + } + } + else { + i=0; + while(el.offsetHeight >= el.scrollHeight+3) { + if(i>100) break; + i++; + ch--; + el.style.height = ch+'px'; + } + el.style.height = (ch+1)+'px'; + } + }; + + this.input.addEventListener('keyup',function(e) { + self.adjust_height(this); + }); + this.input.addEventListener('change',function(e) { + self.adjust_height(this); + }); + this.adjust_height(); + } + + if(this.format) this.input.setAttribute('data-schemaformat',this.format); + + this.control = this.theme.getFormControl(this.label, this.input, this.description); + this.container.appendChild(this.control); + + // Any special formatting that needs to happen after the input is added to the dom + window.requestAnimationFrame(function() { + // Skip in case the input is only a temporary editor, + // otherwise, in the case of an ace_editor creation, + // it will generate an error trying to append it to the missing parentNode + if(self.input.parentNode) self.afterInputReady(); + if(self.adjust_height) self.adjust_height(self.input); + }); + + // Compile and store the template + if(this.schema.template) { + this.template = this.jsoneditor.compileTemplate(this.schema.template, this.template_engine); + this.refreshValue(); + } + else { + this.refreshValue(); + } + }, + enable: function() { + if(!this.always_disabled) { + this.input.disabled = false; + // TODO: WYSIWYG and Markdown editors + } + this._super(); + }, + disable: function() { + this.input.disabled = true; + // TODO: WYSIWYG and Markdown editors + this._super(); + }, + afterInputReady: function() { + var self = this, options; + + // Code editor + if(this.source_code) { + // WYSIWYG html and bbcode editor + if(this.options.wysiwyg && + ['html','bbcode'].indexOf(this.input_type) >= 0 && + window.jQuery && window.jQuery.fn && window.jQuery.fn.sceditor + ) { + options = $extend({},{ + plugins: self.input_type==='html'? 'xhtml' : 'bbcode', + emoticonsEnabled: false, + width: '100%', + height: 300 + },JSONEditor.plugins.sceditor,self.options.sceditor_options||{}); + + window.jQuery(self.input).sceditor(options); + + self.sceditor_instance = window.jQuery(self.input).sceditor('instance'); + + self.sceditor_instance.blur(function() { + // Get editor's value + var val = window.jQuery("
"+self.sceditor_instance.val()+"
"); + // Remove sceditor spans/divs + window.jQuery('#sceditor-start-marker,#sceditor-end-marker,.sceditor-nlf',val).remove(); + // Set the value and update + self.input.value = val.html(); + self.value = self.input.value; + self.is_dirty = true; + self.onChange(true); + }); + } + // EpicEditor for markdown (if it's loaded) + else if (this.input_type === 'markdown' && window.EpicEditor) { + this.epiceditor_container = document.createElement('div'); + this.input.parentNode.insertBefore(this.epiceditor_container,this.input); + this.input.style.display = 'none'; + + options = $extend({},JSONEditor.plugins.epiceditor,{ + container: this.epiceditor_container, + clientSideStorage: false + }); + + this.epiceditor = new window.EpicEditor(options).load(); + + this.epiceditor.importFile(null,this.getValue()); + + this.epiceditor.on('update',function() { + var val = self.epiceditor.exportFile(); + self.input.value = val; + self.value = val; + self.is_dirty = true; + self.onChange(true); + }); + } + // ACE editor for everything else + else if(window.ace) { + var mode = this.input_type; + // aliases for c/cpp + if(mode === 'cpp' || mode === 'c++' || mode === 'c') { + mode = 'c_cpp'; + } + + this.ace_container = document.createElement('div'); + this.ace_container.style.width = '100%'; + this.ace_container.style.position = 'relative'; + this.ace_container.style.height = '400px'; + this.input.parentNode.insertBefore(this.ace_container,this.input); + this.input.style.display = 'none'; + this.ace_editor = window.ace.edit(this.ace_container); + + this.ace_editor.setValue(this.getValue()); + + // The theme + if(JSONEditor.plugins.ace.theme) this.ace_editor.setTheme('ace/theme/'+JSONEditor.plugins.ace.theme); + // The mode + mode = window.ace.require("ace/mode/"+mode); + if(mode) this.ace_editor.getSession().setMode(new mode.Mode()); + + // Listen for changes + this.ace_editor.on('change',function() { + var val = self.ace_editor.getValue(); + self.input.value = val; + self.refreshValue(); + self.is_dirty = true; + self.onChange(true); + }); + } + } + + self.theme.afterInputReady(self.input); + }, + refreshValue: function() { + this.value = this.input.value; + if(typeof this.value !== "string") this.value = ''; + this.serialized = this.value; + }, + destroy: function() { + // If using SCEditor, destroy the editor instance + if(this.sceditor_instance) { + this.sceditor_instance.destroy(); + } + else if(this.epiceditor) { + this.epiceditor.unload(); + } + else if(this.ace_editor) { + this.ace_editor.destroy(); + } + + + this.template = null; + if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input); + if(this.label && this.label.parentNode) this.label.parentNode.removeChild(this.label); + if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description); + + this._super(); + }, + /** + * This is overridden in derivative editors + */ + sanitize: function(value) { + return value; + }, + /** + * Re-calculates the value if needed + */ + onWatchedFieldChange: function() { + var self = this, vars, j; + + // If this editor needs to be rendered by a macro template + if(this.template) { + vars = this.getWatchedFieldValues(); + this.setValue(this.template(vars),false,true); + } + + this._super(); + }, + showValidationErrors: function(errors) { + var self = this; + + if(this.jsoneditor.options.show_errors === "always") {} + else if(!this.is_dirty && this.previous_error_setting===this.jsoneditor.options.show_errors) return; + + this.previous_error_setting = this.jsoneditor.options.show_errors; + + var messages = []; + $each(errors,function(i,error) { + if(error.path === self.path) { + messages.push(error.message); + } + }); + + if(messages.length) { + this.theme.addInputError(this.input, messages.join('. ')+'.'); + } + else { + this.theme.removeInputError(this.input); + } + } +}); + +JSONEditor.defaults.editors.number = JSONEditor.defaults.editors.string.extend({ + sanitize: function(value) { + return (value+"").replace(/[^0-9\.\-eE]/g,''); + }, + getNumColumns: function() { + return 2; + }, + getValue: function() { + return this.value*1; + } +}); + +JSONEditor.defaults.editors.integer = JSONEditor.defaults.editors.number.extend({ + sanitize: function(value) { + value = value + ""; + return value.replace(/[^0-9\-]/g,''); + }, + getNumColumns: function() { + return 2; + } +}); + +JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({ + getDefault: function() { + return $extend({},this.schema["default"] || {}); + }, + getChildEditors: function() { + return this.editors; + }, + register: function() { + this._super(); + if(this.editors) { + for(var i in this.editors) { + if(!this.editors.hasOwnProperty(i)) continue; + this.editors[i].register(); + } + } + }, + unregister: function() { + this._super(); + if(this.editors) { + for(var i in this.editors) { + if(!this.editors.hasOwnProperty(i)) continue; + this.editors[i].unregister(); + } + } + }, + getNumColumns: function() { + return Math.max(Math.min(12,this.maxwidth),3); + }, + enable: function() { + if(this.editjson_button) this.editjson_button.disabled = false; + if(this.addproperty_button) this.addproperty_button.disabled = false; + + this._super(); + if(this.editors) { + for(var i in this.editors) { + if(!this.editors.hasOwnProperty(i)) continue; + this.editors[i].enable(); + } + } + }, + disable: function() { + if(this.editjson_button) this.editjson_button.disabled = true; + if(this.addproperty_button) this.addproperty_button.disabled = true; + this.hideEditJSON(); + + this._super(); + if(this.editors) { + for(var i in this.editors) { + if(!this.editors.hasOwnProperty(i)) continue; + this.editors[i].disable(); + } + } + }, + layoutEditors: function() { + var self = this, i, j; + + if(!this.row_container) return; + + // Sort editors by propertyOrder + this.property_order = Object.keys(this.editors); + this.property_order = this.property_order.sort(function(a,b) { + var ordera = self.editors[a].schema.propertyOrder; + var orderb = self.editors[b].schema.propertyOrder; + if(typeof ordera !== "number") ordera = 1000; + if(typeof orderb !== "number") orderb = 1000; + + return ordera - orderb; + }); + + var container; + + if(this.format === 'grid') { + var rows = []; + $each(this.property_order, function(j,key) { + var editor = self.editors[key]; + if(editor.property_removed) return; + var found = false; + var width = editor.options.hidden? 0 : (editor.options.grid_columns || editor.getNumColumns()); + var height = editor.options.hidden? 0 : editor.container.offsetHeight; + // See if the editor will fit in any of the existing rows first + for(var i=0; i height)) { + found = i; + } + } + } + + // If there isn't a spot in any of the existing rows, start a new row + if(found === false) { + rows.push({ + width: 0, + minh: 999999, + maxh: 0, + editors: [] + }); + found = rows.length-1; + } + + rows[found].editors.push({ + key: key, + //editor: editor, + width: width, + height: height + }); + rows[found].width += width; + rows[found].minh = Math.min(rows[found].minh,height); + rows[found].maxh = Math.max(rows[found].maxh,height); + }); + + // Make almost full rows width 12 + // Do this by increasing all editors' sizes proprotionately + // Any left over space goes to the biggest editor + // Don't touch rows with a width of 6 or less + for(i=0; i rows[i].editors[biggest].width) biggest = j; + rows[i].editors[j].width *= 12/rows[i].width; + rows[i].editors[j].width = Math.floor(rows[i].editors[j].width); + new_width += rows[i].editors[j].width; + } + if(new_width < 12) rows[i].editors[biggest].width += 12-new_width; + rows[i].width = 12; + } + } + + // layout hasn't changed + if(this.layout === JSON.stringify(rows)) return false; + this.layout = JSON.stringify(rows); + + // Layout the form + container = document.createElement('div'); + for(i=0; i= this.schema.maxProperties); + + if(this.addproperty_checkboxes) { + this.addproperty_list.innerHTML = ''; + } + this.addproperty_checkboxes = {}; + + // Check for which editors can't be removed or added back + for(i in this.cached_editors) { + if(!this.cached_editors.hasOwnProperty(i)) continue; + + this.addPropertyCheckbox(i); + + if(this.isRequired(this.cached_editors[i]) && i in this.editors) { + this.addproperty_checkboxes[i].disabled = true; + } + + if(typeof this.schema.minProperties !== "undefined" && num_props <= this.schema.minProperties) { + this.addproperty_checkboxes[i].disabled = this.addproperty_checkboxes[i].checked; + if(!this.addproperty_checkboxes[i].checked) show_modal = true; + } + else if(!(i in this.editors)) { + if(!can_add && !this.schema.properties.hasOwnProperty(i)) { + this.addproperty_checkboxes[i].disabled = true; + } + else { + this.addproperty_checkboxes[i].disabled = false; + show_modal = true; + } + } + else { + show_modal = true; + can_remove = true; + } + } + + if(this.canHaveAdditionalProperties()) { + show_modal = true; + } + + // Additional addproperty checkboxes not tied to a current editor + for(i in this.schema.properties) { + if(!this.schema.properties.hasOwnProperty(i)) continue; + if(this.cached_editors[i]) continue; + show_modal = true; + this.addPropertyCheckbox(i); + } + + // If no editors can be added or removed, hide the modal button + if(!show_modal) { + this.hideAddProperty(); + this.addproperty_controls.style.display = 'none'; + } + // If additional properties are disabled + else if(!this.canHaveAdditionalProperties()) { + this.addproperty_add.style.display = 'none'; + this.addproperty_input.style.display = 'none'; + } + // If no new properties can be added + else if(!can_add) { + this.addproperty_add.disabled = true; + } + // If new properties can be added + else { + this.addproperty_add.disabled = false; + } + }, + isRequired: function(editor) { + if(typeof editor.schema.required === "boolean") return editor.schema.required; + else if(Array.isArray(this.schema.required)) return this.schema.required.indexOf(editor.key) > -1; + else if(this.jsoneditor.options.required_by_default) return true; + else return false; + }, + setValue: function(value, initial) { + var self = this; + value = value || {}; + + if(typeof value !== "object" || Array.isArray(value)) value = {}; + + // First, set the values for all of the defined properties + $each(this.cached_editors, function(i,editor) { + // Value explicitly set + if(typeof value[i] !== "undefined") { + self.addObjectProperty(i); + editor.setValue(value[i],initial); + } + // Otherwise, remove value unless this is the initial set or it's required + else if(!initial && !self.isRequired(editor)) { + self.removeObjectProperty(i); + } + // Otherwise, set the value to the default + else { + editor.setValue(editor.getDefault(),initial); + } + }); + + $each(value, function(i,val) { + if(!self.cached_editors[i]) { + self.addObjectProperty(i); + if(self.editors[i]) self.editors[i].setValue(val,initial); + } + }); + + this.refreshValue(); + this.layoutEditors(); + this.onChange(); + }, + showValidationErrors: function(errors) { + var self = this; + + // Get all the errors that pertain to this editor + var my_errors = []; + var other_errors = []; + $each(errors, function(i,error) { + if(error.path === self.path) { + my_errors.push(error); + } + else { + other_errors.push(error); + } + }); + + // Show errors for this editor + if(this.error_holder) { + if(my_errors.length) { + var message = []; + this.error_holder.innerHTML = ''; + this.error_holder.style.display = ''; + $each(my_errors, function(i,error) { + self.error_holder.appendChild(self.theme.getErrorMessage(error.message)); + }); + } + // Hide error area + else { + this.error_holder.style.display = 'none'; + } + } + + // Show error for the table row if this is inside a table + if(this.options.table_row) { + if(my_errors.length) { + this.theme.addTableRowError(this.container); + } + else { + this.theme.removeTableRowError(this.container); + } + } + + // Show errors for child editors + $each(this.editors, function(i,editor) { + editor.showValidationErrors(other_errors); + }); + } +}); + +JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({ + getDefault: function() { + return this.schema["default"] || []; + }, + register: function() { + this._super(); + if(this.rows) { + for(var i=0; i= this.schema.items.length) { + if(this.schema.additionalItems===true) { + return {}; + } + else if(this.schema.additionalItems) { + return $extend({},this.schema.additionalItems); + } + } + else { + return $extend({},this.schema.items[i]); + } + } + else if(this.schema.items) { + return $extend({},this.schema.items); + } + else { + return {}; + } + }, + getItemInfo: function(i) { + var schema = this.getItemSchema(i); + + // Check if it's cached + this.item_info = this.item_info || {}; + var stringified = JSON.stringify(schema); + if(typeof this.item_info[stringified] !== "undefined") return this.item_info[stringified]; + + // Get the schema for this item + schema = this.jsoneditor.expandRefs(schema); + + this.item_info[stringified] = { + title: schema.title || "item", + 'default': schema["default"], + width: 12, + child_editors: schema.properties || schema.items + }; + + return this.item_info[stringified]; + }, + getElementEditor: function(i) { + var item_info = this.getItemInfo(i); + var schema = this.getItemSchema(i); + schema = this.jsoneditor.expandRefs(schema); + schema.title = item_info.title+' '+(i+1); + + var editor = this.jsoneditor.getEditorClass(schema); + + var holder; + if(this.tabs_holder) { + holder = this.theme.getTabContent(); + } + else if(item_info.child_editors) { + holder = this.theme.getChildEditorHolder(); + } + else { + holder = this.theme.getIndentedPanel(); + } + + this.row_holder.appendChild(holder); + + var ret = this.jsoneditor.createEditor(editor,{ + jsoneditor: this.jsoneditor, + schema: schema, + container: holder, + path: this.path+'.'+i, + parent: this, + required: true + }); + ret.preBuild(); + ret.build(); + ret.postBuild(); + + if(!ret.title_controls) { + ret.array_controls = this.theme.getButtonHolder(); + holder.appendChild(ret.array_controls); + } + + return ret; + }, + destroy: function() { + this.empty(true); + if(this.title && this.title.parentNode) this.title.parentNode.removeChild(this.title); + if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description); + if(this.row_holder && this.row_holder.parentNode) this.row_holder.parentNode.removeChild(this.row_holder); + if(this.controls && this.controls.parentNode) this.controls.parentNode.removeChild(this.controls); + if(this.panel && this.panel.parentNode) this.panel.parentNode.removeChild(this.panel); + + this.rows = this.row_cache = this.title = this.description = this.row_holder = this.panel = this.controls = null; + + this._super(); + }, + empty: function(hard) { + if(!this.rows) return; + var self = this; + $each(this.rows,function(i,row) { + if(hard) { + if(row.tab && row.tab.parentNode) row.tab.parentNode.removeChild(row.tab); + self.destroyRow(row,true); + self.row_cache[i] = null; + } + self.rows[i] = null; + }); + self.rows = []; + if(hard) self.row_cache = []; + }, + destroyRow: function(row,hard) { + var holder = row.container; + if(hard) { + row.destroy(); + if(holder.parentNode) holder.parentNode.removeChild(holder); + if(row.tab && row.tab.parentNode) row.tab.parentNode.removeChild(row.tab); + } + else { + if(row.tab) row.tab.style.display = 'none'; + holder.style.display = 'none'; + row.unregister(); + } + }, + getMax: function() { + if((Array.isArray(this.schema.items)) && this.schema.additionalItems === false) { + return Math.min(this.schema.items.length,this.schema.maxItems || Infinity); + } + else { + return this.schema.maxItems || Infinity; + } + }, + refreshTabs: function(refresh_headers) { + var self = this; + $each(this.rows, function(i,row) { + if(!row.tab) return; + + if(refresh_headers) { + row.tab_text.textContent = row.getHeaderText(); + } + else { + if(row.tab === self.active_tab) { + self.theme.markTabActive(row.tab); + row.container.style.display = ''; + } + else { + self.theme.markTabInactive(row.tab); + row.container.style.display = 'none'; + } + } + }); + }, + setValue: function(value, initial) { + // Update the array's value, adding/removing rows when necessary + value = value || []; + + if(!(Array.isArray(value))) value = [value]; + + var serialized = JSON.stringify(value); + if(serialized === this.serialized) return; + + // Make sure value has between minItems and maxItems items in it + if(this.schema.minItems) { + while(value.length < this.schema.minItems) { + value.push(this.getItemInfo(value.length)["default"]); + } + } + if(this.getMax() && value.length > this.getMax()) { + value = value.slice(0,this.getMax()); + } + + var self = this; + $each(value,function(i,val) { + if(self.rows[i]) { + // TODO: don't set the row's value if it hasn't changed + self.rows[i].setValue(val,initial); + } + else if(self.row_cache[i]) { + self.rows[i] = self.row_cache[i]; + self.rows[i].setValue(val,initial); + self.rows[i].container.style.display = ''; + if(self.rows[i].tab) self.rows[i].tab.style.display = ''; + self.rows[i].register(); + } + else { + self.addRow(val,initial); + } + }); + + for(var j=value.length; j= this.rows.length; + + $each(this.rows,function(i,editor) { + // Hide the move down button for the last row + if(editor.movedown_button) { + if(i === self.rows.length - 1) { + editor.movedown_button.style.display = 'none'; + } + else { + editor.movedown_button.style.display = ''; + } + } + + // Hide the delete button if we have minItems items + if(editor.delete_button) { + if(minItems) { + editor.delete_button.style.display = 'none'; + } + else { + editor.delete_button.style.display = ''; + } + } + + // Get the value for this editor + self.value[i] = editor.getValue(); + }); + + var controls_needed = false; + + if(!this.value.length) { + this.delete_last_row_button.style.display = 'none'; + this.remove_all_rows_button.style.display = 'none'; + } + else if(this.value.length === 1) { + this.remove_all_rows_button.style.display = 'none'; + + // If there are minItems items in the array, hide the delete button beneath the rows + if(minItems || this.hide_delete_buttons) { + this.delete_last_row_button.style.display = 'none'; + } + else { + this.delete_last_row_button.style.display = ''; + controls_needed = true; + } + } + else { + // If there are minItems items in the array, hide the delete button beneath the rows + if(minItems || this.hide_delete_buttons) { + this.delete_last_row_button.style.display = 'none'; + this.remove_all_rows_button.style.display = 'none'; + } + else { + this.delete_last_row_button.style.display = ''; + this.remove_all_rows_button.style.display = ''; + controls_needed = true; + } + } + + // If there are maxItems in the array, hide the add button beneath the rows + if((this.getMax() && this.getMax() <= this.rows.length) || this.hide_add_button){ + this.add_row_button.style.display = 'none'; + } + else { + this.add_row_button.style.display = ''; + controls_needed = true; + } + + if(!this.collapsed && controls_needed) { + this.controls.style.display = 'inline-block'; + } + else { + this.controls.style.display = 'none'; + } + } + }, + addRow: function(value, initial) { + var self = this; + var i = this.rows.length; + + self.rows[i] = this.getElementEditor(i); + self.row_cache[i] = self.rows[i]; + + if(self.tabs_holder) { + self.rows[i].tab_text = document.createElement('span'); + self.rows[i].tab_text.textContent = self.rows[i].getHeaderText(); + self.rows[i].tab = self.theme.getTab(self.rows[i].tab_text); + self.rows[i].tab.addEventListener('click', function(e) { + self.active_tab = self.rows[i].tab; + self.refreshTabs(); + e.preventDefault(); + e.stopPropagation(); + }); + + self.theme.addTab(self.tabs_holder, self.rows[i].tab); + } + + var controls_holder = self.rows[i].title_controls || self.rows[i].array_controls; + + // Buttons to delete row, move row up, and move row down + if(!self.hide_delete_buttons) { + self.rows[i].delete_button = this.getButton(self.getItemTitle(),'delete','Delete '+self.getItemTitle()); + self.rows[i].delete_button.className += ' delete'; + self.rows[i].delete_button.setAttribute('data-i',i); + self.rows[i].delete_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var i = this.getAttribute('data-i')*1; + + var value = self.getValue(); + + var newval = []; + var new_active_tab = null; + $each(value,function(j,row) { + if(j===i) { + // If the one we're deleting is the active tab + if(self.rows[j].tab === self.active_tab) { + // Make the next tab active if there is one + // Note: the next tab is going to be the current tab after deletion + if(self.rows[j+1]) new_active_tab = self.rows[j].tab; + // Otherwise, make the previous tab active if there is one + else if(j) new_active_tab = self.rows[j-1].tab; + } + + return; // If this is the one we're deleting + } + newval.push(row); + }); + self.setValue(newval); + if(new_active_tab) { + self.active_tab = new_active_tab; + self.refreshTabs(); + } + + self.onChange(true); + }); + + if(controls_holder) { + controls_holder.appendChild(self.rows[i].delete_button); + } + } + + if(i && !self.hide_move_buttons) { + self.rows[i].moveup_button = this.getButton('','moveup','Move up'); + self.rows[i].moveup_button.className += ' moveup'; + self.rows[i].moveup_button.setAttribute('data-i',i); + self.rows[i].moveup_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var i = this.getAttribute('data-i')*1; + + if(i<=0) return; + var rows = self.getValue(); + var tmp = rows[i-1]; + rows[i-1] = rows[i]; + rows[i] = tmp; + + self.setValue(rows); + self.active_tab = self.rows[i-1].tab; + self.refreshTabs(); + + self.onChange(true); + }); + + if(controls_holder) { + controls_holder.appendChild(self.rows[i].moveup_button); + } + } + + if(!self.hide_move_buttons) { + self.rows[i].movedown_button = this.getButton('','movedown','Move down'); + self.rows[i].movedown_button.className += ' movedown'; + self.rows[i].movedown_button.setAttribute('data-i',i); + self.rows[i].movedown_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var i = this.getAttribute('data-i')*1; + + var rows = self.getValue(); + if(i>=rows.length-1) return; + var tmp = rows[i+1]; + rows[i+1] = rows[i]; + rows[i] = tmp; + + self.setValue(rows); + self.active_tab = self.rows[i+1].tab; + self.refreshTabs(); + self.onChange(true); + }); + + if(controls_holder) { + controls_holder.appendChild(self.rows[i].movedown_button); + } + } + + if(value) self.rows[i].setValue(value, initial); + self.refreshTabs(); + }, + addControls: function() { + var self = this; + + this.collapsed = false; + this.toggle_button = this.getButton('','collapse','Collapse'); + this.title_controls.appendChild(this.toggle_button); + var row_holder_display = self.row_holder.style.display; + var controls_display = self.controls.style.display; + this.toggle_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + if(self.collapsed) { + self.collapsed = false; + if(self.panel) self.panel.style.display = ''; + self.row_holder.style.display = row_holder_display; + if(self.tabs_holder) self.tabs_holder.style.display = ''; + self.controls.style.display = controls_display; + self.setButtonText(this,'','collapse','Collapse'); + } + else { + self.collapsed = true; + self.row_holder.style.display = 'none'; + if(self.tabs_holder) self.tabs_holder.style.display = 'none'; + self.controls.style.display = 'none'; + if(self.panel) self.panel.style.display = 'none'; + self.setButtonText(this,'','expand','Expand'); + } + }); + + // If it should start collapsed + if(this.options.collapsed) { + $trigger(this.toggle_button,'click'); + } + + // Collapse button disabled + if(this.schema.options && typeof this.schema.options.disable_collapse !== "undefined") { + if(this.schema.options.disable_collapse) this.toggle_button.style.display = 'none'; + } + else if(this.jsoneditor.options.disable_collapse) { + this.toggle_button.style.display = 'none'; + } + + // Add "new row" and "delete last" buttons below editor + this.add_row_button = this.getButton(this.getItemTitle(),'add','Add '+this.getItemTitle()); + + this.add_row_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var i = self.rows.length; + if(self.row_cache[i]) { + self.rows[i] = self.row_cache[i]; + self.rows[i].setValue(self.rows[i].getDefault()); + self.rows[i].container.style.display = ''; + if(self.rows[i].tab) self.rows[i].tab.style.display = ''; + self.rows[i].register(); + } + else { + self.addRow(); + } + self.active_tab = self.rows[i].tab; + self.refreshTabs(); + self.refreshValue(); + self.onChange(true); + }); + self.controls.appendChild(this.add_row_button); + + this.delete_last_row_button = this.getButton('Last '+this.getItemTitle(),'delete','Delete Last '+this.getItemTitle()); + this.delete_last_row_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var rows = self.getValue(); + + var new_active_tab = null; + if(self.rows.length > 1 && self.rows[self.rows.length-1].tab === self.active_tab) new_active_tab = self.rows[self.rows.length-2].tab; + + rows.pop(); + self.setValue(rows); + if(new_active_tab) { + self.active_tab = new_active_tab; + self.refreshTabs(); + } + self.onChange(true); + }); + self.controls.appendChild(this.delete_last_row_button); + + this.remove_all_rows_button = this.getButton('All','delete','Delete All'); + this.remove_all_rows_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + self.setValue([]); + self.onChange(true); + }); + self.controls.appendChild(this.remove_all_rows_button); + + if(self.tabs) { + this.add_row_button.style.width = '100%'; + this.add_row_button.style.textAlign = 'left'; + this.add_row_button.style.marginBottom = '3px'; + + this.delete_last_row_button.style.width = '100%'; + this.delete_last_row_button.style.textAlign = 'left'; + this.delete_last_row_button.style.marginBottom = '3px'; + + this.remove_all_rows_button.style.width = '100%'; + this.remove_all_rows_button.style.textAlign = 'left'; + this.remove_all_rows_button.style.marginBottom = '3px'; + } + }, + showValidationErrors: function(errors) { + var self = this; + + // Get all the errors that pertain to this editor + var my_errors = []; + var other_errors = []; + $each(errors, function(i,error) { + if(error.path === self.path) { + my_errors.push(error); + } + else { + other_errors.push(error); + } + }); + + // Show errors for this editor + if(this.error_holder) { + if(my_errors.length) { + var message = []; + this.error_holder.innerHTML = ''; + this.error_holder.style.display = ''; + $each(my_errors, function(i,error) { + self.error_holder.appendChild(self.theme.getErrorMessage(error.message)); + }); + } + // Hide error area + else { + this.error_holder.style.display = 'none'; + } + } + + // Show errors for child editors + $each(this.rows, function(i,row) { + row.showValidationErrors(other_errors); + }); + } +}); + +JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({ + register: function() { + this._super(); + if(this.rows) { + for(var i=0; i this.schema.maxItems) { + value = value.slice(0,this.schema.maxItems); + } + + var serialized = JSON.stringify(value); + if(serialized === this.serialized) return; + + var numrows_changed = false; + + var self = this; + $each(value,function(i,val) { + if(self.rows[i]) { + // TODO: don't set the row's value if it hasn't changed + self.rows[i].setValue(val); + } + else { + self.addRow(val); + numrows_changed = true; + } + }); + + for(var j=value.length; j= this.rows.length; + + var need_row_buttons = false; + $each(this.rows,function(i,editor) { + // Hide the move down button for the last row + if(editor.movedown_button) { + if(i === self.rows.length - 1) { + editor.movedown_button.style.display = 'none'; + } + else { + need_row_buttons = true; + editor.movedown_button.style.display = ''; + } + } + + // Hide the delete button if we have minItems items + if(editor.delete_button) { + if(minItems) { + editor.delete_button.style.display = 'none'; + } + else { + need_row_buttons = true; + editor.delete_button.style.display = ''; + } + } + + if(editor.moveup_button) { + need_row_buttons = true; + } + }); + + // Show/hide controls column in table + $each(this.rows,function(i,editor) { + if(need_row_buttons) { + editor.controls_cell.style.display = ''; + } + else { + editor.controls_cell.style.display = 'none'; + } + }); + if(need_row_buttons) { + this.controls_header_cell.style.display = ''; + } + else { + this.controls_header_cell.style.display = 'none'; + } + + var controls_needed = false; + + if(!this.value.length) { + this.delete_last_row_button.style.display = 'none'; + this.remove_all_rows_button.style.display = 'none'; + this.table.style.display = 'none'; + } + else if(this.value.length === 1 || this.hide_delete_buttons) { + this.table.style.display = ''; + this.remove_all_rows_button.style.display = 'none'; + + // If there are minItems items in the array, hide the delete button beneath the rows + if(minItems || this.hide_delete_buttons) { + this.delete_last_row_button.style.display = 'none'; + } + else { + this.delete_last_row_button.style.display = ''; + controls_needed = true; + } + } + else { + this.table.style.display = ''; + // If there are minItems items in the array, hide the delete button beneath the rows + if(minItems || this.hide_delete_buttons) { + this.delete_last_row_button.style.display = 'none'; + this.remove_all_rows_button.style.display = 'none'; + } + else { + this.delete_last_row_button.style.display = ''; + this.remove_all_rows_button.style.display = ''; + controls_needed = true; + } + } + + // If there are maxItems in the array, hide the add button beneath the rows + if((this.schema.maxItems && this.schema.maxItems <= this.rows.length) || this.hide_add_button) { + this.add_row_button.style.display = 'none'; + } + else { + this.add_row_button.style.display = ''; + controls_needed = true; + } + + if(!controls_needed) { + this.controls.style.display = 'none'; + } + else { + this.controls.style.display = ''; + } + }, + refreshValue: function() { + var self = this; + this.value = []; + + $each(this.rows,function(i,editor) { + // Get the value for this editor + self.value[i] = editor.getValue(); + }); + this.serialized = JSON.stringify(this.value); + }, + addRow: function(value) { + var self = this; + var i = this.rows.length; + + self.rows[i] = this.getElementEditor(i); + + var controls_holder = self.rows[i].table_controls; + + // Buttons to delete row, move row up, and move row down + if(!this.hide_delete_buttons) { + self.rows[i].delete_button = this.getButton('','delete','Delete'); + self.rows[i].delete_button.className += ' delete'; + self.rows[i].delete_button.setAttribute('data-i',i); + self.rows[i].delete_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var i = this.getAttribute('data-i')*1; + + var value = self.getValue(); + + var newval = []; + $each(value,function(j,row) { + if(j===i) return; // If this is the one we're deleting + newval.push(row); + }); + self.setValue(newval); + self.onChange(true); + }); + controls_holder.appendChild(self.rows[i].delete_button); + } + + + if(i && !this.hide_move_buttons) { + self.rows[i].moveup_button = this.getButton('','moveup','Move up'); + self.rows[i].moveup_button.className += ' moveup'; + self.rows[i].moveup_button.setAttribute('data-i',i); + self.rows[i].moveup_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var i = this.getAttribute('data-i')*1; + + if(i<=0) return; + var rows = self.getValue(); + var tmp = rows[i-1]; + rows[i-1] = rows[i]; + rows[i] = tmp; + + self.setValue(rows); + self.onChange(true); + }); + controls_holder.appendChild(self.rows[i].moveup_button); + } + + if(!this.hide_move_buttons) { + self.rows[i].movedown_button = this.getButton('','movedown','Move down'); + self.rows[i].movedown_button.className += ' movedown'; + self.rows[i].movedown_button.setAttribute('data-i',i); + self.rows[i].movedown_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var i = this.getAttribute('data-i')*1; + var rows = self.getValue(); + if(i>=rows.length-1) return; + var tmp = rows[i+1]; + rows[i+1] = rows[i]; + rows[i] = tmp; + + self.setValue(rows); + self.onChange(true); + }); + controls_holder.appendChild(self.rows[i].movedown_button); + } + + if(value) self.rows[i].setValue(value); + }, + addControls: function() { + var self = this; + + this.collapsed = false; + this.toggle_button = this.getButton('','collapse','Collapse'); + if(this.title_controls) { + this.title_controls.appendChild(this.toggle_button); + this.toggle_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + + if(self.collapsed) { + self.collapsed = false; + self.panel.style.display = ''; + self.setButtonText(this,'','collapse','Collapse'); + } + else { + self.collapsed = true; + self.panel.style.display = 'none'; + self.setButtonText(this,'','expand','Expand'); + } + }); + + // If it should start collapsed + if(this.options.collapsed) { + $trigger(this.toggle_button,'click'); + } + + // Collapse button disabled + if(this.schema.options && typeof this.schema.options.disable_collapse !== "undefined") { + if(this.schema.options.disable_collapse) this.toggle_button.style.display = 'none'; + } + else if(this.jsoneditor.options.disable_collapse) { + this.toggle_button.style.display = 'none'; + } + } + + // Add "new row" and "delete last" buttons below editor + this.add_row_button = this.getButton(this.getItemTitle(),'add','Add '+this.getItemTitle()); + this.add_row_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + + self.addRow(); + self.refreshValue(); + self.refreshRowButtons(); + self.onChange(true); + }); + self.controls.appendChild(this.add_row_button); + + this.delete_last_row_button = this.getButton('Last '+this.getItemTitle(),'delete','Delete Last '+this.getItemTitle()); + this.delete_last_row_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + + var rows = self.getValue(); + rows.pop(); + self.setValue(rows); + self.onChange(true); + }); + self.controls.appendChild(this.delete_last_row_button); + + this.remove_all_rows_button = this.getButton('All','delete','Delete All'); + this.remove_all_rows_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + + self.setValue([]); + self.onChange(true); + }); + self.controls.appendChild(this.remove_all_rows_button); + } +}); + +// Multiple Editor (for when `type` is an array) +JSONEditor.defaults.editors.multiple = JSONEditor.AbstractEditor.extend({ + register: function() { + if(this.editors) { + for(var i=0; inull'; + } + // Array or Object + else if(typeof el === "object") { + // TODO: use theme + var ret = ''; + + $each(el,function(i,child) { + var html = self.getHTML(child); + + // Add the keys to object children + if(!(Array.isArray(el))) { + // TODO: use theme + html = '
'+i+': '+html+'
'; + } + + // TODO: use theme + ret += '
  • '+html+'
  • '; + }); + + if(Array.isArray(el)) ret = '
      '+ret+'
    '; + else ret = "
      "+ret+'
    '; + + return ret; + } + // Boolean + else if(typeof el === "boolean") { + return el? 'true' : 'false'; + } + // String + else if(typeof el === "string") { + return el.replace(/&/g,'&').replace(//g,'>'); + } + // Number + else { + return el; + } + }, + setValue: function(val) { + if(this.value !== val) { + this.value = val; + this.refreshValue(); + this.onChange(); + } + }, + destroy: function() { + if(this.display_area && this.display_area.parentNode) this.display_area.parentNode.removeChild(this.display_area); + if(this.title && this.title.parentNode) this.title.parentNode.removeChild(this.title); + if(this.switcher && this.switcher.parentNode) this.switcher.parentNode.removeChild(this.switcher); + + this._super(); + } +}); + +JSONEditor.defaults.editors.select = JSONEditor.AbstractEditor.extend({ + setValue: function(value,initial) { + value = this.typecast(value||''); + + // Sanitize value before setting it + var sanitized = value; + if(this.enum_values.indexOf(sanitized) < 0) { + sanitized = this.enum_values[0]; + } + + if(this.value === sanitized) { + return; + } + + this.input.value = this.enum_options[this.enum_values.indexOf(sanitized)]; + if(this.select2) this.select2.select2('val',this.input.value); + this.value = sanitized; + this.onChange(); + }, + register: function() { + this._super(); + if(!this.input) return; + this.input.setAttribute('name',this.formname); + }, + unregister: function() { + this._super(); + if(!this.input) return; + this.input.removeAttribute('name'); + }, + getNumColumns: function() { + if(!this.enum_options) return 3; + var longest_text = this.getTitle().length; + for(var i=0; i 2 || (this.enum_options.length && this.enumSource))) { + var options = $extend({},JSONEditor.plugins.select2); + if(this.schema.options && this.schema.options.select2_options) options = $extend(options,this.schema.options.select2_options); + this.select2 = window.jQuery(this.input).select2(options); + var self = this; + this.select2.on('select2-blur',function() { + self.input.value = self.select2.select2('val'); + self.onInputChange(); + }); + } + else { + this.select2 = null; + } + }, + postBuild: function() { + this._super(); + this.theme.afterInputReady(this.input); + this.setupSelect2(); + }, + onWatchedFieldChange: function() { + var self = this, vars, j; + + // If this editor uses a dynamic select box + if(this.enumSource) { + vars = this.getWatchedFieldValues(); + var select_options = []; + var select_titles = []; + + for(var i=0; iSize: '+Math.floor((this.value.length-this.value.split(',')[0].length-1)/1.33333)+' bytes'; + if(mime.substr(0,5)==="image") { + this.preview.innerHTML += '
    '; + var img = document.createElement('img'); + img.style.maxWidth = '100%'; + img.style.maxHeight = '100px'; + img.src = this.value; + this.preview.appendChild(img); + } + } + }, + enable: function() { + if(this.uploader) this.uploader.disabled = false; + this._super(); + }, + disable: function() { + if(this.uploader) this.uploader.disabled = true; + this._super(); + }, + setValue: function(val) { + if(this.value !== val) { + this.value = val; + this.input.value = this.value; + this.refreshPreview(); + this.onChange(); + } + }, + destroy: function() { + if(this.preview && this.preview.parentNode) this.preview.parentNode.removeChild(this.preview); + if(this.title && this.title.parentNode) this.title.parentNode.removeChild(this.title); + if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input); + if(this.uploader && this.uploader.parentNode) this.uploader.parentNode.removeChild(this.uploader); + + this._super(); + } +}); + +JSONEditor.defaults.editors.upload = JSONEditor.AbstractEditor.extend({ + getNumColumns: function() { + return 4; + }, + build: function() { + var self = this; + this.title = this.header = this.label = this.theme.getFormInputLabel(this.getTitle()); + + // Input that holds the base64 string + this.input = this.theme.getFormInputField('hidden'); + this.container.appendChild(this.input); + + // Don't show uploader if this is readonly + if(!this.schema.readOnly && !this.schema.readonly) { + + if(!this.jsoneditor.options.upload) throw "Upload handler required for upload editor"; + + // File uploader + this.uploader = this.theme.getFormInputField('file'); + + this.uploader.addEventListener('change',function(e) { + e.preventDefault(); + e.stopPropagation(); + + if(this.files && this.files.length) { + var fr = new FileReader(); + fr.onload = function(evt) { + self.preview_value = evt.target.result; + self.refreshPreview(); + self.onChange(true); + fr = null; + }; + fr.readAsDataURL(this.files[0]); + } + }); + } + + var description = this.schema.description; + if (!description) description = ''; + + this.preview = this.theme.getFormInputDescription(description); + this.container.appendChild(this.preview); + + this.control = this.theme.getFormControl(this.label, this.uploader||this.input, this.preview); + this.container.appendChild(this.control); + }, + refreshPreview: function() { + if(this.last_preview === this.preview_value) return; + this.last_preview = this.preview_value; + + this.preview.innerHTML = ''; + + if(!this.preview_value) return; + + var self = this; + + var mime = this.preview_value.match(/^data:([^;,]+)[;,]/); + if(mime) mime = mime[1]; + if(!mime) mime = 'unknown'; + + var file = this.uploader.files[0]; + + this.preview.innerHTML = 'Type: '+mime+', Size: '+file.size+' bytes'; + if(mime.substr(0,5)==="image") { + this.preview.innerHTML += '
    '; + var img = document.createElement('img'); + img.style.maxWidth = '100%'; + img.style.maxHeight = '100px'; + img.src = this.preview_value; + this.preview.appendChild(img); + } + + this.preview.innerHTML += '
    '; + var uploadButton = this.getButton('Upload', 'upload', 'Upload'); + this.preview.appendChild(uploadButton); + uploadButton.addEventListener('click',function(event) { + event.preventDefault(); + + uploadButton.setAttribute("disabled", "disabled"); + self.theme.removeInputError(self.uploader); + + if (self.theme.getProgressBar) { + self.progressBar = self.theme.getProgressBar(); + self.preview.appendChild(self.progressBar); + } + + self.jsoneditor.options.upload(self.path, file, { + success: function(url) { + self.setValue(url); + + if(self.parent) self.parent.onChildEditorChange(self); + else self.jsoneditor.onChange(); + + if (self.progressBar) self.preview.removeChild(self.progressBar); + uploadButton.removeAttribute("disabled"); + }, + failure: function(error) { + self.theme.addInputError(self.uploader, error); + if (self.progressBar) self.preview.removeChild(self.progressBar); + uploadButton.removeAttribute("disabled"); + }, + updateProgress: function(progress) { + if (self.progressBar) { + if (progress) self.theme.updateProgressBar(self.progressBar, progress); + else self.theme.updateProgressBarUnknown(self.progressBar); + } + } + }); + }); + }, + enable: function() { + if(this.uploader) this.uploader.disabled = false; + this._super(); + }, + disable: function() { + if(this.uploader) this.uploader.disabled = true; + this._super(); + }, + setValue: function(val) { + if(this.value !== val) { + this.value = val; + this.input.value = this.value; + this.onChange(); + } + }, + destroy: function() { + if(this.preview && this.preview.parentNode) this.preview.parentNode.removeChild(this.preview); + if(this.title && this.title.parentNode) this.title.parentNode.removeChild(this.title); + if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input); + if(this.uploader && this.uploader.parentNode) this.uploader.parentNode.removeChild(this.uploader); + + this._super(); + } +}); + +JSONEditor.defaults.editors.checkbox = JSONEditor.AbstractEditor.extend({ + setValue: function(value,initial) { + this.value = !!value; + this.input.checked = this.value; + this.onChange(); + }, + register: function() { + this._super(); + if(!this.input) return; + this.input.setAttribute('name',this.formname); + }, + unregister: function() { + this._super(); + if(!this.input) return; + this.input.removeAttribute('name'); + }, + getNumColumns: function() { + return Math.min(12,Math.max(this.getTitle().length/7,2)); + }, + build: function() { + var self = this; + if(!this.options.compact) { + this.label = this.header = this.theme.getCheckboxLabel(this.getTitle()); + } + if(this.schema.description) this.description = this.theme.getFormInputDescription(this.schema.description); + if(this.options.compact) this.container.className += ' compact'; + + this.input = this.theme.getCheckbox(); + this.control = this.theme.getFormControl(this.label, this.input, this.description); + + if(this.schema.readOnly || this.schema.readonly) { + this.always_disabled = true; + this.input.disabled = true; + } + + this.input.addEventListener('change',function(e) { + e.preventDefault(); + e.stopPropagation(); + self.value = this.checked; + self.onChange(true); + }); + + this.container.appendChild(this.control); + }, + enable: function() { + if(!this.always_disabled) { + this.input.disabled = false; + } + this._super(); + }, + disable: function() { + this.input.disabled = true; + this._super(); + }, + destroy: function() { + if(this.label && this.label.parentNode) this.label.parentNode.removeChild(this.label); + if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description); + if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input); + this._super(); + } +}); + +var matchKey = (function () { + var elem = document.documentElement; + + if (elem.matches) return 'matches'; + else if (elem.webkitMatchesSelector) return 'webkitMatchesSelector'; + else if (elem.mozMatchesSelector) return 'mozMatchesSelector'; + else if (elem.msMatchesSelector) return 'msMatchesSelector'; + else if (elem.oMatchesSelector) return 'oMatchesSelector'; +})(); + +JSONEditor.AbstractTheme = Class.extend({ + getContainer: function() { + return document.createElement('div'); + }, + getFloatRightLinkHolder: function() { + var el = document.createElement('div'); + el.style = el.style || {}; + el.style.cssFloat = 'right'; + el.style.marginLeft = '10px'; + return el; + }, + getModal: function() { + var el = document.createElement('div'); + el.style.backgroundColor = 'white'; + el.style.border = '1px solid black'; + el.style.boxShadow = '3px 3px black'; + el.style.position = 'absolute'; + el.style.zIndex = '10'; + el.style.display = 'none'; + return el; + }, + getGridContainer: function() { + var el = document.createElement('div'); + return el; + }, + getGridRow: function() { + var el = document.createElement('div'); + el.className = 'row'; + return el; + }, + getGridColumn: function() { + var el = document.createElement('div'); + return el; + }, + setGridColumnSize: function(el,size) { + + }, + getLink: function(text) { + var el = document.createElement('a'); + el.setAttribute('href','#'); + el.appendChild(document.createTextNode(text)); + return el; + }, + disableHeader: function(header) { + header.style.color = '#ccc'; + }, + disableLabel: function(label) { + label.style.color = '#ccc'; + }, + enableHeader: function(header) { + header.style.color = ''; + }, + enableLabel: function(label) { + label.style.color = ''; + }, + getFormInputLabel: function(text) { + var el = document.createElement('label'); + el.appendChild(document.createTextNode(text)); + return el; + }, + getCheckboxLabel: function(text) { + var el = this.getFormInputLabel(text); + el.style.fontWeight = 'normal'; + return el; + }, + getHeader: function(text) { + var el = document.createElement('h3'); + if(typeof text === "string") { + el.textContent = text; + } + else { + el.appendChild(text); + } + + return el; + }, + getCheckbox: function() { + var el = this.getFormInputField('checkbox'); + el.style.display = 'inline-block'; + el.style.width = 'auto'; + return el; + }, + getMultiCheckboxHolder: function(controls,label,description) { + var el = document.createElement('div'); + + if(label) { + label.style.display = 'block'; + el.appendChild(label); + } + + for(var i in controls) { + if(!controls.hasOwnProperty(i)) continue; + controls[i].style.display = 'inline-block'; + controls[i].style.marginRight = '20px'; + el.appendChild(controls[i]); + } + + if(description) el.appendChild(description); + + return el; + }, + getSelectInput: function(options) { + var select = document.createElement('select'); + if(options) this.setSelectOptions(select, options); + return select; + }, + getSwitcher: function(options) { + var switcher = this.getSelectInput(options); + switcher.style.backgroundColor = 'transparent'; + switcher.style.display = 'inline-block'; + switcher.style.fontStyle = 'italic'; + switcher.style.fontWeight = 'normal'; + switcher.style.height = 'auto'; + switcher.style.marginBottom = 0; + switcher.style.marginLeft = '5px'; + switcher.style.padding = '0 0 0 3px'; + switcher.style.width = 'auto'; + return switcher; + }, + getSwitcherOptions: function(switcher) { + return switcher.getElementsByTagName('option'); + }, + setSwitcherOptions: function(switcher, options, titles) { + this.setSelectOptions(switcher, options, titles); + }, + setSelectOptions: function(select, options, titles) { + titles = titles || []; + select.innerHTML = ''; + for(var i=0; i'); + input.errmsg = input.parentNode.getElementsByClassName('error')[0]; + } + else { + input.errmsg.style.display = ''; + } + + input.errmsg.textContent = text; + }, + removeInputError: function(input) { + if(!input.errmsg) return; + input.group.className = input.group.className.replace(/ error/g,''); + input.errmsg.style.display = 'none'; + }, + getProgressBar: function() { + var progressBar = document.createElement('div'); + progressBar.className = 'progress'; + + var meter = document.createElement('span'); + meter.className = 'meter'; + meter.style.width = '0%'; + progressBar.appendChild(meter); + return progressBar; + }, + updateProgressBar: function(progressBar, progress) { + if (!progressBar) return; + progressBar.firstChild.style.width = progress + '%'; + }, + updateProgressBarUnknown: function(progressBar) { + if (!progressBar) return; + progressBar.firstChild.style.width = '100%'; + } +}); + +// Foundation 3 Specific Theme +JSONEditor.defaults.themes.foundation3 = JSONEditor.defaults.themes.foundation.extend({ + getHeaderButtonHolder: function() { + var el = this._super(); + el.style.fontSize = '.6em'; + return el; + }, + getFormInputLabel: function(text) { + var el = this._super(text); + el.style.fontWeight = 'bold'; + return el; + }, + getTabHolder: function() { + var el = document.createElement('div'); + el.className = 'row'; + el.innerHTML = "
    "; + return el; + }, + setGridColumnSize: function(el,size) { + var sizes = ['zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve']; + el.className = 'columns '+sizes[size]; + }, + getTab: function(text) { + var el = document.createElement('dd'); + var a = document.createElement('a'); + a.setAttribute('href','#'); + a.appendChild(text); + el.appendChild(a); + return el; + }, + getTabContentHolder: function(tab_holder) { + return tab_holder.children[1]; + }, + getTabContent: function() { + var el = document.createElement('div'); + el.className = 'content active'; + el.style.paddingLeft = '5px'; + return el; + }, + markTabActive: function(tab) { + tab.className += ' active'; + }, + markTabInactive: function(tab) { + tab.className = tab.className.replace(/\s*active/g,''); + }, + addTab: function(holder, tab) { + holder.children[0].appendChild(tab); + } +}); + +// Foundation 4 Specific Theme +JSONEditor.defaults.themes.foundation4 = JSONEditor.defaults.themes.foundation.extend({ + getHeaderButtonHolder: function() { + var el = this._super(); + el.style.fontSize = '.6em'; + return el; + }, + setGridColumnSize: function(el,size) { + el.className = 'columns large-'+size; + }, + getFormInputDescription: function(text) { + var el = this._super(text); + el.style.fontSize = '.8rem'; + return el; + }, + getFormInputLabel: function(text) { + var el = this._super(text); + el.style.fontWeight = 'bold'; + return el; + } +}); + +// Foundation 5 Specific Theme +JSONEditor.defaults.themes.foundation5 = JSONEditor.defaults.themes.foundation.extend({ + getFormInputDescription: function(text) { + var el = this._super(text); + el.style.fontSize = '.8rem'; + return el; + }, + setGridColumnSize: function(el,size) { + el.className = 'columns medium-'+size; + }, + getButton: function(text, icon, title) { + var el = this._super(text,icon,title); + el.className = el.className.replace(/\s*small/g,'') + ' tiny'; + return el; + }, + getTabHolder: function() { + var el = document.createElement('div'); + el.innerHTML = "
    "; + return el; + }, + getTab: function(text) { + var el = document.createElement('dd'); + var a = document.createElement('a'); + a.setAttribute('href','#'); + a.appendChild(text); + el.appendChild(a); + return el; + }, + getTabContentHolder: function(tab_holder) { + return tab_holder.children[1]; + }, + getTabContent: function() { + var el = document.createElement('div'); + el.className = 'content active'; + el.style.paddingLeft = '5px'; + return el; + }, + markTabActive: function(tab) { + tab.className += ' active'; + }, + markTabInactive: function(tab) { + tab.className = tab.className.replace(/\s*active/g,''); + }, + addTab: function(holder, tab) { + holder.children[0].appendChild(tab); + } +}); + +JSONEditor.defaults.themes.html = JSONEditor.AbstractTheme.extend({ + getFormInputLabel: function(text) { + var el = this._super(text); + el.style.display = 'block'; + el.style.marginBottom = '3px'; + el.style.fontWeight = 'bold'; + return el; + }, + getFormInputDescription: function(text) { + var el = this._super(text); + el.style.fontSize = '.8em'; + el.style.margin = 0; + el.style.display = 'inline-block'; + el.style.fontStyle = 'italic'; + return el; + }, + getIndentedPanel: function() { + var el = this._super(); + el.style.border = '1px solid #ddd'; + el.style.padding = '5px'; + el.style.margin = '5px'; + el.style.borderRadius = '3px'; + return el; + }, + getChildEditorHolder: function() { + var el = this._super(); + el.style.marginBottom = '8px'; + return el; + }, + getHeaderButtonHolder: function() { + var el = this.getButtonHolder(); + el.style.display = 'inline-block'; + el.style.marginLeft = '10px'; + el.style.fontSize = '.8em'; + el.style.verticalAlign = 'middle'; + return el; + }, + getTable: function() { + var el = this._super(); + el.style.borderBottom = '1px solid #ccc'; + el.style.marginBottom = '5px'; + return el; + }, + addInputError: function(input, text) { + input.style.borderColor = 'red'; + + if(!input.errmsg) { + var group = this.closest(input,'.form-control'); + input.errmsg = document.createElement('div'); + input.errmsg.setAttribute('class','errmsg'); + input.errmsg.style = input.errmsg.style || {}; + input.errmsg.style.color = 'red'; + group.appendChild(input.errmsg); + } + else { + input.errmsg.style.display = 'block'; + } + + input.errmsg.innerHTML = ''; + input.errmsg.appendChild(document.createTextNode(text)); + }, + removeInputError: function(input) { + input.style.borderColor = ''; + if(input.errmsg) input.errmsg.style.display = 'none'; + }, + getProgressBar: function() { + var max = 100, start = 0; + + var progressBar = document.createElement('progress'); + progressBar.setAttribute('max', max); + progressBar.setAttribute('value', start); + return progressBar; + }, + updateProgressBar: function(progressBar, progress) { + if (!progressBar) return; + progressBar.setAttribute('value', progress); + }, + updateProgressBarUnknown: function(progressBar) { + if (!progressBar) return; + progressBar.removeAttribute('value'); + } +}); + +JSONEditor.defaults.themes.jqueryui = JSONEditor.AbstractTheme.extend({ + getTable: function() { + var el = this._super(); + el.setAttribute('cellpadding',5); + el.setAttribute('cellspacing',0); + return el; + }, + getTableHeaderCell: function(text) { + var el = this._super(text); + el.className = 'ui-state-active'; + el.style.fontWeight = 'bold'; + return el; + }, + getTableCell: function() { + var el = this._super(); + el.className = 'ui-widget-content'; + return el; + }, + getHeaderButtonHolder: function() { + var el = this.getButtonHolder(); + el.style.marginLeft = '10px'; + el.style.fontSize = '.6em'; + el.style.display = 'inline-block'; + return el; + }, + getFormInputDescription: function(text) { + var el = this.getDescription(text); + el.style.marginLeft = '10px'; + el.style.display = 'inline-block'; + return el; + }, + getFormControl: function(label, input, description) { + var el = this._super(label,input,description); + if(input.type === 'checkbox') { + el.style.lineHeight = '25px'; + + el.style.padding = '3px 0'; + } + else { + el.style.padding = '4px 0 8px 0'; + } + return el; + }, + getDescription: function(text) { + var el = document.createElement('span'); + el.style.fontSize = '.8em'; + el.style.fontStyle = 'italic'; + el.textContent = text; + return el; + }, + getButtonHolder: function() { + var el = document.createElement('div'); + el.className = 'ui-buttonset'; + el.style.fontSize = '.7em'; + return el; + }, + getFormInputLabel: function(text) { + var el = document.createElement('label'); + el.style.fontWeight = 'bold'; + el.style.display = 'block'; + el.textContent = text; + return el; + }, + getButton: function(text, icon, title) { + var button = document.createElement("button"); + button.className = 'ui-button ui-widget ui-state-default ui-corner-all'; + + // Icon only + if(icon && !text) { + button.className += ' ui-button-icon-only'; + icon.className += ' ui-button-icon-primary ui-icon-primary'; + button.appendChild(icon); + } + // Icon and Text + else if(icon) { + button.className += ' ui-button-text-icon-primary'; + icon.className += ' ui-button-icon-primary ui-icon-primary'; + button.appendChild(icon); + } + // Text only + else { + button.className += ' ui-button-text-only'; + } + + var el = document.createElement('span'); + el.className = 'ui-button-text'; + el.textContent = text||title||"."; + button.appendChild(el); + + button.setAttribute('title',title); + + return button; + }, + setButtonText: function(button,text, icon, title) { + button.innerHTML = ''; + button.className = 'ui-button ui-widget ui-state-default ui-corner-all'; + + // Icon only + if(icon && !text) { + button.className += ' ui-button-icon-only'; + icon.className += ' ui-button-icon-primary ui-icon-primary'; + button.appendChild(icon); + } + // Icon and Text + else if(icon) { + button.className += ' ui-button-text-icon-primary'; + icon.className += ' ui-button-icon-primary ui-icon-primary'; + button.appendChild(icon); + } + // Text only + else { + button.className += ' ui-button-text-only'; + } + + var el = document.createElement('span'); + el.className = 'ui-button-text'; + el.textContent = text||title||"."; + button.appendChild(el); + + button.setAttribute('title',title); + }, + getIndentedPanel: function() { + var el = document.createElement('div'); + el.className = 'ui-widget-content ui-corner-all'; + el.style.padding = '1em 1.4em'; + el.style.marginBottom = '20px'; + return el; + }, + afterInputReady: function(input) { + if(input.controls) return; + input.controls = this.closest(input,'.form-control'); + }, + addInputError: function(input,text) { + if(!input.controls) return; + if(!input.errmsg) { + input.errmsg = document.createElement('div'); + input.errmsg.className = 'ui-state-error'; + input.controls.appendChild(input.errmsg); + } + else { + input.errmsg.style.display = ''; + } + + input.errmsg.textContent = text; + }, + removeInputError: function(input) { + if(!input.errmsg) return; + input.errmsg.style.display = 'none'; + }, + markTabActive: function(tab) { + tab.className = tab.className.replace(/\s*ui-widget-header/g,'')+' ui-state-active'; + }, + markTabInactive: function(tab) { + tab.className = tab.className.replace(/\s*ui-state-active/g,'')+' ui-widget-header'; + } +}); + +JSONEditor.AbstractIconLib = Class.extend({ + mapping: { + collapse: '', + expand: '', + "delete": '', + edit: '', + add: '', + cancel: '', + save: '', + moveup: '', + movedown: '' + }, + icon_prefix: '', + getIconClass: function(key) { + if(this.mapping[key]) return this.icon_prefix+this.mapping[key]; + else return null; + }, + getIcon: function(key) { + var iconclass = this.getIconClass(key); + + if(!iconclass) return null; + + var i = document.createElement('i'); + i.className = iconclass; + return i; + } +}); + +JSONEditor.defaults.iconlibs.bootstrap2 = JSONEditor.AbstractIconLib.extend({ + mapping: { + collapse: 'chevron-down', + expand: 'chevron-up', + "delete": 'trash', + edit: 'pencil', + add: 'plus', + cancel: 'ban-circle', + save: 'ok', + moveup: 'arrow-up', + movedown: 'arrow-down' + }, + icon_prefix: 'icon-' +}); + +JSONEditor.defaults.iconlibs.bootstrap3 = JSONEditor.AbstractIconLib.extend({ + mapping: { + collapse: 'chevron-down', + expand: 'chevron-right', + "delete": 'remove', + edit: 'pencil', + add: 'plus', + cancel: 'floppy-remove', + save: 'floppy-saved', + moveup: 'arrow-up', + movedown: 'arrow-down' + }, + icon_prefix: 'glyphicon glyphicon-' +}); + +JSONEditor.defaults.iconlibs.fontawesome3 = JSONEditor.AbstractIconLib.extend({ + mapping: { + collapse: 'chevron-down', + expand: 'chevron-right', + "delete": 'remove', + edit: 'pencil', + add: 'plus', + cancel: 'ban-circle', + save: 'save', + moveup: 'arrow-up', + movedown: 'arrow-down' + }, + icon_prefix: 'icon-' +}); + +JSONEditor.defaults.iconlibs.fontawesome4 = JSONEditor.AbstractIconLib.extend({ + mapping: { + collapse: 'caret-square-o-down', + expand: 'caret-square-o-right', + "delete": 'times', + edit: 'pencil', + add: 'plus', + cancel: 'ban', + save: 'save', + moveup: 'arrow-up', + movedown: 'arrow-down' + }, + icon_prefix: 'fa fa-' +}); + +JSONEditor.defaults.iconlibs.foundation2 = JSONEditor.AbstractIconLib.extend({ + mapping: { + collapse: 'minus', + expand: 'plus', + "delete": 'remove', + edit: 'edit', + add: 'add-doc', + cancel: 'error', + save: 'checkmark', + moveup: 'up-arrow', + movedown: 'down-arrow' + }, + icon_prefix: 'foundicon-' +}); + +JSONEditor.defaults.iconlibs.foundation3 = JSONEditor.AbstractIconLib.extend({ + mapping: { + collapse: 'minus', + expand: 'plus', + "delete": 'x', + edit: 'pencil', + add: 'page-add', + cancel: 'x-circle', + save: 'save', + moveup: 'arrow-up', + movedown: 'arrow-down' + }, + icon_prefix: 'fi-' +}); + +JSONEditor.defaults.iconlibs.jqueryui = JSONEditor.AbstractIconLib.extend({ + mapping: { + collapse: 'triangle-1-s', + expand: 'triangle-1-e', + "delete": 'trash', + edit: 'pencil', + add: 'plusthick', + cancel: 'closethick', + save: 'disk', + moveup: 'arrowthick-1-n', + movedown: 'arrowthick-1-s' + }, + icon_prefix: 'ui-icon ui-icon-' +}); + +JSONEditor.defaults.templates["default"] = function() { + return { + compile: function(template) { + var matches = template.match(/{{\s*([a-zA-Z0-9\-_ \.]+)\s*}}/g); + var l = matches && matches.length; + + // Shortcut if the template contains no variables + if(!l) return function() { return template; }; + + // Pre-compute the search/replace functions + // This drastically speeds up template execution + var replacements = []; + var get_replacement = function(i) { + var p = matches[i].replace(/[{}]+/g,'').trim().split('.'); + var n = p.length; + var func; + + if(n > 1) { + var cur; + func = function(vars) { + cur = vars; + for(i=0; i= 0) { + return 'multiselect'; + } +}); +// Use the multiple editor for schemas with `oneOf` set +JSONEditor.defaults.resolvers.unshift(function(schema) { + // If this schema uses `oneOf` + if(schema.oneOf) return "multiple"; +}); + +/** + * This is a small wrapper for using JSON Editor like a typical jQuery plugin. + */ +(function() { + if(window.jQuery || window.Zepto) { + var $ = window.jQuery || window.Zepto; + $.jsoneditor = JSONEditor.defaults; + + $.fn.jsoneditor = function(options) { + var self = this; + var editor = this.data('jsoneditor'); + if(options === 'value') { + if(!editor) throw "Must initialize jsoneditor before getting/setting the value"; + + // Set value + if(arguments.length > 1) { + editor.setValue(arguments[1]); + } + // Get value + else { + return editor.getValue(); + } + } + else if(options === 'validate') { + if(!editor) throw "Must initialize jsoneditor before validating"; + + // Validate a specific value + if(arguments.length > 1) { + return editor.validate(arguments[1]); + } + // Validate current value + else { + return editor.validate(); + } + } + else if(options === 'destroy') { + if(editor) { + editor.destroy(); + this.data('jsoneditor',null); + } + } + else { + // Destroy first + if(editor) { + editor.destroy(); + } + + // Create editor + editor = new JSONEditor(this.get(0),options); + this.data('jsoneditor',editor); + + // Setup event listeners + editor.on('change',function() { + self.trigger('change'); + }); + editor.on('ready',function() { + self.trigger('ready'); + }); + } + + return this; + }; + } +})(); + + window.JSONEditor = JSONEditor; +})(); + +//# sourceMappingURL=jsoneditor.js.map \ No newline at end of file diff --git a/lib/jsoneditor.js b/lib/jsoneditor.js new file mode 100644 index 00000000000..feea6f75b04 --- /dev/null +++ b/lib/jsoneditor.js @@ -0,0 +1,7287 @@ +/*! JSON Editor v0.7.22 - JSON Schema -> HTML Editor + * By Jeremy Dorn - https://github.com/jdorn/json-editor/ + * Released under the MIT license + * + * Date: 2015-08-12 + */ + +/** + * See README.md for requirements and usage info + */ + +(function() { + +/*jshint loopfunc: true */ +/* Simple JavaScript Inheritance + * By John Resig http://ejohn.org/ + * MIT Licensed. + */ +// Inspired by base2 and Prototype +var Class; +(function(){ + var initializing = false, fnTest = /xyz/.test(function(){window.postMessage("xyz");}) ? /\b_super\b/ : /.*/; + + // The base Class implementation (does nothing) + Class = function(){}; + + // Create a new Class that inherits from this class + Class.extend = function(prop) { + var _super = this.prototype; + + // Instantiate a base class (but only create the instance, + // don't run the init constructor) + initializing = true; + var prototype = new this(); + initializing = false; + + // Copy the properties over onto the new prototype + for (var name in prop) { + // Check if we're overwriting an existing function + prototype[name] = typeof prop[name] == "function" && + typeof _super[name] == "function" && fnTest.test(prop[name]) ? + (function(name, fn){ + return function() { + var tmp = this._super; + + // Add a new ._super() method that is the same method + // but on the super-class + this._super = _super[name]; + + // The method only need to be bound temporarily, so we + // remove it when we're done executing + var ret = fn.apply(this, arguments); + this._super = tmp; + + return ret; + }; + })(name, prop[name]) : + prop[name]; + } + + // The dummy class constructor + function Class() { + // All construction is actually done in the init method + if ( !initializing && this.init ) + this.init.apply(this, arguments); + } + + // Populate our constructed prototype object + Class.prototype = prototype; + + // Enforce the constructor to be what we expect + Class.prototype.constructor = Class; + + // And make this class extendable + Class.extend = arguments.callee; + + return Class; + }; + + return Class; +})(); + +// CustomEvent constructor polyfill +// From MDN +(function () { + function CustomEvent ( event, params ) { + params = params || { bubbles: false, cancelable: false, detail: undefined }; + var evt = document.createEvent( 'CustomEvent' ); + evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail ); + return evt; + } + + CustomEvent.prototype = window.Event.prototype; + + window.CustomEvent = CustomEvent; +})(); + +// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel +// MIT license +(function() { + var lastTime = 0; + var vendors = ['ms', 'moz', 'webkit', 'o']; + for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { + window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; + window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || + window[vendors[x]+'CancelRequestAnimationFrame']; + } + + if (!window.requestAnimationFrame) + window.requestAnimationFrame = function(callback, element) { + var currTime = new Date().getTime(); + var timeToCall = Math.max(0, 16 - (currTime - lastTime)); + var id = window.setTimeout(function() { callback(currTime + timeToCall); }, + timeToCall); + lastTime = currTime + timeToCall; + return id; + }; + + if (!window.cancelAnimationFrame) + window.cancelAnimationFrame = function(id) { + clearTimeout(id); + }; +}()); + +// Array.isArray polyfill +// From MDN +(function() { + if(!Array.isArray) { + Array.isArray = function(arg) { + return Object.prototype.toString.call(arg) === '[object Array]'; + }; + } +}()); +/** + * Taken from jQuery 2.1.3 + * + * @param obj + * @returns {boolean} + */ +var $isplainobject = function( obj ) { + // Not plain objects: + // - Any object or value whose internal [[Class]] property is not "[object Object]" + // - DOM nodes + // - window + if (typeof obj !== "object" || obj.nodeType || (obj !== null && obj === obj.window)) { + return false; + } + + if (obj.constructor && !Object.prototype.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf")) { + return false; + } + + // If the function hasn't returned already, we're confident that + // |obj| is a plain object, created by {} or constructed with new Object + return true; +}; + +var $extend = function(destination) { + var source, i,property; + for(i=1; i 0 && (obj.length - 1) in obj)) { + for(i=0; i= waiting && !callback_fired) { + callback_fired = true; + callback(); + } + }); + } + // Request failed + else { + window.console.log(r); + throw "Failed to fetch ref via ajax- "+url; + } + }; + r.send(); + }); + + if(!waiting) { + callback(); + } + }, + expandRefs: function(schema) { + schema = $extend({},schema); + + while (schema.$ref) { + var ref = schema.$ref; + delete schema.$ref; + + if(!this.refs[ref]) ref = decodeURIComponent(ref); + + schema = this.extendSchemas(schema,this.refs[ref]); + } + return schema; + }, + expandSchema: function(schema) { + var self = this; + var extended = $extend({},schema); + var i; + + // Version 3 `type` + if(typeof schema.type === 'object') { + // Array of types + if(Array.isArray(schema.type)) { + $each(schema.type, function(key,value) { + // Schema + if(typeof value === 'object') { + schema.type[key] = self.expandSchema(value); + } + }); + } + // Schema + else { + schema.type = self.expandSchema(schema.type); + } + } + // Version 3 `disallow` + if(typeof schema.disallow === 'object') { + // Array of types + if(Array.isArray(schema.disallow)) { + $each(schema.disallow, function(key,value) { + // Schema + if(typeof value === 'object') { + schema.disallow[key] = self.expandSchema(value); + } + }); + } + // Schema + else { + schema.disallow = self.expandSchema(schema.disallow); + } + } + // Version 4 `anyOf` + if(schema.anyOf) { + $each(schema.anyOf, function(key,value) { + schema.anyOf[key] = self.expandSchema(value); + }); + } + // Version 4 `dependencies` (schema dependencies) + if(schema.dependencies) { + $each(schema.dependencies,function(key,value) { + if(typeof value === "object" && !(Array.isArray(value))) { + schema.dependencies[key] = self.expandSchema(value); + } + }); + } + // Version 4 `not` + if(schema.not) { + schema.not = this.expandSchema(schema.not); + } + + // allOf schemas should be merged into the parent + if(schema.allOf) { + for(i=0; i= schema.maximum) { + errors.push({ + path: path, + property: 'maximum', + message: this.translate('error_maximum_excl', [schema.maximum]) + }); + } + else if(!schema.exclusiveMaximum && value > schema.maximum) { + errors.push({ + path: path, + property: 'maximum', + message: this.translate('error_maximum_incl', [schema.maximum]) + }); + } + } + + // `minimum` + if(schema.hasOwnProperty('minimum')) { + if(schema.exclusiveMinimum && value <= schema.minimum) { + errors.push({ + path: path, + property: 'minimum', + message: this.translate('error_minimum_excl', [schema.minimum]) + }); + } + else if(!schema.exclusiveMinimum && value < schema.minimum) { + errors.push({ + path: path, + property: 'minimum', + message: this.translate('error_minimum_incl', [schema.minimum]) + }); + } + } + } + // String specific validation + else if(typeof value === "string") { + // `maxLength` + if(schema.maxLength) { + if((value+"").length > schema.maxLength) { + errors.push({ + path: path, + property: 'maxLength', + message: this.translate('error_maxLength', [schema.maxLength]) + }); + } + } + + // `minLength` + if(schema.minLength) { + if((value+"").length < schema.minLength) { + errors.push({ + path: path, + property: 'minLength', + message: this.translate((schema.minLength===1?'error_notempty':'error_minLength'), [schema.minLength]) + }); + } + } + + // `pattern` + if(schema.pattern) { + if(!(new RegExp(schema.pattern)).test(value)) { + errors.push({ + path: path, + property: 'pattern', + message: this.translate('error_pattern') + }); + } + } + } + // Array specific validation + else if(typeof value === "object" && value !== null && Array.isArray(value)) { + // `items` and `additionalItems` + if(schema.items) { + // `items` is an array + if(Array.isArray(schema.items)) { + for(i=0; i schema.maxItems) { + errors.push({ + path: path, + property: 'maxItems', + message: this.translate('error_maxItems', [schema.maxItems]) + }); + } + } + + // `minItems` + if(schema.minItems) { + if(value.length < schema.minItems) { + errors.push({ + path: path, + property: 'minItems', + message: this.translate('error_minItems', [schema.minItems]) + }); + } + } + + // `uniqueItems` + if(schema.uniqueItems) { + var seen = {}; + for(i=0; i schema.maxProperties) { + errors.push({ + path: path, + property: 'maxProperties', + message: this.translate('error_maxProperties', [schema.maxProperties]) + }); + } + } + + // `minProperties` + if(schema.minProperties) { + valid = 0; + for(i in value) { + if(!value.hasOwnProperty(i)) continue; + valid++; + } + if(valid < schema.minProperties) { + errors.push({ + path: path, + property: 'minProperties', + message: this.translate('error_minProperties', [schema.minProperties]) + }); + } + } + // [TODO] find why defaultProperties is not functioning. + // Version 4 `required` + //if(schema.required && Array.isArray(schema.required)) { + // for(i=0; i=0) { + holder = this.theme.getBlockLinkHolder(); + + link = this.theme.getBlockLink(); + link.setAttribute('target','_blank'); + + var media = document.createElement(type); + media.setAttribute('controls','controls'); + + this.theme.createMediaLink(holder,link,media); + + // When a watched field changes, update the url + this.link_watchers.push(function(vars) { + var url = href(vars); + link.setAttribute('href',url); + link.textContent = data.rel || url; + media.setAttribute('src',url); + }); + } + // Text links + else { + holder = this.theme.getBlockLink(); + holder.setAttribute('target','_blank'); + holder.textContent = data.rel; + + // When a watched field changes, update the url + this.link_watchers.push(function(vars) { + var url = href(vars); + holder.setAttribute('href',url); + holder.textContent = data.rel || url; + }); + } + + return holder; + }, + refreshWatchedFieldValues: function() { + if(!this.watched_values) return; + var watched = {}; + var changed = false; + var self = this; + + if(this.watched) { + var val,editor; + for(var name in this.watched) { + if(!this.watched.hasOwnProperty(name)) continue; + editor = self.jsoneditor.getEditor(this.watched[name]); + val = editor? editor.getValue() : null; + if(self.watched_values[name] !== val) changed = true; + watched[name] = val; + } + } + + watched.self = this.getValue(); + if(this.watched_values.self !== watched.self) changed = true; + + this.watched_values = watched; + + return changed; + }, + getWatchedFieldValues: function() { + return this.watched_values; + }, + updateHeaderText: function() { + if(this.header) { + // If the header has children, only update the text node's value + if(this.header.children.length) { + for(var i=0; i -1; + else if(this.jsoneditor.options.required_by_default) return true; + else return false; + }, + getDisplayText: function(arr) { + var disp = []; + var used = {}; + + // Determine how many times each attribute name is used. + // This helps us pick the most distinct display text for the schemas. + $each(arr,function(i,el) { + if(el.title) { + used[el.title] = used[el.title] || 0; + used[el.title]++; + } + if(el.description) { + used[el.description] = used[el.description] || 0; + used[el.description]++; + } + if(el.format) { + used[el.format] = used[el.format] || 0; + used[el.format]++; + } + if(el.type) { + used[el.type] = used[el.type] || 0; + used[el.type]++; + } + }); + + // Determine display text for each element of the array + $each(arr,function(i,el) { + var name; + + // If it's a simple string + if(typeof el === "string") name = el; + // Object + else if(el.title && used[el.title]<=1) name = el.title; + else if(el.format && used[el.format]<=1) name = el.format; + else if(el.type && used[el.type]<=1) name = el.type; + else if(el.description && used[el.description]<=1) name = el.descripton; + else if(el.title) name = el.title; + else if(el.format) name = el.format; + else if(el.type) name = el.type; + else if(el.description) name = el.description; + else if(JSON.stringify(el).length < 50) name = JSON.stringify(el); + else name = "type"; + + disp.push(name); + }); + + // Replace identical display text with "text 1", "text 2", etc. + var inc = {}; + $each(disp,function(i,name) { + inc[name] = inc[name] || 0; + inc[name]++; + + if(used[name] > 1) disp[i] = name + " " + inc[name]; + }); + + return disp; + }, + getOption: function(key) { + try { + throw "getOption is deprecated"; + } + catch(e) { + window.console.error(e); + } + + return this.options[key]; + }, + showValidationErrors: function(errors) { + + } +}); + +JSONEditor.defaults.editors["null"] = JSONEditor.AbstractEditor.extend({ + getValue: function() { + return null; + }, + setValue: function() { + this.onChange(); + }, + getNumColumns: function() { + return 2; + } +}); + +JSONEditor.defaults.editors.string = JSONEditor.AbstractEditor.extend({ + register: function() { + this._super(); + if(!this.input) return; + this.input.setAttribute('name',this.formname); + }, + unregister: function() { + this._super(); + if(!this.input) return; + this.input.removeAttribute('name'); + }, + setValue: function(value,initial,from_template) { + var self = this; + + if(this.template && !from_template) { + return; + } + + if(value === null || typeof value === 'undefined') value = ""; + else if(typeof value === "object") value = JSON.stringify(value); + else if(typeof value !== "string") value = ""+value; + + if(value === this.serialized) return; + + // Sanitize value before setting it + var sanitized = this.sanitize(value); + + if(this.input.value === sanitized) { + return; + } + + this.input.value = sanitized; + + // If using SCEditor, update the WYSIWYG + if(this.sceditor_instance) { + this.sceditor_instance.val(sanitized); + } + else if(this.epiceditor) { + this.epiceditor.importFile(null,sanitized); + } + else if(this.ace_editor) { + this.ace_editor.setValue(sanitized); + } + + var changed = from_template || this.getValue() !== value; + + this.refreshValue(); + + if(initial) this.is_dirty = false; + else if(this.jsoneditor.options.show_errors === "change") this.is_dirty = true; + + if(this.adjust_height) this.adjust_height(this.input); + + // Bubble this setValue to parents if the value changed + this.onChange(changed); + }, + getNumColumns: function() { + var min = Math.ceil(Math.max(this.getTitle().length,this.schema.maxLength||0,this.schema.minLength||0)/5); + var num; + + if(this.input_type === 'textarea') num = 6; + else if(['text','email'].indexOf(this.input_type) >= 0) num = 4; + else num = 2; + + return Math.min(12,Math.max(min,num)); + }, + build: function() { + var self = this, i; + if(!this.options.compact) this.header = this.label = this.theme.getFormInputLabel(this.getTitle()); + if(this.schema.description) this.description = this.theme.getFormInputDescription(this.schema.description); + + this.format = this.schema.format; + if(!this.format && this.schema.media && this.schema.media.type) { + this.format = this.schema.media.type.replace(/(^(application|text)\/(x-)?(script\.)?)|(-source$)/g,''); + } + if(!this.format && this.options.default_format) { + this.format = this.options.default_format; + } + if(this.options.format) { + this.format = this.options.format; + } + + // Specific format + if(this.format) { + // Text Area + if(this.format === 'textarea') { + this.input_type = 'textarea'; + this.input = this.theme.getTextareaInput(); + } + // Range Input + else if(this.format === 'range') { + this.input_type = 'range'; + var min = this.schema.minimum || 0; + var max = this.schema.maximum || Math.max(100,min+1); + var step = 1; + if(this.schema.multipleOf) { + if(min%this.schema.multipleOf) min = Math.ceil(min/this.schema.multipleOf)*this.schema.multipleOf; + if(max%this.schema.multipleOf) max = Math.floor(max/this.schema.multipleOf)*this.schema.multipleOf; + step = this.schema.multipleOf; + } + + this.input = this.theme.getRangeInput(min,max,step); + } + // Source Code + else if([ + 'actionscript', + 'batchfile', + 'bbcode', + 'c', + 'c++', + 'cpp', + 'coffee', + 'csharp', + 'css', + 'dart', + 'django', + 'ejs', + 'erlang', + 'golang', + 'handlebars', + 'haskell', + 'haxe', + 'html', + 'ini', + 'jade', + 'java', + 'javascript', + 'json', + 'less', + 'lisp', + 'lua', + 'makefile', + 'markdown', + 'matlab', + 'mysql', + 'objectivec', + 'pascal', + 'perl', + 'pgsql', + 'php', + 'python', + 'r', + 'ruby', + 'sass', + 'scala', + 'scss', + 'smarty', + 'sql', + 'stylus', + 'svg', + 'twig', + 'vbscript', + 'xml', + 'yaml' + ].indexOf(this.format) >= 0 + ) { + this.input_type = this.format; + this.source_code = true; + + this.input = this.theme.getTextareaInput(); + } + // HTML5 Input type + else { + this.input_type = this.format; + this.input = this.theme.getFormInputField(this.input_type); + } + } + // Normal text input + else { + this.input_type = 'text'; + this.input = this.theme.getFormInputField(this.input_type); + } + + // minLength, maxLength, and pattern + if(typeof this.schema.maxLength !== "undefined") this.input.setAttribute('maxlength',this.schema.maxLength); + if(typeof this.schema.pattern !== "undefined") this.input.setAttribute('pattern',this.schema.pattern); + else if(typeof this.schema.minLength !== "undefined") this.input.setAttribute('pattern','.{'+this.schema.minLength+',}'); + + if(this.options.compact) { + this.container.className += ' compact'; + } + else { + if(this.options.input_width) this.input.style.width = this.options.input_width; + } + + if(this.schema.readOnly || this.schema.readonly || this.schema.template) { + this.always_disabled = true; + this.input.disabled = true; + } + + this.input + .addEventListener('change',function(e) { + e.preventDefault(); + e.stopPropagation(); + + // Don't allow changing if this field is a template + if(self.schema.template) { + this.value = self.value; + return; + } + + var val = this.value; + + // sanitize value + var sanitized = self.sanitize(val); + if(val !== sanitized) { + this.value = sanitized; + } + + self.is_dirty = true; + + self.refreshValue(); + self.onChange(true); + }); + + if(this.options.input_height) this.input.style.height = this.options.input_height; + if(this.options.expand_height) { + this.adjust_height = function(el) { + if(!el) return; + var i, ch=el.offsetHeight; + // Input too short + if(el.offsetHeight < el.scrollHeight) { + i=0; + while(el.offsetHeight < el.scrollHeight+3) { + if(i>100) break; + i++; + ch++; + el.style.height = ch+'px'; + } + } + else { + i=0; + while(el.offsetHeight >= el.scrollHeight+3) { + if(i>100) break; + i++; + ch--; + el.style.height = ch+'px'; + } + el.style.height = (ch+1)+'px'; + } + }; + + this.input.addEventListener('keyup',function(e) { + self.adjust_height(this); + }); + this.input.addEventListener('change',function(e) { + self.adjust_height(this); + }); + this.adjust_height(); + } + + if(this.format) this.input.setAttribute('data-schemaformat',this.format); + + this.control = this.theme.getFormControl(this.label, this.input, this.description); + this.container.appendChild(this.control); + + // Any special formatting that needs to happen after the input is added to the dom + window.requestAnimationFrame(function() { + // Skip in case the input is only a temporary editor, + // otherwise, in the case of an ace_editor creation, + // it will generate an error trying to append it to the missing parentNode + if(self.input.parentNode) self.afterInputReady(); + if(self.adjust_height) self.adjust_height(self.input); + }); + + // Compile and store the template + if(this.schema.template) { + this.template = this.jsoneditor.compileTemplate(this.schema.template, this.template_engine); + this.refreshValue(); + } + else { + this.refreshValue(); + } + }, + enable: function() { + if(!this.always_disabled) { + this.input.disabled = false; + // TODO: WYSIWYG and Markdown editors + } + this._super(); + }, + disable: function() { + this.input.disabled = true; + // TODO: WYSIWYG and Markdown editors + this._super(); + }, + afterInputReady: function() { + var self = this, options; + + // Code editor + if(this.source_code) { + // WYSIWYG html and bbcode editor + if(this.options.wysiwyg && + ['html','bbcode'].indexOf(this.input_type) >= 0 && + window.jQuery && window.jQuery.fn && window.jQuery.fn.sceditor + ) { + options = $extend({},{ + plugins: self.input_type==='html'? 'xhtml' : 'bbcode', + emoticonsEnabled: false, + width: '100%', + height: 300 + },JSONEditor.plugins.sceditor,self.options.sceditor_options||{}); + + window.jQuery(self.input).sceditor(options); + + self.sceditor_instance = window.jQuery(self.input).sceditor('instance'); + + self.sceditor_instance.blur(function() { + // Get editor's value + var val = window.jQuery("
    "+self.sceditor_instance.val()+"
    "); + // Remove sceditor spans/divs + window.jQuery('#sceditor-start-marker,#sceditor-end-marker,.sceditor-nlf',val).remove(); + // Set the value and update + self.input.value = val.html(); + self.value = self.input.value; + self.is_dirty = true; + self.onChange(true); + }); + } + // EpicEditor for markdown (if it's loaded) + else if (this.input_type === 'markdown' && window.EpicEditor) { + this.epiceditor_container = document.createElement('div'); + this.input.parentNode.insertBefore(this.epiceditor_container,this.input); + this.input.style.display = 'none'; + + options = $extend({},JSONEditor.plugins.epiceditor,{ + container: this.epiceditor_container, + clientSideStorage: false + }); + + this.epiceditor = new window.EpicEditor(options).load(); + + this.epiceditor.importFile(null,this.getValue()); + + this.epiceditor.on('update',function() { + var val = self.epiceditor.exportFile(); + self.input.value = val; + self.value = val; + self.is_dirty = true; + self.onChange(true); + }); + } + // ACE editor for everything else + else if(window.ace) { + var mode = this.input_type; + // aliases for c/cpp + if(mode === 'cpp' || mode === 'c++' || mode === 'c') { + mode = 'c_cpp'; + } + + this.ace_container = document.createElement('div'); + this.ace_container.style.width = '100%'; + this.ace_container.style.position = 'relative'; + this.ace_container.style.height = '400px'; + this.input.parentNode.insertBefore(this.ace_container,this.input); + this.input.style.display = 'none'; + this.ace_editor = window.ace.edit(this.ace_container); + + this.ace_editor.setValue(this.getValue()); + + // The theme + if(JSONEditor.plugins.ace.theme) this.ace_editor.setTheme('ace/theme/'+JSONEditor.plugins.ace.theme); + // The mode + mode = window.ace.require("ace/mode/"+mode); + if(mode) this.ace_editor.getSession().setMode(new mode.Mode()); + + // Listen for changes + this.ace_editor.on('change',function() { + var val = self.ace_editor.getValue(); + self.input.value = val; + self.refreshValue(); + self.is_dirty = true; + self.onChange(true); + }); + } + } + + self.theme.afterInputReady(self.input); + }, + refreshValue: function() { + this.value = this.input.value; + if(typeof this.value !== "string") this.value = ''; + this.serialized = this.value; + }, + destroy: function() { + // If using SCEditor, destroy the editor instance + if(this.sceditor_instance) { + this.sceditor_instance.destroy(); + } + else if(this.epiceditor) { + this.epiceditor.unload(); + } + else if(this.ace_editor) { + this.ace_editor.destroy(); + } + + + this.template = null; + if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input); + if(this.label && this.label.parentNode) this.label.parentNode.removeChild(this.label); + if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description); + + this._super(); + }, + /** + * This is overridden in derivative editors + */ + sanitize: function(value) { + return value; + }, + /** + * Re-calculates the value if needed + */ + onWatchedFieldChange: function() { + var self = this, vars, j; + + // If this editor needs to be rendered by a macro template + if(this.template) { + vars = this.getWatchedFieldValues(); + this.setValue(this.template(vars),false,true); + } + + this._super(); + }, + showValidationErrors: function(errors) { + var self = this; + + if(this.jsoneditor.options.show_errors === "always") {} + else if(!this.is_dirty && this.previous_error_setting===this.jsoneditor.options.show_errors) return; + + this.previous_error_setting = this.jsoneditor.options.show_errors; + + var messages = []; + $each(errors,function(i,error) { + if(error.path === self.path) { + messages.push(error.message); + } + }); + + if(messages.length) { + this.theme.addInputError(this.input, messages.join('. ')+'.'); + } + else { + this.theme.removeInputError(this.input); + } + } +}); + +JSONEditor.defaults.editors.number = JSONEditor.defaults.editors.string.extend({ + sanitize: function(value) { + return (value+"").replace(/[^0-9\.\-eE]/g,''); + }, + getNumColumns: function() { + return 2; + }, + getValue: function() { + return this.value*1; + } +}); + +JSONEditor.defaults.editors.integer = JSONEditor.defaults.editors.number.extend({ + sanitize: function(value) { + value = value + ""; + return value.replace(/[^0-9\-]/g,''); + }, + getNumColumns: function() { + return 2; + } +}); + +JSONEditor.defaults.editors.object = JSONEditor.AbstractEditor.extend({ + getDefault: function() { + return $extend({},this.schema["default"] || {}); + }, + getChildEditors: function() { + return this.editors; + }, + register: function() { + this._super(); + if(this.editors) { + for(var i in this.editors) { + if(!this.editors.hasOwnProperty(i)) continue; + this.editors[i].register(); + } + } + }, + unregister: function() { + this._super(); + if(this.editors) { + for(var i in this.editors) { + if(!this.editors.hasOwnProperty(i)) continue; + this.editors[i].unregister(); + } + } + }, + getNumColumns: function() { + return Math.max(Math.min(12,this.maxwidth),3); + }, + enable: function() { + if(this.editjson_button) this.editjson_button.disabled = false; + if(this.addproperty_button) this.addproperty_button.disabled = false; + + this._super(); + if(this.editors) { + for(var i in this.editors) { + if(!this.editors.hasOwnProperty(i)) continue; + this.editors[i].enable(); + } + } + }, + disable: function() { + if(this.editjson_button) this.editjson_button.disabled = true; + if(this.addproperty_button) this.addproperty_button.disabled = true; + this.hideEditJSON(); + + this._super(); + if(this.editors) { + for(var i in this.editors) { + if(!this.editors.hasOwnProperty(i)) continue; + this.editors[i].disable(); + } + } + }, + layoutEditors: function() { + var self = this, i, j; + + if(!this.row_container) return; + + // Sort editors by propertyOrder + this.property_order = Object.keys(this.editors); + this.property_order = this.property_order.sort(function(a,b) { + var ordera = self.editors[a].schema.propertyOrder; + var orderb = self.editors[b].schema.propertyOrder; + if(typeof ordera !== "number") ordera = 1000; + if(typeof orderb !== "number") orderb = 1000; + + return ordera - orderb; + }); + + var container; + + if(this.format === 'grid') { + var rows = []; + $each(this.property_order, function(j,key) { + var editor = self.editors[key]; + if(editor.property_removed) return; + var found = false; + var width = editor.options.hidden? 0 : (editor.options.grid_columns || editor.getNumColumns()); + var height = editor.options.hidden? 0 : editor.container.offsetHeight; + // See if the editor will fit in any of the existing rows first + for(var i=0; i height)) { + found = i; + } + } + } + + // If there isn't a spot in any of the existing rows, start a new row + if(found === false) { + rows.push({ + width: 0, + minh: 999999, + maxh: 0, + editors: [] + }); + found = rows.length-1; + } + + rows[found].editors.push({ + key: key, + //editor: editor, + width: width, + height: height + }); + rows[found].width += width; + rows[found].minh = Math.min(rows[found].minh,height); + rows[found].maxh = Math.max(rows[found].maxh,height); + }); + + // Make almost full rows width 12 + // Do this by increasing all editors' sizes proprotionately + // Any left over space goes to the biggest editor + // Don't touch rows with a width of 6 or less + for(i=0; i rows[i].editors[biggest].width) biggest = j; + rows[i].editors[j].width *= 12/rows[i].width; + rows[i].editors[j].width = Math.floor(rows[i].editors[j].width); + new_width += rows[i].editors[j].width; + } + if(new_width < 12) rows[i].editors[biggest].width += 12-new_width; + rows[i].width = 12; + } + } + + // layout hasn't changed + if(this.layout === JSON.stringify(rows)) return false; + this.layout = JSON.stringify(rows); + + // Layout the form + container = document.createElement('div'); + for(i=0; i= this.schema.maxProperties); + + if(this.addproperty_checkboxes) { + this.addproperty_list.innerHTML = ''; + } + this.addproperty_checkboxes = {}; + + // Check for which editors can't be removed or added back + for(i in this.cached_editors) { + if(!this.cached_editors.hasOwnProperty(i)) continue; + + this.addPropertyCheckbox(i); + + if(this.isRequired(this.cached_editors[i]) && i in this.editors) { + this.addproperty_checkboxes[i].disabled = true; + } + + if(typeof this.schema.minProperties !== "undefined" && num_props <= this.schema.minProperties) { + this.addproperty_checkboxes[i].disabled = this.addproperty_checkboxes[i].checked; + if(!this.addproperty_checkboxes[i].checked) show_modal = true; + } + else if(!(i in this.editors)) { + if(!can_add && !this.schema.properties.hasOwnProperty(i)) { + this.addproperty_checkboxes[i].disabled = true; + } + else { + this.addproperty_checkboxes[i].disabled = false; + show_modal = true; + } + } + else { + show_modal = true; + can_remove = true; + } + } + + if(this.canHaveAdditionalProperties()) { + show_modal = true; + } + + // Additional addproperty checkboxes not tied to a current editor + for(i in this.schema.properties) { + if(!this.schema.properties.hasOwnProperty(i)) continue; + if(this.cached_editors[i]) continue; + show_modal = true; + this.addPropertyCheckbox(i); + } + + // If no editors can be added or removed, hide the modal button + if(!show_modal) { + this.hideAddProperty(); + this.addproperty_controls.style.display = 'none'; + } + // If additional properties are disabled + else if(!this.canHaveAdditionalProperties()) { + this.addproperty_add.style.display = 'none'; + this.addproperty_input.style.display = 'none'; + } + // If no new properties can be added + else if(!can_add) { + this.addproperty_add.disabled = true; + } + // If new properties can be added + else { + this.addproperty_add.disabled = false; + } + }, + isRequired: function(editor) { + if(typeof editor.schema.required === "boolean") return editor.schema.required; + else if(Array.isArray(this.schema.required)) return this.schema.required.indexOf(editor.key) > -1; + else if(this.jsoneditor.options.required_by_default) return true; + else return false; + }, + setValue: function(value, initial) { + var self = this; + value = value || {}; + + if(typeof value !== "object" || Array.isArray(value)) value = {}; + + // First, set the values for all of the defined properties + $each(this.cached_editors, function(i,editor) { + // Value explicitly set + if(typeof value[i] !== "undefined") { + self.addObjectProperty(i); + editor.setValue(value[i],initial); + } + // Otherwise, remove value unless this is the initial set or it's required + else if(!initial && !self.isRequired(editor)) { + self.removeObjectProperty(i); + } + // Otherwise, set the value to the default + else { + editor.setValue(editor.getDefault(),initial); + } + }); + + $each(value, function(i,val) { + if(!self.cached_editors[i]) { + self.addObjectProperty(i); + if(self.editors[i]) self.editors[i].setValue(val,initial); + } + }); + + this.refreshValue(); + this.layoutEditors(); + this.onChange(); + }, + showValidationErrors: function(errors) { + var self = this; + + // Get all the errors that pertain to this editor + var my_errors = []; + var other_errors = []; + $each(errors, function(i,error) { + if(error.path === self.path) { + my_errors.push(error); + } + else { + other_errors.push(error); + } + }); + + // Show errors for this editor + if(this.error_holder) { + if(my_errors.length) { + var message = []; + this.error_holder.innerHTML = ''; + this.error_holder.style.display = ''; + $each(my_errors, function(i,error) { + self.error_holder.appendChild(self.theme.getErrorMessage(error.message)); + }); + } + // Hide error area + else { + this.error_holder.style.display = 'none'; + } + } + + // Show error for the table row if this is inside a table + if(this.options.table_row) { + if(my_errors.length) { + this.theme.addTableRowError(this.container); + } + else { + this.theme.removeTableRowError(this.container); + } + } + + // Show errors for child editors + $each(this.editors, function(i,editor) { + editor.showValidationErrors(other_errors); + }); + } +}); + +JSONEditor.defaults.editors.array = JSONEditor.AbstractEditor.extend({ + getDefault: function() { + return this.schema["default"] || []; + }, + register: function() { + this._super(); + if(this.rows) { + for(var i=0; i= this.schema.items.length) { + if(this.schema.additionalItems===true) { + return {}; + } + else if(this.schema.additionalItems) { + return $extend({},this.schema.additionalItems); + } + } + else { + return $extend({},this.schema.items[i]); + } + } + else if(this.schema.items) { + return $extend({},this.schema.items); + } + else { + return {}; + } + }, + getItemInfo: function(i) { + var schema = this.getItemSchema(i); + + // Check if it's cached + this.item_info = this.item_info || {}; + var stringified = JSON.stringify(schema); + if(typeof this.item_info[stringified] !== "undefined") return this.item_info[stringified]; + + // Get the schema for this item + schema = this.jsoneditor.expandRefs(schema); + + this.item_info[stringified] = { + title: schema.title || "item", + 'default': schema["default"], + width: 12, + child_editors: schema.properties || schema.items + }; + + return this.item_info[stringified]; + }, + getElementEditor: function(i) { + var item_info = this.getItemInfo(i); + var schema = this.getItemSchema(i); + schema = this.jsoneditor.expandRefs(schema); + schema.title = item_info.title+' '+(i+1); + + var editor = this.jsoneditor.getEditorClass(schema); + + var holder; + if(this.tabs_holder) { + holder = this.theme.getTabContent(); + } + else if(item_info.child_editors) { + holder = this.theme.getChildEditorHolder(); + } + else { + holder = this.theme.getIndentedPanel(); + } + + this.row_holder.appendChild(holder); + + var ret = this.jsoneditor.createEditor(editor,{ + jsoneditor: this.jsoneditor, + schema: schema, + container: holder, + path: this.path+'.'+i, + parent: this, + required: true + }); + ret.preBuild(); + ret.build(); + ret.postBuild(); + + if(!ret.title_controls) { + ret.array_controls = this.theme.getButtonHolder(); + holder.appendChild(ret.array_controls); + } + + return ret; + }, + destroy: function() { + this.empty(true); + if(this.title && this.title.parentNode) this.title.parentNode.removeChild(this.title); + if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description); + if(this.row_holder && this.row_holder.parentNode) this.row_holder.parentNode.removeChild(this.row_holder); + if(this.controls && this.controls.parentNode) this.controls.parentNode.removeChild(this.controls); + if(this.panel && this.panel.parentNode) this.panel.parentNode.removeChild(this.panel); + + this.rows = this.row_cache = this.title = this.description = this.row_holder = this.panel = this.controls = null; + + this._super(); + }, + empty: function(hard) { + if(!this.rows) return; + var self = this; + $each(this.rows,function(i,row) { + if(hard) { + if(row.tab && row.tab.parentNode) row.tab.parentNode.removeChild(row.tab); + self.destroyRow(row,true); + self.row_cache[i] = null; + } + self.rows[i] = null; + }); + self.rows = []; + if(hard) self.row_cache = []; + }, + destroyRow: function(row,hard) { + var holder = row.container; + if(hard) { + row.destroy(); + if(holder.parentNode) holder.parentNode.removeChild(holder); + if(row.tab && row.tab.parentNode) row.tab.parentNode.removeChild(row.tab); + } + else { + if(row.tab) row.tab.style.display = 'none'; + holder.style.display = 'none'; + row.unregister(); + } + }, + getMax: function() { + if((Array.isArray(this.schema.items)) && this.schema.additionalItems === false) { + return Math.min(this.schema.items.length,this.schema.maxItems || Infinity); + } + else { + return this.schema.maxItems || Infinity; + } + }, + refreshTabs: function(refresh_headers) { + var self = this; + $each(this.rows, function(i,row) { + if(!row.tab) return; + + if(refresh_headers) { + row.tab_text.textContent = row.getHeaderText(); + } + else { + if(row.tab === self.active_tab) { + self.theme.markTabActive(row.tab); + row.container.style.display = ''; + } + else { + self.theme.markTabInactive(row.tab); + row.container.style.display = 'none'; + } + } + }); + }, + setValue: function(value, initial) { + // Update the array's value, adding/removing rows when necessary + value = value || []; + + if(!(Array.isArray(value))) value = [value]; + + var serialized = JSON.stringify(value); + if(serialized === this.serialized) return; + + // Make sure value has between minItems and maxItems items in it + if(this.schema.minItems) { + while(value.length < this.schema.minItems) { + value.push(this.getItemInfo(value.length)["default"]); + } + } + if(this.getMax() && value.length > this.getMax()) { + value = value.slice(0,this.getMax()); + } + + var self = this; + $each(value,function(i,val) { + if(self.rows[i]) { + // TODO: don't set the row's value if it hasn't changed + self.rows[i].setValue(val,initial); + } + else if(self.row_cache[i]) { + self.rows[i] = self.row_cache[i]; + self.rows[i].setValue(val,initial); + self.rows[i].container.style.display = ''; + if(self.rows[i].tab) self.rows[i].tab.style.display = ''; + self.rows[i].register(); + } + else { + self.addRow(val,initial); + } + }); + + for(var j=value.length; j= this.rows.length; + + $each(this.rows,function(i,editor) { + // Hide the move down button for the last row + if(editor.movedown_button) { + if(i === self.rows.length - 1) { + editor.movedown_button.style.display = 'none'; + } + else { + editor.movedown_button.style.display = ''; + } + } + + // Hide the delete button if we have minItems items + if(editor.delete_button) { + if(minItems) { + editor.delete_button.style.display = 'none'; + } + else { + editor.delete_button.style.display = ''; + } + } + + // Get the value for this editor + self.value[i] = editor.getValue(); + }); + + var controls_needed = false; + + if(!this.value.length) { + this.delete_last_row_button.style.display = 'none'; + this.remove_all_rows_button.style.display = 'none'; + } + else if(this.value.length === 1) { + this.remove_all_rows_button.style.display = 'none'; + + // If there are minItems items in the array, hide the delete button beneath the rows + if(minItems || this.hide_delete_buttons) { + this.delete_last_row_button.style.display = 'none'; + } + else { + this.delete_last_row_button.style.display = ''; + controls_needed = true; + } + } + else { + // If there are minItems items in the array, hide the delete button beneath the rows + if(minItems || this.hide_delete_buttons) { + this.delete_last_row_button.style.display = 'none'; + this.remove_all_rows_button.style.display = 'none'; + } + else { + this.delete_last_row_button.style.display = ''; + this.remove_all_rows_button.style.display = ''; + controls_needed = true; + } + } + + // If there are maxItems in the array, hide the add button beneath the rows + if((this.getMax() && this.getMax() <= this.rows.length) || this.hide_add_button){ + this.add_row_button.style.display = 'none'; + } + else { + this.add_row_button.style.display = ''; + controls_needed = true; + } + + if(!this.collapsed && controls_needed) { + this.controls.style.display = 'inline-block'; + } + else { + this.controls.style.display = 'none'; + } + } + }, + addRow: function(value, initial) { + var self = this; + var i = this.rows.length; + + self.rows[i] = this.getElementEditor(i); + self.row_cache[i] = self.rows[i]; + + if(self.tabs_holder) { + self.rows[i].tab_text = document.createElement('span'); + self.rows[i].tab_text.textContent = self.rows[i].getHeaderText(); + self.rows[i].tab = self.theme.getTab(self.rows[i].tab_text); + self.rows[i].tab.addEventListener('click', function(e) { + self.active_tab = self.rows[i].tab; + self.refreshTabs(); + e.preventDefault(); + e.stopPropagation(); + }); + + self.theme.addTab(self.tabs_holder, self.rows[i].tab); + } + + var controls_holder = self.rows[i].title_controls || self.rows[i].array_controls; + + // Buttons to delete row, move row up, and move row down + if(!self.hide_delete_buttons) { + self.rows[i].delete_button = this.getButton(self.getItemTitle(),'delete','Delete '+self.getItemTitle()); + self.rows[i].delete_button.className += ' delete'; + self.rows[i].delete_button.setAttribute('data-i',i); + self.rows[i].delete_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var i = this.getAttribute('data-i')*1; + + var value = self.getValue(); + + var newval = []; + var new_active_tab = null; + $each(value,function(j,row) { + if(j===i) { + // If the one we're deleting is the active tab + if(self.rows[j].tab === self.active_tab) { + // Make the next tab active if there is one + // Note: the next tab is going to be the current tab after deletion + if(self.rows[j+1]) new_active_tab = self.rows[j].tab; + // Otherwise, make the previous tab active if there is one + else if(j) new_active_tab = self.rows[j-1].tab; + } + + return; // If this is the one we're deleting + } + newval.push(row); + }); + self.setValue(newval); + if(new_active_tab) { + self.active_tab = new_active_tab; + self.refreshTabs(); + } + + self.onChange(true); + }); + + if(controls_holder) { + controls_holder.appendChild(self.rows[i].delete_button); + } + } + + if(i && !self.hide_move_buttons) { + self.rows[i].moveup_button = this.getButton('','moveup','Move up'); + self.rows[i].moveup_button.className += ' moveup'; + self.rows[i].moveup_button.setAttribute('data-i',i); + self.rows[i].moveup_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var i = this.getAttribute('data-i')*1; + + if(i<=0) return; + var rows = self.getValue(); + var tmp = rows[i-1]; + rows[i-1] = rows[i]; + rows[i] = tmp; + + self.setValue(rows); + self.active_tab = self.rows[i-1].tab; + self.refreshTabs(); + + self.onChange(true); + }); + + if(controls_holder) { + controls_holder.appendChild(self.rows[i].moveup_button); + } + } + + if(!self.hide_move_buttons) { + self.rows[i].movedown_button = this.getButton('','movedown','Move down'); + self.rows[i].movedown_button.className += ' movedown'; + self.rows[i].movedown_button.setAttribute('data-i',i); + self.rows[i].movedown_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var i = this.getAttribute('data-i')*1; + + var rows = self.getValue(); + if(i>=rows.length-1) return; + var tmp = rows[i+1]; + rows[i+1] = rows[i]; + rows[i] = tmp; + + self.setValue(rows); + self.active_tab = self.rows[i+1].tab; + self.refreshTabs(); + self.onChange(true); + }); + + if(controls_holder) { + controls_holder.appendChild(self.rows[i].movedown_button); + } + } + + if(value) self.rows[i].setValue(value, initial); + self.refreshTabs(); + }, + addControls: function() { + var self = this; + + this.collapsed = false; + this.toggle_button = this.getButton('','collapse','Collapse'); + this.title_controls.appendChild(this.toggle_button); + var row_holder_display = self.row_holder.style.display; + var controls_display = self.controls.style.display; + this.toggle_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + if(self.collapsed) { + self.collapsed = false; + if(self.panel) self.panel.style.display = ''; + self.row_holder.style.display = row_holder_display; + if(self.tabs_holder) self.tabs_holder.style.display = ''; + self.controls.style.display = controls_display; + self.setButtonText(this,'','collapse','Collapse'); + } + else { + self.collapsed = true; + self.row_holder.style.display = 'none'; + if(self.tabs_holder) self.tabs_holder.style.display = 'none'; + self.controls.style.display = 'none'; + if(self.panel) self.panel.style.display = 'none'; + self.setButtonText(this,'','expand','Expand'); + } + }); + + // If it should start collapsed + if(this.options.collapsed) { + $trigger(this.toggle_button,'click'); + } + + // Collapse button disabled + if(this.schema.options && typeof this.schema.options.disable_collapse !== "undefined") { + if(this.schema.options.disable_collapse) this.toggle_button.style.display = 'none'; + } + else if(this.jsoneditor.options.disable_collapse) { + this.toggle_button.style.display = 'none'; + } + + // Add "new row" and "delete last" buttons below editor + this.add_row_button = this.getButton(this.getItemTitle(),'add','Add '+this.getItemTitle()); + + this.add_row_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var i = self.rows.length; + if(self.row_cache[i]) { + self.rows[i] = self.row_cache[i]; + self.rows[i].setValue(self.rows[i].getDefault()); + self.rows[i].container.style.display = ''; + if(self.rows[i].tab) self.rows[i].tab.style.display = ''; + self.rows[i].register(); + } + else { + self.addRow(); + } + self.active_tab = self.rows[i].tab; + self.refreshTabs(); + self.refreshValue(); + self.onChange(true); + }); + self.controls.appendChild(this.add_row_button); + + this.delete_last_row_button = this.getButton('Last '+this.getItemTitle(),'delete','Delete Last '+this.getItemTitle()); + this.delete_last_row_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var rows = self.getValue(); + + var new_active_tab = null; + if(self.rows.length > 1 && self.rows[self.rows.length-1].tab === self.active_tab) new_active_tab = self.rows[self.rows.length-2].tab; + + rows.pop(); + self.setValue(rows); + if(new_active_tab) { + self.active_tab = new_active_tab; + self.refreshTabs(); + } + self.onChange(true); + }); + self.controls.appendChild(this.delete_last_row_button); + + this.remove_all_rows_button = this.getButton('All','delete','Delete All'); + this.remove_all_rows_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + self.setValue([]); + self.onChange(true); + }); + self.controls.appendChild(this.remove_all_rows_button); + + if(self.tabs) { + this.add_row_button.style.width = '100%'; + this.add_row_button.style.textAlign = 'left'; + this.add_row_button.style.marginBottom = '3px'; + + this.delete_last_row_button.style.width = '100%'; + this.delete_last_row_button.style.textAlign = 'left'; + this.delete_last_row_button.style.marginBottom = '3px'; + + this.remove_all_rows_button.style.width = '100%'; + this.remove_all_rows_button.style.textAlign = 'left'; + this.remove_all_rows_button.style.marginBottom = '3px'; + } + }, + showValidationErrors: function(errors) { + var self = this; + + // Get all the errors that pertain to this editor + var my_errors = []; + var other_errors = []; + $each(errors, function(i,error) { + if(error.path === self.path) { + my_errors.push(error); + } + else { + other_errors.push(error); + } + }); + + // Show errors for this editor + if(this.error_holder) { + if(my_errors.length) { + var message = []; + this.error_holder.innerHTML = ''; + this.error_holder.style.display = ''; + $each(my_errors, function(i,error) { + self.error_holder.appendChild(self.theme.getErrorMessage(error.message)); + }); + } + // Hide error area + else { + this.error_holder.style.display = 'none'; + } + } + + // Show errors for child editors + $each(this.rows, function(i,row) { + row.showValidationErrors(other_errors); + }); + } +}); + +JSONEditor.defaults.editors.table = JSONEditor.defaults.editors.array.extend({ + register: function() { + this._super(); + if(this.rows) { + for(var i=0; i this.schema.maxItems) { + value = value.slice(0,this.schema.maxItems); + } + + var serialized = JSON.stringify(value); + if(serialized === this.serialized) return; + + var numrows_changed = false; + + var self = this; + $each(value,function(i,val) { + if(self.rows[i]) { + // TODO: don't set the row's value if it hasn't changed + self.rows[i].setValue(val); + } + else { + self.addRow(val); + numrows_changed = true; + } + }); + + for(var j=value.length; j= this.rows.length; + + var need_row_buttons = false; + $each(this.rows,function(i,editor) { + // Hide the move down button for the last row + if(editor.movedown_button) { + if(i === self.rows.length - 1) { + editor.movedown_button.style.display = 'none'; + } + else { + need_row_buttons = true; + editor.movedown_button.style.display = ''; + } + } + + // Hide the delete button if we have minItems items + if(editor.delete_button) { + if(minItems) { + editor.delete_button.style.display = 'none'; + } + else { + need_row_buttons = true; + editor.delete_button.style.display = ''; + } + } + + if(editor.moveup_button) { + need_row_buttons = true; + } + }); + + // Show/hide controls column in table + $each(this.rows,function(i,editor) { + if(need_row_buttons) { + editor.controls_cell.style.display = ''; + } + else { + editor.controls_cell.style.display = 'none'; + } + }); + if(need_row_buttons) { + this.controls_header_cell.style.display = ''; + } + else { + this.controls_header_cell.style.display = 'none'; + } + + var controls_needed = false; + + if(!this.value.length) { + this.delete_last_row_button.style.display = 'none'; + this.remove_all_rows_button.style.display = 'none'; + this.table.style.display = 'none'; + } + else if(this.value.length === 1 || this.hide_delete_buttons) { + this.table.style.display = ''; + this.remove_all_rows_button.style.display = 'none'; + + // If there are minItems items in the array, hide the delete button beneath the rows + if(minItems || this.hide_delete_buttons) { + this.delete_last_row_button.style.display = 'none'; + } + else { + this.delete_last_row_button.style.display = ''; + controls_needed = true; + } + } + else { + this.table.style.display = ''; + // If there are minItems items in the array, hide the delete button beneath the rows + if(minItems || this.hide_delete_buttons) { + this.delete_last_row_button.style.display = 'none'; + this.remove_all_rows_button.style.display = 'none'; + } + else { + this.delete_last_row_button.style.display = ''; + this.remove_all_rows_button.style.display = ''; + controls_needed = true; + } + } + + // If there are maxItems in the array, hide the add button beneath the rows + if((this.schema.maxItems && this.schema.maxItems <= this.rows.length) || this.hide_add_button) { + this.add_row_button.style.display = 'none'; + } + else { + this.add_row_button.style.display = ''; + controls_needed = true; + } + + if(!controls_needed) { + this.controls.style.display = 'none'; + } + else { + this.controls.style.display = ''; + } + }, + refreshValue: function() { + var self = this; + this.value = []; + + $each(this.rows,function(i,editor) { + // Get the value for this editor + self.value[i] = editor.getValue(); + }); + this.serialized = JSON.stringify(this.value); + }, + addRow: function(value) { + var self = this; + var i = this.rows.length; + + self.rows[i] = this.getElementEditor(i); + + var controls_holder = self.rows[i].table_controls; + + // Buttons to delete row, move row up, and move row down + if(!this.hide_delete_buttons) { + self.rows[i].delete_button = this.getButton('','delete','Delete'); + self.rows[i].delete_button.className += ' delete'; + self.rows[i].delete_button.setAttribute('data-i',i); + self.rows[i].delete_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var i = this.getAttribute('data-i')*1; + + var value = self.getValue(); + + var newval = []; + $each(value,function(j,row) { + if(j===i) return; // If this is the one we're deleting + newval.push(row); + }); + self.setValue(newval); + self.onChange(true); + }); + controls_holder.appendChild(self.rows[i].delete_button); + } + + + if(i && !this.hide_move_buttons) { + self.rows[i].moveup_button = this.getButton('','moveup','Move up'); + self.rows[i].moveup_button.className += ' moveup'; + self.rows[i].moveup_button.setAttribute('data-i',i); + self.rows[i].moveup_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var i = this.getAttribute('data-i')*1; + + if(i<=0) return; + var rows = self.getValue(); + var tmp = rows[i-1]; + rows[i-1] = rows[i]; + rows[i] = tmp; + + self.setValue(rows); + self.onChange(true); + }); + controls_holder.appendChild(self.rows[i].moveup_button); + } + + if(!this.hide_move_buttons) { + self.rows[i].movedown_button = this.getButton('','movedown','Move down'); + self.rows[i].movedown_button.className += ' movedown'; + self.rows[i].movedown_button.setAttribute('data-i',i); + self.rows[i].movedown_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + var i = this.getAttribute('data-i')*1; + var rows = self.getValue(); + if(i>=rows.length-1) return; + var tmp = rows[i+1]; + rows[i+1] = rows[i]; + rows[i] = tmp; + + self.setValue(rows); + self.onChange(true); + }); + controls_holder.appendChild(self.rows[i].movedown_button); + } + + if(value) self.rows[i].setValue(value); + }, + addControls: function() { + var self = this; + + this.collapsed = false; + this.toggle_button = this.getButton('','collapse','Collapse'); + if(this.title_controls) { + this.title_controls.appendChild(this.toggle_button); + this.toggle_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + + if(self.collapsed) { + self.collapsed = false; + self.panel.style.display = ''; + self.setButtonText(this,'','collapse','Collapse'); + } + else { + self.collapsed = true; + self.panel.style.display = 'none'; + self.setButtonText(this,'','expand','Expand'); + } + }); + + // If it should start collapsed + if(this.options.collapsed) { + $trigger(this.toggle_button,'click'); + } + + // Collapse button disabled + if(this.schema.options && typeof this.schema.options.disable_collapse !== "undefined") { + if(this.schema.options.disable_collapse) this.toggle_button.style.display = 'none'; + } + else if(this.jsoneditor.options.disable_collapse) { + this.toggle_button.style.display = 'none'; + } + } + + // Add "new row" and "delete last" buttons below editor + this.add_row_button = this.getButton(this.getItemTitle(),'add','Add '+this.getItemTitle()); + this.add_row_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + + self.addRow(); + self.refreshValue(); + self.refreshRowButtons(); + self.onChange(true); + }); + self.controls.appendChild(this.add_row_button); + + this.delete_last_row_button = this.getButton('Last '+this.getItemTitle(),'delete','Delete Last '+this.getItemTitle()); + this.delete_last_row_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + + var rows = self.getValue(); + rows.pop(); + self.setValue(rows); + self.onChange(true); + }); + self.controls.appendChild(this.delete_last_row_button); + + this.remove_all_rows_button = this.getButton('All','delete','Delete All'); + this.remove_all_rows_button.addEventListener('click',function(e) { + e.preventDefault(); + e.stopPropagation(); + + self.setValue([]); + self.onChange(true); + }); + self.controls.appendChild(this.remove_all_rows_button); + } +}); + +// Multiple Editor (for when `type` is an array) +JSONEditor.defaults.editors.multiple = JSONEditor.AbstractEditor.extend({ + register: function() { + if(this.editors) { + for(var i=0; inull'; + } + // Array or Object + else if(typeof el === "object") { + // TODO: use theme + var ret = ''; + + $each(el,function(i,child) { + var html = self.getHTML(child); + + // Add the keys to object children + if(!(Array.isArray(el))) { + // TODO: use theme + html = '
    '+i+': '+html+'
    '; + } + + // TODO: use theme + ret += '
  • '+html+'
  • '; + }); + + if(Array.isArray(el)) ret = '
      '+ret+'
    '; + else ret = "
      "+ret+'
    '; + + return ret; + } + // Boolean + else if(typeof el === "boolean") { + return el? 'true' : 'false'; + } + // String + else if(typeof el === "string") { + return el.replace(/&/g,'&').replace(//g,'>'); + } + // Number + else { + return el; + } + }, + setValue: function(val) { + if(this.value !== val) { + this.value = val; + this.refreshValue(); + this.onChange(); + } + }, + destroy: function() { + if(this.display_area && this.display_area.parentNode) this.display_area.parentNode.removeChild(this.display_area); + if(this.title && this.title.parentNode) this.title.parentNode.removeChild(this.title); + if(this.switcher && this.switcher.parentNode) this.switcher.parentNode.removeChild(this.switcher); + + this._super(); + } +}); + +JSONEditor.defaults.editors.select = JSONEditor.AbstractEditor.extend({ + setValue: function(value,initial) { + value = this.typecast(value||''); + + // Sanitize value before setting it + var sanitized = value; + if(this.enum_values.indexOf(sanitized) < 0) { + sanitized = this.enum_values[0]; + } + + if(this.value === sanitized) { + return; + } + + this.input.value = this.enum_options[this.enum_values.indexOf(sanitized)]; + if(this.select2) this.select2.select2('val',this.input.value); + this.value = sanitized; + this.onChange(); + }, + register: function() { + this._super(); + if(!this.input) return; + this.input.setAttribute('name',this.formname); + }, + unregister: function() { + this._super(); + if(!this.input) return; + this.input.removeAttribute('name'); + }, + getNumColumns: function() { + if(!this.enum_options) return 3; + var longest_text = this.getTitle().length; + for(var i=0; i 2 || (this.enum_options.length && this.enumSource))) { + var options = $extend({},JSONEditor.plugins.select2); + if(this.schema.options && this.schema.options.select2_options) options = $extend(options,this.schema.options.select2_options); + this.select2 = window.jQuery(this.input).select2(options); + var self = this; + this.select2.on('select2-blur',function() { + self.input.value = self.select2.select2('val'); + self.onInputChange(); + }); + } + else { + this.select2 = null; + } + }, + postBuild: function() { + this._super(); + this.theme.afterInputReady(this.input); + this.setupSelect2(); + }, + onWatchedFieldChange: function() { + var self = this, vars, j; + + // If this editor uses a dynamic select box + if(this.enumSource) { + vars = this.getWatchedFieldValues(); + var select_options = []; + var select_titles = []; + + for(var i=0; iSize: '+Math.floor((this.value.length-this.value.split(',')[0].length-1)/1.33333)+' bytes'; + if(mime.substr(0,5)==="image") { + this.preview.innerHTML += '
    '; + var img = document.createElement('img'); + img.style.maxWidth = '100%'; + img.style.maxHeight = '100px'; + img.src = this.value; + this.preview.appendChild(img); + } + } + }, + enable: function() { + if(this.uploader) this.uploader.disabled = false; + this._super(); + }, + disable: function() { + if(this.uploader) this.uploader.disabled = true; + this._super(); + }, + setValue: function(val) { + if(this.value !== val) { + this.value = val; + this.input.value = this.value; + this.refreshPreview(); + this.onChange(); + } + }, + destroy: function() { + if(this.preview && this.preview.parentNode) this.preview.parentNode.removeChild(this.preview); + if(this.title && this.title.parentNode) this.title.parentNode.removeChild(this.title); + if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input); + if(this.uploader && this.uploader.parentNode) this.uploader.parentNode.removeChild(this.uploader); + + this._super(); + } +}); + +JSONEditor.defaults.editors.upload = JSONEditor.AbstractEditor.extend({ + getNumColumns: function() { + return 4; + }, + build: function() { + var self = this; + this.title = this.header = this.label = this.theme.getFormInputLabel(this.getTitle()); + + // Input that holds the base64 string + this.input = this.theme.getFormInputField('hidden'); + this.container.appendChild(this.input); + + // Don't show uploader if this is readonly + if(!this.schema.readOnly && !this.schema.readonly) { + + if(!this.jsoneditor.options.upload) throw "Upload handler required for upload editor"; + + // File uploader + this.uploader = this.theme.getFormInputField('file'); + + this.uploader.addEventListener('change',function(e) { + e.preventDefault(); + e.stopPropagation(); + + if(this.files && this.files.length) { + var fr = new FileReader(); + fr.onload = function(evt) { + self.preview_value = evt.target.result; + self.refreshPreview(); + self.onChange(true); + fr = null; + }; + fr.readAsDataURL(this.files[0]); + } + }); + } + + var description = this.schema.description; + if (!description) description = ''; + + this.preview = this.theme.getFormInputDescription(description); + this.container.appendChild(this.preview); + + this.control = this.theme.getFormControl(this.label, this.uploader||this.input, this.preview); + this.container.appendChild(this.control); + }, + refreshPreview: function() { + if(this.last_preview === this.preview_value) return; + this.last_preview = this.preview_value; + + this.preview.innerHTML = ''; + + if(!this.preview_value) return; + + var self = this; + + var mime = this.preview_value.match(/^data:([^;,]+)[;,]/); + if(mime) mime = mime[1]; + if(!mime) mime = 'unknown'; + + var file = this.uploader.files[0]; + + this.preview.innerHTML = 'Type: '+mime+', Size: '+file.size+' bytes'; + if(mime.substr(0,5)==="image") { + this.preview.innerHTML += '
    '; + var img = document.createElement('img'); + img.style.maxWidth = '100%'; + img.style.maxHeight = '100px'; + img.src = this.preview_value; + this.preview.appendChild(img); + } + + this.preview.innerHTML += '
    '; + var uploadButton = this.getButton('Upload', 'upload', 'Upload'); + this.preview.appendChild(uploadButton); + uploadButton.addEventListener('click',function(event) { + event.preventDefault(); + + uploadButton.setAttribute("disabled", "disabled"); + self.theme.removeInputError(self.uploader); + + if (self.theme.getProgressBar) { + self.progressBar = self.theme.getProgressBar(); + self.preview.appendChild(self.progressBar); + } + + self.jsoneditor.options.upload(self.path, file, { + success: function(url) { + self.setValue(url); + + if(self.parent) self.parent.onChildEditorChange(self); + else self.jsoneditor.onChange(); + + if (self.progressBar) self.preview.removeChild(self.progressBar); + uploadButton.removeAttribute("disabled"); + }, + failure: function(error) { + self.theme.addInputError(self.uploader, error); + if (self.progressBar) self.preview.removeChild(self.progressBar); + uploadButton.removeAttribute("disabled"); + }, + updateProgress: function(progress) { + if (self.progressBar) { + if (progress) self.theme.updateProgressBar(self.progressBar, progress); + else self.theme.updateProgressBarUnknown(self.progressBar); + } + } + }); + }); + }, + enable: function() { + if(this.uploader) this.uploader.disabled = false; + this._super(); + }, + disable: function() { + if(this.uploader) this.uploader.disabled = true; + this._super(); + }, + setValue: function(val) { + if(this.value !== val) { + this.value = val; + this.input.value = this.value; + this.onChange(); + } + }, + destroy: function() { + if(this.preview && this.preview.parentNode) this.preview.parentNode.removeChild(this.preview); + if(this.title && this.title.parentNode) this.title.parentNode.removeChild(this.title); + if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input); + if(this.uploader && this.uploader.parentNode) this.uploader.parentNode.removeChild(this.uploader); + + this._super(); + } +}); + +JSONEditor.defaults.editors.checkbox = JSONEditor.AbstractEditor.extend({ + setValue: function(value,initial) { + this.value = !!value; + this.input.checked = this.value; + this.onChange(); + }, + register: function() { + this._super(); + if(!this.input) return; + this.input.setAttribute('name',this.formname); + }, + unregister: function() { + this._super(); + if(!this.input) return; + this.input.removeAttribute('name'); + }, + getNumColumns: function() { + return Math.min(12,Math.max(this.getTitle().length/7,2)); + }, + build: function() { + var self = this; + if(!this.options.compact) { + this.label = this.header = this.theme.getCheckboxLabel(this.getTitle()); + } + if(this.schema.description) this.description = this.theme.getFormInputDescription(this.schema.description); + if(this.options.compact) this.container.className += ' compact'; + + this.input = this.theme.getCheckbox(); + this.control = this.theme.getFormControl(this.label, this.input, this.description); + + if(this.schema.readOnly || this.schema.readonly) { + this.always_disabled = true; + this.input.disabled = true; + } + + this.input.addEventListener('change',function(e) { + e.preventDefault(); + e.stopPropagation(); + self.value = this.checked; + self.onChange(true); + }); + + this.container.appendChild(this.control); + }, + enable: function() { + if(!this.always_disabled) { + this.input.disabled = false; + } + this._super(); + }, + disable: function() { + this.input.disabled = true; + this._super(); + }, + destroy: function() { + if(this.label && this.label.parentNode) this.label.parentNode.removeChild(this.label); + if(this.description && this.description.parentNode) this.description.parentNode.removeChild(this.description); + if(this.input && this.input.parentNode) this.input.parentNode.removeChild(this.input); + this._super(); + } +}); + +var matchKey = (function () { + var elem = document.documentElement; + + if (elem.matches) return 'matches'; + else if (elem.webkitMatchesSelector) return 'webkitMatchesSelector'; + else if (elem.mozMatchesSelector) return 'mozMatchesSelector'; + else if (elem.msMatchesSelector) return 'msMatchesSelector'; + else if (elem.oMatchesSelector) return 'oMatchesSelector'; +})(); + +JSONEditor.AbstractTheme = Class.extend({ + getContainer: function() { + return document.createElement('div'); + }, + getFloatRightLinkHolder: function() { + var el = document.createElement('div'); + el.style = el.style || {}; + el.style.cssFloat = 'right'; + el.style.marginLeft = '10px'; + return el; + }, + getModal: function() { + var el = document.createElement('div'); + el.style.backgroundColor = 'white'; + el.style.border = '1px solid black'; + el.style.boxShadow = '3px 3px black'; + el.style.position = 'absolute'; + el.style.zIndex = '10'; + el.style.display = 'none'; + return el; + }, + getGridContainer: function() { + var el = document.createElement('div'); + return el; + }, + getGridRow: function() { + var el = document.createElement('div'); + el.className = 'row'; + return el; + }, + getGridColumn: function() { + var el = document.createElement('div'); + return el; + }, + setGridColumnSize: function(el,size) { + + }, + getLink: function(text) { + var el = document.createElement('a'); + el.setAttribute('href','#'); + el.appendChild(document.createTextNode(text)); + return el; + }, + disableHeader: function(header) { + header.style.color = '#ccc'; + }, + disableLabel: function(label) { + label.style.color = '#ccc'; + }, + enableHeader: function(header) { + header.style.color = ''; + }, + enableLabel: function(label) { + label.style.color = ''; + }, + getFormInputLabel: function(text) { + var el = document.createElement('label'); + el.appendChild(document.createTextNode(text)); + return el; + }, + getCheckboxLabel: function(text) { + var el = this.getFormInputLabel(text); + el.style.fontWeight = 'normal'; + return el; + }, + getHeader: function(text) { + var el = document.createElement('h3'); + if(typeof text === "string") { + el.textContent = text; + } + else { + el.appendChild(text); + } + + return el; + }, + getCheckbox: function() { + var el = this.getFormInputField('checkbox'); + el.style.display = 'inline-block'; + el.style.width = 'auto'; + return el; + }, + getMultiCheckboxHolder: function(controls,label,description) { + var el = document.createElement('div'); + + if(label) { + label.style.display = 'block'; + el.appendChild(label); + } + + for(var i in controls) { + if(!controls.hasOwnProperty(i)) continue; + controls[i].style.display = 'inline-block'; + controls[i].style.marginRight = '20px'; + el.appendChild(controls[i]); + } + + if(description) el.appendChild(description); + + return el; + }, + getSelectInput: function(options) { + var select = document.createElement('select'); + if(options) this.setSelectOptions(select, options); + return select; + }, + getSwitcher: function(options) { + var switcher = this.getSelectInput(options); + switcher.style.backgroundColor = 'transparent'; + switcher.style.display = 'inline-block'; + switcher.style.fontStyle = 'italic'; + switcher.style.fontWeight = 'normal'; + switcher.style.height = 'auto'; + switcher.style.marginBottom = 0; + switcher.style.marginLeft = '5px'; + switcher.style.padding = '0 0 0 3px'; + switcher.style.width = 'auto'; + return switcher; + }, + getSwitcherOptions: function(switcher) { + return switcher.getElementsByTagName('option'); + }, + setSwitcherOptions: function(switcher, options, titles) { + this.setSelectOptions(switcher, options, titles); + }, + setSelectOptions: function(select, options, titles) { + titles = titles || []; + select.innerHTML = ''; + for(var i=0; i'); + input.errmsg = input.parentNode.getElementsByClassName('error')[0]; + } + else { + input.errmsg.style.display = ''; + } + + input.errmsg.textContent = text; + }, + removeInputError: function(input) { + if(!input.errmsg) return; + input.group.className = input.group.className.replace(/ error/g,''); + input.errmsg.style.display = 'none'; + }, + getProgressBar: function() { + var progressBar = document.createElement('div'); + progressBar.className = 'progress'; + + var meter = document.createElement('span'); + meter.className = 'meter'; + meter.style.width = '0%'; + progressBar.appendChild(meter); + return progressBar; + }, + updateProgressBar: function(progressBar, progress) { + if (!progressBar) return; + progressBar.firstChild.style.width = progress + '%'; + }, + updateProgressBarUnknown: function(progressBar) { + if (!progressBar) return; + progressBar.firstChild.style.width = '100%'; + } +}); + +// Foundation 3 Specific Theme +JSONEditor.defaults.themes.foundation3 = JSONEditor.defaults.themes.foundation.extend({ + getHeaderButtonHolder: function() { + var el = this._super(); + el.style.fontSize = '.6em'; + return el; + }, + getFormInputLabel: function(text) { + var el = this._super(text); + el.style.fontWeight = 'bold'; + return el; + }, + getTabHolder: function() { + var el = document.createElement('div'); + el.className = 'row'; + el.innerHTML = "
    "; + return el; + }, + setGridColumnSize: function(el,size) { + var sizes = ['zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve']; + el.className = 'columns '+sizes[size]; + }, + getTab: function(text) { + var el = document.createElement('dd'); + var a = document.createElement('a'); + a.setAttribute('href','#'); + a.appendChild(text); + el.appendChild(a); + return el; + }, + getTabContentHolder: function(tab_holder) { + return tab_holder.children[1]; + }, + getTabContent: function() { + var el = document.createElement('div'); + el.className = 'content active'; + el.style.paddingLeft = '5px'; + return el; + }, + markTabActive: function(tab) { + tab.className += ' active'; + }, + markTabInactive: function(tab) { + tab.className = tab.className.replace(/\s*active/g,''); + }, + addTab: function(holder, tab) { + holder.children[0].appendChild(tab); + } +}); + +// Foundation 4 Specific Theme +JSONEditor.defaults.themes.foundation4 = JSONEditor.defaults.themes.foundation.extend({ + getHeaderButtonHolder: function() { + var el = this._super(); + el.style.fontSize = '.6em'; + return el; + }, + setGridColumnSize: function(el,size) { + el.className = 'columns large-'+size; + }, + getFormInputDescription: function(text) { + var el = this._super(text); + el.style.fontSize = '.8rem'; + return el; + }, + getFormInputLabel: function(text) { + var el = this._super(text); + el.style.fontWeight = 'bold'; + return el; + } +}); + +// Foundation 5 Specific Theme +JSONEditor.defaults.themes.foundation5 = JSONEditor.defaults.themes.foundation.extend({ + getFormInputDescription: function(text) { + var el = this._super(text); + el.style.fontSize = '.8rem'; + return el; + }, + setGridColumnSize: function(el,size) { + el.className = 'columns medium-'+size; + }, + getButton: function(text, icon, title) { + var el = this._super(text,icon,title); + el.className = el.className.replace(/\s*small/g,'') + ' tiny'; + return el; + }, + getTabHolder: function() { + var el = document.createElement('div'); + el.innerHTML = "
    "; + return el; + }, + getTab: function(text) { + var el = document.createElement('dd'); + var a = document.createElement('a'); + a.setAttribute('href','#'); + a.appendChild(text); + el.appendChild(a); + return el; + }, + getTabContentHolder: function(tab_holder) { + return tab_holder.children[1]; + }, + getTabContent: function() { + var el = document.createElement('div'); + el.className = 'content active'; + el.style.paddingLeft = '5px'; + return el; + }, + markTabActive: function(tab) { + tab.className += ' active'; + }, + markTabInactive: function(tab) { + tab.className = tab.className.replace(/\s*active/g,''); + }, + addTab: function(holder, tab) { + holder.children[0].appendChild(tab); + } +}); + +JSONEditor.defaults.themes.html = JSONEditor.AbstractTheme.extend({ + getFormInputLabel: function(text) { + var el = this._super(text); + el.style.display = 'block'; + el.style.marginBottom = '3px'; + el.style.fontWeight = 'bold'; + return el; + }, + getFormInputDescription: function(text) { + var el = this._super(text); + el.style.fontSize = '.8em'; + el.style.margin = 0; + el.style.display = 'inline-block'; + el.style.fontStyle = 'italic'; + return el; + }, + getIndentedPanel: function() { + var el = this._super(); + el.style.border = '1px solid #ddd'; + el.style.padding = '5px'; + el.style.margin = '5px'; + el.style.borderRadius = '3px'; + return el; + }, + getChildEditorHolder: function() { + var el = this._super(); + el.style.marginBottom = '8px'; + return el; + }, + getHeaderButtonHolder: function() { + var el = this.getButtonHolder(); + el.style.display = 'inline-block'; + el.style.marginLeft = '10px'; + el.style.fontSize = '.8em'; + el.style.verticalAlign = 'middle'; + return el; + }, + getTable: function() { + var el = this._super(); + el.style.borderBottom = '1px solid #ccc'; + el.style.marginBottom = '5px'; + return el; + }, + addInputError: function(input, text) { + input.style.borderColor = 'red'; + + if(!input.errmsg) { + var group = this.closest(input,'.form-control'); + input.errmsg = document.createElement('div'); + input.errmsg.setAttribute('class','errmsg'); + input.errmsg.style = input.errmsg.style || {}; + input.errmsg.style.color = 'red'; + group.appendChild(input.errmsg); + } + else { + input.errmsg.style.display = 'block'; + } + + input.errmsg.innerHTML = ''; + input.errmsg.appendChild(document.createTextNode(text)); + }, + removeInputError: function(input) { + input.style.borderColor = ''; + if(input.errmsg) input.errmsg.style.display = 'none'; + }, + getProgressBar: function() { + var max = 100, start = 0; + + var progressBar = document.createElement('progress'); + progressBar.setAttribute('max', max); + progressBar.setAttribute('value', start); + return progressBar; + }, + updateProgressBar: function(progressBar, progress) { + if (!progressBar) return; + progressBar.setAttribute('value', progress); + }, + updateProgressBarUnknown: function(progressBar) { + if (!progressBar) return; + progressBar.removeAttribute('value'); + } +}); + +JSONEditor.defaults.themes.jqueryui = JSONEditor.AbstractTheme.extend({ + getTable: function() { + var el = this._super(); + el.setAttribute('cellpadding',5); + el.setAttribute('cellspacing',0); + return el; + }, + getTableHeaderCell: function(text) { + var el = this._super(text); + el.className = 'ui-state-active'; + el.style.fontWeight = 'bold'; + return el; + }, + getTableCell: function() { + var el = this._super(); + el.className = 'ui-widget-content'; + return el; + }, + getHeaderButtonHolder: function() { + var el = this.getButtonHolder(); + el.style.marginLeft = '10px'; + el.style.fontSize = '.6em'; + el.style.display = 'inline-block'; + return el; + }, + getFormInputDescription: function(text) { + var el = this.getDescription(text); + el.style.marginLeft = '10px'; + el.style.display = 'inline-block'; + return el; + }, + getFormControl: function(label, input, description) { + var el = this._super(label,input,description); + if(input.type === 'checkbox') { + el.style.lineHeight = '25px'; + + el.style.padding = '3px 0'; + } + else { + el.style.padding = '4px 0 8px 0'; + } + return el; + }, + getDescription: function(text) { + var el = document.createElement('span'); + el.style.fontSize = '.8em'; + el.style.fontStyle = 'italic'; + el.textContent = text; + return el; + }, + getButtonHolder: function() { + var el = document.createElement('div'); + el.className = 'ui-buttonset'; + el.style.fontSize = '.7em'; + return el; + }, + getFormInputLabel: function(text) { + var el = document.createElement('label'); + el.style.fontWeight = 'bold'; + el.style.display = 'block'; + el.textContent = text; + return el; + }, + getButton: function(text, icon, title) { + var button = document.createElement("button"); + button.className = 'ui-button ui-widget ui-state-default ui-corner-all'; + + // Icon only + if(icon && !text) { + button.className += ' ui-button-icon-only'; + icon.className += ' ui-button-icon-primary ui-icon-primary'; + button.appendChild(icon); + } + // Icon and Text + else if(icon) { + button.className += ' ui-button-text-icon-primary'; + icon.className += ' ui-button-icon-primary ui-icon-primary'; + button.appendChild(icon); + } + // Text only + else { + button.className += ' ui-button-text-only'; + } + + var el = document.createElement('span'); + el.className = 'ui-button-text'; + el.textContent = text||title||"."; + button.appendChild(el); + + button.setAttribute('title',title); + + return button; + }, + setButtonText: function(button,text, icon, title) { + button.innerHTML = ''; + button.className = 'ui-button ui-widget ui-state-default ui-corner-all'; + + // Icon only + if(icon && !text) { + button.className += ' ui-button-icon-only'; + icon.className += ' ui-button-icon-primary ui-icon-primary'; + button.appendChild(icon); + } + // Icon and Text + else if(icon) { + button.className += ' ui-button-text-icon-primary'; + icon.className += ' ui-button-icon-primary ui-icon-primary'; + button.appendChild(icon); + } + // Text only + else { + button.className += ' ui-button-text-only'; + } + + var el = document.createElement('span'); + el.className = 'ui-button-text'; + el.textContent = text||title||"."; + button.appendChild(el); + + button.setAttribute('title',title); + }, + getIndentedPanel: function() { + var el = document.createElement('div'); + el.className = 'ui-widget-content ui-corner-all'; + el.style.padding = '1em 1.4em'; + el.style.marginBottom = '20px'; + return el; + }, + afterInputReady: function(input) { + if(input.controls) return; + input.controls = this.closest(input,'.form-control'); + }, + addInputError: function(input,text) { + if(!input.controls) return; + if(!input.errmsg) { + input.errmsg = document.createElement('div'); + input.errmsg.className = 'ui-state-error'; + input.controls.appendChild(input.errmsg); + } + else { + input.errmsg.style.display = ''; + } + + input.errmsg.textContent = text; + }, + removeInputError: function(input) { + if(!input.errmsg) return; + input.errmsg.style.display = 'none'; + }, + markTabActive: function(tab) { + tab.className = tab.className.replace(/\s*ui-widget-header/g,'')+' ui-state-active'; + }, + markTabInactive: function(tab) { + tab.className = tab.className.replace(/\s*ui-state-active/g,'')+' ui-widget-header'; + } +}); + +JSONEditor.AbstractIconLib = Class.extend({ + mapping: { + collapse: '', + expand: '', + "delete": '', + edit: '', + add: '', + cancel: '', + save: '', + moveup: '', + movedown: '' + }, + icon_prefix: '', + getIconClass: function(key) { + if(this.mapping[key]) return this.icon_prefix+this.mapping[key]; + else return null; + }, + getIcon: function(key) { + var iconclass = this.getIconClass(key); + + if(!iconclass) return null; + + var i = document.createElement('i'); + i.className = iconclass; + return i; + } +}); + +JSONEditor.defaults.iconlibs.bootstrap2 = JSONEditor.AbstractIconLib.extend({ + mapping: { + collapse: 'chevron-down', + expand: 'chevron-up', + "delete": 'trash', + edit: 'pencil', + add: 'plus', + cancel: 'ban-circle', + save: 'ok', + moveup: 'arrow-up', + movedown: 'arrow-down' + }, + icon_prefix: 'icon-' +}); + +JSONEditor.defaults.iconlibs.bootstrap3 = JSONEditor.AbstractIconLib.extend({ + mapping: { + collapse: 'chevron-down', + expand: 'chevron-right', + "delete": 'remove', + edit: 'pencil', + add: 'plus', + cancel: 'floppy-remove', + save: 'floppy-saved', + moveup: 'arrow-up', + movedown: 'arrow-down' + }, + icon_prefix: 'glyphicon glyphicon-' +}); + +JSONEditor.defaults.iconlibs.fontawesome3 = JSONEditor.AbstractIconLib.extend({ + mapping: { + collapse: 'chevron-down', + expand: 'chevron-right', + "delete": 'remove', + edit: 'pencil', + add: 'plus', + cancel: 'ban-circle', + save: 'save', + moveup: 'arrow-up', + movedown: 'arrow-down' + }, + icon_prefix: 'icon-' +}); + +JSONEditor.defaults.iconlibs.fontawesome4 = JSONEditor.AbstractIconLib.extend({ + mapping: { + collapse: 'caret-square-o-down', + expand: 'caret-square-o-right', + "delete": 'times', + edit: 'pencil', + add: 'plus', + cancel: 'ban', + save: 'save', + moveup: 'arrow-up', + movedown: 'arrow-down' + }, + icon_prefix: 'fa fa-' +}); + +JSONEditor.defaults.iconlibs.foundation2 = JSONEditor.AbstractIconLib.extend({ + mapping: { + collapse: 'minus', + expand: 'plus', + "delete": 'remove', + edit: 'edit', + add: 'add-doc', + cancel: 'error', + save: 'checkmark', + moveup: 'up-arrow', + movedown: 'down-arrow' + }, + icon_prefix: 'foundicon-' +}); + +JSONEditor.defaults.iconlibs.foundation3 = JSONEditor.AbstractIconLib.extend({ + mapping: { + collapse: 'minus', + expand: 'plus', + "delete": 'x', + edit: 'pencil', + add: 'page-add', + cancel: 'x-circle', + save: 'save', + moveup: 'arrow-up', + movedown: 'arrow-down' + }, + icon_prefix: 'fi-' +}); + +JSONEditor.defaults.iconlibs.jqueryui = JSONEditor.AbstractIconLib.extend({ + mapping: { + collapse: 'triangle-1-s', + expand: 'triangle-1-e', + "delete": 'trash', + edit: 'pencil', + add: 'plusthick', + cancel: 'closethick', + save: 'disk', + moveup: 'arrowthick-1-n', + movedown: 'arrowthick-1-s' + }, + icon_prefix: 'ui-icon ui-icon-' +}); + +JSONEditor.defaults.templates["default"] = function() { + return { + compile: function(template) { + var matches = template.match(/{{\s*([a-zA-Z0-9\-_ \.]+)\s*}}/g); + var l = matches && matches.length; + + // Shortcut if the template contains no variables + if(!l) return function() { return template; }; + + // Pre-compute the search/replace functions + // This drastically speeds up template execution + var replacements = []; + var get_replacement = function(i) { + var p = matches[i].replace(/[{}]+/g,'').trim().split('.'); + var n = p.length; + var func; + + if(n > 1) { + var cur; + func = function(vars) { + cur = vars; + for(i=0; i= 0) { + return 'multiselect'; + } +}); +// Use the multiple editor for schemas with `oneOf` set +JSONEditor.defaults.resolvers.unshift(function(schema) { + // If this schema uses `oneOf` + if(schema.oneOf) return "multiple"; +}); + +/** + * This is a small wrapper for using JSON Editor like a typical jQuery plugin. + */ +(function() { + if(window.jQuery || window.Zepto) { + var $ = window.jQuery || window.Zepto; + $.jsoneditor = JSONEditor.defaults; + + $.fn.jsoneditor = function(options) { + var self = this; + var editor = this.data('jsoneditor'); + if(options === 'value') { + if(!editor) throw "Must initialize jsoneditor before getting/setting the value"; + + // Set value + if(arguments.length > 1) { + editor.setValue(arguments[1]); + } + // Get value + else { + return editor.getValue(); + } + } + else if(options === 'validate') { + if(!editor) throw "Must initialize jsoneditor before validating"; + + // Validate a specific value + if(arguments.length > 1) { + return editor.validate(arguments[1]); + } + // Validate current value + else { + return editor.validate(); + } + } + else if(options === 'destroy') { + if(editor) { + editor.destroy(); + this.data('jsoneditor',null); + } + } + else { + // Destroy first + if(editor) { + editor.destroy(); + } + + // Create editor + editor = new JSONEditor(this.get(0),options); + this.data('jsoneditor',editor); + + // Setup event listeners + editor.on('change',function() { + self.trigger('change'); + }); + editor.on('ready',function() { + self.trigger('ready'); + }); + } + + return this; + }; + } +})(); + + window.JSONEditor = JSONEditor; +})(); + +//# sourceMappingURL=jsoneditor.js.map \ No newline at end of file diff --git a/package.json b/package.json index 0078ee99e90..66a8dc088e7 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,10 @@ "contributors": [{ "name": "Mohsen Azimi", "email": "me@azimi.me" + }, + { + "name": "Fares Droubi", + "email": "fares.droubi@gmail.com" }], "description": "Swagger UI is a dependency-free collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API", "version": "2.1.1-M2", diff --git a/src/main/html/css/api-explorer.css b/src/main/html/css/api-explorer.css index c2b4cf2a9e7..ef3abd4e97c 100644 --- a/src/main/html/css/api-explorer.css +++ b/src/main/html/css/api-explorer.css @@ -205,7 +205,7 @@ background: #ff9a57 } -.swagger-section .form-control.error { +.swagger-section .ui-form-control.error { border-color: #fd8888; border-width: 2px } @@ -346,17 +346,17 @@ } } -.swagger-section .parameter-item .form-control { +.swagger-section .parameter-item .ui-form-control { width: auto; max-width: 100% } -.swagger-section .parameter-item .form-control.body-textarea { +.swagger-section .parameter-item .ui-form-control.body-textarea { min-height: 100px; width: 100% } -.swagger-section .parameter-item select.form-control { +.swagger-section .parameter-item select.ui-form-control { width: auto } diff --git a/src/main/html/css/index.css b/src/main/html/css/index.css index c352d986441..96e7585f1b1 100644 --- a/src/main/html/css/index.css +++ b/src/main/html/css/index.css @@ -1657,6 +1657,21 @@ pre code { margin-right: -15px; margin-left: -15px; } + +.row { + margin-right: -15px; + margin-left: -15px; +} + +.editor_holder .row { + margin-right: 0 !important; + margin-left: 0 !important; +} + +.editor_holder .row { + margin-right: 0 !important; + margin-left: 0 !important; +} .col-xs-1, .col-sm-1, .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2, .col-md-2, .col-lg-2, .col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, .col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, .col-xs-5, .col-sm-5, .col-md-5, .col-lg-5, .col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, .col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, .col-xs-8, .col-sm-8, .col-md-8, .col-lg-8, .col-xs-9, .col-sm-9, .col-md-9, .col-lg-9, .col-xs-10, .col-sm-10, .col-md-10, .col-lg-10, .col-xs-11, .col-sm-11, .col-md-11, .col-lg-11, .col-xs-12, .col-sm-12, .col-md-12, .col-lg-12 { position: relative; min-height: 1px; @@ -2592,7 +2607,7 @@ output { line-height: 1.42857143; color: #555; } -.form-control { +.ui-form-control { display: block; width: 100%; height: 34px; @@ -2610,33 +2625,33 @@ output { -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; } -.form-control:focus { +.ui-form-control:focus { border-color: #66afe9; outline: 0; -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6); box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102, 175, 233, .6); } -.form-control::-moz-placeholder { +.ui-form-control::-moz-placeholder { color: #999; opacity: 1; } -.form-control:-ms-input-placeholder { +.ui-form-control:-ms-input-placeholder { color: #999; } -.form-control::-webkit-input-placeholder { +.ui-form-control::-webkit-input-placeholder { color: #999; } -.form-control[disabled], -.form-control[readonly], -fieldset[disabled] .form-control { +.ui-form-control[disabled], +.ui-form-control[readonly], +fieldset[disabled] .ui-form-control { background-color: #eee; opacity: 1; } -.form-control[disabled], -fieldset[disabled] .form-control { +.ui-form-control[disabled], +fieldset[disabled] .ui-form-control { cursor: not-allowed; } -textarea.form-control { +textarea.ui-form-control { height: auto; } input[type="search"] { @@ -2735,14 +2750,14 @@ fieldset[disabled] .radio label, fieldset[disabled] .checkbox label { cursor: not-allowed; } -.form-control-static { +.ui-form-control-static { min-height: 34px; padding-top: 7px; padding-bottom: 7px; margin-bottom: 0; } -.form-control-static.input-lg, -.form-control-static.input-sm { +.ui-form-control-static.input-lg, +.ui-form-control-static.input-sm { padding-right: 0; padding-left: 0; } @@ -2761,22 +2776,22 @@ textarea.input-sm, select[multiple].input-sm { height: auto; } -.form-group-sm .form-control { +.form-group-sm .ui-form-control { height: 30px; padding: 5px 10px; font-size: 12px; line-height: 1.5; border-radius: 3px; } -select.form-group-sm .form-control { +select.form-group-sm .ui-form-control { height: 30px; line-height: 30px; } -textarea.form-group-sm .form-control, -select[multiple].form-group-sm .form-control { +textarea.form-group-sm .ui-form-control, +select[multiple].form-group-sm .ui-form-control { height: auto; } -.form-group-sm .form-control-static { +.form-group-sm .ui-form-control-static { height: 30px; min-height: 32px; padding: 5px 10px; @@ -2798,22 +2813,22 @@ textarea.input-lg, select[multiple].input-lg { height: auto; } -.form-group-lg .form-control { +.form-group-lg .ui-form-control { height: 46px; padding: 10px 16px; font-size: 18px; line-height: 1.3333333; border-radius: 6px; } -select.form-group-lg .form-control { +select.form-group-lg .ui-form-control { height: 46px; line-height: 46px; } -textarea.form-group-lg .form-control, -select[multiple].form-group-lg .form-control { +textarea.form-group-lg .ui-form-control, +select[multiple].form-group-lg .ui-form-control { height: auto; } -.form-group-lg .form-control-static { +.form-group-lg .ui-form-control-static { height: 46px; min-height: 38px; padding: 10px 16px; @@ -2823,10 +2838,10 @@ select[multiple].form-group-lg .form-control { .has-feedback { position: relative; } -.has-feedback .form-control { +.has-feedback .ui-form-control { padding-right: 42.5px; } -.form-control-feedback { +.ui-form-control-feedback { position: absolute; top: 0; right: 0; @@ -2838,12 +2853,12 @@ select[multiple].form-group-lg .form-control { text-align: center; pointer-events: none; } -.input-lg + .form-control-feedback { +.input-lg + .ui-form-control-feedback { width: 46px; height: 46px; line-height: 46px; } -.input-sm + .form-control-feedback { +.input-sm + .ui-form-control-feedback { width: 30px; height: 30px; line-height: 30px; @@ -2860,12 +2875,12 @@ select[multiple].form-group-lg .form-control { .has-success.checkbox-inline label { color: #3c763d; } -.has-success .form-control { +.has-success .ui-form-control { border-color: #3c763d; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); } -.has-success .form-control:focus { +.has-success .ui-form-control:focus { border-color: #2b542c; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #67b168; box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #67b168; @@ -2875,7 +2890,7 @@ select[multiple].form-group-lg .form-control { background-color: #dff0d8; border-color: #3c763d; } -.has-success .form-control-feedback { +.has-success .ui-form-control-feedback { color: #3c763d; } .has-warning .help-block, @@ -2890,12 +2905,12 @@ select[multiple].form-group-lg .form-control { .has-warning.checkbox-inline label { color: #8a6d3b; } -.has-warning .form-control { +.has-warning .ui-form-control { border-color: #8a6d3b; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); } -.has-warning .form-control:focus { +.has-warning .ui-form-control:focus { border-color: #66512c; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #c0a16b; box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #c0a16b; @@ -2905,7 +2920,7 @@ select[multiple].form-group-lg .form-control { background-color: #fcf8e3; border-color: #8a6d3b; } -.has-warning .form-control-feedback { +.has-warning .ui-form-control-feedback { color: #8a6d3b; } .has-error .help-block, @@ -2920,12 +2935,12 @@ select[multiple].form-group-lg .form-control { .has-error.checkbox-inline label { color: #a94442; } -.has-error .form-control { +.has-error .ui-form-control { border-color: #a94442; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); } -.has-error .form-control:focus { +.has-error .ui-form-control:focus { border-color: #843534; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #ce8483; box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #ce8483; @@ -2935,13 +2950,13 @@ select[multiple].form-group-lg .form-control { background-color: #f2dede; border-color: #a94442; } -.has-error .form-control-feedback { +.has-error .ui-form-control-feedback { color: #a94442; } -.has-feedback label ~ .form-control-feedback { +.has-feedback label ~ .ui-form-control-feedback { top: 25px; } -.has-feedback label.sr-only ~ .form-control-feedback { +.has-feedback label.sr-only ~ .ui-form-control-feedback { top: 0; } .help-block { @@ -2956,12 +2971,12 @@ select[multiple].form-group-lg .form-control { margin-bottom: 0; vertical-align: middle; } - .form-inline .form-control { + .form-inline .ui-form-control { display: inline-block; width: auto; vertical-align: middle; } - .form-inline .form-control-static { + .form-inline .ui-form-control-static { display: inline-block; } .form-inline .input-group { @@ -2970,10 +2985,10 @@ select[multiple].form-group-lg .form-control { } .form-inline .input-group .input-group-addon, .form-inline .input-group .input-group-btn, - .form-inline .input-group .form-control { + .form-inline .input-group .ui-form-control { width: auto; } - .form-inline .input-group > .form-control { + .form-inline .input-group > .ui-form-control { width: 100%; } .form-inline .control-label { @@ -2996,7 +3011,7 @@ select[multiple].form-group-lg .form-control { position: relative; margin-left: 0; } - .form-inline .has-feedback .form-control-feedback { + .form-inline .has-feedback .ui-form-control-feedback { top: 0; } } @@ -3023,7 +3038,7 @@ select[multiple].form-group-lg .form-control { text-align: right; } } -.form-horizontal .has-feedback .form-control-feedback { +.form-horizontal .has-feedback .ui-form-control-feedback { right: 15px; } @media (min-width: 768px) { @@ -3780,14 +3795,14 @@ tbody.collapse.in { padding-right: 0; padding-left: 0; } -.input-group .form-control { +.input-group .ui-form-control { position: relative; z-index: 2; float: left; width: 100%; margin-bottom: 0; } -.input-group-lg > .form-control, +.input-group-lg > .ui-form-control, .input-group-lg > .input-group-addon, .input-group-lg > .input-group-btn > .btn { height: 46px; @@ -3796,21 +3811,21 @@ tbody.collapse.in { line-height: 1.3333333; border-radius: 6px; } -select.input-group-lg > .form-control, +select.input-group-lg > .ui-form-control, select.input-group-lg > .input-group-addon, select.input-group-lg > .input-group-btn > .btn { height: 46px; line-height: 46px; } -textarea.input-group-lg > .form-control, +textarea.input-group-lg > .ui-form-control, textarea.input-group-lg > .input-group-addon, textarea.input-group-lg > .input-group-btn > .btn, -select[multiple].input-group-lg > .form-control, +select[multiple].input-group-lg > .ui-form-control, select[multiple].input-group-lg > .input-group-addon, select[multiple].input-group-lg > .input-group-btn > .btn { height: auto; } -.input-group-sm > .form-control, +.input-group-sm > .ui-form-control, .input-group-sm > .input-group-addon, .input-group-sm > .input-group-btn > .btn { height: 30px; @@ -3819,28 +3834,28 @@ select[multiple].input-group-lg > .input-group-btn > .btn { line-height: 1.5; border-radius: 3px; } -select.input-group-sm > .form-control, +select.input-group-sm > .ui-form-control, select.input-group-sm > .input-group-addon, select.input-group-sm > .input-group-btn > .btn { height: 30px; line-height: 30px; } -textarea.input-group-sm > .form-control, +textarea.input-group-sm > .ui-form-control, textarea.input-group-sm > .input-group-addon, textarea.input-group-sm > .input-group-btn > .btn, -select[multiple].input-group-sm > .form-control, +select[multiple].input-group-sm > .ui-form-control, select[multiple].input-group-sm > .input-group-addon, select[multiple].input-group-sm > .input-group-btn > .btn { height: auto; } .input-group-addon, .input-group-btn, -.input-group .form-control { +.input-group .ui-form-control { display: table-cell; } .input-group-addon:not(:first-child):not(:last-child), .input-group-btn:not(:first-child):not(:last-child), -.input-group .form-control:not(:first-child):not(:last-child) { +.input-group .ui-form-control:not(:first-child):not(:last-child) { border-radius: 0; } .input-group-addon, @@ -3874,7 +3889,7 @@ select[multiple].input-group-sm > .input-group-btn > .btn { .input-group-addon input[type="checkbox"] { margin-top: 0; } -.input-group .form-control:first-child, +.input-group .ui-form-control:first-child, .input-group-addon:first-child, .input-group-btn:first-child > .btn, .input-group-btn:first-child > .btn-group > .btn, @@ -3887,7 +3902,7 @@ select[multiple].input-group-sm > .input-group-btn > .btn { .input-group-addon:first-child { border-right: 0; } -.input-group .form-control:last-child, +.input-group .ui-form-control:last-child, .input-group-addon:last-child, .input-group-btn:last-child > .btn, .input-group-btn:last-child > .btn-group > .btn, @@ -4334,12 +4349,12 @@ select[multiple].input-group-sm > .input-group-btn > .btn { margin-bottom: 0; vertical-align: middle; } - .navbar-form .form-control { + .navbar-form .ui-form-control { display: inline-block; width: auto; vertical-align: middle; } - .navbar-form .form-control-static { + .navbar-form .ui-form-control-static { display: inline-block; } .navbar-form .input-group { @@ -4348,10 +4363,10 @@ select[multiple].input-group-sm > .input-group-btn > .btn { } .navbar-form .input-group .input-group-addon, .navbar-form .input-group .input-group-btn, - .navbar-form .input-group .form-control { + .navbar-form .input-group .ui-form-control { width: auto; } - .navbar-form .input-group > .form-control { + .navbar-form .input-group > .ui-form-control { width: 100%; } .navbar-form .control-label { @@ -4374,7 +4389,7 @@ select[multiple].input-group-sm > .input-group-btn > .btn { position: relative; margin-left: 0; } - .navbar-form .has-feedback .form-control-feedback { + .navbar-form .has-feedback .ui-form-control-feedback { top: 0; } } diff --git a/src/main/html/css/print.css b/src/main/html/css/print.css index b4fc18036ef..32764df8378 100644 --- a/src/main/html/css/print.css +++ b/src/main/html/css/print.css @@ -82,7 +82,7 @@ .swagger-section pre .vhdl .attribute, .swagger-section pre .clojure .attribute, .swagger-section pre .coffeescript .property { - color: #8888ff; + color: #88F; } .swagger-section pre .keyword, .swagger-section pre .id, @@ -126,6 +126,7 @@ max-width: 960px; margin-left: auto; margin-right: auto; + /* JSONEditor specific styling */ } .swagger-section .swagger-ui-wrap b, .swagger-section .swagger-ui-wrap strong { @@ -456,6 +457,17 @@ font-family: "Droid Sans", sans-serif; font-weight: bold; } +.swagger-section .swagger-ui-wrap .editor_holder { + font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace; + font-size: 0.9em; +} +.swagger-section .swagger-ui-wrap .editor_holder label { + font-weight: normal!important; + /* JSONEditor uses bold by default for all labels, we revert that back to normal to not give the impression that by default fields are required */ +} +.swagger-section .swagger-ui-wrap .editor_holder label.required { + font-weight: bold!important; +} .swagger-section .swagger-ui-wrap .heading_with_menu { float: none; clear: both; diff --git a/src/main/html/css/screen.css b/src/main/html/css/screen.css index 32b199b17b6..12ec0c57d5b 100644 --- a/src/main/html/css/screen.css +++ b/src/main/html/css/screen.css @@ -1,1256 +1,9 @@ -/* Original style from softwaremaniacs.org (c) Ivan Sagalaev */ -.swagger-section pre code { - display: block; - padding: 0.5em; - background: #F0F0F0; +.swagger-section .swagger-collapse:before { + content: "-"; } -.swagger-section pre code, -.swagger-section pre .subst, -.swagger-section pre .tag .title, -.swagger-section pre .lisp .title, -.swagger-section pre .clojure .built_in, -.swagger-section pre .nginx .title { - color: black; +.swagger-section .swagger-expand:before { + content: "+"; } -.swagger-section pre .string, -.swagger-section pre .title, -.swagger-section pre .constant, -.swagger-section pre .parent, -.swagger-section pre .tag .value, -.swagger-section pre .rules .value, -.swagger-section pre .rules .value .number, -.swagger-section pre .preprocessor, -.swagger-section pre .ruby .symbol, -.swagger-section pre .ruby .symbol .string, -.swagger-section pre .aggregate, -.swagger-section pre .template_tag, -.swagger-section pre .django .variable, -.swagger-section pre .smalltalk .class, -.swagger-section pre .addition, -.swagger-section pre .flow, -.swagger-section pre .stream, -.swagger-section pre .bash .variable, -.swagger-section pre .apache .tag, -.swagger-section pre .apache .cbracket, -.swagger-section pre .tex .command, -.swagger-section pre .tex .special, -.swagger-section pre .erlang_repl .function_or_atom, -.swagger-section pre .markdown .header { - color: #800; -} -.swagger-section pre .comment, -.swagger-section pre .annotation, -.swagger-section pre .template_comment, -.swagger-section pre .diff .header, -.swagger-section pre .chunk, -.swagger-section pre .markdown .blockquote { - color: #888; -} -.swagger-section pre .number, -.swagger-section pre .date, -.swagger-section pre .regexp, -.swagger-section pre .literal, -.swagger-section pre .smalltalk .symbol, -.swagger-section pre .smalltalk .char, -.swagger-section pre .go .constant, -.swagger-section pre .change, -.swagger-section pre .markdown .bullet, -.swagger-section pre .markdown .link_url { - color: #080; -} -.swagger-section pre .label, -.swagger-section pre .javadoc, -.swagger-section pre .ruby .string, -.swagger-section pre .decorator, -.swagger-section pre .filter .argument, -.swagger-section pre .localvars, -.swagger-section pre .array, -.swagger-section pre .attr_selector, -.swagger-section pre .important, -.swagger-section pre .pseudo, -.swagger-section pre .pi, -.swagger-section pre .doctype, -.swagger-section pre .deletion, -.swagger-section pre .envvar, -.swagger-section pre .shebang, -.swagger-section pre .apache .sqbracket, -.swagger-section pre .nginx .built_in, -.swagger-section pre .tex .formula, -.swagger-section pre .erlang_repl .reserved, -.swagger-section pre .prompt, -.swagger-section pre .markdown .link_label, -.swagger-section pre .vhdl .attribute, -.swagger-section pre .clojure .attribute, -.swagger-section pre .coffeescript .property { - color: #8888ff; -} -.swagger-section pre .keyword, -.swagger-section pre .id, -.swagger-section pre .phpdoc, -.swagger-section pre .title, -.swagger-section pre .built_in, -.swagger-section pre .aggregate, -.swagger-section pre .css .tag, -.swagger-section pre .javadoctag, -.swagger-section pre .phpdoc, -.swagger-section pre .yardoctag, -.swagger-section pre .smalltalk .class, -.swagger-section pre .winutils, -.swagger-section pre .bash .variable, -.swagger-section pre .apache .tag, -.swagger-section pre .go .typename, -.swagger-section pre .tex .command, -.swagger-section pre .markdown .strong, -.swagger-section pre .request, -.swagger-section pre .status { - font-weight: bold; -} -.swagger-section pre .markdown .emphasis { - font-style: italic; -} -.swagger-section pre .nginx .built_in { - font-weight: normal; -} -.swagger-section pre .coffeescript .javascript, -.swagger-section pre .javascript .xml, -.swagger-section pre .tex .formula, -.swagger-section pre .xml .javascript, -.swagger-section pre .xml .vbscript, -.swagger-section pre .xml .css, -.swagger-section pre .xml .cdata { - opacity: 0.5; -} -.swagger-section .swagger-ui-wrap { - line-height: 1; - font-family: "Droid Sans", sans-serif; - max-width: 960px; - margin-left: auto; - margin-right: auto; -} -.swagger-section .swagger-ui-wrap b, -.swagger-section .swagger-ui-wrap strong { - font-family: "Droid Sans", sans-serif; - font-weight: bold; -} -.swagger-section .swagger-ui-wrap q, -.swagger-section .swagger-ui-wrap blockquote { - quotes: none; -} -.swagger-section .swagger-ui-wrap p { - line-height: 1.4em; - padding: 0 0 10px; - color: #333333; -} -.swagger-section .swagger-ui-wrap q:before, -.swagger-section .swagger-ui-wrap q:after, -.swagger-section .swagger-ui-wrap blockquote:before, -.swagger-section .swagger-ui-wrap blockquote:after { - content: none; -} -.swagger-section .swagger-ui-wrap .heading_with_menu h1, -.swagger-section .swagger-ui-wrap .heading_with_menu h2, -.swagger-section .swagger-ui-wrap .heading_with_menu h3, -.swagger-section .swagger-ui-wrap .heading_with_menu h4, -.swagger-section .swagger-ui-wrap .heading_with_menu h5, -.swagger-section .swagger-ui-wrap .heading_with_menu h6 { - display: block; - clear: none; - float: left; - -moz-box-sizing: border-box; - -webkit-box-sizing: border-box; - -ms-box-sizing: border-box; - box-sizing: border-box; - width: 60%; -} -.swagger-section .swagger-ui-wrap table { - border-collapse: collapse; - border-spacing: 0; -} -.swagger-section .swagger-ui-wrap table thead tr th { - padding: 5px; - font-size: 0.9em; - color: #666666; - border-bottom: 1px solid #999999; -} -.swagger-section .swagger-ui-wrap table tbody tr:last-child td { - border-bottom: none; -} -.swagger-section .swagger-ui-wrap table tbody tr.offset { - background-color: #f0f0f0; -} -.swagger-section .swagger-ui-wrap table tbody tr td { - padding: 6px; - font-size: 0.9em; - border-bottom: 1px solid #cccccc; - vertical-align: top; - line-height: 1.3em; -} -.swagger-section .swagger-ui-wrap ol { - margin: 0px 0 10px; - padding: 0 0 0 18px; - list-style-type: decimal; -} -.swagger-section .swagger-ui-wrap ol li { - padding: 5px 0px; - font-size: 0.9em; - color: #333333; -} -.swagger-section .swagger-ui-wrap ol, -.swagger-section .swagger-ui-wrap ul { - list-style: none; -} -.swagger-section .swagger-ui-wrap h1 a, -.swagger-section .swagger-ui-wrap h2 a, -.swagger-section .swagger-ui-wrap h3 a, -.swagger-section .swagger-ui-wrap h4 a, -.swagger-section .swagger-ui-wrap h5 a, -.swagger-section .swagger-ui-wrap h6 a { - text-decoration: none; -} -.swagger-section .swagger-ui-wrap h1 a:hover, -.swagger-section .swagger-ui-wrap h2 a:hover, -.swagger-section .swagger-ui-wrap h3 a:hover, -.swagger-section .swagger-ui-wrap h4 a:hover, -.swagger-section .swagger-ui-wrap h5 a:hover, -.swagger-section .swagger-ui-wrap h6 a:hover { - text-decoration: underline; -} -.swagger-section .swagger-ui-wrap h1 span.divider, -.swagger-section .swagger-ui-wrap h2 span.divider, -.swagger-section .swagger-ui-wrap h3 span.divider, -.swagger-section .swagger-ui-wrap h4 span.divider, -.swagger-section .swagger-ui-wrap h5 span.divider, -.swagger-section .swagger-ui-wrap h6 span.divider { - color: #aaaaaa; -} -.swagger-section .swagger-ui-wrap a { - color: #547f00; -} -.swagger-section .swagger-ui-wrap a img { - border: none; -} -.swagger-section .swagger-ui-wrap article, -.swagger-section .swagger-ui-wrap aside, -.swagger-section .swagger-ui-wrap details, -.swagger-section .swagger-ui-wrap figcaption, -.swagger-section .swagger-ui-wrap figure, -.swagger-section .swagger-ui-wrap footer, -.swagger-section .swagger-ui-wrap header, -.swagger-section .swagger-ui-wrap hgroup, -.swagger-section .swagger-ui-wrap menu, -.swagger-section .swagger-ui-wrap nav, -.swagger-section .swagger-ui-wrap section, -.swagger-section .swagger-ui-wrap summary { - display: block; -} -.swagger-section .swagger-ui-wrap pre { - font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace; - background-color: #fcf6db; - border: 1px solid #e5e0c6; - padding: 10px; -} -.swagger-section .swagger-ui-wrap pre code { - line-height: 1.6em; - background: none; -} -.swagger-section .swagger-ui-wrap .content > .content-type > div > label { - clear: both; - display: block; - color: #0F6AB4; - font-size: 1.1em; - margin: 0; - padding: 15px 0 5px; -} -.swagger-section .swagger-ui-wrap .content pre { - font-size: 12px; - margin-top: 5px; - padding: 5px; -} -.swagger-section .swagger-ui-wrap .icon-btn { - cursor: pointer; -} -.swagger-section .swagger-ui-wrap .info_title { - padding-bottom: 10px; - font-weight: bold; - font-size: 25px; -} -.swagger-section .swagger-ui-wrap p.big, -.swagger-section .swagger-ui-wrap div.big p { - font-size: 1em; - margin-bottom: 10px; -} -.swagger-section .swagger-ui-wrap form.fullwidth ol li.string input, -.swagger-section .swagger-ui-wrap form.fullwidth ol li.url input, -.swagger-section .swagger-ui-wrap form.fullwidth ol li.text textarea, -.swagger-section .swagger-ui-wrap form.fullwidth ol li.numeric input { - width: 500px !important; -} -.swagger-section .swagger-ui-wrap .info_license { - padding-bottom: 5px; -} -.swagger-section .swagger-ui-wrap .info_tos { - padding-bottom: 5px; -} -.swagger-section .swagger-ui-wrap .message-fail { - color: #cc0000; -} -.swagger-section .swagger-ui-wrap .info_url { - padding-bottom: 5px; -} -.swagger-section .swagger-ui-wrap .info_email { - padding-bottom: 5px; -} -.swagger-section .swagger-ui-wrap .info_name { - padding-bottom: 5px; -} -.swagger-section .swagger-ui-wrap .info_description { - padding-bottom: 10px; - font-size: 15px; -} -.swagger-section .swagger-ui-wrap .markdown ol li, -.swagger-section .swagger-ui-wrap .markdown ul li { - padding: 3px 0px; - line-height: 1.4em; - color: #333333; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.string input, -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.url input, -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.numeric input { - display: block; - padding: 4px; - width: auto; - clear: both; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.string input.title, -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.url input.title, -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.numeric input.title { - font-size: 1.3em; -} -.swagger-section .swagger-ui-wrap table.fullwidth { - width: 100%; -} -.swagger-section .swagger-ui-wrap .model-signature { - font-family: "Droid Sans", sans-serif; - font-size: 1em; - line-height: 1.5em; -} -.swagger-section .swagger-ui-wrap .model-signature .signature-nav a { - text-decoration: none; - color: #AAA; -} -.swagger-section .swagger-ui-wrap .model-signature .signature-nav a:hover { - text-decoration: underline; - color: black; -} -.swagger-section .swagger-ui-wrap .model-signature .signature-nav .selected { - color: black; - text-decoration: none; -} -.swagger-section .swagger-ui-wrap .model-signature .propType { - color: #5555aa; -} -.swagger-section .swagger-ui-wrap .model-signature pre:hover { - background-color: #ffffdd; -} -.swagger-section .swagger-ui-wrap .model-signature pre { - font-size: .85em; - line-height: 1.2em; - overflow: auto; - max-height: 200px; - cursor: pointer; -} -.swagger-section .swagger-ui-wrap .model-signature ul.signature-nav { - display: block; - margin: 0; - padding: 0; -} -.swagger-section .swagger-ui-wrap .model-signature ul.signature-nav li:last-child { - padding-right: 0; - border-right: none; -} -.swagger-section .swagger-ui-wrap .model-signature ul.signature-nav li { - float: left; - margin: 0 5px 5px 0; - padding: 2px 5px 2px 0; - border-right: 1px solid #ddd; -} -.swagger-section .swagger-ui-wrap .model-signature .propOpt { - color: #555; -} -.swagger-section .swagger-ui-wrap .model-signature .snippet small { - font-size: 0.75em; -} -.swagger-section .swagger-ui-wrap .model-signature .propOptKey { - font-style: italic; -} -.swagger-section .swagger-ui-wrap .model-signature .description .strong { - font-weight: bold; - color: #000; - font-size: .9em; -} -.swagger-section .swagger-ui-wrap .model-signature .description div { - font-size: 0.9em; - line-height: 1.5em; - margin-left: 1em; -} -.swagger-section .swagger-ui-wrap .model-signature .description .stronger { - font-weight: bold; - color: #000; -} -.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper { - border-spacing: 0; - position: absolute; - background-color: #ffffff; - border: 1px solid #bbbbbb; - display: none; - font-size: 11px; - max-width: 400px; - line-height: 30px; - color: black; - padding: 5px; - margin-left: 10px; -} -.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper th { - text-align: center; - background-color: #eeeeee; - border: 1px solid #bbbbbb; - font-size: 11px; - color: #666666; - font-weight: bold; - padding: 5px; - line-height: 15px; -} -.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper .optionName { - font-weight: bold; -} -.swagger-section .swagger-ui-wrap .model-signature .propName { - font-weight: bold; -} -.swagger-section .swagger-ui-wrap .model-signature .signature-container { - clear: both; -} -.swagger-section .swagger-ui-wrap .body-textarea { - width: 300px; - height: 100px; - border: 1px solid #aaa; -} -.swagger-section .swagger-ui-wrap .markdown p code, -.swagger-section .swagger-ui-wrap .markdown li code { - font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace; - background-color: #f0f0f0; - color: black; - padding: 1px 3px; -} -.swagger-section .swagger-ui-wrap .required { - font-weight: bold; -} -.swagger-section .swagger-ui-wrap input.parameter { - width: 300px; - border: 1px solid #aaa; -} -.swagger-section .swagger-ui-wrap h1 { - color: black; - font-size: 1.5em; - line-height: 1.3em; - padding: 10px 0 10px 0; - font-family: "Droid Sans", sans-serif; - font-weight: bold; -} -.swagger-section .swagger-ui-wrap .heading_with_menu { - float: none; - clear: both; - overflow: hidden; - display: block; -} -.swagger-section .swagger-ui-wrap .heading_with_menu ul { - display: block; - clear: none; - float: right; - -moz-box-sizing: border-box; - -webkit-box-sizing: border-box; - -ms-box-sizing: border-box; - box-sizing: border-box; - margin-top: 10px; -} -.swagger-section .swagger-ui-wrap h2 { - color: black; - font-size: 1.3em; - padding: 10px 0 10px 0; -} -.swagger-section .swagger-ui-wrap h2 a { - color: black; -} -.swagger-section .swagger-ui-wrap h2 span.sub { - font-size: 0.7em; - color: #999999; - font-style: italic; -} -.swagger-section .swagger-ui-wrap h2 span.sub a { - color: #777777; -} -.swagger-section .swagger-ui-wrap span.weak { - color: #666666; -} -.swagger-section .swagger-ui-wrap .message-success { - color: #89BF04; -} -.swagger-section .swagger-ui-wrap caption, -.swagger-section .swagger-ui-wrap th, -.swagger-section .swagger-ui-wrap td { - text-align: left; - font-weight: normal; - vertical-align: middle; -} -.swagger-section .swagger-ui-wrap .code { - font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.text textarea { - font-family: "Droid Sans", sans-serif; - height: 250px; - padding: 4px; - display: block; - clear: both; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.select select { - display: block; - clear: both; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.boolean { - float: none; - clear: both; - overflow: hidden; - display: block; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.boolean label { - display: block; - float: left; - clear: none; - margin: 0; - padding: 0; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.boolean input { - display: block; - float: left; - clear: none; - margin: 0 5px 0 0; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li.required label { - color: black; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li label { - display: block; - clear: both; - width: auto; - padding: 0 0 3px; - color: #666666; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li label abbr { - padding-left: 3px; - color: #888888; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.inputs ol li p.inline-hints { - margin-left: 0; - font-style: italic; - font-size: 0.9em; - margin: 0; -} -.swagger-section .swagger-ui-wrap form.formtastic fieldset.buttons { - margin: 0; - padding: 0; -} -.swagger-section .swagger-ui-wrap span.blank, -.swagger-section .swagger-ui-wrap span.empty { - color: #888888; - font-style: italic; -} -.swagger-section .swagger-ui-wrap .markdown h3 { - color: #547f00; -} -.swagger-section .swagger-ui-wrap .markdown h4 { - color: #666666; -} -.swagger-section .swagger-ui-wrap .markdown pre { - font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace; - background-color: #fcf6db; - border: 1px solid #e5e0c6; - padding: 10px; - margin: 0 0 10px 0; -} -.swagger-section .swagger-ui-wrap .markdown pre code { - line-height: 1.6em; -} -.swagger-section .swagger-ui-wrap div.gist { - margin: 20px 0 25px 0 !important; -} -.swagger-section .swagger-ui-wrap ul#resources { - font-family: "Droid Sans", sans-serif; - font-size: 0.9em; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource { - border-bottom: 1px solid #dddddd; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource:hover div.heading h2 a, -.swagger-section .swagger-ui-wrap ul#resources li.resource.active div.heading h2 a { - color: black; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource:hover div.heading ul.options li a, -.swagger-section .swagger-ui-wrap ul#resources li.resource.active div.heading ul.options li a { - color: #555555; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource:last-child { - border-bottom: none; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading { - border: 1px solid transparent; - float: none; - clear: both; - overflow: hidden; - display: block; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options { - overflow: hidden; - padding: 0; - display: block; - clear: none; - float: right; - margin: 14px 10px 0 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li { - float: left; - clear: none; - margin: 0; - padding: 2px 10px; - border-right: 1px solid #dddddd; - color: #666666; - font-size: 0.9em; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a { - color: #aaaaaa; - text-decoration: none; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a:hover { - text-decoration: underline; - color: black; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a:hover, -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a:active, -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li a.active { - text-decoration: underline; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li:first-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li.first { - padding-left: 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li:last-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options li.last { - padding-right: 0; - border-right: none; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options:first-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading ul.options.first { - padding-left: 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 { - color: #999999; - padding-left: 0; - display: block; - clear: none; - float: left; - font-family: "Droid Sans", sans-serif; - font-weight: bold; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 a { - color: #999999; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 a:hover { - color: black; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation { - float: none; - clear: both; - overflow: hidden; - display: block; - margin: 0 0 10px; - padding: 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading { - float: none; - clear: both; - overflow: hidden; - display: block; - margin: 0; - padding: 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 { - display: block; - clear: none; - float: left; - width: auto; - margin: 0; - padding: 0; - line-height: 1.1em; - color: black; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.path { - padding-left: 10px; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.path a { - color: black; - text-decoration: none; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.path a:hover { - text-decoration: underline; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span.http_method a { - text-transform: uppercase; - text-decoration: none; - color: white; - display: inline-block; - width: 50px; - font-size: 0.7em; - text-align: center; - padding: 7px 0 4px; - -moz-border-radius: 2px; - -webkit-border-radius: 2px; - -o-border-radius: 2px; - -ms-border-radius: 2px; - -khtml-border-radius: 2px; - border-radius: 2px; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading h3 span { - margin: 0; - padding: 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options { - overflow: hidden; - padding: 0; - display: block; - clear: none; - float: right; - margin: 6px 10px 0 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li { - float: left; - clear: none; - margin: 0; - padding: 2px 10px; - font-size: 0.9em; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li a { - text-decoration: none; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.heading ul.options li.access { - color: black; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content { - border-top: none; - padding: 10px; - -moz-border-radius-bottomleft: 6px; - -webkit-border-bottom-left-radius: 6px; - -o-border-bottom-left-radius: 6px; - -ms-border-bottom-left-radius: 6px; - -khtml-border-bottom-left-radius: 6px; - border-bottom-left-radius: 6px; - -moz-border-radius-bottomright: 6px; - -webkit-border-bottom-right-radius: 6px; - -o-border-bottom-right-radius: 6px; - -ms-border-bottom-right-radius: 6px; - -khtml-border-bottom-right-radius: 6px; - border-bottom-right-radius: 6px; - margin: 0 0 20px; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content h4 { - font-size: 1.1em; - margin: 0; - padding: 15px 0 5px; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header { - float: none; - clear: both; - overflow: hidden; - display: block; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header a { - padding: 4px 0 0 10px; - display: inline-block; - font-size: 0.9em; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header input.submit { - display: block; - clear: none; - float: left; - padding: 6px 8px; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.sandbox_header span.response_throbber { - background-image: url('../images/throbber.gif'); - width: 128px; - height: 16px; - display: block; - clear: none; - float: right; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content form input[type='text'].error { - outline: 2px solid black; - outline-color: #cc0000; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation div.content div.response div.block pre { - font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace; - padding: 10px; - font-size: 0.9em; - max-height: 400px; - overflow-y: auto; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading { - background-color: #f9f2e9; - border: 1px solid #f0e0ca; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading h3 span.http_method a { - background-color: #c5862b; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li { - border-right: 1px solid #dddddd; - border-right-color: #f0e0ca; - color: #c5862b; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li a { - color: #c5862b; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content { - background-color: #faf5ee; - border: 1px solid #f0e0ca; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content h4 { - color: #c5862b; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content div.sandbox_header a { - color: #dcb67f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading { - background-color: #fcffcd; - border: 1px solid black; - border-color: #ffd20f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading h3 span.http_method a { - text-transform: uppercase; - background-color: #ffd20f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li { - border-right: 1px solid #dddddd; - border-right-color: #ffd20f; - color: #ffd20f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li a { - color: #ffd20f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content { - background-color: #fcffcd; - border: 1px solid black; - border-color: #ffd20f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content h4 { - color: #ffd20f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content div.sandbox_header a { - color: #6fc992; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading { - background-color: #f5e8e8; - border: 1px solid #e8c6c7; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading h3 span.http_method a { - text-transform: uppercase; - background-color: #a41e22; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li { - border-right: 1px solid #dddddd; - border-right-color: #e8c6c7; - color: #a41e22; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li a { - color: #a41e22; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content { - background-color: #f7eded; - border: 1px solid #e8c6c7; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content h4 { - color: #a41e22; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content div.sandbox_header a { - color: #c8787a; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading { - background-color: #e7f6ec; - border: 1px solid #c3e8d1; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading h3 span.http_method a { - background-color: #10a54a; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li { - border-right: 1px solid #dddddd; - border-right-color: #c3e8d1; - color: #10a54a; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li a { - color: #10a54a; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content { - background-color: #ebf7f0; - border: 1px solid #c3e8d1; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content h4 { - color: #10a54a; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content div.sandbox_header a { - color: #6fc992; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading { - background-color: #FCE9E3; - border: 1px solid #F5D5C3; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading h3 span.http_method a { - background-color: #D38042; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li { - border-right: 1px solid #dddddd; - border-right-color: #f0cecb; - color: #D38042; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li a { - color: #D38042; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content { - background-color: #faf0ef; - border: 1px solid #f0cecb; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content h4 { - color: #D38042; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content div.sandbox_header a { - color: #dcb67f; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading { - background-color: #e7f0f7; - border: 1px solid #c3d9ec; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading h3 span.http_method a { - background-color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li { - border-right: 1px solid #dddddd; - border-right-color: #c3d9ec; - color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li a { - color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content { - background-color: #ebf3f9; - border: 1px solid #c3d9ec; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content h4 { - color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content div.sandbox_header a { - color: #6fa5d2; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading { - background-color: #e7f0f7; - border: 1px solid #c3d9ec; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading h3 span.http_method a { - background-color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading ul.options li { - border-right: 1px solid #dddddd; - border-right-color: #c3d9ec; - color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.heading ul.options li a { - color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.content { - background-color: #ebf3f9; - border: 1px solid #c3d9ec; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.content h4 { - color: #0f6ab4; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.options div.content div.sandbox_header a { - color: #6fa5d2; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.content, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.content, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.content, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.content, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.content, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.content { - border-top: none; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li:last-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li:last-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li:last-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li:last-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li:last-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li:last-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.get div.heading ul.options li.last, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.post div.heading ul.options li.last, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.head div.heading ul.options li.last, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.put div.heading ul.options li.last, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.patch div.heading ul.options li.last, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operation.delete div.heading ul.options li.last { - padding-right: 0; - border-right: none; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li a:hover, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li a:active, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li a.active { - text-decoration: underline; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li:first-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations ul.options li.first { - padding-left: 0; -} -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations:first-child, -.swagger-section .swagger-ui-wrap ul#resources li.resource ul.endpoints li.endpoint ul.operations.first { - padding-left: 0; -} -.swagger-section .swagger-ui-wrap p#colophon { - margin: 0 15px 40px 15px; - padding: 10px 0; - font-size: 0.8em; - border-top: 1px solid #dddddd; - font-family: "Droid Sans", sans-serif; - color: #999999; - font-style: italic; -} -.swagger-section .swagger-ui-wrap p#colophon a { - text-decoration: none; - color: #547f00; -} -.swagger-section .swagger-ui-wrap h3 { - color: black; - font-size: 1.1em; - padding: 10px 0 10px 0; -} -.swagger-section .swagger-ui-wrap .markdown ol, -.swagger-section .swagger-ui-wrap .markdown ul { - font-family: "Droid Sans", sans-serif; - margin: 5px 0 10px; - padding: 0 0 0 18px; - list-style-type: disc; -} -.swagger-section .swagger-ui-wrap form.form_box { - background-color: #ebf3f9; - border: 1px solid #c3d9ec; - padding: 10px; -} -.swagger-section .swagger-ui-wrap form.form_box label { - color: #0f6ab4 !important; -} -.swagger-section .swagger-ui-wrap form.form_box input[type=submit] { - display: block; - padding: 10px; -} -.swagger-section .swagger-ui-wrap form.form_box p.weak { - font-size: 0.8em; -} -.swagger-section .swagger-ui-wrap form.form_box p { - font-size: 0.9em; - padding: 0 0 15px; - color: #7e7b6d; -} -.swagger-section .swagger-ui-wrap form.form_box p a { - color: #646257; -} -.swagger-section .swagger-ui-wrap form.form_box p strong { - color: black; -} -.swagger-section .title { - font-style: bold; -} -.swagger-section .secondary_form { - display: none; -} -.swagger-section .main_image { - display: block; - margin-left: auto; - margin-right: auto; -} -.swagger-section .oauth_body { - margin-left: 100px; - margin-right: 100px; -} -.swagger-section .oauth_submit { - text-align: center; -} -.swagger-section .api-popup-dialog { - z-index: 10000; - position: absolute; - width: 500px; - background: #FFF; - padding: 20px; - border: 1px solid #ccc; - border-radius: 5px; - display: none; - font-size: 13px; - color: #777; -} -.swagger-section .api-popup-dialog .api-popup-title { - font-size: 24px; - padding: 10px 0; -} -.swagger-section .api-popup-dialog .api-popup-title { - font-size: 24px; - padding: 10px 0; -} -.swagger-section .api-popup-dialog p.error-msg { - padding-left: 5px; - padding-bottom: 5px; -} -.swagger-section .api-popup-dialog button.api-popup-authbtn { - height: 30px; -} -.swagger-section .api-popup-dialog button.api-popup-cancel { - height: 30px; -} -.swagger-section .api-popup-scopes { - padding: 10px 20px; -} -.swagger-section .api-popup-scopes li { - padding: 5px 0; - line-height: 20px; -} -.swagger-section .api-popup-scopes .api-scope-desc { - padding-left: 20px; - font-style: italic; -} -.swagger-section .api-popup-scopes li input { - position: relative; - top: 2px; -} -.swagger-section .api-popup-actions { - padding-top: 10px; -} -.swagger-section .access { - float: right; -} -.swagger-section .auth { - float: right; -} -.swagger-section #api_information_panel { - position: absolute; - background: #FFF; - border: 1px solid #ccc; - border-radius: 5px; - display: none; - font-size: 13px; - max-width: 300px; - line-height: 30px; - color: black; - padding: 5px; -} -.swagger-section #api_information_panel p .api-msg-enabled { - color: green; -} -.swagger-section #api_information_panel p .api-msg-disabled { - color: red; -} -.swagger-section .api-ic { - height: 18px; - vertical-align: middle; - display: inline-block; - background: url(../images/explorer_icons.png) no-repeat; -} -.swagger-section .ic-info { - background-position: 0 0; - width: 18px; - margin-top: -7px; - margin-left: 4px; -} -.swagger-section .ic-warning { - background-position: -60px 0; - width: 18px; - margin-top: -7px; - margin-left: 4px; -} -.swagger-section .ic-error { - background-position: -30px 0; - width: 18px; - margin-top: -7px; - margin-left: 4px; -} -.swagger-section .ic-off { - background-position: -90px 0; - width: 58px; - margin-top: -4px; - cursor: pointer; -} -.swagger-section .ic-on { - background-position: -160px 0; - width: 58px; - margin-top: -4px; - cursor: pointer; -} -.swagger-section #header { - background-color: #89bf04; - padding: 14px; -} -.swagger-section #header a#logo { - font-size: 1.5em; - font-weight: bold; - text-decoration: none; - background: transparent url(../images/logo_small.png) no-repeat left center; - padding: 20px 0 20px 40px; - color: white; -} -.swagger-section #header form#api_selector { - display: block; - clear: none; - float: right; -} -.swagger-section #header form#api_selector .input { - display: block; - clear: none; - float: left; - margin: 0 10px 0 0; -} -.swagger-section #header form#api_selector .input input#input_apiKey { - width: 200px; -} -.swagger-section #header form#api_selector .input input#input_baseUrl { - width: 400px; -} -.swagger-section #header form#api_selector .input a#explore { - display: block; - text-decoration: none; - font-weight: bold; - padding: 6px 8px; - font-size: 0.9em; - color: white; - background-color: #547f00; - -moz-border-radius: 4px; - -webkit-border-radius: 4px; - -o-border-radius: 4px; - -ms-border-radius: 4px; - -khtml-border-radius: 4px; - border-radius: 4px; -} -.swagger-section #header form#api_selector .input a#explore:hover { - background-color: #547f00; -} -.swagger-section #header form#api_selector .input input { - font-size: 0.9em; - padding: 3px; - margin: 0; -} -.swagger-section #content_message { - margin: 10px 15px; - font-style: italic; - color: #999999; -} -.swagger-section #message-bar { - min-height: 30px; - text-align: center; - padding-top: 10px; +.swagger-section .property-selector input[type="checkbox"] { + margin: 3px; } diff --git a/src/main/html/images/json_editor_integration.png b/src/main/html/images/json_editor_integration.png new file mode 100644 index 00000000000..faa85602bb3 Binary files /dev/null and b/src/main/html/images/json_editor_integration.png differ diff --git a/src/main/html/index.html b/src/main/html/index.html index 06c35c17658..6eb256e8b3b 100644 --- a/src/main/html/index.html +++ b/src/main/html/index.html @@ -12,6 +12,7 @@ + @@ -21,6 +22,7 @@ + @@ -81,7 +83,7 @@ log("Unable to Load SwaggerUI"); }, docExpansion: "none", - sorter: "alpha" + sorter: "alpha", }); function addApiKeyAuthorization() { diff --git a/src/main/javascript/SwaggerUi.js b/src/main/javascript/SwaggerUi.js index add0a67c585..718f055bfa8 100644 --- a/src/main/javascript/SwaggerUi.js +++ b/src/main/javascript/SwaggerUi.js @@ -61,6 +61,14 @@ window.SwaggerUi = Backbone.Router.extend({ return that.updateSwaggerUi(data); }); */ + //JSon Editor custom theming + JSONEditor.defaults.iconlibs.swagger = JSONEditor.AbstractIconLib.extend({ + mapping: { + collapse: 'collapse', + expand: 'expand' + }, + icon_prefix: 'swagger-' + }); }, // Set an option after initializing diff --git a/src/main/javascript/view/MainView.js b/src/main/javascript/view/MainView.js index e14793a7277..b1bf1a504b2 100644 --- a/src/main/javascript/view/MainView.js +++ b/src/main/javascript/view/MainView.js @@ -86,6 +86,14 @@ SwaggerUi.Views.MainView = Backbone.View.extend({ this.model.validatorUrl = window.location.protocol + '//online.swagger.io/validator'; } } + // JSonEditor requires type='object' to be present on defined types, we add it if it's missing + // is there any valid case were it should not be added ? + var def; + for(def in this.model.definitions){ + if (!this.model.definitions[def].type){ + this.model.definitions[def].type = 'object'; + } + } }, render: function () { @@ -146,6 +154,10 @@ SwaggerUi.Views.MainView = Backbone.View.extend({ addResource: function (resource, auths) { // Render a resource and add it to resources li resource.id = resource.id.replace(/\s/g, '_'); + + // Make all definitions available at the root of the resource so that they can + // be loaded by the JSonEditor + resource.definitions = this.model.definitions; var resourceView = new SwaggerUi.Views.ResourceView({ model: resource, router: this.router, diff --git a/src/main/javascript/view/OperationView.js b/src/main/javascript/view/OperationView.js index 97292c058c6..71079045a8a 100644 --- a/src/main/javascript/view/OperationView.js +++ b/src/main/javascript/view/OperationView.js @@ -253,12 +253,29 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({ addParameter: function (param, consumes) { // Render a parameter param.consumes = consumes; + // Copy this param JSON spec so that it will be available for JsonEditor + if(param.schema){ + $.extend(true, param.schema, this.model.definitions[param.type]); + param.schema.definitions = this.model.definitions; + // This is required for JsonEditor to display the root properly + if(!param.schema.type){ + param.schema.type = 'object'; + } + // This is the title that will be used by JsonEditor for the root + // Since we already display the parameter's name in the Parameter column + // We set this to space, we can't set it to null or space otherwise JsonEditor + // will replace it with the text "root" which won't look good on screen + if(!param.schema.title){ + param.schema.title = ' '; + } + } var paramView = new SwaggerUi.Views.ParameterView({ model: param, tagName: 'div', className: 'parameter-item', - readOnly: this.model.isReadOnly - }); + readOnly: this.model.isReadOnly, + swaggerOptions: this.options.swaggerOptions + }); $('.operation-params', $(this.el)).append(paramView.render().el); }, @@ -281,7 +298,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({ } form = $('.sandbox', $(this.el)); error_free = true; - form.find('input.required').each(function () { + form.find('input.required:visible').each(function () { $(this).removeClass('error'); if (jQuery.trim($(this).val()) === '') { $(this).addClass('error'); @@ -341,6 +358,14 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({ map[o.name] = val; } } + var pi; + for(pi = 0; pi < this.model.parameters.length; pi++){ + var p = this.model.parameters[pi]; + if( p.jsonEditor && p.jsonEditor.isEnabled()){ + var json = p.jsonEditor.getValue(); + map[p.name] = JSON.stringify(json); + } + } opts.responseContentType = $('div select[name=responseContentType]', $(this.el)).val(); opts.requestContentType = $('div select[name=parameterContentType]', $(this.el)).val(); $(".submit", $(this.el)).button("loading"); diff --git a/src/main/javascript/view/ParameterView.js b/src/main/javascript/view/ParameterView.js index bec51e42e4f..ea6ec981123 100644 --- a/src/main/javascript/view/ParameterView.js +++ b/src/main/javascript/view/ParameterView.js @@ -1,4 +1,29 @@ 'use strict'; +/* + * [TODO] defaultProperties is not take in the required properties into consideration, this implementation respects the specs of JSON Editor v0.7.22 + { + { + "type": "object", + "properties": { + "name": {"type": "string"}, + "age": {"type": "integer"} + }, + defaultProperties": ["name"] + } + */ +function setDefaultProperties(obj) { + if (obj instanceof Object) { + for (var k in obj){ + if(obj.hasOwnProperty("type") && obj.type == "object") { + obj.defaultProperties = obj.required ? obj.required : []; + } + // recursive call to setDefaultProperties + setDefaultProperties( obj[k] ); + } + } else { + // not an Object, break the recursion. + }; +} SwaggerUi.Views.ParameterView = Backbone.View.extend({ initialize: function(){ @@ -45,8 +70,48 @@ SwaggerUi.Views.ParameterView = Backbone.View.extend({ var template = this.template(); $(this.el).html(template(this.model)); + var signatureModel = { + sampleJSON: this.model.sampleJSON, + isParam: true, + signature: this.model.signature, + defaultRendering: this.model.defaultRendering + }; + var isParam = false; + if( this.options.swaggerOptions.jsonEditor && this.model.isBody && this.model.schema){ + var jsonEditorOptions = this.options.swaggerOptions.jsonEditorOptions; + var $self = $(this.el); + if (jsonEditorOptions && jsonEditorOptions.noDefaultProperties) setDefaultProperties(this.model.schema); + this.model.jsonEditor = + /* global JSONEditor */ + new JSONEditor($('.editor_holder', $self)[0], + {schema: this.model.schema, startval : this.model.default, + ajax:true, + disable_properties:jsonEditorOptions && jsonEditorOptions.disableProperties, + disable_edit_json:jsonEditorOptions && jsonEditorOptions.disableEditJson, + remove_empty_properties:jsonEditorOptions && jsonEditorOptions.removeEmptyProperties, + iconlib: 'swagger' }); + // This is so that the signature can send back the sample to the json editor + // TODO: SignatureView should expose an event "onSampleClicked" instead + signatureModel.jsonEditor = this.model.jsonEditor; + $('.body-textarea', $self).hide(); + $('.editor_holder', $self).show(); + $('.parameter-content-type', $self) + .change(function(e){ + if(e.target.value === 'application/xml'){ + $('.body-textarea', $self).show(); + $('.editor_holder', $self).hide(); + this.model.jsonEditor.disable(); + } + else { + $('.body-textarea', $self).hide(); + $('.editor_holder', $self).show(); + this.model.jsonEditor.enable(); + } + }); + } + if (this.model.isBody) { isParam = true; } diff --git a/src/main/javascript/view/ResourceView.js b/src/main/javascript/view/ResourceView.js index 8d3ea85a6e2..aa5e85b8ae4 100644 --- a/src/main/javascript/view/ResourceView.js +++ b/src/main/javascript/view/ResourceView.js @@ -33,6 +33,8 @@ SwaggerUi.Views.ResourceView = Backbone.View.extend({ operation.nickname = id; operation.parentId = this.model.id; + operation.definitions = this.model.definitions; // make Json Schema available for JSonEditor in this operation + this.addOperation(operation); } diff --git a/src/main/javascript/view/SignatureView.js b/src/main/javascript/view/SignatureView.js index 3613a89e869..7abb8a57891 100644 --- a/src/main/javascript/view/SignatureView.js +++ b/src/main/javascript/view/SignatureView.js @@ -24,6 +24,10 @@ SwaggerUi.Views.SignatureView = Backbone.View.extend({ var textArea = $('textarea', $(this.el.parentNode.parentNode.parentNode)); if ($.trim(textArea.val()) === '') { textArea.val(this.model.sampleJSON); + // TODO move this code outside of the view and expose an event instead + if( this.model.jsonEditor && this.model.jsonEditor.isEnabled()){ + this.model.jsonEditor.setValue(JSON.parse(this.model.sampleJSON)); + } } } } diff --git a/src/main/less/screen.less b/src/main/less/screen.less index 4867dcc74f0..59de2b5340c 100644 --- a/src/main/less/screen.less +++ b/src/main/less/screen.less @@ -1,139 +1,13 @@ -@import 'src/main/less/highlight_default.less'; -@import 'src/main/less/specs.less'; -@import 'src/main/less/auth.less'; - .swagger-section { - -.access { - float: right; -} - -.auth { - float: right; -} - -#api_information_panel { - position: absolute; - background: #FFF; - border: 1px solid #ccc; - border-radius: 5px; - display: none; - font-size: 13px; - max-width: 300px; - line-height: 30px; - color: black; - padding: 5px; - p { - .api-msg-enabled { - color: green; - } - .api-msg-disabled { - color: red; - } + .swagger-collapse:before { + content: "-"; } -} - -.api-ic { - height: 18px; - vertical-align: middle; - display: inline-block; - background: url(../images/explorer_icons.png) no-repeat; -} -.ic-info { - background-position: 0 0; - width: 18px; - margin-top: -7px; - margin-left: 4px; -} -.ic-warning { - background-position: -60px 0; - width: 18px; - margin-top: -7px; - margin-left: 4px; -} -.ic-error { - background-position: -30px 0; - width: 18px; - margin-top: -7px; - margin-left: 4px; -} -.ic-off { - background-position: -90px 0; - width: 58px; - margin-top: -4px; - cursor: pointer; -} -.ic-on { - background-position: -160px 0; - width: 58px; - margin-top: -4px; - cursor: pointer; -} - -#header { - background-color: #89bf04; - padding: 14px; - a#logo { - font-size: 1.5em; - font-weight: bold; - text-decoration: none; - background: transparent url(../images/logo_small.png) no-repeat left center; - padding: 20px 0 20px 40px; - color: white; - } - form#api_selector { - display: block; - clear: none; - float: right; - .input { - display: block; - clear: none; - float: left; - margin: 0 10px 0 0; - input#input_apiKey { - width: 200px; - } - input#input_baseUrl { - width: 400px; - } - a#explore { - display: block; - text-decoration: none; - font-weight: bold; - padding: 6px 8px; - font-size: 0.9em; - color: white; - background-color: #547f00; - -moz-border-radius: 4px; - -webkit-border-radius: 4px; - -o-border-radius: 4px; - -ms-border-radius: 4px; - -khtml-border-radius: 4px; - border-radius: 4px; - } - a#explore:hover { - background-color: #547f00; - } - input { - font-size: 0.9em; - padding: 3px; - margin: 0; - } - } + .swagger-expand:before { + content: "+"; } -} - -#content_message { - margin: 10px 15px; - font-style: italic; - color: #999999; -} -#message-bar { - min-height: 30px; - text-align: center; - padding-top: 10px; + .property-selector input[type="checkbox"] { + margin: 3px; + } } - -} \ No newline at end of file diff --git a/src/main/less/specs.less b/src/main/less/specs.less index 309a8b882c3..aefbf58f498 100644 --- a/src/main/less/specs.less +++ b/src/main/less/specs.less @@ -356,6 +356,18 @@ font-family: "Droid Sans", sans-serif; font-weight: bold; } + /* JSONEditor specific styling */ + .editor_holder { + font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace; + font-size: 0.9em; + label { + font-weight:normal!important; /* JSONEditor uses bold by default for all labels, we revert that back to normal to not give the impression that by default fields are required */ + } + } + + .editor_holder label.required { + font-weight:bold!important; + } .heading_with_menu { float: none; diff --git a/src/main/template/main.handlebars b/src/main/template/main.handlebars index d59a046ba3f..152ba34c61c 100644 --- a/src/main/template/main.handlebars +++ b/src/main/template/main.handlebars @@ -8,14 +8,14 @@
    -
    -
    diff --git a/src/main/template/param.handlebars b/src/main/template/param.handlebars index 2fc67ae0813..601a43477ba 100644 --- a/src/main/template/param.handlebars +++ b/src/main/template/param.handlebars @@ -7,10 +7,13 @@
    {{else}} {{#if default}} - +
    + +
    {{else}} - + +
    {{/if}} {{/if}} @@ -30,9 +33,9 @@
    {{else}} {{#if default}} - + {{else}} - + {{/if}} {{/if}}
    diff --git a/src/main/template/param_list.handlebars b/src/main/template/param_list.handlebars index ade02054df8..c51fdef75ca 100644 --- a/src/main/template/param_list.handlebars +++ b/src/main/template/param_list.handlebars @@ -1,7 +1,7 @@
    {{name}}
    - {{#if required}} {{else}} {{#if default}} diff --git a/src/main/template/param_readonly.handlebars b/src/main/template/param_readonly.handlebars index 8df453a5960..045b8ad3997 100644 --- a/src/main/template/param_readonly.handlebars +++ b/src/main/template/param_readonly.handlebars @@ -2,7 +2,7 @@
    {{#if isBody}} - +
    {{else}} {{#if default}} diff --git a/src/main/template/param_readonly_required.handlebars b/src/main/template/param_readonly_required.handlebars index db06b5388da..7a7d25c5a62 100644 --- a/src/main/template/param_readonly_required.handlebars +++ b/src/main/template/param_readonly_required.handlebars @@ -2,7 +2,7 @@
    {{#if isBody}} - +
    {{else}} {{#if default}} diff --git a/src/main/template/param_required.handlebars b/src/main/template/param_required.handlebars index bc77422c1be..15a684ae3e8 100644 --- a/src/main/template/param_required.handlebars +++ b/src/main/template/param_required.handlebars @@ -5,21 +5,24 @@ {{else}} {{#if default}} - +
    +
    {{else}} - + +
    +
    {{/if}} {{/if}} {{else}} {{#if isFile}} - + {{else}} {{#if default}} - + {{else}} - + {{/if}} {{/if}} {{/if}} diff --git a/src/main/template/parameter_content_type.handlebars b/src/main/template/parameter_content_type.handlebars index 90937776624..8b3d34f1d66 100644 --- a/src/main/template/parameter_content_type.handlebars +++ b/src/main/template/parameter_content_type.handlebars @@ -1,6 +1,6 @@
    - {{#if consumes}} {{#each consumes}} diff --git a/src/main/template/response_content_type.handlebars b/src/main/template/response_content_type.handlebars index dadd29e6f54..119bba944a4 100644 --- a/src/main/template/response_content_type.handlebars +++ b/src/main/template/response_content_type.handlebars @@ -2,7 +2,7 @@
    Response Type
    - {{#if produces}} {{#each produces}}