Created
November 26, 2015 13:28
-
-
Save tobynet/afbfa52321280f9ee90b to your computer and use it in GitHub Desktop.
[Practice] Tweet Box Using jQuery
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
div.well.clearfix | |
textarea.form-control | |
br | |
span 140 | |
button.js-tweet-button.btn.btn-primary.pull-right(disabled) Tweet | |
button.js-add-photo-button.btn.btn-default.pull-right Add Photo |
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
// ref. http://reactfordesigners.com/labs/reactjs-introduction-for-people-who-know-just-enough-jquery-to-get-by/ | |
$("textarea").on("input", (event) => { | |
// Show text count | |
if ($(".js-add-photo-button").hasClass("is-on")) { | |
$("span").text(140 - 23 - $(event.target).val().length); | |
} else { | |
$("span").text(140 - $(event.target).val().length); | |
} | |
if ($(event.target).val().length > 0 | |
|| $(".js-add-photo-button").hasClass("is-on")) { | |
$(".js-tweet-button").prop("disabled", false); | |
} else { | |
$(".js-tweet-button").prop("disabled", true); | |
} | |
}); | |
$(".js-add-photo-button").on("click", function(event){ | |
if ($(event.target).hasClass("is-on")) { | |
$(event.target) | |
.removeClass("is-on") | |
.text("Add Photo"); | |
$("span").text(140 - $("textarea").val().length); | |
if ($("textarea").val().length === 0) { | |
$(".js-tweet-button").prop("disabled", true); | |
} | |
} else { | |
$(event.target) | |
.addClass("is-on") | |
.text("✔ Photo Added"); | |
$("span").text(140 - 23 - $("textarea").val().length); | |
$(".js-tweet-button").prop("disabled", false); | |
} | |
}); |
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
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> |
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
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment