-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Animated change transitions #26
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -385,19 +385,31 @@ | |
LiveReload.prototype.performReload = function(message) { | ||
var _ref, _ref1; | ||
this.log("LiveReload received reload request: " + (JSON.stringify(message, null, 2))); | ||
return this.reloader.reload(message.path, { | ||
this.reloader.reload(message.path, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't send There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understood. |
||
liveCSS: (_ref = message.liveCSS) != null ? _ref : true, | ||
liveImg: (_ref1 = message.liveImg) != null ? _ref1 : true, | ||
originalPath: message.originalPath || '', | ||
overrideURL: message.overrideURL || '', | ||
serverURL: "http://" + this.options.host + ":" + this.options.port | ||
serverURL: "//" + this.options.host + ":" + this.options.port | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the most curious line. Why did you remove http: here? At least in LiveReload 2 app, SSL isn't handled by the built-in web server used for the Override URL feature (which is, of course, lame, but hey). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually an outdated build. I since undid that change in CoffeeScript file because I didn't want to introduce unrelated changes in this PR. |
||
}); | ||
return this.performTransition(); | ||
}; | ||
|
||
LiveReload.prototype.performAlert = function(message) { | ||
return alert(message.message); | ||
}; | ||
|
||
LiveReload.prototype.performTransition = function() { | ||
var existingHtmlClass, html, reloadedClass, _ref; | ||
html = document.body.parentNode; | ||
reloadedClass = ' livereload-reloaded '; | ||
existingHtmlClass = (_ref = html.getAttribute('class')) != null ? _ref : ''; | ||
html.setAttribute('class', "" + (existingHtmlClass.replace(reloadedClass, '')) + " " + reloadedClass); | ||
return setTimeout((function() { | ||
return html.setAttribute('class', existingHtmlClass.replace(reloadedClass, '')); | ||
}), parseInt(this.options.animation_duration, 10) + 20); | ||
}; | ||
|
||
LiveReload.prototype.shutDown = function() { | ||
var _base; | ||
this.connector.disconnect(); | ||
|
@@ -450,6 +462,24 @@ | |
}); | ||
}; | ||
|
||
LiveReload.prototype.setUpCSSTransitions = function() { | ||
var cssText, head, prefixer, styleNode; | ||
prefixer = function(declaration) { | ||
return (['-webkit-', '-moz-', ''].map(function(item) { | ||
return "" + item + declaration; | ||
})).join(' '); | ||
}; | ||
head = document.getElementsByTagName('head')[0]; | ||
styleNode = document.createElement("style"); | ||
cssText = ".livereload-reloaded * { " + (prefixer('transition: all ' + this.options.animation_duration + 'ms ease-out;')) + " }"; | ||
if (styleNode.styleSheet) { | ||
styleNode.styleSheet.cssText = cssText; | ||
} else { | ||
styleNode.appendChild(document.createTextNode(cssText)); | ||
} | ||
return head.appendChild(styleNode); | ||
}; | ||
|
||
return LiveReload; | ||
|
||
})(); | ||
|
@@ -470,6 +500,8 @@ | |
this.mindelay = 1000; | ||
this.maxdelay = 60000; | ||
this.handshake_timeout = 5000; | ||
this.animate = false; | ||
this.animation_duration = 280; | ||
} | ||
|
||
Options.prototype.set = function(name, value) { | ||
|
@@ -1095,6 +1127,9 @@ | |
}); | ||
|
||
LiveReload.on('connect', function() { | ||
if (!!/true|1$/.test(LiveReload.options.animate)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's cleaner to put all parsing in |
||
LiveReload.setUpCSSTransitions(); | ||
} | ||
return CustomEvents.fire(document, 'LiveReloadConnect'); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
background: green; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>LiveReload Test</title> | ||
<link rel="stylesheet" href="test.css"> | ||
</head> | ||
<body> | ||
<h1>Test animated transitions</h1> | ||
<script src="../../../dist/livereload.js?host=localhost&animation=true" async defer></script> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want to allow e.g.
animate=200
,animate=400
in addition toanimate=true
to optionally specify the duration?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea. I'll update.