github.com/qubitproducts/logspray@v0.2.14/server/swagger-ui/src/main/javascript/view/SignatureView.js (about)

     1  'use strict';
     2  
     3  SwaggerUi.Views.SignatureView = Backbone.View.extend({
     4    events: {
     5      'click a.description-link'       : 'switchToDescription',
     6      'click a.snippet-link'           : 'switchToSnippet',
     7      'mousedown .snippet_json'          : 'jsonSnippetMouseDown',
     8      'mousedown .snippet_xml'          : 'xmlSnippetMouseDown'
     9    },
    10  
    11    initialize: function () {
    12    },
    13  
    14    render: function(){
    15  
    16      $(this.el).html(Handlebars.templates.signature(this.model));
    17  
    18      if (this.model.defaultRendering === 'model') {
    19        this.switchToDescription();
    20      } else {
    21        this.switchToSnippet();
    22      }
    23  
    24      return this;
    25    },
    26  
    27    // handler for show signature
    28    switchToDescription: function(e){
    29      if (e) { e.preventDefault(); }
    30  
    31      $('.snippet', $(this.el)).hide();
    32      $('.description', $(this.el)).show();
    33      $('.description-link', $(this.el)).addClass('selected');
    34      $('.snippet-link', $(this.el)).removeClass('selected');
    35    },
    36  
    37    // handler for show sample
    38    switchToSnippet: function(e){
    39      if (e) { e.preventDefault(); }
    40  
    41      $('.snippet', $(this.el)).show();
    42      $('.description', $(this.el)).hide();
    43      $('.snippet-link', $(this.el)).addClass('selected');
    44      $('.description-link', $(this.el)).removeClass('selected');
    45    },
    46  
    47    // handler for snippet to text area
    48    snippetToTextArea: function(val) {
    49      var textArea = $('textarea', $(this.el.parentNode.parentNode.parentNode));
    50  
    51      // Fix for bug in IE 10/11 which causes placeholder text to be copied to "value"
    52      if ($.trim(textArea.val()) === '' || textArea.prop('placeholder') === textArea.val()) {
    53        textArea.val(val);
    54        // TODO move this code outside of the view and expose an event instead
    55        if( this.model.jsonEditor && this.model.jsonEditor.isEnabled()){
    56          this.model.jsonEditor.setValue(JSON.parse(this.model.sampleJSON));
    57        }
    58      }
    59    },
    60  
    61    jsonSnippetMouseDown: function (e) {
    62      if (this.model.isParam) {
    63        if (e) { e.preventDefault(); }
    64  
    65        this.snippetToTextArea(this.model.sampleJSON);
    66      }
    67    },
    68  
    69    xmlSnippetMouseDown: function (e) {
    70      if (this.model.isParam) {
    71        if (e) { e.preventDefault(); }
    72  
    73        this.snippetToTextArea(this.model.sampleXML);
    74      }
    75    }
    76  });