$(function() { // Helper function for vertically aligning DOM elements // http://www.seodenver.com/simple-vertical-align-plugin-for-jquery/ $.fn.vAlign = function() { return this.each(function(i){ var ah = $(this).height(); var ph = $(this).parent().height(); var mh = (ph - ah) / 2; $(this).css('margin-top', mh); }); }; $.fn.stretchFormtasticInputWidthToParent = function() { return this.each(function(i){ var p_width = $(this).closest("form").innerWidth(); var p_padding = parseInt($(this).closest("form").css('padding-left') ,10) + parseInt($(this).closest("form").css('padding-right'), 10); var this_padding = parseInt($(this).css('padding-left'), 10) + parseInt($(this).css('padding-right'), 10); $(this).css('width', p_width - p_padding - this_padding); }); }; $('form.formtastic li.string input, form.formtastic textarea').stretchFormtasticInputWidthToParent(); // Vertically center these paragraphs // Parent may need a min-height for this to work.. $('ul.downplayed li div.content p').vAlign(); // When a sandbox form is submitted.. $("form.sandbox").submit(function(){ var error_free = true; // Cycle through the forms required inputs $(this).find("input.required").each(function() { // Remove any existing error styles from the input $(this).removeClass('error'); // Tack the error style on if the input is empty.. if ($(this).val() == '') { $(this).addClass('error'); $(this).wiggle(); error_free = false; } }); return error_free; }); }); function clippyCopiedCallback(a) { $('#api_key_copied').fadeIn().delay(1000).fadeOut(); // var b = $("#clippy_tooltip_" + a); // b.length != 0 && (b.attr("title", "copied!").trigger("tipsy.reload"), setTimeout(function() { // b.attr("title", "copy to clipboard") // }, // 500)) } // Logging function that accounts for browsers that don't have window.console function log() { if (window.console) console.log.apply(console,arguments); } // Handle browsers that do console incorrectly (IE9 and below, see http://stackoverflow.com/a/5539378/7913) if (Function.prototype.bind && console && typeof console.log == "object") { [ "log","info","warn","error","assert","dir","clear","profile","profileEnd" ].forEach(function (method) { console[method] = this.bind(console[method], console); }, Function.prototype.call); } var Docs = { shebang: function() { // If shebang has an operation nickname in it.. // e.g. /docs/#!/words/get_search var fragments = $.param.fragment().split('/'); fragments.shift(); // get rid of the bang switch (fragments.length) { case 1: // Expand all operations for the resource and scroll to it // log('shebang resource:' + fragments[0]); var dom_id = 'resource_' + fragments[0]; Docs.expandEndpointListForResource(fragments[0]); $("#"+dom_id).slideto({highlight: false}); break; case 2: // Refer to the endpoint DOM element, e.g. #words_get_search // log('shebang endpoint: ' + fragments.join('_')); // Expand Resource Docs.expandEndpointListForResource(fragments[0]); $("#"+dom_id).slideto({highlight: false}); // Expand operation var li_dom_id = fragments.join('_'); var li_content_dom_id = li_dom_id + "_content"; // log("li_dom_id " + li_dom_id); // log("li_content_dom_id " + li_content_dom_id); Docs.expandOperation($('#'+li_content_dom_id)); $('#'+li_dom_id).slideto({highlight: false}); break; } }, toggleEndpointListForResource: function(resource) { var elem = $('li#resource_' + Docs.escapeResourceName(resource) + ' ul.endpoints'); if (elem.is(':visible')) { Docs.collapseEndpointListForResource(resource); } else { Docs.expandEndpointListForResource(resource); } }, // Expand resource expandEndpointListForResource: function(resource) { var resource = Docs.escapeResourceName(resource); if (resource == '') { $('.resource ul.endpoints').slideDown(); return; } $('li#resource_' + resource).addClass('active'); var elem = $('li#resource_' + resource + ' ul.endpoints'); elem.slideDown(); }, // Collapse resource and mark as explicitly closed collapseEndpointListForResource: function(resource) { var resource = Docs.escapeResourceName(resource); $('li#resource_' + resource).removeClass('active'); var elem = $('li#resource_' + resource + ' ul.endpoints'); elem.slideUp(); }, expandOperationsForResource: function(resource) { // Make sure the resource container is open.. Docs.expandEndpointListForResource(resource); if (resource == '') { $('.resource ul.endpoints li.operation div.content').slideDown(); return; } $('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() { Docs.expandOperation($(this)); }); }, collapseOperationsForResource: function(resource) { // Make sure the resource container is open.. Docs.expandEndpointListForResource(resource); $('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() { Docs.collapseOperation($(this)); }); }, escapeResourceName: function(resource) { return resource.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g, "\\$&"); }, expandOperation: function(elem) { elem.slideDown(); }, collapseOperation: function(elem) { elem.slideUp(); } }; (function() { var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; templates['content_type'] = template(function (Handlebars,depth0,helpers,partials,data) { helpers = helpers || Handlebars.helpers; var buffer = "", stack1, stack2, foundHelper, tmp1, self=this, functionType="function", helperMissing=helpers.helperMissing, undef=void 0; function program1(depth0,data) { var buffer = "", stack1, stack2; buffer += "\n "; foundHelper = helpers.produces; stack1 = foundHelper || depth0.produces; stack2 = helpers.each; tmp1 = self.program(2, program2, data); tmp1.hash = {}; tmp1.fn = tmp1; tmp1.inverse = self.noop; stack1 = stack2.call(depth0, stack1, tmp1); if(stack1 || stack1 === 0) { buffer += stack1; } buffer += "\n"; return buffer;} function program2(depth0,data) { var buffer = "", stack1; buffer += "\n \n "; return buffer;} function program4(depth0,data) { return "\n \n";} buffer += "\n\n"; return buffer;}); })(); (function() { var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; templates['main'] = template(function (Handlebars,depth0,helpers,partials,data) { helpers = helpers || Handlebars.helpers; var buffer = "", stack1, stack2, foundHelper, tmp1, self=this, functionType="function", helperMissing=helpers.helperMissing, undef=void 0, escapeExpression=this.escapeExpression; function program1(depth0,data) { var buffer = "", stack1; buffer += "\n , api version: "; foundHelper = helpers.apiVersion; stack1 = foundHelper || depth0.apiVersion; if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); } else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "apiVersion", { hash: {} }); } buffer += escapeExpression(stack1) + "\n "; return buffer;} buffer += "\n
"; foundHelper = helpers.notes; stack1 = foundHelper || depth0.notes; if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); } else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "notes", { hash: {} }); } if(stack1 || stack1 === 0) { buffer += stack1; } buffer += "
\n "; return buffer;} function program3(depth0,data) { return "\n\n
Parameter | \nValue | \nDescription | \nData Type | \n
---|
HTTP Status Code | \nReason | \n
---|
";
foundHelper = helpers.sampleJSON;
stack1 = foundHelper || depth0.sampleJSON;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "sampleJSON", { hash: {} }); }
buffer += escapeExpression(stack1) + "
\n \n " + invocationUrl + ""); $(".response_throbber", $(this.el)).show(); obj = { type: this.model.httpMethod, url: invocationUrl, headers: headerParams, data: bodyParam, contentType: consumes, dataType: 'json', processData: false, error: function(xhr, textStatus, error) { return _this.showErrorStatus(xhr, textStatus, error); }, success: function(data) { return _this.showResponse(data); }, complete: function(data) { return _this.showCompleteStatus(data); } }; paramContentTypeField = $("td select[name=contentType]", $(this.el)).val(); if (paramContentTypeField) { obj.contentType = paramContentTypeField; } log('content type = ' + obj.contentType); if (!obj.data || (obj.type === 'GET' || obj.type === 'DELETE')) { obj.contentType = false; } log('content type is now = ' + obj.contentType); responseContentTypeField = $('.content > .content-type > div > select[name=contentType]', $(this.el)).val(); if (responseContentTypeField) { obj.headers = obj.headers != null ? obj.headers : {}; obj.headers.accept = responseContentTypeField; } jQuery.ajax(obj); return false; } }; OperationView.prototype.hideResponse = function(e) { if (e != null) { e.preventDefault(); } $(".response", $(this.el)).slideUp(); return $(".response_hider", $(this.el)).fadeOut(); }; OperationView.prototype.showResponse = function(response) { var prettyJson; prettyJson = JSON.stringify(response, null, "\t").replace(/\n/g, "
').text(JSON.stringify(JSON.parse(data.responseText), null, 2));
pre = $('').append(code);
} catch (error) {
code = $('
').text(this.formatXml(data.responseText));
pre = $('').append(code);
}
response_body = pre;
$(".response_code", $(this.el)).html("" + data.status + ""); $(".response_body", $(this.el)).html(response_body); $(".response_headers", $(this.el)).html("
" + data.getAllResponseHeaders() + ""); $(".response", $(this.el)).slideDown(); $(".response_hider", $(this.el)).show(); $(".response_throbber", $(this.el)).hide(); return hljs.highlightBlock($('.response_body', $(this.el))[0]); }; OperationView.prototype.toggleOperationContent = function() { var elem; elem = $('#' + Docs.escapeResourceName(this.model.resourceName) + "_" + this.model.nickname + "_" + this.model.httpMethod + "_" + this.model.number + "_content"); if (elem.is(':visible')) { return Docs.collapseOperation(elem); } else { return Docs.expandOperation(elem); } }; return OperationView; })(Backbone.View); StatusCodeView = (function(_super) { __extends(StatusCodeView, _super); function StatusCodeView() { return StatusCodeView.__super__.constructor.apply(this, arguments); } StatusCodeView.prototype.initialize = function() {}; StatusCodeView.prototype.render = function() { var template; template = this.template(); $(this.el).html(template(this.model)); return this; }; StatusCodeView.prototype.template = function() { return Handlebars.templates.status_code; }; return StatusCodeView; })(Backbone.View); ParameterView = (function(_super) { __extends(ParameterView, _super); function ParameterView() { return ParameterView.__super__.constructor.apply(this, arguments); } ParameterView.prototype.initialize = function() {}; ParameterView.prototype.render = function() { var contentTypeModel, contentTypeView, signatureModel, signatureView, template; if (this.model.paramType === 'body') { this.model.isBody = true; } if (this.model.dataType === 'file') { this.model.isFile = true; } template = this.template(); $(this.el).html(template(this.model)); signatureModel = { sampleJSON: this.model.sampleJSON, isParam: true, signature: this.model.signature }; if (this.model.sampleJSON) { signatureView = new SignatureView({ model: signatureModel, tagName: 'div' }); $('.model-signature', $(this.el)).append(signatureView.render().el); } else { $('.model-signature', $(this.el)).html(this.model.signature); } contentTypeModel = { isParam: false }; if (this.model.supportedContentTypes) { contentTypeModel.produces = this.model.supportedContentTypes; } if (this.model.produces) { contentTypeModel.produces = this.model.produces; } contentTypeView = new ContentTypeView({ model: contentTypeModel }); $('.content-type', $(this.el)).append(contentTypeView.render().el); return this; }; ParameterView.prototype.template = function() { if (this.model.isList) { return Handlebars.templates.param_list; } else { if (this.options.readOnly) { if (this.model.required) { return Handlebars.templates.param_readonly_required; } else { return Handlebars.templates.param_readonly; } } else { if (this.model.required) { return Handlebars.templates.param_required; } else { return Handlebars.templates.param; } } } }; return ParameterView; })(Backbone.View); SignatureView = (function(_super) { __extends(SignatureView, _super); function SignatureView() { return SignatureView.__super__.constructor.apply(this, arguments); } SignatureView.prototype.events = { 'click a.description-link': 'switchToDescription', 'click a.snippet-link': 'switchToSnippet', 'mousedown .snippet': 'snippetToTextArea' }; SignatureView.prototype.initialize = function() {}; SignatureView.prototype.render = function() { var template; template = this.template(); $(this.el).html(template(this.model)); this.switchToDescription(); this.isParam = this.model.isParam; if (this.isParam) { $('.notice', $(this.el)).text('Click to set as parameter value'); } return this; }; SignatureView.prototype.template = function() { return Handlebars.templates.signature; }; SignatureView.prototype.switchToDescription = function(e) { if (e != null) { e.preventDefault(); } $(".snippet", $(this.el)).hide(); $(".description", $(this.el)).show(); $('.description-link', $(this.el)).addClass('selected'); return $('.snippet-link', $(this.el)).removeClass('selected'); }; SignatureView.prototype.switchToSnippet = function(e) { if (e != null) { e.preventDefault(); } $(".description", $(this.el)).hide(); $(".snippet", $(this.el)).show(); $('.snippet-link', $(this.el)).addClass('selected'); return $('.description-link', $(this.el)).removeClass('selected'); }; SignatureView.prototype.snippetToTextArea = function(e) { var textArea; if (this.isParam) { if (e != null) { e.preventDefault(); } textArea = $('textarea', $(this.el.parentNode.parentNode.parentNode)); if ($.trim(textArea.val()) === '') { return textArea.val(this.model.sampleJSON); } } }; return SignatureView; })(Backbone.View); ContentTypeView = (function(_super) { __extends(ContentTypeView, _super); function ContentTypeView() { return ContentTypeView.__super__.constructor.apply(this, arguments); } ContentTypeView.prototype.initialize = function() {}; ContentTypeView.prototype.render = function() { var template; template = this.template(); $(this.el).html(template(this.model)); this.isParam = this.model.isParam; if (this.isParam) { $('label[for=contentType]', $(this.el)).text('Parameter content type:'); } else { $('label[for=contentType]', $(this.el)).text('Response Content Type'); } return this; }; ContentTypeView.prototype.template = function() { return Handlebars.templates.content_type; }; return ContentTypeView; })(Backbone.View); }).call(this);