Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var navSearch = {
- button: '#search input:submit',
- input: '#search input:text',
- placeholder: 'Type here to search...',
- openWidth: 300,
- closedWidth: 50,
- openSearch: function() {
- $(this.input).css('width', this.openWidth);
- },
- closeSearch: function() {
- $(this.input).attr('placeholder', '');
- if ($(this.input).val().length == 0) {
- $(this.input).css('width', this.closedWidth);
- }
- },
- setPlaceholder: function() {
- if ($(this.input).val().length == 0) {
- $(this.input).attr('placeholder', this.placeholder);
- }
- },
- isOpen: function() {
- if (!$(this.input).is(':focus')
- && $(this.input).val().length == 0
- && $(this.input).outerWidth() == this.closedWidth) {
- return false;
- }
- return true;
- }
- };
- $(navSearch.input).focus(function() {
- navSearch.setPlaceholder();
- });
- $(navSearch.input).blur(function() {
- navSearch.closeSearch();
- });
- $(navSearch.button).click(function() {
- if (!navSearch.isOpen()) {
- $(navSearch.input).focus();
- navSearch.openSearch();
- return false;
- } else if ($(navSearch.input).val().length > 0) {
- // Submit the search. TODO
- console.log($(navSearch.input).val());
- return false;
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment