Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove jquery from govspeak #1657

Merged
merged 5 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
useful summary for people upgrading their application, not a replication
of the commit log.

## Unreleased

* Remove jquery from govspeak ([PR #1657](https://github.com/alphagov/govuk_publishing_components/pull/1657))

## 21.63.2

* Fix the on blue logic for the search component ([PR #1663](https://github.com/alphagov/govuk_publishing_components/pull/1663))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ window.GOVUK = window.GOVUK || {}
window.GOVUK.Modules = window.GOVUK.Modules || {};

(function (Modules) {
'use strict'
function Govspeak () { }

Modules.Govspeak = function () {
this.start = function ($element) {
if (!$element.hasClass('disable-youtube')) {
this.embedYoutube($element)
}
Govspeak.prototype.start = function ($module) {
this.$module = $module[0]

this.createBarcharts($element)
if (this.$module.className.indexOf('disable-youtube') === -1) {
this.embedYoutube()
}

this.embedYoutube = function ($jqElement) {
var enhancement = new window.GOVUK.GovspeakYoutubeLinkEnhancement($jqElement[0])
enhancement.init()
}
this.createBarcharts()
}

this.createBarcharts = function ($element) {
var enhancement = new window.GOVUK.GovspeakBarchartEnhancement($element)
enhancement.init()
}
Govspeak.prototype.embedYoutube = function () {
var enhancement = new window.GOVUK.GovspeakYoutubeLinkEnhancement(this.$module)
enhancement.init()
}

Govspeak.prototype.createBarcharts = function () {
var enhancement = new window.GOVUK.GovspeakBarchartEnhancement(this.$module)
enhancement.init()
}

Modules.Govspeak = Govspeak
})(window.GOVUK.Modules)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// = require govuk_publishing_components/vendor/magna-charta.min
// = require govuk_publishing_components/lib/govspeak/magna-charta

window.GOVUK = window.GOVUK || {};

Expand All @@ -10,16 +10,23 @@ window.GOVUK = window.GOVUK || {};
}

BarchartEnhancement.prototype.init = function () {
// the not selectors are protection against initialising twice since that
// causes quite a mess. The not .mc-chart is because it creates a second
// .js-barchart-table element with .mc-chart and then the
// .js-barchart-table-init is given when we initialise
var $barcharts = this.$element.find('.js-barchart-table:not(.mc-chart):not(.js-barchart-table-init)')
$barcharts.each(function () {
var $table = $(this)
$.magnaCharta($table, { toggleText: 'Change between chart and table' })
$table.addClass('js-barchart-table-init')
})
var $barchartsOriginal = this.$element.querySelectorAll('.js-barchart-table')
var $barcharts = []

for (var j = 0; j < $barchartsOriginal.length; j++) {
// this prevents the code from initialising more than once
// we'd use :not selectors for $barchartsOriginal but for lack of IE8 support
var styles = $barchartsOriginal[j].className
if (styles.indexOf('mc-chart') === -1 && styles.indexOf('js-barchart-table-init') === -1) {
$barcharts.push($barchartsOriginal[j])
}
}

for (var i = 0; i < $barcharts.length; i++) {
var $table = $barcharts[i]
new GOVUK.Modules.MagnaCharta().start($table, { toggleText: 'Change between chart and table' })
$table.className = $table.className + ' js-barchart-table-init'
}
}

GOVUK.GovspeakBarchartEnhancement = BarchartEnhancement
Expand Down
Loading