Files
spring-session/js/projectDocumentationWidget.js
Rob Winch b02094230f Merge spring-projects/gh-pages (#748)
* Display Pivotal Education related courseware

This change adds a new "Related Courseware" section in the side
container; this section lists links to courses and talks that are
relevant to the current project page.

Relevant content is fetched by the browser, with an AJAX request sent to
the Pivotal Education LMS API. This API uses the Referrer HTTP header as
input parameter to its content selection algorithm.

Note that CORS HTTP headers are also used to allow/disallow AJAX cross
domain requests.

* Revert "Display Pivotal Education related courseware"

This reverts commit bf15ee8a6da0f232254ac8d186184a5c274d63b3.

* Conditionalize showing reference doc/api doc links

If the reference doc URL of the API doc URL is empty, don't display a hyperlink.

* Fix content warning issues over https

When served with HTTP/2 and TLS, project pages show several mixed
content errors:

* the imported Google fonts
* the AJAX call to spring.io to get the current project information
* the newsletter iframe

This commit changes URLs to use https or protocol-relative URLs when
possible. This also deletes the now defunct newsletter integration.

* Update for changes in github pages

* Upgrade rbenv Ruby version to 2.2.0

* Fix markdown syntax error

The kramdown backend doesn't support titles whithout empty lines before
them.

* Replace ZeroClipboard with clipboard.js

For copy/paste support in our code samples, we are using the
ZeroClipboard library which relies heavily on Flash.
Because many browsers/extensions are disabling this plugin nowadays,
this commit replaces ZeroClipboard with a native, lightweight solution
for this feature.

* Add rouge gem

* Polish page.html

Remove default attributes and other little improvements.

* remove alt attribute in <div>

* Upgrade github-pages gem to fix deprecation warnings

Previously, when running bundle exec jekyll serve a false-positive
deprecation warning was reported:

Deprecation: Auto-regeneration can no longer be set from your
configuration file(s). Use the --[no-]watch/-w command-line option
instead.

See https://github.com/jekyll/jekyll/issues/4831 for some details.
Jekyll 3.0.5 fixes the problem. This commit upgrades to the latest
version of github-pages, thereby also upgrading to Jekyll 3.0.5

* Jekyll must be run with "bundle exec" command

* Add defensive check for empty repository key
2017-03-27 13:00:33 -05:00

193 lines
5.3 KiB
JavaScript

window.Spring = window.Spring || {};
/* ERB style templates conflict with Jekyll HTML escaping */
_.templateSettings = {
evaluate : /\{@([\s\S]+?)@\}/g,
interpolate : /\{@=([\s\S]+?)@\}/g,
escape : /\{@-([\s\S]+?)@\}/g
};
Spring.ProjectDocumentationWidget = function () {
var quickStartEl = $('[data-download-widget-controls]');
var mavenWidgetEl = $('.js-download-maven-widget');
var documentationEl = $('.js-documentation-widget');
var projectUrl = apiBaseUrl + "/project_metadata/" + projectId;
var promise = Spring.loadProject(projectUrl);
promise.then(function (project) {
Spring.buildDocumentationWidget(documentationEl, project);
Spring.buildQuickStartWidget(quickStartEl, mavenWidgetEl, project);
});
};
Spring.buildDocumentationWidget = function (documentationEl, project) {
new Spring.DocumentationWidgetView({
el: documentationEl,
model: project,
template: $("#project-documentation-widget-template").text()
}).render();
}
Spring.buildQuickStartWidget = function (quickStartEl, mavenWidgetEl, project) {
new Spring.QuickStartSelectorView({
el: quickStartEl,
model: project,
template: $("#project-download-widget-controls-template").text(),
snippetWidgetEl: mavenWidgetEl
}).render();
}
Spring.loadProject = function (url) {
return $.ajax(url, {
dataType: 'jsonp',
processData: false
}).then(function (value) {
return new Spring.Project(value);
});
}
Spring.Release = function (data) {
_.extend(this, data);
}
Spring.Release.prototype = {
statusIconClass: function () {
if (this.preRelease) {
return "spring-icon-pre-release";
} else if (this.generalAvailability) {
return "spring-icon-ga-release";
} else {
return "spring-icon-snapshot-release";
}
}
}
Spring.Project = function (data) {
_.extend(this, data);
var self = this;
this.releases = _.map(this.projectReleases, function (r) {
return new Spring.Release(r);
});
return this;
};
Spring.DocumentationWidgetView = Backbone.View.extend({
initialize: function () {
this.template = _.template(this.options.template);
_.bindAll(this, "render");
},
render: function () {
this.$el.html(
this.template(this.model)
);
return this;
}
});
Spring.SnippetView = Backbone.View.extend({
initialize: function () {
var snippetType = this.options.snippetType;
var downloadTemplate = $(document.createElement('div')).html($("#project-download-" + snippetType + "-widget-template").text());
var repositoryTemplate = $(document.createElement('div')).html($("#project-repository-" + snippetType + "-widget-template").text());
this.combinedTemplate = _.template(
"<div class=\"highlight\"><pre><code>" +
downloadTemplate.find("code:first").html() +
"{@ if (typeof(repository) != \"undefined\") { @}" +
repositoryTemplate.find("code:first").html() +
"{@ } @}" +
"</code></pre></div>"
);
_.bindAll(this, "render");
},
render: function () {
var html = $(this.combinedTemplate(this.model));
this.$el.html(html);
Spring.buildCopyButton(html.find(":first"), "snippet");
return this;
},
remove: function() {
this.undelegateEvents();
this.$el.empty();
this.unbind();
}
});
Spring.QuickStartSelectorView = Backbone.View.extend({
events: {
"change .selector": "renderActiveWidget",
"click .js-item": "changeDownloadSource"
},
initialize: function () {
this.template = _.template(this.options.template);
this.snippetWidgetEl = this.options.snippetWidgetEl;
_.bindAll(this, "render", "renderActiveWidget", "changeDownloadSource", "_moveItemSlider", "selectCurrent");
},
render: function () {
this.$el.html(
this.template(this.model)
);
this.renderActiveWidget();
this.selectCurrent();
this.$('.selectpicker').selectpicker();
return this;
},
selectCurrent: function() {
var selectedIndex = $('.selectpicker [data-current="true"]').val();
if(selectedIndex == undefined) {
selectedIndex = 0;
}
this.$('.selectpicker').val(selectedIndex).change();
},
renderActiveWidget: function() {
if(this.activeWidget != null) this.activeWidget.remove();
this.activeWidget = new Spring.SnippetView({
el: this.snippetWidgetEl,
model: this.model.releases[this.$('.selector :selected').val()],
snippetType: this.$('.js-active').data('snippet-type')
});
this.activeWidget.render();
},
changeDownloadSource: function (event) {
var target = $(event.target);
target.addClass("js-active");
target.siblings().removeClass("js-active");
this._moveItemSlider();
this.renderActiveWidget();
},
_moveItemSlider: function () {
var activeItem = $(".js-item-slider--wrapper .js-item.js-active");
if (activeItem.length == 0) {
return;
} else {
var activeItemPosition = activeItem.position();
var activeItemOffset = activeItemPosition.left;
var activeItemWidth = activeItem.outerWidth();
var slider = $(".js-item--slider");
var sliderPosition = slider.position();
var sliderOffset = sliderPosition.left;
var sliderTarget = activeItemOffset - sliderOffset;
slider.width(activeItemWidth);
slider.css("margin-left", sliderTarget);
}
}
});