Created
July 2, 2014 16:12
-
-
Save justinhillsjohnson/971cfd127153556ac6e4 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
/** | |
* @module views/AppView | |
*/ | |
define([ | |
'jquery', | |
'underscore', | |
'backbone', | |
'app' | |
], | |
function( | |
$, | |
_, | |
Backbone, | |
App | |
) { | |
'use strict'; | |
return Backbone.View.extend({ | |
'defaults': { | |
}, | |
'events': { | |
}, | |
'templates': {}, | |
'initialize': function() { | |
var view = this; | |
view.render(); | |
log('AppView : Initialized'); | |
}, | |
'render': function() { | |
var view = this; | |
view.polyfillPlaceholder(); | |
}, | |
'polyfillPlaceholder': function() { | |
var view = this; | |
if (view.supportsPlaceholder() === false) { | |
view.$('input[type=text], input[type=email]').each(function() { | |
view.setInputPlaceholder($(this), $(this).attr('placeholder')); | |
}); | |
} | |
}, | |
/** | |
* Check for support of INPUT placeholder attribute. | |
*/ | |
'supportsPlaceholder': function() { | |
return document.createElement('input').placeholder !== undefined; | |
}, | |
/** | |
* Use placeholder text when INPUT tag is empty. | |
* @param input {String} ID of INPUT tag | |
* @param placeholderTxt {String} | |
*/ | |
'setInputPlaceholder': function($input, placeholderTxt) { | |
var placeholder = placeholderTxt; | |
$input.val(placeholder).addClass('placeholder').focus(function() { | |
if ($input.val() === placeholder) { | |
$input.val('').removeClass('placeholder'); | |
} | |
}).blur(function() { | |
if ($input.val() === '') { | |
$input.val(placeholder).addClass('placeholder'); | |
} | |
}); | |
} | |
}); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment