ratchet_design 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/ratchet/core.js +3 -3
  3. data/app/assets/javascripts/ratchet/enhancement/_collapse.js +3 -6
  4. data/app/assets/javascripts/ratchet/enhancement/_swap.js +61 -72
  5. data/app/assets/javascripts/ratchet/enhancement/lightbox.js +43 -135
  6. data/app/assets/javascripts/ratchet/{enhancement → utility}/loader.js +7 -2
  7. data/app/assets/stylesheets/ratchet/_core.scss +1 -1
  8. data/app/assets/stylesheets/ratchet/enhancement/_lightbox.scss +8 -3
  9. data/app/assets/stylesheets/ratchet/{enhancement → utility}/_loader.scss +0 -0
  10. data/app/views/layouts/ratchet/default.html.slim +1 -1
  11. data/lib/ratchet_design/version.rb +1 -1
  12. data/public/assets/ratchet/core-0.1.1.js +103 -0
  13. data/public/assets/ratchet/core-0.1.1.js.gz +0 -0
  14. data/public/assets/ratchet/core-0.1.1.map.json +1 -0
  15. data/public/assets/ratchet/core-0.1.7.js +18018 -0
  16. data/public/assets/ratchet/fonts-woff-0.1.1.css +55 -0
  17. data/public/assets/ratchet/{fonts-woff-0.1.8.css.gz → fonts-woff-0.1.1.css.gz} +0 -0
  18. data/public/assets/ratchet/{fonts-woff-0.1.8.css → fonts-woff-0.1.7.css} +0 -0
  19. data/public/assets/ratchet/fonts-woff2-0.1.1.css +55 -0
  20. data/public/assets/ratchet/{fonts-woff2-0.1.8.css.gz → fonts-woff2-0.1.1.css.gz} +0 -0
  21. data/public/assets/ratchet/{fonts-woff2-0.1.8.css → fonts-woff2-0.1.7.css} +0 -0
  22. metadata +15 -13
  23. data/app/assets/javascripts/ratchet/utility/ajax.js +0 -122
  24. data/public/assets/ratchet/core-0.1.8.js +0 -107
  25. data/public/assets/ratchet/core-0.1.8.js.gz +0 -0
  26. data/public/assets/ratchet/core-0.1.8.map.json +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c1131fa26386e461f0d5a3bea05a5438a954038
4
- data.tar.gz: 8fa3b4cf22a717aefc7d9fb95c0bcadf4ae43ab3
3
+ metadata.gz: aef44c1ad9f928199a956dea5dba0cf289bb48df
4
+ data.tar.gz: 720ddc559f457ce0210126e87d45e0b6936ca690
5
5
  SHA512:
6
- metadata.gz: 43ad5b3a613966848c28df7cd19cd20e09e0014a9fde5688cdf6cbb1b90e03b08a1127e3bef67de878990071d135c3383f5d276a10b2819b7340cf88a43f4757
7
- data.tar.gz: faa591cf3997ebfed5d8026113b9ce8d21b1ed7fc2ffa86e787e722357623b4d9715af8617dbe770c612255ee186c47730c10198b03eaaec6f4275d93d75cb51
6
+ metadata.gz: 9e21b41531dc60488671e22d57b64a8490a93c6973afc80767b514baedcc22707815c262f2fae0ce21f4177b62f662fd3879903e33e9968df6440d978e4c0e08
7
+ data.tar.gz: d9135ea36d1f05cb47df0567ec752a15af756b9296999c9aa405c11552be3886226bdfac2f118f1aa2542236b7473371753a5f1d40cfee6e2a24ef091cf1d53f
@@ -16,7 +16,8 @@ var getNext = require( './utility/get_next' );
16
16
  var wordCount = require( './utility/word_count' );
17
17
  var compileData = require( './utility/compile_data' );
18
18
  var timeout = require( './utility/timeout' );
19
- var ajax = require( './utility/ajax' );
19
+ var ajax = require( 'superagent' );
20
+ var loader = require( './utility/loader' );
20
21
 
21
22
  // Base modules
22
23
  var mobileMenu = require( './base/mobilemenu' );
