Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/0.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinballard committed May 5, 2019
2 parents 19e740a + c2a4342 commit f93b132
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# IDE & OS specific
.DS_Store
.idea

# Logs
logs
*.log

# Dependencies
node_modules

# Coverage
coverage

# Release
lib
26 changes: 26 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# IDE & OS specific
.DS_Store
.idea

# Logs
logs
*.log

# Dependencies
node_modules

# Coverage
coverage

# Sources, tests and builder files
builder
src
test
internals
.babelrc
.eslintignore
.eslintrc
.travis.yml
jest.json
renovate.json
rollup.config.js
84 changes: 84 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
export const STEP_CONTACT_INFORMATION = 'contact_information';
export const STEP_SHIPPING_METHOD = 'shipping_method';
export const STEP_PAYMENT_METHOD = 'payment_method';
export const STEP_REVIEW = 'review';
export const STEP_THANK_YOU = 'thank_you';
export const STEP_ORDER_STATUS = 'order_status';
export const STEPS_ALL = [STEP_CONTACT_INFORMATION, STEP_SHIPPING_METHOD, STEP_PAYMENT_METHOD, STEP_REVIEW, STEP_THANK_YOU, STEP_ORDER_STATUS];

export class Custard {

constructor(moduleClasses) {
this.moduleClasses = moduleClasses;
}

init($, step, options = {}) {
this.$ = $;
this.step = step;
this.options = options;

// Instantiate module classes.
this.modules = this.moduleClasses.map((moduleClass) => {
return new moduleClass($, step, options);
});

// Register event listeners.
this.$(document).on('page:load page:change', this.pageChangeHandler.bind(this));
}

pageChangeHandler(event) {
this.modules.forEach((module) => {
if(module.steps().includes(this.step)) {
if(this.step === STEP_SHIPPING_METHOD && this.isPollRefreshElementPresent()) {
return;
}

module.init();
}
});
}

isPollRefreshElementPresent() {
return this.$('[data-poll-refresh]').length;
}

}

export class CustardModule {

constructor($, step, options) {
this.$ = $;
this.step = step;
this.options = options;

this.$element = null;
}

id() {
throw 'Not implemented';
}

steps() {
return [];
}

selector() {
return 'document';
}

init() {
this.$element = this.$(this.selector());

// Bail if already initialised.
if(this.$element.hasClass(this.id())) {
return;
}

// Setup
this.$element.addClass(this.id());
this.setup();
}

setup() {}

}
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "custard-js",
"version": "0.0.1",
"description": "Javascript library for standardising Shopify checkout customisations.",
"main": "index.js",
"author": "Gavin Ballard",
"repository": {
"type": "git",
"url": "https://github.com/discolabs/custard-js.git"
},
"keywords": [
"shopify"
]
}

0 comments on commit f93b132

Please sign in to comment.