Skip to content

Instantly share code, notes, and snippets.

@justinhillsjohnson
Created July 2, 2014 16:12
Show Gist options
  • Save justinhillsjohnson/971cfd127153556ac6e4 to your computer and use it in GitHub Desktop.
Save justinhillsjohnson/971cfd127153556ac6e4 to your computer and use it in GitHub Desktop.
/**
* @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