This repository has been archived by the owner on Feb 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |