Created
December 14, 2016 00:42
-
-
Save brettmarshall/55a902534e388135de5739f0c9f22d4d to your computer and use it in GitHub Desktop.
Ninja Forms
This file contains hidden or 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 ($) { | |
'use strict'; | |
/** | |
* Instantiate Chosen | |
* https://harvesthq.github.io/chosen/ | |
*/ | |
var fancySelects = function () { | |
var query = 'select'; | |
if (!$(query).length) return; | |
var $selects = $(query); | |
$selects.attr('data-placeholder', 'Select Multiple') | |
/*jshint camelcase: false */ | |
.chosen({disable_search_threshold: 10}); | |
}; | |
/** | |
* Instantiate iCheck | |
* http://icheck.fronteed.com/ | |
*/ | |
var fancyChoices = function () { | |
var query = 'input[type=radio]:not(.starrating input[type=radio]), input[type=checkbox]'; | |
if (!$(query).length) return; | |
var $inputs = $(query); | |
$inputs.iCheck({ | |
checkboxClass: 'icheckbox_minimal', | |
radioClass: 'iradio_minimal', | |
increaseArea: '20%' | |
}); | |
}; | |
/** | |
* Instantiate floatlabel | |
* https://github.com/derpoho/floatlabels.js | |
*/ | |
var flPattern = function () { | |
var query = 'input, textarea'; | |
if (!$(query).length) return; | |
var $inputs = $(query); | |
$inputs.floatlabel(); | |
}; | |
module.exports = { | |
fancySelects:fancySelects, | |
fancyChoices:fancyChoices, | |
flPattern:flPattern | |
}; | |
})(jQuery); |
This file contains hidden or 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
/*global Marionette */ | |
/*global Backbone */ | |
(function ($) { | |
'use strict'; | |
var formHelpers = require('./globals/form-helpers.js'); | |
/** | |
* Fire Ninja Form JavaScript using Backbone | |
* https://gist.github.com/klhall1987/a39c3825eda0629ab593995e29f44763 | |
*/ | |
var CustomFormJS = Marionette.Object.extend({ | |
initialize: function () { | |
this.listenTo(Backbone.Radio.channel('form'), 'render:view', this.fireFormJS); | |
}, | |
fireFormJS: function () { | |
formHelpers.fancySelects(); | |
formHelpers.fancyChoices(); | |
formHelpers.flPattern(); | |
} | |
}); | |
/** | |
* Utilizes the event when a form is submitted | |
*/ | |
var CustomFormJSSubmitController = Marionette.Object.extend({ | |
initialize: function () { | |
this.listenTo(Backbone.Radio.channel('forms'), 'submit:response', this.actionSubmit); | |
}, | |
actionSubmit: function (response) { | |
formHelpers.fancySelects(); | |
formHelpers.fancyChoices(); | |
formHelpers.flPattern(); | |
console.log(response); | |
} | |
}); | |
$(document).ready(function () { | |
new CustomFormJS(); | |
new CustomFormJSSubmitController(); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment