Skip to content

Commit 4d36fa3

Browse files
committed
Add animate option to transition to all changes
1 parent 2cf6dcb commit 4d36fa3

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

lib/public/livereload.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ __options.Options = Options = (function() {
327327
this.mindelay = 1000;
328328
this.maxdelay = 60000;
329329
this.handshake_timeout = 5000;
330+
this.animate = false;
330331
}
331332
Options.prototype.set = function(name, value) {
332333
switch (typeof this[name]) {
@@ -918,15 +919,16 @@ __livereload.LiveReload = LiveReload = (function() {
918919
};
919920

920921
LiveReload.prototype.performReload = function(message) {
921-
var _ref, _ref2;
922+
var _base, _ref, _ref2;
922923
this.log("LiveReload received reload request for " + message.path + ".");
923-
return this.reloader.reload(message.path, {
924+
this.reloader.reload(message.path, {
924925
liveCSS: (_ref = message.liveCSS) != null ? _ref : true,
925926
liveImg: (_ref2 = message.liveImg) != null ? _ref2 : true,
926927
originalPath: message.originalPath || '',
927928
overrideURL: message.overrideURL || '',
928929
serverURL: "http://" + this.options.host + ":" + this.options.port
929930
});
931+
return typeof (_base = this.listeners).reload === "function" ? _base.reload() : void 0;
930932
};
931933

932934
LiveReload.prototype.performAlert = function(message) {
@@ -980,6 +982,24 @@ __livereload.LiveReload = LiveReload = (function() {
980982
});
981983
};
982984

985+
LiveReload.prototype.setUpCSSTransitions = function() {
986+
var cssText, head, prefixer, styleNode;
987+
prefixer = function(declaration) {
988+
return (['-webkit-', '-moz-', ''].map(function(item) {
989+
return "" + item + declaration;
990+
})).join(' ');
991+
};
992+
head = document.getElementsByTagName('head')[0];
993+
styleNode = document.createElement("style");
994+
cssText = ".livereload-reloaded * { " + (prefixer('transition: all 280ms ease-out;')) + " }";
995+
if (styleNode.styleSheet) {
996+
styleNode.styleSheet.cssText = cssText;
997+
} else {
998+
styleNode.appendChild(document.createTextNode(cssText));
999+
}
1000+
return head.appendChild(styleNode);
1001+
};
1002+
9831003
return LiveReload;
9841004

9851005
})();
@@ -1072,11 +1092,24 @@ LiveReload.on('shutdown', function() {
10721092
return delete window.LiveReload;
10731093
});
10741094
LiveReload.on('connect', function() {
1095+
if (!!/true|1$/.test(LiveReload.options.animate)) {
1096+
LiveReload.setUpCSSTransitions();
1097+
}
10751098
return CustomEvents.fire(document, 'LiveReloadConnect');
10761099
});
10771100
LiveReload.on('disconnect', function() {
10781101
return CustomEvents.fire(document, 'LiveReloadDisconnect');
10791102
});
1103+
LiveReload.on('reload', function() {
1104+
var existingHtmlClass, html, reloadedClass, _ref;
1105+
html = document.body.parentNode;
1106+
reloadedClass = ' livereload-reloaded';
1107+
existingHtmlClass = (_ref = html.getAttribute('class')) != null ? _ref : '';
1108+
html.setAttribute('class', "" + (existingHtmlClass.replace(reloadedClass, '')) + " " + reloadedClass);
1109+
return setTimeout((function() {
1110+
return html.setAttribute('class', existingHtmlClass.replace(reloadedClass, ''));
1111+
}), 300);
1112+
});
10801113
CustomEvents.bind(document, 'LiveReloadShutDown', function() {
10811114
return LiveReload.shutDown();
10821115
});

0 commit comments

Comments
 (0)