replace application.js sprockets output with webpack-generated equivalent

This commit is contained in:
Mike Greiling 2016-10-28 03:22:02 -05:00
parent 31bd36845b
commit 55f291e8ce
13 changed files with 2797 additions and 22 deletions

View file

@ -22,6 +22,7 @@
/*= require jquery.endless-scroll */
/*= require jquery.highlight */
/*= require jquery.waitforimages */
/*= require jquery.caret */
/*= require jquery.atwho */
/*= require jquery.scrollTo */
/*= require jquery.turbolinks */

View file

@ -17,7 +17,7 @@
w.gl.utils.days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
w.gl.utils.formatDate = function(datetime) {
return dateFormat(datetime, 'mmm d, yyyy h:MMtt Z');
return (new Date(datetime)).format('mmm d, yyyy h:MMtt Z');
};
w.gl.utils.getDayName = function(date) {

View file

@ -33,7 +33,7 @@
date.setDate(date.getDate() + i);
var day = date.getDay();
var count = timestamps[dateFormat(date, 'yyyy-mm-dd')];
var count = timestamps[date.format('yyyy-mm-dd')];
// Create a new group array if this is the first day of the week
// or if is first object
@ -122,7 +122,7 @@
if (stamp.count > 0) {
contribText = stamp.count + " contribution" + (stamp.count > 1 ? 's' : '');
}
dateText = dateFormat(date, 'mmm d, yyyy');
dateText = date.format('mmm d, yyyy');
return contribText + "<br />" + (gl.utils.getDayName(date)) + " " + dateText;
};
})(this)).attr('class', 'user-contrib-cell js-tooltip').attr('fill', (function(_this) {

View file

@ -0,0 +1,293 @@
/* eslint-disable */
/**
* Simulate sprockets compile order of application.js through CommonJS require statements
*
* Currently exports everything appropriate to window until the scripts that rely on this behavior
* can be refactored.
*
* Test the output from this against sprockets output and it should be almost identical apart from
* webpack's CommonJS wrapper. You can add the following line to webpack.config.js to fix the
* script indentation:
* config.output.sourcePrefix = '';
*/
/*= require jquery2 */
window.jQuery = window.$ = require('jquery');
/*= require jquery-ui/autocomplete */
// depends on jquery-ui/core, jquery-ui/widget, jquery-ui/menu, jquery-ui/position
require('jquery-ui/ui/core');
require('jquery-ui/ui/widget');
require('jquery-ui/ui/position');
require('jquery-ui/ui/menu');
require('jquery-ui/ui/autocomplete');
/*= require jquery-ui/datepicker */
// depends on jquery-ui/core
require('jquery-ui/ui/datepicker');
/*= require jquery-ui/draggable */
// depends on jquery-ui/core, jquery-ui/widget, jquery-ui/mouse
require('jquery-ui/ui/mouse');
require('jquery-ui/ui/draggable');
/*= require jquery-ui/effect-highlight */
// depends on jquery-ui/effect
require('jquery-ui/ui/effect');
require('jquery-ui/ui/effect-highlight');
/*= require jquery-ui/sortable */
// depends on jquery-ui/core, jquery-ui/widget, jquery-ui/mouse
require('jquery-ui/ui/sortable');
/*= require jquery_ujs */
require('jquery-ujs');
/*= require jquery.endless-scroll */
require('vendor/jquery.endless-scroll');
/*= require jquery.highlight */
require('vendor/jquery.highlight');
/*= require jquery.waitforimages */
require('vendor/jquery.waitforimages');
/*= require jquery.atwho */
require('vendor/jquery.caret'); // required by jquery.atwho
require('vendor/jquery.atwho');
/*= require jquery.scrollTo */
require('vendor/jquery.scrollTo');
/*= require jquery.turbolinks */
require('vendor/jquery.turbolinks');
/*= require js.cookie */
window.Cookies = require('vendor/js.cookie');
/*= require turbolinks */
require('vendor/turbolinks');
/*= require autosave */
require('../autosave');
/*= require bootstrap/affix */
require('bootstrap/js/affix');
/*= require bootstrap/alert */
require('bootstrap/js/alert');
/*= require bootstrap/button */
require('bootstrap/js/button');
/*= require bootstrap/collapse */
require('bootstrap/js/collapse');
/*= require bootstrap/dropdown */
require('bootstrap/js/dropdown');
/*= require bootstrap/modal */
require('bootstrap/js/modal');
/*= require bootstrap/scrollspy */
require('bootstrap/js/scrollspy');
/*= require bootstrap/tab */
require('bootstrap/js/tab');
/*= require bootstrap/transition */
require('bootstrap/js/transition');
/*= require bootstrap/tooltip */
require('bootstrap/js/tooltip');
/*= require bootstrap/popover */
require('bootstrap/js/popover');
/*= require select2 */
require('select2/select2.js');
/*= require underscore */
window._ = require('underscore');
/*= require dropzone */
window.Dropzone = require('dropzone');
/*= require mousetrap */
require('mousetrap');
/*= require mousetrap/pause */
require('mousetrap/plugins/pause/mousetrap-pause');
/*= require shortcuts */
require('../shortcuts');
/*= require shortcuts_navigation */
require('../shortcuts_navigation');
/*= require shortcuts_dashboard_navigation */
require('../shortcuts_dashboard_navigation');
/*= require shortcuts_issuable */
require('../shortcuts_issuable');
/*= require shortcuts_network */
require('../shortcuts_network');
/*= require jquery.nicescroll */
require('vendor/jquery.nicescroll');
/*= require date.format */
require('vendor/date.format');
/*= require_directory ./behaviors */
require('vendor/jquery.ba-resize');
window.autosize = require('vendor/autosize');
require('../behaviors/autosize'); // requires vendor/jquery.ba-resize and vendor/autosize
require('../behaviors/details_behavior');
require('../extensions/jquery');
require('../behaviors/quick_submit'); // requires extensions/jquery
require('../behaviors/requires_input');
require('../behaviors/toggler_behavior');
/*= require_directory ./blob */
require('../blob/template_selector');
require('../blob/blob_ci_yaml'); // requires template_selector
require('../blob/blob_file_dropzone');
require('../blob/blob_gitignore_selector');
require('../blob/blob_gitignore_selectors');
require('../blob/blob_license_selector');
require('../blob/blob_license_selectors');
/*= require_directory ./templates */
require('../templates/issuable_template_selector');
require('../templates/issuable_template_selectors');
/*= require_directory ./commit */
require('../commit/file');
require('../commit/image_file');
/*= require_directory ./extensions */
require('../extensions/array');
require('../extensions/element');
/*= require_directory ./lib/utils */
require('../lib/utils/animate');
require('../lib/utils/common_utils');
require('../lib/utils/datetime_utility');
// require('../lib/utils/emoji_aliases.js.erb');
window.gl.emojiAliases = function() { return require('emoji-aliases'); };
require('../lib/utils/jquery.timeago');
require('../lib/utils/notify');
require('../lib/utils/text_utility');
require('../lib/utils/type_utility');
require('../lib/utils/url_utility');
/*= require_directory ./u2f */
require('../u2f/authenticate');
require('../u2f/error');
require('../u2f/register');
require('../u2f/util');
/*= require_directory . */
require('../abuse_reports');
require('../activities');
require('../admin');
require('../api');
require('../aside');
require('../awards_handler');
require('../breakpoints');
require('../broadcast_message');
require('../build');
require('../build_artifacts');
require('../build_variables');
require('../commit');
require('../commits');
require('../compare');
require('../compare_autocomplete');
require('../confirm_danger_modal');
window.Clipboard = require('vendor/clipboard'); // required by copy_to_clipboard
require('../copy_to_clipboard');
require('../create_label');
require('vue'); // required by cycle_analytics
require('../cycle_analytics');
require('../diff');
require('../dispatcher');
require('../preview_markdown');
require('../dropzone_input');
require('../due_date_select');
require('../files_comment_button');
require('../flash');
require('../gfm_auto_complete');
require('../gl_dropdown');
require('../gl_field_errors');
require('../gl_form');
require('../group_avatar');
require('../groups_select');
require('../header');
require('../importer_status');
require('../issuable');
require('../issuable_context');
require('../issuable_form');
require('vendor/task_list'); // required by issue
require('../issue');
require('../issue_status_select');
require('../issues_bulk_assignment');
require('../label_manager');
require('../labels');
require('../labels_select');
require('../layout_nav');
require('../line_highlighter');
require('../logo');
require('../member_expiration_date');
require('../members');
require('../merge_request_tabs');
require('../merge_request');
require('../merge_request_widget');
require('../merged_buttons');
require('../milestone');
require('../milestone_select');
require('../namespace_select');
require('../new_branch_form');
require('../new_commit_form');
require('../notes');
require('../notifications_dropdown');
require('../notifications_form');
require('../pager');
require('../pipelines');
require('../project');
require('../project_avatar');
require('../project_find_file');
require('../project_fork');
require('../project_import');
require('../project_new');
require('../project_select');
require('../project_show');
require('../projects_list');
require('../right_sidebar');
require('../search');
require('../search_autocomplete');
require('../shortcuts_blob');
require('../shortcuts_find_file');
require('../sidebar');
require('../single_file_diff');
require('../snippets_list');
require('../star');
require('../subscription');
require('../subscription_select');
require('../syntax_highlight');
require('../todos');
require('../tree');
require('../user');
require('../user_tabs');
require('../username_validator');
require('../users_select');
require('vendor/latinise'); // required by wikis
require('../wikis');
require('../zen_mode');
/*= require fuzzaldrin-plus */
require('vendor/fuzzaldrin-plus');
require('../application');

View file

@ -1,4 +0,0 @@
var HelloWorld = require('./hello_world').default;
var message = new HelloWorld('webpack');
message.sayHello();

View file

@ -1,11 +0,0 @@
/* eslint-disable no-undef, no-alert */
export default class HelloWorld {
constructor(name) {
this.message = `Hello ${name}!`;
}
sayHello() {
alert(this.message);
}
}

View file

@ -28,8 +28,7 @@
= stylesheet_link_tag "application", media: "all"
= stylesheet_link_tag "print", media: "print"
= javascript_include_tag "application"
= javascript_include_tag *webpack_asset_paths("bundle")
= javascript_include_tag *webpack_asset_paths("application")
- if content_for?(:page_specific_javascripts)
= yield :page_specific_javascripts

View file

@ -14,7 +14,7 @@ var DEV_SERVER_PORT = 3808;
var config = {
context: ROOT_PATH,
entry: {
bundle: './app/assets/javascripts/webpack/bundle.js'
application: './app/assets/javascripts/webpack/application.js'
},
output: {
@ -31,6 +31,15 @@ var config = {
test: /\.es6$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.(js|es6)$/,
loader: 'imports-loader',
query: 'this=>window'
},
{
test: /\.json$/,
loader: 'json-loader'
}
]
},
@ -48,7 +57,14 @@ var config = {
],
resolve: {
extensions: ['', '.js', '.es6', '.js.es6']
extensions: ['', '.js', '.es6', '.js.es6'],
alias: {
'bootstrap/js': 'bootstrap-sass/assets/javascripts/bootstrap',
'emoji-aliases$': path.join(ROOT_PATH, 'fixtures/emojis/aliases.json'),
'vendor': path.join(ROOT_PATH, 'vendor/assets/javascripts'),
'vue$': 'vue/dist/vue.js',
'vue-resource$': 'vue-resource/dist/vue-resource.js'
}
}
}

View file

@ -10,7 +10,20 @@
"babel": "^5.8.38",
"babel-core": "^5.8.38",
"babel-loader": "^5.4.2",
"bootstrap-sass": "3.3.6",
"dropzone": "4.2.0",
"exports-loader": "^0.6.3",
"imports-loader": "^0.6.5",
"jquery": "2.2.1",
"jquery-ui": "github:jquery/jquery-ui#1.11.4",
"jquery-ujs": "1.2.1",
"json-loader": "^0.5.4",
"mousetrap": "1.4.6",
"select2": "3.5.2-browserify",
"stats-webpack-plugin": "^0.4.2",
"underscore": "1.8.3",
"vue": "1.0.26",
"vue-resource": "0.9.3",
"webpack": "^1.13.2",
"webpack-dev-server": "^1.16.2"
},

1202
vendor/assets/javascripts/jquery.atwho.js vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,436 @@
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(["jquery"], function ($) {
return (root.returnExportsGlobal = factory($));
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory(require("jquery"));
} else {
factory(jQuery);
}
}(this, function ($) {
/*
Implement Github like autocomplete mentions
http://ichord.github.com/At.js
Copyright (c) 2013 chord.luo@gmail.com
Licensed under the MIT license.
*/
/*
本插件操作 textarea 或者 input 内的插入符
只实现了获得插入符在文本框中的位置我设置
插入符的位置.
*/
"use strict";
var EditableCaret, InputCaret, Mirror, Utils, discoveryIframeOf, methods, oDocument, oFrame, oWindow, pluginName, setContextBy;
pluginName = 'caret';
EditableCaret = (function() {
function EditableCaret($inputor) {
this.$inputor = $inputor;
this.domInputor = this.$inputor[0];
}
EditableCaret.prototype.setPos = function(pos) {
var fn, found, offset, sel;
if (sel = oWindow.getSelection()) {
offset = 0;
found = false;
(fn = function(pos, parent) {
var node, range, _i, _len, _ref, _results;
_ref = parent.childNodes;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
node = _ref[_i];
if (found) {
break;
}
if (node.nodeType === 3) {
if (offset + node.length >= pos) {
found = true;
range = oDocument.createRange();
range.setStart(node, pos - offset);
sel.removeAllRanges();
sel.addRange(range);
break;
} else {
_results.push(offset += node.length);
}
} else {
_results.push(fn(pos, node));
}
}
return _results;
})(pos, this.domInputor);
}
return this.domInputor;
};
EditableCaret.prototype.getIEPosition = function() {
return this.getPosition();
};
EditableCaret.prototype.getPosition = function() {
var inputor_offset, offset;
offset = this.getOffset();
inputor_offset = this.$inputor.offset();
offset.left -= inputor_offset.left;
offset.top -= inputor_offset.top;
return offset;
};
EditableCaret.prototype.getOldIEPos = function() {
var preCaretTextRange, textRange;
textRange = oDocument.selection.createRange();
preCaretTextRange = oDocument.body.createTextRange();
preCaretTextRange.moveToElementText(this.domInputor);
preCaretTextRange.setEndPoint("EndToEnd", textRange);
return preCaretTextRange.text.length;
};
EditableCaret.prototype.getPos = function() {
var clonedRange, pos, range;
if (range = this.range()) {
clonedRange = range.cloneRange();
clonedRange.selectNodeContents(this.domInputor);
clonedRange.setEnd(range.endContainer, range.endOffset);
pos = clonedRange.toString().length;
clonedRange.detach();
return pos;
} else if (oDocument.selection) {
return this.getOldIEPos();
}
};
EditableCaret.prototype.getOldIEOffset = function() {
var range, rect;
range = oDocument.selection.createRange().duplicate();
range.moveStart("character", -1);
rect = range.getBoundingClientRect();
return {
height: rect.bottom - rect.top,
left: rect.left,
top: rect.top
};
};
EditableCaret.prototype.getOffset = function(pos) {
var clonedRange, offset, range, rect, shadowCaret;
if (oWindow.getSelection && (range = this.range())) {
if (range.endOffset - 1 > 0 && range.endContainer !== this.domInputor) {
clonedRange = range.cloneRange();
clonedRange.setStart(range.endContainer, range.endOffset - 1);
clonedRange.setEnd(range.endContainer, range.endOffset);
rect = clonedRange.getBoundingClientRect();
offset = {
height: rect.height,
left: rect.left + rect.width,
top: rect.top
};
clonedRange.detach();
}
if (!offset || (offset != null ? offset.height : void 0) === 0) {
clonedRange = range.cloneRange();
shadowCaret = $(oDocument.createTextNode("|"));
clonedRange.insertNode(shadowCaret[0]);
clonedRange.selectNode(shadowCaret[0]);
rect = clonedRange.getBoundingClientRect();
offset = {
height: rect.height,
left: rect.left,
top: rect.top
};
shadowCaret.remove();
clonedRange.detach();
}
} else if (oDocument.selection) {
offset = this.getOldIEOffset();
}
if (offset) {
offset.top += $(oWindow).scrollTop();
offset.left += $(oWindow).scrollLeft();
}
return offset;
};
EditableCaret.prototype.range = function() {
var sel;
if (!oWindow.getSelection) {
return;
}
sel = oWindow.getSelection();
if (sel.rangeCount > 0) {
return sel.getRangeAt(0);
} else {
return null;
}
};
return EditableCaret;
})();
InputCaret = (function() {
function InputCaret($inputor) {
this.$inputor = $inputor;
this.domInputor = this.$inputor[0];
}
InputCaret.prototype.getIEPos = function() {
var endRange, inputor, len, normalizedValue, pos, range, textInputRange;
inputor = this.domInputor;
range = oDocument.selection.createRange();
pos = 0;
if (range && range.parentElement() === inputor) {
normalizedValue = inputor.value.replace(/\r\n/g, "\n");
len = normalizedValue.length;
textInputRange = inputor.createTextRange();
textInputRange.moveToBookmark(range.getBookmark());
endRange = inputor.createTextRange();
endRange.collapse(false);
if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
pos = len;
} else {
pos = -textInputRange.moveStart("character", -len);
}
}
return pos;
};
InputCaret.prototype.getPos = function() {
if (oDocument.selection) {
return this.getIEPos();
} else {
return this.domInputor.selectionStart;
}
};
InputCaret.prototype.setPos = function(pos) {
var inputor, range;
inputor = this.domInputor;
if (oDocument.selection) {
range = inputor.createTextRange();
range.move("character", pos);
range.select();
} else if (inputor.setSelectionRange) {
inputor.setSelectionRange(pos, pos);
}
return inputor;
};
InputCaret.prototype.getIEOffset = function(pos) {
var h, textRange, x, y;
textRange = this.domInputor.createTextRange();
pos || (pos = this.getPos());
textRange.move('character', pos);
x = textRange.boundingLeft;
y = textRange.boundingTop;
h = textRange.boundingHeight;
return {
left: x,
top: y,
height: h
};
};
InputCaret.prototype.getOffset = function(pos) {
var $inputor, offset, position;
$inputor = this.$inputor;
if (oDocument.selection) {
offset = this.getIEOffset(pos);
offset.top += $(oWindow).scrollTop() + $inputor.scrollTop();
offset.left += $(oWindow).scrollLeft() + $inputor.scrollLeft();
return offset;
} else {
offset = $inputor.offset();
position = this.getPosition(pos);
return offset = {
left: offset.left + position.left - $inputor.scrollLeft(),
top: offset.top + position.top - $inputor.scrollTop(),
height: position.height
};
}
};
InputCaret.prototype.getPosition = function(pos) {
var $inputor, at_rect, end_range, format, html, mirror, start_range;
$inputor = this.$inputor;
format = function(value) {
value = value.replace(/<|>|`|"|&/g, '?').replace(/\r\n|\r|\n/g, "<br/>");
if (/firefox/i.test(navigator.userAgent)) {
value = value.replace(/\s/g, '&nbsp;');
}
return value;
};
if (pos === void 0) {
pos = this.getPos();
}
start_range = $inputor.val().slice(0, pos);
end_range = $inputor.val().slice(pos);
html = "<span style='position: relative; display: inline;'>" + format(start_range) + "</span>";
html += "<span id='caret' style='position: relative; display: inline;'>|</span>";
html += "<span style='position: relative; display: inline;'>" + format(end_range) + "</span>";
mirror = new Mirror($inputor);
return at_rect = mirror.create(html).rect();
};
InputCaret.prototype.getIEPosition = function(pos) {
var h, inputorOffset, offset, x, y;
offset = this.getIEOffset(pos);
inputorOffset = this.$inputor.offset();
x = offset.left - inputorOffset.left;
y = offset.top - inputorOffset.top;
h = offset.height;
return {
left: x,
top: y,
height: h
};
};
return InputCaret;
})();
Mirror = (function() {
Mirror.prototype.css_attr = ["borderBottomWidth", "borderLeftWidth", "borderRightWidth", "borderTopStyle", "borderRightStyle", "borderBottomStyle", "borderLeftStyle", "borderTopWidth", "boxSizing", "fontFamily", "fontSize", "fontWeight", "height", "letterSpacing", "lineHeight", "marginBottom", "marginLeft", "marginRight", "marginTop", "outlineWidth", "overflow", "overflowX", "overflowY", "paddingBottom", "paddingLeft", "paddingRight", "paddingTop", "textAlign", "textOverflow", "textTransform", "whiteSpace", "wordBreak", "wordWrap"];
function Mirror($inputor) {
this.$inputor = $inputor;
}
Mirror.prototype.mirrorCss = function() {
var css,
_this = this;
css = {
position: 'absolute',
left: -9999,
top: 0,
zIndex: -20000
};
if (this.$inputor.prop('tagName') === 'TEXTAREA') {
this.css_attr.push('width');
}
$.each(this.css_attr, function(i, p) {
return css[p] = _this.$inputor.css(p);
});
return css;
};
Mirror.prototype.create = function(html) {
this.$mirror = $('<div></div>');
this.$mirror.css(this.mirrorCss());
this.$mirror.html(html);
this.$inputor.after(this.$mirror);
return this;
};
Mirror.prototype.rect = function() {
var $flag, pos, rect;
$flag = this.$mirror.find("#caret");
pos = $flag.position();
rect = {
left: pos.left,
top: pos.top,
height: $flag.height()
};
this.$mirror.remove();
return rect;
};
return Mirror;
})();
Utils = {
contentEditable: function($inputor) {
return !!($inputor[0].contentEditable && $inputor[0].contentEditable === 'true');
}
};
methods = {
pos: function(pos) {
if (pos || pos === 0) {
return this.setPos(pos);
} else {
return this.getPos();
}
},
position: function(pos) {
if (oDocument.selection) {
return this.getIEPosition(pos);
} else {
return this.getPosition(pos);
}
},
offset: function(pos) {
var offset;
offset = this.getOffset(pos);
return offset;
}
};
oDocument = null;
oWindow = null;
oFrame = null;
setContextBy = function(settings) {
var iframe;
if (iframe = settings != null ? settings.iframe : void 0) {
oFrame = iframe;
oWindow = iframe.contentWindow;
return oDocument = iframe.contentDocument || oWindow.document;
} else {
oFrame = void 0;
oWindow = window;
return oDocument = document;
}
};
discoveryIframeOf = function($dom) {
var error;
oDocument = $dom[0].ownerDocument;
oWindow = oDocument.defaultView || oDocument.parentWindow;
try {
return oFrame = oWindow.frameElement;
} catch (_error) {
error = _error;
}
};
$.fn.caret = function(method, value, settings) {
var caret;
if (methods[method]) {
if ($.isPlainObject(value)) {
setContextBy(value);
value = void 0;
} else {
setContextBy(settings);
}
caret = Utils.contentEditable(this) ? new EditableCaret(this) : new InputCaret(this);
return methods[method].apply(caret, [value]);
} else {
return $.error("Method " + method + " does not exist on jQuery.caret");
}
};
$.fn.caret.EditableCaret = EditableCaret;
$.fn.caret.InputCaret = InputCaret;
$.fn.caret.Utils = Utils;
$.fn.caret.apis = methods;
}));

View file

@ -0,0 +1,49 @@
// Generated by CoffeeScript 1.7.1
/*
jQuery.Turbolinks ~ https://github.com/kossnocorp/jquery.turbolinks
jQuery plugin for drop-in fix binded events problem caused by Turbolinks
The MIT License
Copyright (c) 2012-2013 Sasha Koss & Rico Sta. Cruz
*/
(function() {
var $, $document;
$ = window.jQuery || (typeof require === "function" ? require('jquery') : void 0);
$document = $(document);
$.turbo = {
version: '2.1.0',
isReady: false,
use: function(load, fetch) {
return $document.off('.turbo').on("" + load + ".turbo", this.onLoad).on("" + fetch + ".turbo", this.onFetch);
},
addCallback: function(callback) {
if ($.turbo.isReady) {
callback($);
}
return $document.on('turbo:ready', function() {
return callback($);
});
},
onLoad: function() {
$.turbo.isReady = true;
return $document.trigger('turbo:ready');
},
onFetch: function() {
return $.turbo.isReady = false;
},
register: function() {
$(this.onLoad);
return $.fn.ready = this.addCallback;
}
};
$.turbo.register();
$.turbo.use('page:load', 'page:fetch');
}).call(this);

781
vendor/assets/javascripts/turbolinks.js vendored Normal file
View file

@ -0,0 +1,781 @@
// Turbolinks Classic v2.5.3 compiled from CoffeeScript
(function() {
var CSRFToken, Click, ComponentUrl, EVENTS, Link, ProgressBar, browserIsntBuggy, browserSupportsCustomEvents, browserSupportsPushState, browserSupportsTurbolinks, bypassOnLoadPopstate, cacheCurrentPage, cacheSize, changePage, clone, constrainPageCacheTo, createDocument, crossOriginRedirect, currentState, enableProgressBar, enableTransitionCache, executeScriptTags, extractTitleAndBody, fetch, fetchHistory, fetchReplacement, historyStateIsDefined, initializeTurbolinks, installDocumentReadyPageEventTriggers, installHistoryChangeHandler, installJqueryAjaxSuccessPageUpdateTrigger, loadedAssets, manuallyTriggerHashChangeForFirefox, pageCache, pageChangePrevented, pagesCached, popCookie, processResponse, progressBar, recallScrollPosition, ref, referer, reflectNewUrl, reflectRedirectedUrl, rememberCurrentState, rememberCurrentUrl, rememberReferer, removeNoscriptTags, requestMethodIsSafe, resetScrollPosition, setAutofocusElement, transitionCacheEnabled, transitionCacheFor, triggerEvent, visit, xhr,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty,
slice = [].slice,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
pageCache = {};
cacheSize = 10;
transitionCacheEnabled = false;
progressBar = null;
currentState = null;
loadedAssets = null;
referer = null;
xhr = null;
EVENTS = {
BEFORE_CHANGE: 'page:before-change',
FETCH: 'page:fetch',
RECEIVE: 'page:receive',
CHANGE: 'page:change',
UPDATE: 'page:update',
LOAD: 'page:load',
RESTORE: 'page:restore',
BEFORE_UNLOAD: 'page:before-unload',
EXPIRE: 'page:expire'
};
fetch = function(url) {
var cachedPage;
url = new ComponentUrl(url);
rememberReferer();
cacheCurrentPage();
if (progressBar != null) {
progressBar.start();
}
if (transitionCacheEnabled && (cachedPage = transitionCacheFor(url.absolute))) {
fetchHistory(cachedPage);
return fetchReplacement(url, null, false);
} else {
return fetchReplacement(url, resetScrollPosition);
}
};
transitionCacheFor = function(url) {
var cachedPage;
cachedPage = pageCache[url];
if (cachedPage && !cachedPage.transitionCacheDisabled) {
return cachedPage;
}
};
enableTransitionCache = function(enable) {
if (enable == null) {
enable = true;
}
return transitionCacheEnabled = enable;
};
enableProgressBar = function(enable) {
if (enable == null) {
enable = true;
}
if (!browserSupportsTurbolinks) {
return;
}
if (enable) {
return progressBar != null ? progressBar : progressBar = new ProgressBar('html');
} else {
if (progressBar != null) {
progressBar.uninstall();
}
return progressBar = null;
}
};
fetchReplacement = function(url, onLoadFunction, showProgressBar) {
if (showProgressBar == null) {
showProgressBar = true;
}
triggerEvent(EVENTS.FETCH, {
url: url.absolute
});
if (xhr != null) {
xhr.abort();
}
xhr = new XMLHttpRequest;
xhr.open('GET', url.withoutHashForIE10compatibility(), true);
xhr.setRequestHeader('Accept', 'text/html, application/xhtml+xml, application/xml');
xhr.setRequestHeader('X-XHR-Referer', referer);
xhr.onload = function() {
var doc;
triggerEvent(EVENTS.RECEIVE, {
url: url.absolute
});
if (doc = processResponse()) {
reflectNewUrl(url);
reflectRedirectedUrl();
changePage.apply(null, extractTitleAndBody(doc));
manuallyTriggerHashChangeForFirefox();
if (typeof onLoadFunction === "function") {
onLoadFunction();
}
return triggerEvent(EVENTS.LOAD);
} else {
return document.location.href = crossOriginRedirect() || url.absolute;
}
};
if (progressBar && showProgressBar) {
xhr.onprogress = (function(_this) {
return function(event) {
var percent;
percent = event.lengthComputable ? event.loaded / event.total * 100 : progressBar.value + (100 - progressBar.value) / 10;
return progressBar.advanceTo(percent);
};
})(this);
}
xhr.onloadend = function() {
return xhr = null;
};
xhr.onerror = function() {
return document.location.href = url.absolute;
};
return xhr.send();
};
fetchHistory = function(cachedPage) {
if (xhr != null) {
xhr.abort();
}
changePage(cachedPage.title, cachedPage.body);
recallScrollPosition(cachedPage);
return triggerEvent(EVENTS.RESTORE);
};
cacheCurrentPage = function() {
var currentStateUrl;
currentStateUrl = new ComponentUrl(currentState.url);
pageCache[currentStateUrl.absolute] = {
url: currentStateUrl.relative,
body: document.body,
title: document.title,
positionY: window.pageYOffset,
positionX: window.pageXOffset,
cachedAt: new Date().getTime(),
transitionCacheDisabled: document.querySelector('[data-no-transition-cache]') != null
};
return constrainPageCacheTo(cacheSize);
};
pagesCached = function(size) {
if (size == null) {
size = cacheSize;
}
if (/^[\d]+$/.test(size)) {
return cacheSize = parseInt(size);
}
};
constrainPageCacheTo = function(limit) {
var cacheTimesRecentFirst, i, key, len, pageCacheKeys, results;
pageCacheKeys = Object.keys(pageCache);
cacheTimesRecentFirst = pageCacheKeys.map(function(url) {
return pageCache[url].cachedAt;
}).sort(function(a, b) {
return b - a;
});
results = [];
for (i = 0, len = pageCacheKeys.length; i < len; i++) {
key = pageCacheKeys[i];
if (!(pageCache[key].cachedAt <= cacheTimesRecentFirst[limit])) {
continue;
}
triggerEvent(EVENTS.EXPIRE, pageCache[key]);
results.push(delete pageCache[key]);
}
return results;
};
changePage = function(title, body, csrfToken, runScripts) {
triggerEvent(EVENTS.BEFORE_UNLOAD);
document.title = title;
document.documentElement.replaceChild(body, document.body);
if (csrfToken != null) {
CSRFToken.update(csrfToken);
}
setAutofocusElement();
if (runScripts) {
executeScriptTags();
}
currentState = window.history.state;
if (progressBar != null) {
progressBar.done();
}
triggerEvent(EVENTS.CHANGE);
return triggerEvent(EVENTS.UPDATE);
};
executeScriptTags = function() {
var attr, copy, i, j, len, len1, nextSibling, parentNode, ref, ref1, script, scripts;
scripts = Array.prototype.slice.call(document.body.querySelectorAll('script:not([data-turbolinks-eval="false"])'));
for (i = 0, len = scripts.length; i < len; i++) {
script = scripts[i];
if (!((ref = script.type) === '' || ref === 'text/javascript')) {
continue;
}
copy = document.createElement('script');
ref1 = script.attributes;
for (j = 0, len1 = ref1.length; j < len1; j++) {
attr = ref1[j];
copy.setAttribute(attr.name, attr.value);
}
if (!script.hasAttribute('async')) {
copy.async = false;
}
copy.appendChild(document.createTextNode(script.innerHTML));
parentNode = script.parentNode, nextSibling = script.nextSibling;
parentNode.removeChild(script);
parentNode.insertBefore(copy, nextSibling);
}
};
removeNoscriptTags = function(node) {
node.innerHTML = node.innerHTML.replace(/<noscript[\S\s]*?<\/noscript>/ig, '');
return node;
};
setAutofocusElement = function() {
var autofocusElement, list;
autofocusElement = (list = document.querySelectorAll('input[autofocus], textarea[autofocus]'))[list.length - 1];
if (autofocusElement && document.activeElement !== autofocusElement) {
return autofocusElement.focus();
}
};
reflectNewUrl = function(url) {
if ((url = new ComponentUrl(url)).absolute !== referer) {
return window.history.pushState({
turbolinks: true,
url: url.absolute
}, '', url.absolute);
}
};
reflectRedirectedUrl = function() {
var location, preservedHash;
if (location = xhr.getResponseHeader('X-XHR-Redirected-To')) {
location = new ComponentUrl(location);
preservedHash = location.hasNoHash() ? document.location.hash : '';
return window.history.replaceState(window.history.state, '', location.href + preservedHash);
}
};
crossOriginRedirect = function() {
var redirect;
if (((redirect = xhr.getResponseHeader('Location')) != null) && (new ComponentUrl(redirect)).crossOrigin()) {
return redirect;
}
};
rememberReferer = function() {
return referer = document.location.href;
};
rememberCurrentUrl = function() {
return window.history.replaceState({
turbolinks: true,
url: document.location.href
}, '', document.location.href);
};
rememberCurrentState = function() {
return currentState = window.history.state;
};
manuallyTriggerHashChangeForFirefox = function() {
var url;
if (navigator.userAgent.match(/Firefox/) && !(url = new ComponentUrl).hasNoHash()) {
window.history.replaceState(currentState, '', url.withoutHash());
return document.location.hash = url.hash;
}
};
recallScrollPosition = function(page) {
return window.scrollTo(page.positionX, page.positionY);
};
resetScrollPosition = function() {
if (document.location.hash) {
return document.location.href = document.location.href;
} else {
return window.scrollTo(0, 0);
}
};
clone = function(original) {
var copy, key, value;
if ((original == null) || typeof original !== 'object') {
return original;
}
copy = new original.constructor();
for (key in original) {
value = original[key];
copy[key] = clone(value);
}
return copy;
};
popCookie = function(name) {
var ref, value;
value = ((ref = document.cookie.match(new RegExp(name + "=(\\w+)"))) != null ? ref[1].toUpperCase() : void 0) || '';
document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/';
return value;
};
triggerEvent = function(name, data) {
var event;
if (typeof Prototype !== 'undefined') {
Event.fire(document, name, data, true);
}
event = document.createEvent('Events');
if (data) {
event.data = data;
}
event.initEvent(name, true, true);
return document.dispatchEvent(event);
};
pageChangePrevented = function(url) {
return !triggerEvent(EVENTS.BEFORE_CHANGE, {
url: url
});
};
processResponse = function() {
var assetsChanged, clientOrServerError, doc, extractTrackAssets, intersection, validContent;
clientOrServerError = function() {
var ref;
return (400 <= (ref = xhr.status) && ref < 600);
};
validContent = function() {
var contentType;
return ((contentType = xhr.getResponseHeader('Content-Type')) != null) && contentType.match(/^(?:text\/html|application\/xhtml\+xml|application\/xml)(?:;|$)/);
};
extractTrackAssets = function(doc) {
var i, len, node, ref, results;
ref = doc.querySelector('head').childNodes;
results = [];
for (i = 0, len = ref.length; i < len; i++) {
node = ref[i];
if ((typeof node.getAttribute === "function" ? node.getAttribute('data-turbolinks-track') : void 0) != null) {
results.push(node.getAttribute('src') || node.getAttribute('href'));
}
}
return results;
};
assetsChanged = function(doc) {
var fetchedAssets;
loadedAssets || (loadedAssets = extractTrackAssets(document));
fetchedAssets = extractTrackAssets(doc);
return fetchedAssets.length !== loadedAssets.length || intersection(fetchedAssets, loadedAssets).length !== loadedAssets.length;
};
intersection = function(a, b) {
var i, len, ref, results, value;
if (a.length > b.length) {
ref = [b, a], a = ref[0], b = ref[1];
}
results = [];
for (i = 0, len = a.length; i < len; i++) {
value = a[i];
if (indexOf.call(b, value) >= 0) {
results.push(value);
}
}
return results;
};
if (!clientOrServerError() && validContent()) {
doc = createDocument(xhr.responseText);
if (doc && !assetsChanged(doc)) {
return doc;
}
}
};
extractTitleAndBody = function(doc) {
var title;
title = doc.querySelector('title');
return [title != null ? title.textContent : void 0, removeNoscriptTags(doc.querySelector('body')), CSRFToken.get(doc).token, 'runScripts'];
};
CSRFToken = {
get: function(doc) {
var tag;
if (doc == null) {
doc = document;
}
return {
node: tag = doc.querySelector('meta[name="csrf-token"]'),
token: tag != null ? typeof tag.getAttribute === "function" ? tag.getAttribute('content') : void 0 : void 0
};
},
update: function(latest) {
var current;
current = this.get();
if ((current.token != null) && (latest != null) && current.token !== latest) {
return current.node.setAttribute('content', latest);
}
}
};
createDocument = function(html) {
var doc;
doc = document.documentElement.cloneNode();
doc.innerHTML = html;
doc.head = doc.querySelector('head');
doc.body = doc.querySelector('body');
return doc;
};
ComponentUrl = (function() {
function ComponentUrl(original1) {
this.original = original1 != null ? original1 : document.location.href;
if (this.original.constructor === ComponentUrl) {
return this.original;
}
this._parse();
}
ComponentUrl.prototype.withoutHash = function() {
return this.href.replace(this.hash, '').replace('#', '');
};
ComponentUrl.prototype.withoutHashForIE10compatibility = function() {
return this.withoutHash();
};
ComponentUrl.prototype.hasNoHash = function() {
return this.hash.length === 0;
};
ComponentUrl.prototype.crossOrigin = function() {
return this.origin !== (new ComponentUrl).origin;
};
ComponentUrl.prototype._parse = function() {
var ref;
(this.link != null ? this.link : this.link = document.createElement('a')).href = this.original;
ref = this.link, this.href = ref.href, this.protocol = ref.protocol, this.host = ref.host, this.hostname = ref.hostname, this.port = ref.port, this.pathname = ref.pathname, this.search = ref.search, this.hash = ref.hash;
this.origin = [this.protocol, '//', this.hostname].join('');
if (this.port.length !== 0) {
this.origin += ":" + this.port;
}
this.relative = [this.pathname, this.search, this.hash].join('');
return this.absolute = this.href;
};
return ComponentUrl;
})();
Link = (function(superClass) {
extend(Link, superClass);
Link.HTML_EXTENSIONS = ['html'];
Link.allowExtensions = function() {
var extension, extensions, i, len;
extensions = 1 <= arguments.length ? slice.call(arguments, 0) : [];
for (i = 0, len = extensions.length; i < len; i++) {
extension = extensions[i];
Link.HTML_EXTENSIONS.push(extension);
}
return Link.HTML_EXTENSIONS;
};
function Link(link1) {
this.link = link1;
if (this.link.constructor === Link) {
return this.link;
}
this.original = this.link.href;
this.originalElement = this.link;
this.link = this.link.cloneNode(false);
Link.__super__.constructor.apply(this, arguments);
}
Link.prototype.shouldIgnore = function() {
return this.crossOrigin() || this._anchored() || this._nonHtml() || this._optOut() || this._target();
};
Link.prototype._anchored = function() {
return (this.hash.length > 0 || this.href.charAt(this.href.length - 1) === '#') && (this.withoutHash() === (new ComponentUrl).withoutHash());
};
Link.prototype._nonHtml = function() {
return this.pathname.match(/\.[a-z]+$/g) && !this.pathname.match(new RegExp("\\.(?:" + (Link.HTML_EXTENSIONS.join('|')) + ")?$", 'g'));
};
Link.prototype._optOut = function() {
var ignore, link;
link = this.originalElement;
while (!(ignore || link === document)) {
ignore = link.getAttribute('data-no-turbolink') != null;
link = link.parentNode;
}
return ignore;
};
Link.prototype._target = function() {
return this.link.target.length !== 0;
};
return Link;
})(ComponentUrl);
Click = (function() {
Click.installHandlerLast = function(event) {
if (!event.defaultPrevented) {
document.removeEventListener('click', Click.handle, false);
return document.addEventListener('click', Click.handle, false);
}
};
Click.handle = function(event) {
return new Click(event);
};
function Click(event1) {
this.event = event1;
if (this.event.defaultPrevented) {
return;
}
this._extractLink();
if (this._validForTurbolinks()) {
if (!pageChangePrevented(this.link.absolute)) {
visit(this.link.href);
}
this.event.preventDefault();
}
}
Click.prototype._extractLink = function() {
var link;
link = this.event.target;
while (!(!link.parentNode || link.nodeName === 'A')) {
link = link.parentNode;
}
if (link.nodeName === 'A' && link.href.length !== 0) {
return this.link = new Link(link);
}
};
Click.prototype._validForTurbolinks = function() {
return (this.link != null) && !(this.link.shouldIgnore() || this._nonStandardClick());
};
Click.prototype._nonStandardClick = function() {
return this.event.which > 1 || this.event.metaKey || this.event.ctrlKey || this.event.shiftKey || this.event.altKey;
};
return Click;
})();
ProgressBar = (function() {
var className;
className = 'turbolinks-progress-bar';
function ProgressBar(elementSelector) {
this.elementSelector = elementSelector;
this._trickle = bind(this._trickle, this);
this.value = 0;
this.content = '';
this.speed = 300;
this.opacity = 0.99;
this.install();
}
ProgressBar.prototype.install = function() {
this.element = document.querySelector(this.elementSelector);
this.element.classList.add(className);
this.styleElement = document.createElement('style');
document.head.appendChild(this.styleElement);
return this._updateStyle();
};
ProgressBar.prototype.uninstall = function() {
this.element.classList.remove(className);
return document.head.removeChild(this.styleElement);
};
ProgressBar.prototype.start = function() {
return this.advanceTo(5);
};
ProgressBar.prototype.advanceTo = function(value) {
var ref;
if ((value > (ref = this.value) && ref <= 100)) {
this.value = value;
this._updateStyle();
if (this.value === 100) {
return this._stopTrickle();
} else if (this.value > 0) {
return this._startTrickle();
}
}
};
ProgressBar.prototype.done = function() {
if (this.value > 0) {
this.advanceTo(100);
return this._reset();
}
};
ProgressBar.prototype._reset = function() {
var originalOpacity;
originalOpacity = this.opacity;
setTimeout((function(_this) {
return function() {
_this.opacity = 0;
return _this._updateStyle();
};
})(this), this.speed / 2);
return setTimeout((function(_this) {
return function() {
_this.value = 0;
_this.opacity = originalOpacity;
return _this._withSpeed(0, function() {
return _this._updateStyle(true);
});
};
})(this), this.speed);
};
ProgressBar.prototype._startTrickle = function() {
if (this.trickling) {
return;
}
this.trickling = true;
return setTimeout(this._trickle, this.speed);
};
ProgressBar.prototype._stopTrickle = function() {
return delete this.trickling;
};
ProgressBar.prototype._trickle = function() {
if (!this.trickling) {
return;
}
this.advanceTo(this.value + Math.random() / 2);
return setTimeout(this._trickle, this.speed);
};
ProgressBar.prototype._withSpeed = function(speed, fn) {
var originalSpeed, result;
originalSpeed = this.speed;
this.speed = speed;
result = fn();
this.speed = originalSpeed;
return result;
};
ProgressBar.prototype._updateStyle = function(forceRepaint) {
if (forceRepaint == null) {
forceRepaint = false;
}
if (forceRepaint) {
this._changeContentToForceRepaint();
}
return this.styleElement.textContent = this._createCSSRule();
};
ProgressBar.prototype._changeContentToForceRepaint = function() {
return this.content = this.content === '' ? ' ' : '';
};
ProgressBar.prototype._createCSSRule = function() {
return this.elementSelector + "." + className + "::before {\n content: '" + this.content + "';\n position: fixed;\n top: 0;\n left: 0;\n z-index: 2000;\n background-color: #0076ff;\n height: 3px;\n opacity: " + this.opacity + ";\n width: " + this.value + "%;\n transition: width " + this.speed + "ms ease-out, opacity " + (this.speed / 2) + "ms ease-in;\n transform: translate3d(0,0,0);\n}";
};
return ProgressBar;
})();
bypassOnLoadPopstate = function(fn) {
return setTimeout(fn, 500);
};
installDocumentReadyPageEventTriggers = function() {
return document.addEventListener('DOMContentLoaded', (function() {
triggerEvent(EVENTS.CHANGE);
return triggerEvent(EVENTS.UPDATE);
}), true);
};
installJqueryAjaxSuccessPageUpdateTrigger = function() {
if (typeof jQuery !== 'undefined') {
return jQuery(document).on('ajaxSuccess', function(event, xhr, settings) {
if (!jQuery.trim(xhr.responseText)) {
return;
}
return triggerEvent(EVENTS.UPDATE);
});
}
};
installHistoryChangeHandler = function(event) {
var cachedPage, ref;
if ((ref = event.state) != null ? ref.turbolinks : void 0) {
if (cachedPage = pageCache[(new ComponentUrl(event.state.url)).absolute]) {
cacheCurrentPage();
return fetchHistory(cachedPage);
} else {
return visit(event.target.location.href);
}
}
};
initializeTurbolinks = function() {
rememberCurrentUrl();
rememberCurrentState();
document.addEventListener('click', Click.installHandlerLast, true);
window.addEventListener('hashchange', function(event) {
rememberCurrentUrl();
return rememberCurrentState();
}, false);
return bypassOnLoadPopstate(function() {
return window.addEventListener('popstate', installHistoryChangeHandler, false);
});
};
historyStateIsDefined = window.history.state !== void 0 || navigator.userAgent.match(/Firefox\/2[6|7]/);
browserSupportsPushState = window.history && window.history.pushState && window.history.replaceState && historyStateIsDefined;
browserIsntBuggy = !navigator.userAgent.match(/CriOS\//);
requestMethodIsSafe = (ref = popCookie('request_method')) === 'GET' || ref === '';
browserSupportsTurbolinks = browserSupportsPushState && browserIsntBuggy && requestMethodIsSafe;
browserSupportsCustomEvents = document.addEventListener && document.createEvent;
if (browserSupportsCustomEvents) {
installDocumentReadyPageEventTriggers();
installJqueryAjaxSuccessPageUpdateTrigger();
}
if (browserSupportsTurbolinks) {
visit = fetch;
initializeTurbolinks();
} else {
visit = function(url) {
return document.location.href = url;
};
}
this.Turbolinks = {
visit: visit,
pagesCached: pagesCached,
enableTransitionCache: enableTransitionCache,
enableProgressBar: enableProgressBar,
allowLinkExtensions: Link.allowExtensions,
supported: browserSupportsTurbolinks,
EVENTS: clone(EVENTS)
};
}).call(this);