Last active
December 15, 2015 08:59
-
-
Save shimomura1004/5234567 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
if (location.pathname.indexOf("/chat/room") == 0) { | |
var message = $("#message").css({ | |
"-webkit-transition" : "height 0.3s ease-in-out", | |
"-webkit-transition" : "width 0.3s ease-in-out", | |
"transition" : "height 0.3s ease-in-out", | |
"transition" : "width 0.3s ease-in-out", | |
}); | |
var defaultStyle = { | |
"width" : message.css("width"), | |
"height" : message.css("height"), | |
"margin-left" : message.css("margin-left"), | |
}; | |
var expandStyle = { | |
"width" : "100%", | |
"height" : "10em", | |
"margin-left" : "0px", | |
}; | |
function needsExpansion(){ | |
var value = message.val(); | |
var lineNumber = value.split("\n").length; | |
var charNumber = value.length; | |
return (lineNumber >= 3 || charNumber >= 30); | |
} | |
function resize(){ | |
if (needsExpansion()) { | |
expand(); | |
} else { | |
shrink(); | |
} | |
} | |
function expand(){ | |
if (needsExpansion()) { | |
message.css(expandStyle); | |
} | |
} | |
function shrink(){ | |
message.css(defaultStyle); | |
} | |
message.bind("keyup", expand); | |
message.bind("focus blur", resize); | |
$("form.inputarea").bind("submit", shrink); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment