shipyard-framework 0.5.81 → 0.5.82

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84bba4d9d29150b6e1f2dd9182d0111032b8f542379c53b0737a86febdb7ee6a
4
- data.tar.gz: abaab7f264f6c7eedb8e9de91f872347ad176b67bd5d53f9cf3e120c9f70b242
3
+ metadata.gz: 27e61f49bdbd5ae0eeba8e929285f5cfaeda2a52df04b9a91a24bbce7b386b20
4
+ data.tar.gz: 6148ea0dd24160e5416f2990fd36960edfbb901140c689579073ab44a2233236
5
5
  SHA512:
6
- metadata.gz: 542ca4978afa92443c5e42c065b9c8e1ca883b9f6dab4c9e8d216dd00681a6ac5d5aeca0fc4333b7054de85c6d0164cf1653267814cf50a8b717b9f6dcdb3741
7
- data.tar.gz: 0be7b4235f28af8dbb48a71fb337379a68cfb45d82f2b81772f80c565c9ad4c0fb4b3608215347cffeff4aa061f9fbdc6b2bb6fbb3cc6a905475cff1e2506e42
6
+ metadata.gz: af369bcfb123990a1996bbb1a29f63ecd582f653d06bbacc9b735284cbcb537b00d87a0c6067fd7421c5fe889ffb739ec566e2f51232ceff553575a6a774826f
7
+ data.tar.gz: 77dcacad8a505853a62b8d2fc09fc56275b89038c807bc1fe423ddefea3df11c935465b3f140b0fc9f56122241f381c4bd8f7b728804599bac11ef1899a69609
@@ -2,13 +2,15 @@
2
2
  //= require ./shipyard/scroll
3
3
  //= require ./shipyard/hamburger
4
4
  //= require ./shipyard/alert
5
+ //= require ./shipyard/alert-timer
5
6
  //= require ./shipyard/accordion
7
+ //= require ./shipyard/accordion-trigger
6
8
  //= require ./shipyard/modal
7
9
  //= require ./shipyard/modal-trigger
8
10
 
9
- var shipyard = new Shipyard('html')
10
- var windowScroll = new Scroll(window)
11
- var hamburger = new Hamburger('[shipyard=hamburger]')
12
- var shipyardAlert = new Alert('[shipyard=alert]')
13
- var modalTrigger = new ModalTrigger('[modal-trigger]')
14
- var accordion = new Accordion('[accordion]')
11
+ var shipyard = new Shipyard(document.documentElement)
12
+ shipyard.windowScroll = new Scroll(window)
13
+ shipyard.hamburger = new Shipyard('[shipyard=hamburger]', Hamburger)
14
+ shipyard.alerts = new Shipyard('[shipyard=alert]', Alert)
15
+ shipyard.modalTriggers = new Shipyard('[modal-trigger]', ModalTrigger)
16
+ shipyard.accordionTriggers = new Shipyard('[accordion]', AccordionTrigger)
@@ -0,0 +1,7 @@
1
+ class AccordionTrigger extends Shipyard {
2
+ constructor (el) {
3
+ super(el)
4
+ this.accordion = new Accordion(this.attr('accordion'))
5
+ this.on('click', (e) => { this.accordion.trigger('toggle') })
6
+ }
7
+ }
@@ -1,10 +1,10 @@
1
1
  class Accordion extends Shipyard {
2
2
  constructor (el) {
3
3
  super(el)
4
- this.on('click', this.toggle)
4
+ this.on('toggle', () => { this.toggle() })
5
5
  }
6
6
 
7
- toggle (event, el) {
8
- document.querySelector(el.getAttribute('accordion')).classList.toggle('accordion-closed')
7
+ toggle () {
8
+ this.toggleClass('accordion-closed')
9
9
  }
10
10
  }
@@ -0,0 +1,17 @@
1
+ class AlertTimer extends Shipyard {
2
+ constructor (el, alert) {
3
+ super(el)
4
+ this.alert = alert
5
+ this.duration = this.data('duration')
6
+ if (this.duration) this.css('animation-duration', `${this.duration}s`)
7
+ this.on('start', () => { this.start() })
8
+ }
9
+
10
+ start () {
11
+ setTimeout(() => { this.end() }, this.duration * 1000)
12
+ }
13
+
14
+ end () {
15
+ this.alert.trigger('close')
16
+ }
17
+ }
@@ -1,13 +1,28 @@
1
1
  class Alert extends Shipyard {
2
2
  constructor (el) {
3
3
  super(el)
4
- this.el.forEach((el) => {
5
- el.querySelector('[shipyard=alert-close]')
6
- .addEventListener('click', () => { this.close(el) })
7
- })
4
+ this.on('show', (e) => { this.show(e) })
5
+ this.on('close', (e) => { this.close(e) })
6
+ this.on('click', '[shipyard=alert-close]', (e) => { this.close(e) })
7
+
8
+ // Initiate the Alert Timer if it exists.
9
+ this.timer = this.child('.alert-timer')
10
+ if (this.timer) this.timer = new AlertTimer(this.timer, this)
11
+ }
12
+
13
+ options(options) {
14
+ this.on('afterClose', options.afterClose)
15
+ }
16
+
17
+ show (e) {
18
+ this.options(e.detail)
19
+ this.removeClass('alert-closed')
20
+ if (this.timer) this.timer.trigger('start')
8
21
  }
9
22
 
10
- close (el) {
11
- el.classList.add('alert-closed')
23
+ close (e) {
24
+ e.preventDefault()
25
+ this.addClass('alert-closed')
26
+ this.trigger('afterClose')
12
27
  }
13
28
  }
@@ -1,45 +1,90 @@
1
1
  class Shipyard {
2
- constructor (el) {
3
- this.el = typeof el === 'string' ? document.querySelectorAll(el) : [el]
4
- this.html = document.documentElement
2
+ constructor (el, subClass) {
3
+ if (subClass) {
4
+ this.els = []
5
+ document.querySelectorAll(el).forEach((el) => {
6
+ this.els.push(new subClass(el))
7
+ })
8
+ } else if (typeof el === 'string') {
9
+ this.el = document.querySelector(el)
10
+ } else {
11
+ this.el = el
12
+ }
5
13
  return this
6
14
  }
7
15
 
8
- on (events, callback) {
9
- this.el.forEach((el) => {
16
+ on (events, selector, callback) {
17
+ if (typeof selector != 'string') callback = selector
18
+ let objects = (typeof selector === 'string') ? this.find(selector) : [this]
19
+
20
+ objects.forEach((obj) => {
10
21
  events.split(' ').forEach((eventName) => {
11
- el.addEventListener(eventName, (e) => {
12
- callback(e, el)
13
- })
22
+ obj.el.addEventListener(eventName, callback)
14
23
  })
15
24
  })
16
25
  return this
17
26
  }
18
27
 
19
- trigger (events) {
20
- this.el.forEach((el) => {
21
- events.split(' ').forEach((eventName) => {
22
- el.dispatchEvent(new Event(eventName))
23
- })
28
+ trigger () {
29
+ let events = arguments[0]
30
+ events.split(' ').forEach((eventName) => {
31
+ this.el.dispatchEvent(
32
+ new CustomEvent(eventName, { detail: arguments[1] })
33
+ )
24
34
  })
25
35
  return this
26
36
  }
27
37
 
28
- css (el, value) {
29
- return window.getComputedStyle(el).getPropertyValue(value)
38
+ find (selector) {
39
+ let els = []
40
+ this.el.querySelectorAll(selector).forEach((el) => {
41
+ els.push(new Shipyard(el))
42
+ })
43
+ return els
44
+ }
45
+
46
+ filter (selector) {
47
+ let els = this.els.filter(obj => obj.el == document.querySelector(selector))
48
+ return els[0]
49
+ }
50
+
51
+ child (selector) {
52
+ return this.el.querySelector(selector)
53
+ }
54
+
55
+ data (name) {
56
+ return this.el.dataset[name]
57
+ }
58
+
59
+ html (value) {
60
+ this.el.innerHTML = value
61
+ return this
62
+ }
63
+
64
+ css (property, value) {
65
+ if (value) {
66
+ this.el.style[property] = value
67
+ } else {
68
+ return window.getComputedStyle(this.el).getPropertyValue(property)
69
+ }
70
+ }
71
+
72
+ attr (name) {
73
+ return this.el.getAttribute(name)
30
74
  }
31
75
 
32
76
  addClass(className) {
33
- this.el.forEach((el) => {
34
- el.classList.add(className)
35
- })
77
+ this.el.classList.add(className)
36
78
  return this
37
79
  }
38
80
 
39
81
  removeClass(className) {
40
- this.el.forEach((el) => {
41
- el.classList.remove(className)
42
- })
82
+ this.el.classList.remove(className)
83
+ return this
84
+ }
85
+
86
+ toggleClass(className, condition) {
87
+ this.el.classList.toggle(className, condition)
43
88
  return this
44
89
  }
45
90
  }
@@ -1,10 +1,11 @@
1
1
  class Hamburger extends Shipyard {
2
2
  constructor (el) {
3
3
  super(el)
4
- this.on('click', () => { this.onClick() })
4
+ this.on('click', this.toggle)
5
5
  }
6
6
 
7
- onClick () {
8
- this.html.classList.toggle('hamburger-button-clicked')
7
+ toggle (e) {
8
+ e.preventDefault()
9
+ shipyard.toggleClass('hamburger-button-clicked')
9
10
  }
10
11
  }
@@ -1,13 +1,7 @@
1
1
  class ModalTrigger extends Shipyard {
2
2
  constructor (el) {
3
3
  super(el)
4
- this.on('click', () => { this.open() })
5
- this.el.forEach((el) => {
6
- this.modal = new Modal(`[modal=${el.getAttribute('modal-trigger')}]`)
7
- })
8
- }
9
-
10
- open () {
11
- this.modal.open()
4
+ this.modal = new Modal(`[modal=${el.getAttribute('modal-trigger')}]`)
5
+ this.on('click', (e) => { this.modal.trigger('open') })
12
6
  }
13
7
  }
@@ -1,20 +1,17 @@
1
1
  class Modal extends Shipyard {
2
2
  constructor (el) {
3
3
  super(el)
4
+ this.on('open', () => { this.open() })
5
+ this.on('click', '[modal-close]', () => { this.close() })
4
6
  }
5
7
 
6
8
  open () {
7
9
  this.removeClass('display-none')
8
- this.html.classList.add('modal-open')
9
- this.el.forEach((el) => {
10
- el.querySelectorAll('[modal-close]').forEach((btn) => {
11
- btn.addEventListener('click', () => { this.close() })
12
- })
13
- })
10
+ shipyard.addClass('modal-open')
14
11
  }
15
12
 
16
13
  close () {
17
14
  this.addClass('display-none')
18
- this.html.classList.remove('modal-open')
15
+ shipyard.removeClass('modal-open')
19
16
  }
20
17
  }
@@ -1,12 +1,12 @@
1
1
  class Scroll extends Shipyard {
2
2
  constructor (el) {
3
3
  super(el)
4
- this.on('scroll resize', () => { this.scroll() }).trigger('scroll')
4
+ this.on('scroll resize', this.scroll).trigger('scroll')
5
5
  }
6
6
 
7
7
  scroll () {
8
- this.html.classList.toggle('scrolling', window.pageYOffset > 0)
9
- this.html.classList.toggle('scroll-top', window.pageYOffset <= 0)
10
- this.html.classList.toggle('scroll-bottom', window.pageYOffset + window.innerHeight >= document.body.scrollHeight)
8
+ shipyard.toggleClass('scrolling', window.pageYOffset > 0)
9
+ shipyard.toggleClass('scroll-top', window.pageYOffset <= 0)
10
+ shipyard.toggleClass('scroll-bottom', window.pageYOffset + window.innerHeight >= document.body.scrollHeight)
11
11
  }
12
12
  }
@@ -15,3 +15,9 @@
15
15
  transform: translateX(-7px) translateY(0)
16
16
  87.5%
17
17
  transform: translateX(3px) translateY(0)
18
+
19
+ @keyframes slide-in-from-left
20
+ from
21
+ transform: translatex(-100%)
22
+ to
23
+ transform: translatex(0%)
@@ -5,17 +5,21 @@ module Shipyard
5
5
  class Alert < Liquid::Block
6
6
  include Shipyard::AlertHelper
7
7
 
8
- def initialize(tag_name, type, options)
8
+ def initialize(tag_name, params, options)
9
9
  super
10
- @type = type.strip.tr(':','').to_sym unless type.blank?
10
+ @params = params.strip.split(',').map(&:strip)
11
+ @args = []
12
+ @params.each do |param|
13
+ if param.start_with?(':')
14
+ @args << param.tr(':','').to_sym
15
+ else
16
+ @args << eval("{#{param}}")
17
+ end
18
+ end
11
19
  end
12
20
 
13
21
  def render(context)
14
- if @type
15
- flash_alert @type, super
16
- else
17
- flash_alert super
18
- end
22
+ flash_alert(*@args, super)
19
23
  end
20
24
  end
21
25
  end
@@ -1,3 +1,3 @@
1
1
  module Shipyard
2
- VERSION = '0.5.81'
2
+ VERSION = '0.5.82'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- shipyard-framework (0.5.81)
4
+ shipyard-framework (0.5.82)
5
5
  actionview (~> 5.0)
6
6
  sprockets-es6 (~> 0.9.2)
7
7
 
@@ -1,2 +1,6 @@
1
1
  //= require shipyard
2
+ //= require views/components/alert-trigger
2
3
  //= require views/utilities/colors
4
+
5
+ shipyard.alertTriggers = new Shipyard('[alert-trigger]', AlertTrigger)
6
+ shipyard.colors = new Shipyard('[shade-color]', ShadeColor)
@@ -0,0 +1,20 @@
1
+ class AlertTrigger extends Shipyard {
2
+ constructor (el) {
3
+ super(el)
4
+ this.alert = shipyard.alerts.filter(this.attr('alert-trigger'))
5
+ this.on('click', (e) => { this.click(e) })
6
+ }
7
+
8
+ click (e) {
9
+ e.preventDefault()
10
+ this.addClass('btn-loading')
11
+ this.el.blur()
12
+ this.alert.trigger('show', {
13
+ afterClose: () => { this.reset() }
14
+ })
15
+ }
16
+
17
+ reset () {
18
+ this.removeClass('btn-loading')
19
+ }
20
+ }
@@ -1,12 +1,7 @@
1
- class ShadeList extends Shipyard {
1
+ class ShadeColor extends Shipyard {
2
2
  constructor (el) {
3
3
  super(el)
4
-
5
- this.el.forEach((list) => {
6
- list.querySelectorAll('[shade-color]').forEach((shade) => {
7
- shade.innerHTML = this.rgbToHex(this.css(shade, 'background-color'))
8
- })
9
- })
4
+ this.html(this.rgbToHex(this.css('background-color')))
10
5
  }
11
6
 
12
7
  rgbToHex (rgb) {
@@ -17,5 +12,3 @@ class ShadeList extends Shipyard {
17
12
  return `#${hex}`;
18
13
  }
19
14
  }
20
-
21
- new ShadeList('[shade-list]')
@@ -7,6 +7,31 @@ description: Alerts should be used to grab a user's attention before proceeding
7
7
 
8
8
  ---
9
9
 
10
+ ### Timed Alerts
11
+ Useful when you want to display an alert for a predetermined amount of time.
12
+ {: .section-description }
13
+
14
+ {% alert :success, :dismissible, id: 'timed-alert-5s', class: 'alert-closed' %}
15
+ Pack your bags! You'll be on the next flight to Hawaii.
16
+ <div class="alert-timer alert-timer-on" data-duration="5"></div>
17
+ {% endalert %}
18
+
19
+ {% alert :success, :dismissible, id: 'timed-alert-10s', class: 'alert-closed' %}
20
+ Pack your bags! You'll be on the next flight to Tahiti.
21
+ <div class="alert-timer alert-timer-on" data-duration="10"></div>
22
+ {% endalert %}
23
+
24
+ {% alert :success, :dismissible, id: 'timed-alert-15s', class: 'alert-closed' %}
25
+ Pack your bags! You'll be on the next flight to Corsica.
26
+ <div class="alert-timer alert-timer-on" data-duration="15"></div>
27
+ {% endalert %}
28
+
29
+ <button class="btn btn-primary margin-right-xs" alert-trigger="#timed-alert-5s">5 Seconds</button>
30
+ <button class="btn btn-primary margin-right-xs" alert-trigger="#timed-alert-10s">10 Seconds</button>
31
+ <button class="btn btn-primary" alert-trigger="#timed-alert-15s">15 Seconds</button>
32
+
33
+ ---
34
+
10
35
  ### Dismissible
11
36
  Used to display notes, tips, and other non-critical information.
12
37
  {: .section-description }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shipyard-framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.81
4
+ version: 0.5.82
5
5
  platform: ruby
6
6
  authors:
7
7
  - Codeship
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-06 00:00:00.000000000 Z
11
+ date: 2017-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -202,7 +202,9 @@ files:
202
202
  - assets/images/arrows/down.svg
203
203
  - assets/images/checkmark.svg
204
204
  - assets/javascripts/shipyard.es6
205
+ - assets/javascripts/shipyard/accordion-trigger.es6
205
206
  - assets/javascripts/shipyard/accordion.es6
207
+ - assets/javascripts/shipyard/alert-timer.es6
206
208
  - assets/javascripts/shipyard/alert.es6
207
209
  - assets/javascripts/shipyard/core.es6
208
210
  - assets/javascripts/shipyard/hamburger.es6
@@ -318,6 +320,7 @@ files:
318
320
  - styleguide/_assets/img/arrows/down.svg
319
321
  - styleguide/_assets/img/checkmark.svg
320
322
  - styleguide/_assets/js/application.es6
323
+ - styleguide/_assets/js/views/components/alert-trigger.es6
321
324
  - styleguide/_assets/js/views/utilities/colors.es6
322
325
  - styleguide/_config.yml
323
326
  - styleguide/_data/breakpoints.yml