Convert view/SignatureView.coffee
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
class SignatureView extends Backbone.View
|
||||
events: {
|
||||
'click a.description-link' : 'switchToDescription'
|
||||
'click a.snippet-link' : 'switchToSnippet'
|
||||
'mousedown .snippet' : 'snippetToTextArea'
|
||||
}
|
||||
|
||||
initialize: ->
|
||||
|
||||
render: ->
|
||||
template = @template()
|
||||
$(@el).html(template(@model))
|
||||
|
||||
@switchToSnippet()
|
||||
|
||||
@isParam = @model.isParam
|
||||
|
||||
if @isParam
|
||||
$('.notice', $(@el)).text('Click to set as parameter value')
|
||||
|
||||
@
|
||||
|
||||
template: ->
|
||||
Handlebars.templates.signature
|
||||
|
||||
# handler for show signature
|
||||
switchToDescription: (e) ->
|
||||
e?.preventDefault()
|
||||
$(".snippet", $(@el)).hide()
|
||||
$(".description", $(@el)).show()
|
||||
$('.description-link', $(@el)).addClass('selected')
|
||||
$('.snippet-link', $(@el)).removeClass('selected')
|
||||
|
||||
# handler for show sample
|
||||
switchToSnippet: (e) ->
|
||||
e?.preventDefault()
|
||||
$(".description", $(@el)).hide()
|
||||
$(".snippet", $(@el)).show()
|
||||
$('.snippet-link', $(@el)).addClass('selected')
|
||||
$('.description-link', $(@el)).removeClass('selected')
|
||||
|
||||
# handler for snippet to text area
|
||||
snippetToTextArea: (e) ->
|
||||
if @isParam
|
||||
e?.preventDefault()
|
||||
textArea = $('textarea', $(@el.parentNode.parentNode.parentNode))
|
||||
if $.trim(textArea.val()) == ''
|
||||
textArea.val(@model.sampleJSON)
|
||||
|
||||
|
||||
|
||||
60
src/main/coffeescript/view/SignatureView.js
Normal file
60
src/main/coffeescript/view/SignatureView.js
Normal file
@@ -0,0 +1,60 @@
|
||||
'use strict';
|
||||
|
||||
var SignatureView = Backbone.View.extend({
|
||||
events: {
|
||||
'click a.description-link' : 'switchToDescription',
|
||||
'click a.snippet-link' : 'switchToSnippet',
|
||||
'mousedown .snippet' : 'snippetToTextArea'
|
||||
},
|
||||
|
||||
initialize: function () {
|
||||
|
||||
},
|
||||
|
||||
render: function(){
|
||||
|
||||
$(this.el).html(Handlebars.templates.signature(this.model));
|
||||
|
||||
this.switchToSnippet();
|
||||
|
||||
this.isParam = this.model.isParam;
|
||||
|
||||
if (this.isParam) {
|
||||
$('.notice', $(this.el)).text('Click to set as parameter value');
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
// handler for show signature
|
||||
switchToDescription: function(e){
|
||||
if (e) { e.preventDefault(); }
|
||||
|
||||
$('.snippet', $(this.el)).hide();
|
||||
$('.description', $(this.el)).show();
|
||||
$('.description-link', $(this.el)).addClass('selected');
|
||||
$('.snippet-link', $(this.el)).removeClass('selected');
|
||||
},
|
||||
|
||||
// handler for show sample
|
||||
switchToSnippet: function(e){
|
||||
if (e) { e.preventDefault(); }
|
||||
|
||||
$('.description', $(this.el)).hide();
|
||||
$('.snippet', $(this.el)).show();
|
||||
$('.snippet-link', $(this.el)).addClass('selected');
|
||||
$('.description-link', $(this.el)).removeClass('selected');
|
||||
},
|
||||
|
||||
// handler for snippet to text area
|
||||
snippetToTextArea: function(e) {
|
||||
if (this.isParam) {
|
||||
if (e) { e.preventDefault(); }
|
||||
|
||||
var textArea = $('textarea', $(this.el.parentNode.parentNode.parentNode));
|
||||
if ($.trim(textArea.val()) === '') {
|
||||
textArea.val(this.model.sampleJSON);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user