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

     1  'use strict';
     2  
     3  
     4  $(function() {
     5  
     6  	// Helper function for vertically aligning DOM elements
     7  	// http://www.seodenver.com/simple-vertical-align-plugin-for-jquery/
     8  	$.fn.vAlign = function() {
     9  		return this.each(function(){
    10  			var ah = $(this).height();
    11  			var ph = $(this).parent().height();
    12  			var mh = (ph - ah) / 2;
    13  			$(this).css('margin-top', mh);
    14  		});
    15  	};
    16  
    17  	$.fn.stretchFormtasticInputWidthToParent = function() {
    18  		return this.each(function(){
    19  			var p_width = $(this).closest("form").innerWidth();
    20  			var p_padding = parseInt($(this).closest("form").css('padding-left') ,10) + parseInt($(this).closest('form').css('padding-right'), 10);
    21  			var this_padding = parseInt($(this).css('padding-left'), 10) + parseInt($(this).css('padding-right'), 10);
    22  			$(this).css('width', p_width - p_padding - this_padding);
    23  		});
    24  	};
    25  
    26  	$('form.formtastic li.string input, form.formtastic textarea').stretchFormtasticInputWidthToParent();
    27  
    28  	// Vertically center these paragraphs
    29  	// Parent may need a min-height for this to work..
    30  	$('ul.downplayed li div.content p').vAlign();
    31  
    32  	// When a sandbox form is submitted..
    33  	$("form.sandbox").submit(function(){
    34  
    35  		var error_free = true;
    36  
    37  		// Cycle through the forms required inputs
    38   		$(this).find("input.required").each(function() {
    39  
    40  			// Remove any existing error styles from the input
    41  			$(this).removeClass('error');
    42  
    43  			// Tack the error style on if the input is empty..
    44  			if ($(this).val() === '') {
    45  				$(this).addClass('error');
    46  				$(this).wiggle();
    47  				error_free = false;
    48  			}
    49  
    50  		});
    51  
    52  		return error_free;
    53  	});
    54  
    55  });
    56  
    57  function clippyCopiedCallback() {
    58    $('#api_key_copied').fadeIn().delay(1000).fadeOut();
    59  
    60    // var b = $("#clippy_tooltip_" + a);
    61    // b.length != 0 && (b.attr("title", "copied!").trigger("tipsy.reload"), setTimeout(function() {
    62    //   b.attr("title", "copy to clipboard")
    63    // },
    64    // 500))
    65  }
    66  
    67  // Logging function that accounts for browsers that don't have window.console
    68  function log(){
    69    log.history = log.history || [];
    70    log.history.push(arguments);
    71    if(this.console){
    72      console.log( Array.prototype.slice.call(arguments)[0] );
    73    }
    74  }
    75  
    76  // Handle browsers that do console incorrectly (IE9 and below, see http://stackoverflow.com/a/5539378/7913)
    77  if (Function.prototype.bind && console && typeof console.log === "object") {
    78      [
    79        "log","info","warn","error","assert","dir","clear","profile","profileEnd"
    80      ].forEach(function (method) {
    81          console[method] = this.bind(console[method], console);
    82      }, Function.prototype.call);
    83  }
    84  
    85  window.Docs = {
    86  
    87  	shebang: function() {
    88  
    89  		// If shebang has an operation nickname in it..
    90  		// e.g. /docs/#!/words/get_search
    91  		var fragments = $.param.fragment().split('/');
    92  		fragments.shift(); // get rid of the bang
    93  
    94  		switch (fragments.length) {
    95  			case 1:
    96          if (fragments[0].length > 0) { // prevent matching "#/"
    97            // Expand all operations for the resource and scroll to it
    98            var dom_id = 'resource_' + fragments[0];
    99  
   100            Docs.expandEndpointListForResource(fragments[0]);
   101            $("#"+dom_id).slideto({highlight: false});
   102          }
   103  				break;
   104  			case 2:
   105  				// Refer to the endpoint DOM element, e.g. #words_get_search
   106  
   107          // Expand Resource
   108          Docs.expandEndpointListForResource(fragments[0]);
   109          $("#"+dom_id).slideto({highlight: false});
   110  
   111              // Expand operation
   112              var li_dom_id = fragments.join('_');
   113              var li_content_dom_id = li_dom_id + "_content";
   114  
   115  
   116              Docs.expandOperation($('#'+li_content_dom_id));
   117              $('#'+li_dom_id).slideto({highlight: false});
   118              break;
   119  		}
   120  	},
   121  
   122  	toggleEndpointListForResource: function(resource) {
   123  		var elem = $('li#resource_' + Docs.escapeResourceName(resource) + ' ul.endpoints');
   124  		if (elem.is(':visible')) {
   125  			$.bbq.pushState('#/', 2);
   126  			Docs.collapseEndpointListForResource(resource);
   127  		} else {
   128              $.bbq.pushState('#/' + resource, 2);
   129  			Docs.expandEndpointListForResource(resource);
   130  		}
   131  	},
   132  
   133  	// Expand resource
   134  	expandEndpointListForResource: function(resource) {
   135  		var resource = Docs.escapeResourceName(resource);
   136  		if (resource == '') {
   137  			$('.resource ul.endpoints').slideDown();
   138  			return;
   139  		}
   140  
   141  		$('li#resource_' + resource).addClass('active');
   142  
   143  		var elem = $('li#resource_' + resource + ' ul.endpoints');
   144  		elem.slideDown();
   145  	},
   146  
   147  	// Collapse resource and mark as explicitly closed
   148  	collapseEndpointListForResource: function(resource) {
   149  		var resource = Docs.escapeResourceName(resource);
   150  		if (resource == '') {
   151  			$('.resource ul.endpoints').slideUp();
   152  			return;
   153  		}
   154  
   155  		$('li#resource_' + resource).removeClass('active');
   156  
   157  		var elem = $('li#resource_' + resource + ' ul.endpoints');
   158  		elem.slideUp();
   159  	},
   160  
   161  	expandOperationsForResource: function(resource) {
   162  		// Make sure the resource container is open..
   163  		Docs.expandEndpointListForResource(resource);
   164  
   165  		if (resource == '') {
   166  			$('.resource ul.endpoints li.operation div.content').slideDown();
   167  			return;
   168  		}
   169  
   170  		$('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() {
   171  			Docs.expandOperation($(this));
   172  		});
   173  	},
   174  
   175  	collapseOperationsForResource: function(resource) {
   176  		// Make sure the resource container is open..
   177  		Docs.expandEndpointListForResource(resource);
   178  
   179  		if (resource == '') {
   180  			$('.resource ul.endpoints li.operation div.content').slideUp();
   181  			return;
   182  		}
   183  
   184  		$('li#resource_' + Docs.escapeResourceName(resource) + ' li.operation div.content').each(function() {
   185  			Docs.collapseOperation($(this));
   186  		});
   187  	},
   188  
   189  	escapeResourceName: function(resource) {
   190  		return resource.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g, "\\$&");
   191  	},
   192  
   193  	expandOperation: function(elem) {
   194  		elem.slideDown();
   195  	},
   196  
   197  	collapseOperation: function(elem) {
   198  		elem.slideUp();
   199  	}
   200  };