@@ -24,7 +25,6 @@ var form = require( './base/form' );
24
25
  var validation = require( './base/validation' );
25
26
 
26
27
  // Enhancement modules
27
- var loader = require( './enhancement/loader' );
28
28
  var waypoints = require( './enhancement/waypoints' );
29
29
  var notice = require( './enhancement/notice' );
30
30
  var sticky = require( './enhancement/sticky' );
@@ -66,10 +66,10 @@ window.ratchet = module.exports = {
66
66
  compileData : compileData,
67
67
  timeout : timeout,
68
68
  ajax : ajax,
69
+ loader : loader,
69
70
  mobileMenu : mobileMenu,
70
71
  form : form,
71
72
  validation : validation,
72
- loader : loader,
73
73
  waypoints : waypoints,
74
74
  notice : notice,
75
75
  sticky : sticky,
@@ -5,9 +5,6 @@
5
5
  * @license MIT
6
6
  **/
7
7
 
8
- // Dependencies
9
- var getClosest = require('../utility/get_closest')
10
-
11
8
  ;( function( root, factory ) {
12
9
  if ( typeof define === 'function' && define.amd ) {
13
10
  define( factory );
@@ -29,7 +26,7 @@ var getClosest = require('../utility/get_closest')
29
26
  defaults = {
30
27
  expandText : 'Show more ∨',
31
28
  collapseText : 'Show less ∧',
32
- triggerText : ' '
29
+ triggerText : '{{ more }}'
33
30
  };
34
31
 
35
32
  // Only run if selector exists
@@ -77,7 +74,7 @@ var getClosest = require('../utility/get_closest')
77
74
  event.preventDefault();
78
75
 
79
76
  // Scoped variables
80
- var expandable = getClosest( event.target, element ),
77
+ var expandable = compose.getClosest( event.target, element ),
81
78
  stateObject = state[ expandable.dataset.idx ];
82
79
 
83
80
  // Toggle between excerpt and full text
@@ -93,4 +90,4 @@ var getClosest = require('../utility/get_closest')
93
90
  // Public API
94
91
  return exports;
95
92
 
96
- });
93
+ });
@@ -4,9 +4,7 @@
4
4
  * @license MIT
5
5
  **/
6
6
 
