From 2ca6aaaeccdcd61e371d3ac8c9d10e5dfe859f33 Mon Sep 17 00:00:00 2001 From: Theodor Vararu Date: Tue, 9 Aug 2016 16:24:44 +0100 Subject: [PATCH] Remove selection-buttons.js A copy of this file already gets imported and served through https://github.com/alphagov/govuk_prototype_kit/blob/master/server.js#L58. As such, we don't need this file. Relevant discusson: https://github.com/alphagov/govuk_prototype_kit/pull/223#discussion_r70628261 --- .../javascripts/govuk/selection-buttons.js | 111 ------------------ 1 file changed, 111 deletions(-) delete mode 100644 app/assets/javascripts/govuk/selection-buttons.js diff --git a/app/assets/javascripts/govuk/selection-buttons.js b/app/assets/javascripts/govuk/selection-buttons.js deleted file mode 100644 index 69d0284b3f..0000000000 --- a/app/assets/javascripts/govuk/selection-buttons.js +++ /dev/null @@ -1,111 +0,0 @@ -(function () { - "use strict"; - var root = this, - $ = root.jQuery; - - if (typeof GOVUK === 'undefined') { root.GOVUK = {}; } - - var SelectionButtons = function (elmsOrSelector, opts) { - var $elms; - - this.selectedClass = 'selected'; - this.focusedClass = 'focused'; - if (opts !== undefined) { - $.each(opts, function (optionName, optionObj) { - this[optionName] = optionObj; - }.bind(this)); - } - if (typeof elmsOrSelector === 'string') { - $elms = $(elmsOrSelector); - this.selector = elmsOrSelector; - this.setInitialState($(this.selector)); - } else if (elmsOrSelector !== undefined) { - this.$elms = elmsOrSelector; - this.setInitialState(this.$elms); - } - this.addEvents(); - }; - SelectionButtons.prototype.addEvents = function () { - if (typeof this.$elms !== 'undefined') { - this.addElementLevelEvents(); - } else { - this.addDocumentLevelEvents(); - } - }; - SelectionButtons.prototype.setInitialState = function ($elms) { - $elms.each(function (idx, elm) { - var $elm = $(elm); - - if ($elm.is(':checked')) { - this.markSelected($elm); - } - }.bind(this)); - }; - SelectionButtons.prototype.markFocused = function ($elm, state) { - if (state === 'focused') { - $elm.parent('label').addClass(this.focusedClass); - } else { - $elm.parent('label').removeClass(this.focusedClass); - } - }; - SelectionButtons.prototype.markSelected = function ($elm) { - var radioName; - - if ($elm.attr('type') === 'radio') { - radioName = $elm.attr('name'); - $($elm[0].form).find('input[name="' + radioName + '"]') - .parent('label') - .removeClass(this.selectedClass); - $elm.parent('label').addClass(this.selectedClass); - } else { // checkbox - if ($elm.is(':checked')) { - $elm.parent('label').addClass(this.selectedClass); - } else { - $elm.parent('label').removeClass(this.selectedClass); - } - } - }; - SelectionButtons.prototype.addElementLevelEvents = function () { - this.clickHandler = this.getClickHandler(); - this.focusHandler = this.getFocusHandler({ 'level' : 'element' }); - - this.$elms - .on('click', this.clickHandler) - .on('focus blur', this.focusHandler); - }; - SelectionButtons.prototype.addDocumentLevelEvents = function () { - this.clickHandler = this.getClickHandler(); - this.focusHandler = this.getFocusHandler({ 'level' : 'document' }); - - $(document) - .on('click', this.selector, this.clickHandler) - .on('focus blur', this.selector, this.focusHandler); - }; - SelectionButtons.prototype.getClickHandler = function () { - return function (e) { - this.markSelected($(e.target)); - }.bind(this); - }; - SelectionButtons.prototype.getFocusHandler = function (opts) { - var focusEvent = (opts.level === 'document') ? 'focusin' : 'focus'; - - return function (e) { - var state = (e.type === focusEvent) ? 'focused' : 'blurred'; - - this.markFocused($(e.target), state); - }.bind(this); - }; - SelectionButtons.prototype.destroy = function () { - if (typeof this.selector !== 'undefined') { - $(document) - .off('click', this.selector, this.clickHandler) - .off('focus blur', this.selector, this.focusHandler); - } else { - this.$elms - .off('click', this.clickHandler) - .off('focus blur', this.focusHandler); - } - }; - - root.GOVUK.SelectionButtons = SelectionButtons; -}).call(this);