Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ministryofjustice/frontend

Package Overview
Dependencies
Maintainers
3
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ministryofjustice/frontend - npm Package Compare versions

Comparing version 0.0.2-alpha to 0.0.3-alpha

components/moj-add-another/_add-another.scss

72

all.js

@@ -31,2 +31,74 @@ var MOJFrontend = {};

MOJFrontend.AddAnother = function(container) {
this.container = $(container);
this.container.on('click', '.moj-add-another__remove-button', $.proxy(this, 'onRemoveButtonClick'));
this.container.on('click', '.moj-add-another__add-button', $.proxy(this, 'onAddButtonClick'));
this.container.find('.moj-add-another__add-button, moj-add-another__remove-button').prop('type', 'button');
};
MOJFrontend.AddAnother.prototype.onAddButtonClick = function(e) {
var item = this.getNewItem();
this.updateAttributes(this.getItems().length, item);
this.resetItem(item);
var firstItem = this.getItems().first();
if(!this.hasRemoveButton(firstItem)) {
this.createRemoveButton(firstItem);
}
this.getItems().last().after(item);
item.find('input, textarea, select').first().focus();
};
MOJFrontend.AddAnother.prototype.hasRemoveButton = function(item) {
return item.find('.moj-add-another__remove-button').length;
};
MOJFrontend.AddAnother.prototype.getItems = function() {
return this.container.find('.moj-add-another__item');
};
MOJFrontend.AddAnother.prototype.getNewItem = function() {
var item = this.getItems().first().clone();
if(!this.hasRemoveButton(item)) {
this.createRemoveButton(item);
}
return item;
};
MOJFrontend.AddAnother.prototype.updateAttributes = function(index, item) {
item.find('[data-name]').each(function(i, el) {
el.name = $(el).attr('data-name').replace(/%index%/, index);
el.id = $(el).attr('data-id').replace(/%index%/, index);
($(el).prev('label')[0] || $(el).parents('label')[0]).htmlFor = el.id;
});
};
MOJFrontend.AddAnother.prototype.createRemoveButton = function(item) {
item.append('<button type="button" class="govuk-button govuk-button--secondary moj-add-another__remove-button">Remove</button>');
};
MOJFrontend.AddAnother.prototype.resetItem = function(item) {
item.find('[data-name], [data-id]').each(function(index, el) {
if(el.type == 'checkbox' || el.type == 'radio') {
el.checked = false;
} else {
el.value = '';
}
});
};
MOJFrontend.AddAnother.prototype.onRemoveButtonClick = function(e) {
$(e.currentTarget).parents('.moj-add-another__item').remove();
var items = this.getItems();
if(items.length === 1) {
items.find('.moj-add-another__remove-button').remove();
}
items.each($.proxy(function(index, el) {
this.updateAttributes(index, $(el));
}, this));
this.focusHeading();
};
MOJFrontend.AddAnother.prototype.focusHeading = function() {
this.container.find('.moj-add-another__heading').focus();
};
MOJFrontend.FormValidator = function(form, options) {

@@ -33,0 +105,0 @@ this.form = form;

2

package.json
{
"name": "@ministryofjustice/frontend",
"description": "The MOJ Frontend contains the code you need to start building user interfaces for UK Ministry of Justice government services.",
"version": "0.0.2-alpha",
"version": "0.0.3-alpha",
"main": "all.js",

@@ -6,0 +6,0 @@ "sass": "all.scss",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc