Skip to content

Commit

Permalink
consistently style our javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
danslo committed Feb 13, 2018
1 parent 79f80bf commit 5c30375
Show file tree
Hide file tree
Showing 11 changed files with 231 additions and 251 deletions.
41 changes: 19 additions & 22 deletions src/view/frontend/web/js/mixin/abstract-total-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@
* Copyright © 2018 Rubic. All rights reserved.
* See LICENSE.txt for license details.
*/
define(
[
'Magento_Checkout/js/model/step-navigator'
],
function (stepNavigator) {
'use strict';
define([
'Magento_Checkout/js/model/step-navigator'
], function (stepNavigator) {
'use strict';

/**
* Allow configuration to force total full mode.
*/
return function (target) {
return target.extend({
isFullMode: function () {
if (!this.getTotals()) {
return false;
}

return window.checkoutConfig.forceTotalsFullMode ?
true : stepNavigator.isProcessed('shipping');
/**
* Allow configuration to force total full mode.
*/
return function (target) {
return target.extend({
isFullMode: function () {
if (!this.getTotals()) {
return false;
}
});
};
}
);

return window.checkoutConfig.forceTotalsFullMode ?
true : stepNavigator.isProcessed('shipping');
}
});
};
});
4 changes: 3 additions & 1 deletion src/view/frontend/web/js/mixin/cart-items-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* Copyright © 2018 Rubic. All rights reserved.
* See LICENSE.txt for license details.
*/
define([], function () {
define([

], function () {
'use strict';

/**
Expand Down
4 changes: 3 additions & 1 deletion src/view/frontend/web/js/mixin/email-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* Copyright © 2018 Rubic. All rights reserved.
* See LICENSE.txt for license details.
*/
define(['Magento_Checkout/js/checkout-data'], function (checkoutData) {
define([
'Magento_Checkout/js/checkout-data'
], function (checkoutData) {
'use strict';

/**
Expand Down
41 changes: 19 additions & 22 deletions src/view/frontend/web/js/mixin/payment-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@
* Copyright © 2018 Rubic. All rights reserved.
* See LICENSE.txt for license details.
*/
define(
[
'ko',
'Magento_Checkout/js/model/quote',
'Magento_Customer/js/model/customer'
],
function (ko, quote, customer) {
'use strict';
define([
'ko',
'Magento_Checkout/js/model/quote',
'Magento_Customer/js/model/customer'
], function (ko, quote, customer) {
'use strict';

/**
* Disable visibility on billing, since it's no longer the first step.
*/
return function (target) {
return target.extend({
defaults: {
template: 'Rubic_CleanCheckout/payment',
activeMethod: ''
},
/**
* Disable visibility on billing, since it's no longer the first step.
*/
return function (target) {
return target.extend({
defaults: {
template: 'Rubic_CleanCheckout/payment',
activeMethod: ''
},

isVisible: ko.observable(customer.isLoggedIn() && quote.isVirtual())
});
};
}
);
isVisible: ko.observable(customer.isLoggedIn() && quote.isVirtual())
});
};
});
4 changes: 3 additions & 1 deletion src/view/frontend/web/js/mixin/progress-bar-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* Copyright © 2018 Rubic. All rights reserved.
* See LICENSE.txt for license details.
*/
define([], function () {
define([

], function () {
'use strict';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* Copyright © 2018 Rubic. All rights reserved.
* See LICENSE.txt for license details.
*/
define([], function () {
define([

], function () {
'use strict';

/**
Expand Down
4 changes: 3 additions & 1 deletion src/view/frontend/web/js/mixin/summary-shipping-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* Copyright © 2018 Rubic. All rights reserved.
* See LICENSE.txt for license details.
*/
define([], function () {
define([

], function () {
'use strict';

/**
Expand Down
181 changes: 89 additions & 92 deletions src/view/frontend/web/js/view/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,113 +2,110 @@
* Copyright © 2018 Rubic. All rights reserved.
* See LICENSE.txt for license details.
*/
define(
[
'uiComponent',
'jquery',
'async'
],
function (Component, $, async) {
'use strict';
define([
'uiComponent',
'jquery',
'async'
], function (Component, $, async) {
'use strict';

return Component.extend({
autocomplete: [],
return Component.extend({
autocomplete: [],

streetFieldSelector: "input[name='street[0]']",
streetFieldSelector: "input[name='street[0]']",

fields: {
postal_code: { short_name: "input[name='postcode']" },
locality: { long_name: "input[name='city']" },
postal_town: { short_name: "input[name='city']" },
country: { short_name: "select[name='country_id']" },
administrative_area_level_1: { long_name: "input[name='region']:visible" }
},
fields: {
postal_code: { short_name: "input[name='postcode']" },
locality: { long_name: "input[name='city']" },
postal_town: { short_name: "input[name='city']" },
country: { short_name: "select[name='country_id']" },
administrative_area_level_1: { long_name: "input[name='region']:visible" }
},

initialize: function () {
if (window.checkoutConfig.autoComplete.enabled) {
async.load(
'https://maps.googleapis.com/maps/api/js?key=' + window.checkoutConfig.autoComplete.apiKey + '&libraries=places&callback=initAutocomplete',
requirejs,
function () {
$(document).on('keypress', this.streetFieldSelector, function (e) {
if (typeof this.autocomplete[e.target.id] === 'undefined') {
var autocomplete = new google.maps.places.Autocomplete(e.target, {types: ['geocode']});
autocomplete.addListener('place_changed', this.fillAddressFields);
autocomplete.e = e.target;
autocomplete.c = this;
this.autocomplete[e.target.id] = autocomplete;
}
}.bind(this));
}.bind(this),
{isBuild: false}
);
}
return this._super();
},
initialize: function () {
if (window.checkoutConfig.autoComplete.enabled) {
async.load(
'https://maps.googleapis.com/maps/api/js?key=' + window.checkoutConfig.autoComplete.apiKey + '&libraries=places&callback=initAutocomplete',
requirejs,
function () {
$(document).on('keypress', this.streetFieldSelector, function (e) {
if (typeof this.autocomplete[e.target.id] === 'undefined') {
var autocomplete = new google.maps.places.Autocomplete(e.target, {types: ['geocode']});
autocomplete.addListener('place_changed', this.fillAddressFields);
autocomplete.e = e.target;
autocomplete.c = this;
this.autocomplete[e.target.id] = autocomplete;
}
}.bind(this));
}.bind(this),
{isBuild: false}
);
}
return this._super();
},

findComponentValue: function (place, type, subtype) {
for (var i = 0; i < place.address_components.length; i++) {
for (var j = 0; j < place.address_components[i].types.length; j++) {
var addressType = place.address_components[i].types[j];
if (addressType === type) {
return place.address_components[i][subtype];
}
findComponentValue: function (place, type, subtype) {
for (var i = 0; i < place.address_components.length; i++) {
for (var j = 0; j < place.address_components[i].types.length; j++) {
var addressType = place.address_components[i].types[j];
if (addressType === type) {
return place.address_components[i][subtype];
}
}
return null;
},
}
return null;
},

shouldSplitStreetFields: function () {
return window.checkoutConfig.autoComplete.splitStreetFields;
},
shouldSplitStreetFields: function () {
return window.checkoutConfig.autoComplete.splitStreetFields;
},

fillStreetFields: function (element, place) {
var streetNumberElement = $(element).closest('fieldset').find("input[name='street[1]']");
if (streetNumberElement.length && this.shouldSplitStreetFields()) {
var route = this.findComponentValue(place, 'route', 'long_name');
var number = this.findComponentValue(place, 'street_number', 'short_name');
$(element).val(route).change();
streetNumberElement.val(number).change();
} else {
$(element).val(place.name).change();
}
},
fillStreetFields: function (element, place) {
var streetNumberElement = $(element).closest('fieldset').find("input[name='street[1]']");
if (streetNumberElement.length && this.shouldSplitStreetFields()) {
var route = this.findComponentValue(place, 'route', 'long_name');
var number = this.findComponentValue(place, 'street_number', 'short_name');
$(element).val(route).change();
streetNumberElement.val(number).change();
} else {
$(element).val(place.name).change();
}
},

fillOtherFields: function (element, place) {
for (var type in this.fields) {
if (this.fields.hasOwnProperty(type)) {
for (var subtype in this.fields[type]) {
if (this.fields[type].hasOwnProperty(subtype)) {
var selector = this.fields[type][subtype];
var form = $(element).closest('form');
var field = form.find(selector);
var value = this.findComponentValue(place, type, subtype);
fillOtherFields: function (element, place) {
for (var type in this.fields) {
if (this.fields.hasOwnProperty(type)) {
for (var subtype in this.fields[type]) {
if (this.fields[type].hasOwnProperty(subtype)) {
var selector = this.fields[type][subtype];
var form = $(element).closest('form');
var field = form.find(selector);
var value = this.findComponentValue(place, type, subtype);

if (value !== null) {
if (field.length) {
field.val(value).change();
} else if (type === 'administrative_area_level_1') {
// Couldn't find visible region input, dealing with a dropdown.
var regionSelector = "select[name='region_id'] option";
form.find(regionSelector).filter(function () {
return $(this).text() === value;
}).prop('selected', true).change();
}
if (value !== null) {
if (field.length) {
field.val(value).change();
} else if (type === 'administrative_area_level_1') {
// Couldn't find visible region input, dealing with a dropdown.
var regionSelector = "select[name='region_id'] option";
form.find(regionSelector).filter(function () {
return $(this).text() === value;
}).prop('selected', true).change();
}
}
}
}
}
},
}
},

fillAddressFields: function () {
var place = this.getPlace();
if (typeof place === 'undefined') {
return;
}
this.c.fillStreetFields(this.e, place);
this.c.fillOtherFields(this.e, place);
fillAddressFields: function () {
var place = this.getPlace();
if (typeof place === 'undefined') {
return;
}
});
}
);
this.c.fillStreetFields(this.e, place);
this.c.fillOtherFields(this.e, place);
}
});
});
Loading

0 comments on commit 5c30375

Please sign in to comment.