7
- // Dependencies
8
- var matches = require( '../utility/matches' );
9
-
7
+ // Transport
10
8
  ;( function( root, factory ) {
11
9
  if ( typeof define === 'function' && define.amd ) {
12
10
  define( factory );
@@ -19,109 +17,100 @@ var matches = require( '../utility/matches' );
19
17
 
20
18
  'use strict';
21
19
 
22
- // Overridable defaults
23
- var defaults = {
24
- activeClass : 'open',
25
- assignHash : false
26
- };
20
+ var triggers = document.querySelectorAll( '.swap-trigger' );
21
+
22
+ if ( triggers.length ) {
27
23
 
28
- // Public API function
29
- var swap = function( element, settings ) {
24
+ // Assignment
25
+ var location = window.location.hash;
30
26
 
31
- // Parameter variables
32
- var options = Object.assign( {}, defaults, settings ),
33
- selectors = document.querySelectorAll( element ),
34
- location;
27
+ // Swap function
28
+ var swap = function( trigger, target ) {
35
29
 
36
- // Only run if selector exists
37
- if ( !selectors.length ) return false;
30
+ // Find all current `selected` class elements
31
+ var currentSelection = document.querySelectorAll( '.selected' );
38
32
 
39
- // Attach window load listener (if hashes are turned on)
40
- if ( options.assignHash ) window.addEventListener( 'load', hashHandler, false );
33
+ // And deselect them
34
+ for ( var i = 0; i < currentSelection.length; i++ ) {
35
+ currentSelection[ i ].classList.remove( 'selected' );
36
+ }
41
37
 
42
- for ( var i = 0; i < selectors.length; i++ ) {
38
+ // Select our new elements
39
+ trigger.classList.add( 'selected' );
40
+ target.classList.add( 'selected' );
41
+ };
43
42
 
44
- // Attach click event listener
45
- selectors[ i ].addEventListener( 'click', clickHandler, false );
43
+ // Get current window hash
44
+ var getHash = function() {
45
+ return location.split( '#' )[ 1 ];
46
+ };
46
47
 
47
- }
48
+ // Get link target hash
49
+ var getLinkTarget = function( link ) {
50
+ return link.href.split( '#' )[ 1 ];
51
+ };
48
52
 
49
- // Window hash handler function
50
- function hashHandler() {
53
+ // Hash check function
54
+ var hashCheck = function( event ) {
51
55
 
52
- // Cache window hash
53
- var windowHash = window.location.hash;
56
+ // If no hash
57
+ if ( !location ) {
54
58
 
55
- // If no window hash exists
56
- if ( !windowHash ) {
59
+ // Assign first element(s) variables
60
+ var firstTrigger = document.querySelector( '.swap-trigger' ),
61
+ firstTarget = document.querySelector( '.swappable' );
57
62
 
58
- // Perform swap function on selector’s first instance of anchor link
59
- swap( selector.querySelector( 'a[href^="#"]' ) );
63
+ // And select them
64
+ swap( firstTrigger, firstTarget );
60
65
 
61
66
  // Otherwise
62
67
  } else {
63
68
 
64
69
  // Stop default anchor tag jump
65
- window.scrollTo( 0, 0 );
70
+ window.scrollTo(0, 0);
66
71
 
67
- // Perform swap function on appropriate anchor link
68
- swap( selector.querySelector( 'a[href="' + windowHash + '"]' ) );
72
+ // Assign appropriate element(s) variables
73
+ var loadedTarget = document.querySelector( '#' + getHash() ),
74
+ loadedTrigger = document.querySelector('[href="#' + getHash() + '"]' );
75
+
76
+ // And select them
77
+ swap( loadedTrigger, loadedTarget );
69
78
 
70
79
  }
71
80
 
72
- }
81
+ };
73
82
 
74
83
  // Click handler function
75
- function clickHandler( event ) {
76
-
77
- // Only run on anchor links
78
- if ( !matches( event.target, 'a[href^="#"]' ) ) return false;
84
+ var clickHandler = function( event ) {
79
85
 
80
86
  // Prevent default behavior
87
+ event.stopPropagation();
81
88
  event.preventDefault();
82
89
 
83
- // Only run if not clicking on currently active element
84
- if ( event.target.classList.contains( options.activeClass ) ) return false;
90
+ // Local assignment
91
+ var triggerElem = this,
92
+ linkTarget = getLinkTarget( triggerElem ),
93
+ targetElem = document.querySelector( '#' + linkTarget );
85
94
 
86
- // Swap out the appropriate element
87
- swap( event.target );
95
+ // Select the appropriate elements
96
+ swap ( triggerElem, targetElem );
88
97
 
89
- }
90
-
91
- // Where the magic happens
92
- function swap( target ) {
93
-
94
- // Scoped variables
95
- var newAnchor = target,
96
- oldAnchor = newAnchor.parentNode.querySelector( '.' + options.activeClass ),
97
- newTarget = document.querySelector( '#' + newAnchor.href.split( '#' )[ 1 ] ),
98
- oldTarget = newTarget.parentNode.querySelector( ':scope > .' + options.activeClass );
99
-
100
- // If an old active anchor exists, deactivate it
101
- if ( oldAnchor ) oldAnchor.classList.remove( options.activeClass );
98
+ // Replace the hash
99
+ history.replaceState( null, '', '#' + linkTarget );
102
100
 
103
- // And activate the new achor
104
- newAnchor.classList.add( options.activeClass );
101
+ };
105
102
 
106
- // If an old active element exists, deactivate it
107
- if ( oldTarget ) oldTarget.classList.remove( options.activeClass );
103
+ // Run hash check on window load
104
+ window.addEventListener( 'load', hashCheck, false );
108
105
 
109
- // And activate the new element
110
- newTarget.classList.add( options.activeClass );
106
+ // Iterate over each swap trigger
107
+ for ( var i = 0; i < triggers.length; i++ ) {
111
108
 
112
- // Then replace the hash (if hashes are turned on)
113
- if ( options.assignHash ) history.pushState( null, '', '#' + newAnchor.href.split( '#' )[ 1 ] );
109
+ // And attach our click listener
110
+ triggers[ i ].addEventListener( 'click', clickHandler, false );
114
111
 
115
112
  }
116
113
 
117
- };
118
-
119
- // Public API
120
- return swap;
121
-
122
- });
114
+ }
123
115
 
124
- // Instantiation
125
- swap( '.swap-nav', {
126
- activeClass : 'selected'
127
116
  });
@@ -3,15 +3,19 @@
3
3
  * A simple lightbox module
4
4
  * @author Kyle Foster (@hkfoster)
5
5
  * @license MIT
6
- */
6
+ **/
7
7
 
8
8
  // Dependencies
9
- var loader = require( '../enhancement/loader' ),
9
+ var Event = require( 'compose-event' ),
10
+ loader = require( '../utility/loader' ),
10
11
  timeout = require( '../utility/timeout' );
11
12
 
12
13
  // Public API function
13
14
  var lightbox = function( element, settings ) {
14
15
 
16
+ // Apply default element selector
17
+ element = element || 'a[href$=jpg] ,a[href$=png], a[href$=gif], a[href$=svg]';
18
+
15
19
  // Overridable defaults
16
20
  var defaults = {
17
21
  initWidth : '700px'
@@ -19,126 +23,39 @@ var lightbox = function( element, settings ) {
19
23
 
20
24
  // Main variables
21
25
  options = Object.assign( {}, defaults, settings ),
22
- selectors = document.querySelectorAll( element ),
23
- widthQuery = window.matchMedia( '(min-width: ' + options.initWidth + ')' ),
26
+ selector = document.querySelector( element ),
27
+ widthQuery = window.matchMedia( '(max-width: ' + options.initWidth + ')' ),
24
28
  spinner = loader({ loadingMessage: 'Loading image', failureMessage : 'No image found' }),
25
29
  docBody = document.body,
26
- tempImg,
27
- active;
30
+ tempImg;
28
31
 
29
32
  // Only run when selectors exist
30
- if ( !selectors.length ) return false;
31
-
32
- // Call media query listener function explicitly at run time
33
- queryHandler( widthQuery );
34
-
35
- // Attach media query listener
36
- widthQuery.addListener( queryHandler );
37
-
38
- // Media query handler function
39
- function queryHandler( condition ) {
40
-
41
- // If media query matches init width
42
- if ( condition.matches ) {
43
-
44
- // Initialize lightbox
45
- init();
46
-
47
- // Otherwise
48
- } else {
33
+ if ( !selector ) return false;
49
34
 
50
- // Terminate lightbox
51
- terminate();
35
+ // Attach open lightbox click listener
36
+ Event.on( document, 'click', 'a[href$=jpg] ,a[href$=png], a[href$=gif], a[href$=svg]', clickHandler );
52
37
 
53
- }
54
-
55
- }
38
+ // Attach close lightbox click listener
39
+ Event.on( document, 'click', '.lightbox', hideLightbox );
56
40
 
57
41
  // Initialize lightbox function
58
42
  function init() {
59
43
 
60
- // Turn on active state
61
- active = true;
62
-
63
- // If a lightbox has already been initiated
64
- if ( document.querySelector( '.lightbox' ) ) {
65
-
66
- // Loop over lightbox images
67
- for ( var i = 0; i < selectors.length; i++ ) {
68
-
69
- // And activate their anchor links
70
- selectors[ i ].parentNode.setAttribute( 'data-open-lightbox', '' );
71
-
72
- }
73
-
74
- // Then kick rocks
75
- return false;
76
-
77
- }
78
-
79
44
  // Insert lightbox container into body
80
- docBody.insertAdjacentHTML( 'afterbegin', '<aside class="lightbox"><figure><img src="" alt=""><button data-close-lightbox></button></figure></aside>' );
45
+ docBody.insertAdjacentHTML( 'afterbegin', '<aside class="lightbox"><figure><img src="" alt=""><button></button></figure></aside>' );
81
46
 
82
47
  // Cache temporary placeholder image
83
48
  tempImg = document.querySelector( '.lightbox img' );
84
49
 
85
- // Loop over lightbox images
86
- for ( var j = 0; j < selectors.length; j++ ) {
87
-
88
- // Cache current img selector
89
- var selector = selectors[ j ],
90
- imgSrc = selector.src,
91
- dataSrc = selector.getAttribute( 'data-lightbox' ),
92
- lightboxSrc = dataSrc !== '' ? dataSrc : imgSrc;
93
-
94
- // If thumbnail size is passed and image is in Cloudinary
95
- if ( selector.hasAttribute( 'data-thumb-size' ) && imgSrc.split( '//' )[ 1 ].substring( 0, 18 ) === 'res.cloudinary.com' ) {
96
-
97
- // Split img src url
98
- var splitSrc = imgSrc.split( 'upload' );
99
-
100
- // Switch out image src for Cloudinary-resized src
101
- selector.src = splitSrc[ 0 ] + 'upload/w_' + selector.getAttribute( 'data-thumb-size' ) + splitSrc[ 1 ];
102
-
103
- }
104
-
105
- // Wrap the image in a `data-lightbox` anchor tag
106
- selector.insertAdjacentHTML( 'beforebegin', '<a data-open-lightbox href="' + lightboxSrc + '"></a>' );
107
- selector.previousSibling.insertAdjacentElement( 'afterbegin', selector );
108
-
109
- }
110
-
111
- // Attach click listener
112
- docBody.addEventListener( 'click', clickHandler, false );
113
-
114
- }
115
-
116
- // Terminate lightbox function
117
- function terminate() {
118
-
119
- // Turn off active state
120
- active = false;
121
-
122
- // If no lightbox exists, fugetaboutit … capisce?
123
- if ( !document.querySelector( '.lightbox' ) ) return false;
124
-
125
- // Remove lightbox classes from body
126
- docBody.classList.remove( 'lightbox-active' );
127
-
128
- // Loop over lightbox images
129
- for ( var i = 0; i < selectors.length; i++ ) {
130
-
131
- // And inactivate their anchor links
132
- selectors[ i ].parentNode.setAttribute( 'data-open-lightbox', 'inactive' );
133
-
134
- }
135
-
136
50
  }
137
51
 
138
52
  // Hide lightbox function
139
- function hideLightbox() {
53
+ function hideLightbox( event ) {
54
+
55
+ // Don’t apply when image is clicked
56
+ if ( event && event.target.tagName === 'IMG' ) return false;
140
57
 
141
- // And hide the spinner
58
+ // Hide the spinner
142
59
  spinner.hide();
143
60
 
144
61
  // Remove active lightbox class from body
@@ -180,9 +97,6 @@ var lightbox = function( element, settings ) {
180
97
  // Image load failure function
181
98
  function loadFailure( event ) {
182
99
 
183
- // Prevent any further attempts to open image
184
- document.querySelector( 'a[href="' + event.target.src + '"]' ).setAttribute( 'data-open-lightbox', 'inactive' );
185
-
186
100
  // Wait a second…
187
101
  timeout.set( function() {
188
102
 
@@ -200,51 +114,45 @@ var lightbox = function( element, settings ) {
200
114
  }, 2500 );
201
115
 
202
116
  // Remove image load event listener
203
- tempImg.removeEventListener( 'load', loadSuccess, false );
117
+ Event.off( tempImg, 'load', loadSuccess );
204
118
 
205
119
  // Remove image error event listener
206
- tempImg.removeEventListener( 'error', loadFailure, false );
120
+ Event.off( tempImg, 'error', loadFailure );
121
+
207
122
  }
208
123
 
209
124
  // Click handler function
210
125
  function clickHandler( event ) {
211
126
 
212
- // Only run on `data-open-lightbox` links
213
- if ( event.target.parentNode.hasAttribute( 'data-open-lightbox' ) ) {
214
-
215
- // Prevent default behavior
216
- event.preventDefault();
217
-
218
- // Abort if lightbox and/or link is no longer active
219
- if ( !active || event.target.parentNode.getAttribute( 'data-open-lightbox' ) === 'inactive' ) return false;
127
+ // Prevent default behavior
128
+ event.preventDefault();
220
129
 
221
- // Load lightbox image
222
- loadPending( event.target );
130
+ // If viewport is smaller than <initWidth>, abort
131
+ if ( widthQuery.matches ) return false;
223
132
 
224
- // If it has loaded successfully
225
- if ( tempImg.complete ) {
133
+ // If lightbox hasn’t already been instantiated, :doit:
134
+ if ( !document.querySelector( '.lightbox' ) ) init();
226
135
 
227
- // Kick off image load success function
228
- loadSuccess();
136
+ // Allow escape to close lightbox
137
+ Event.keyOne( 'esc', hideLightbox );
229
138
 
230
- // Otherwise
231
- } else {
139
+ // Load lightbox image
140
+ loadPending( event.target );
232
141
 
233
- // Listen for image load event
234
- tempImg.addEventListener( 'load', loadSuccess, false );
142
+ // If it has loaded successfully
143
+ if ( tempImg.complete ) {
235
144
 
236
- // Listen for image error event
237
- tempImg.addEventListener( 'error', loadFailure, false );
145
+ // Kick off image load success function
146
+ loadSuccess();
238
147
 
239
- }
240
-
241
- }
148
+ // Otherwise
149
+ } else {
242
150
 
243
- // Run on `close lightbox` links
244
- if ( event.target.hasAttribute( 'data-close-lightbox') || event.target.classList.contains( 'lightbox' ) ) {
151
+ // Listen for image load event
152
+ Event.on( tempImg, 'load', loadSuccess );
245
153
 
246
- // Hide the lightbox
247
- hideLightbox();
154
+ // Listen for image error event
155
+ Event.on( tempImg, 'error', loadFailure );
248
156
 
249
157
  }
250
158
 
@@ -23,8 +23,13 @@ var loader = function( settings ) {
23
23
  // Extend defaults
24
24
  var options = Object.assign( {}, defaults, settings );
25
25
 
26
- // Create and prepend loader element
27
- options.selector.insertAdjacentHTML( 'afterbegin', '<div class="' + options.loaderClass + '"></div>' );
26
+ // If it doesn’t already exist
27
+ if ( !document.querySelector( 'div.' + options.loaderClass ) ) {
28
+
29
+ // Create and prepend loader element
30
+ options.selector.insertAdjacentHTML( 'afterbegin', '<div class="' + options.loaderClass + '"></div>' );
31
+
32
+ }
28
33
 
29
34
  // Cache loader element
30
35
  var element = document.querySelector( 'div.' + options.loaderClass );
@@ -1,6 +1,7 @@
1
1
  // Utility modules
2
2
  @import 'utility/global';
3
3
  @import 'utility/grid';
4
+ @import 'utility/loader';
4
5
 
5
6
  // Base modules
6
7
  @import 'base/text';
@@ -12,7 +13,6 @@
12
13
  @import 'base/document';
13
14
 
14
15
  // Enhancement modules
15
- @import 'enhancement/loader';
16
16
  @import 'enhancement/feature';
17
17
  @import 'enhancement/sticky-sidebar';
18
18
  @import 'enhancement/notice';
@@ -87,7 +87,12 @@
87
87
  }
88
88
  }
89
89
 
90
- // Inactive anchor links
91
- a[data-open-lightbox='inactive'] {
92
- cursor: default;
90
+ // Deactivate anchor links under 700px
91
+ @media (max-width: 700px) {
92
+ a[href$=jpg],
93
+ a[href$=png],
94
+ a[href$=gif],
95
+ a[href$=svg] {
96
+ cursor: default;
97
+ }
93
98
  }
@@ -21,7 +21,7 @@ html
21
21
 
22
22
  / Favicon
23
23
  - if content_for?(:favicon)
24
- = yield :favicon
24
+ = yield :favicon
25
25
 
26
26
  / Ratchet core JS
27
27
  = javascript_tag "core"
@@ -1,3 +1,3 @@
1
1
  module RatchetDesign
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end