-
Notifications
You must be signed in to change notification settings - Fork 37
/
index.html
executable file
·489 lines (431 loc) · 24 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<!DOCTYPE html>
<html>
<head>
<title>SimpleStateManager - Responsive state manager for JS</title>
<link rel="stylesheet" href="docs/css/styles.css">
<link href='http://fonts.googleapis.com/css?family=Lato:400,700' rel='stylesheet' type='text/css'>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<script src="docs/js/vendor/respond.min.js"></script>
</head>
<body data-spy="scroll" data-target=".navbar" id="home">
<a class="github-ribbon visible-desktop" href="https://github.com/SimpleStateManager/SimpleStateManager">
<img style="position: fixed; top: 0; right: 0; border: 0; z-index: 9999;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub">
</a>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="#home">Simple State Manager</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li class="active">
<a href="#home">Home</a>
</li>
<li class="">
<a href="#getstarted">Get started</a>
</li>
<li class="">
<a href="#api">API</a>
</li>
<li class="">
<a href="#extend">Extend</a>
</li>
<li class="">
<a href="#debugger">Debugger</a>
</li>
<li class="">
<a href="#log">Release Log</a>
</li>
<li class="">
<a href="#licence">Licence</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<header id="hero">
<div class="container">
<img src="docs/images/ssm-logo.png" class="logo">
<h1>Simple State Manager 2.2.6</h1>
<p class="lead">Simple State Manager (SSM for short) is a javascript state manager for responsive websites. It is built to be light weight, has no dependencies (except javascript of course) and aims to be really easy to simply drop into your project ready to use.</p>
<a class="btn btn-large btn-primary" href="https://github.com/jonathan-fielding/SimpleStateManager/archive/master.zip">Download</a>
</div>
</header>
<section id="intro">
<div class="container">
<p>As a state manager, SSM allows you to target different javascript towards different states of your site. It allows you to define as many states as your site requires and allows you to have independent Enter, Leave and Resize events for each of the states.</p>
<h2>Why should I use SSM</h2>
<ul>
<li>You require different javascript events dependant on the state of your browser e.g mobile, tablet or desktop</li>
<li>You need to provide a different resize event to different states of your site</li>
<li>You need to adjust your site using JS after it switches between states (mobile, tablet, desktop), potentially cleaning up after a state or adding extra functionality specific to a state</li>
</ul>
</div>
</section>
<section id="getstarted">
<div class="container">
<h2>Get started</h2>
<p>To get started with SSM the first step is to include it in your project, you can do this in two ways</p>
<ul>
<li>Download and add the ssm.js (or ssm.min.js) file to your site</li>
<li>Use Bower to add to your project using <code>bower install SimpleStateManager</code></li>
</ul>
</div>
</section>
<section id="api">
<div class="container">
<h2>API</h2>
<h3>Add States</h3>
<p>With Simple State Manager you can add multiple states based on your needs, the most simple way to add a state is to simply pass the information about your state to SSM using <code>ssm.addState</code>. You are able to add as many states as you need, your states are able to overlap and your states can each have their own <code>onEnter</code>, <code>onLeave</code> and <code>onResize</code> events. It is important to remember that the if you do not pass minWidth and maxWidth values they will revert to the default values (0 for minWidth and 99999 for maxWidth)</p>
<pre>ssm.addState({
id: 'mobile',
maxWidth: 767,
onEnter: function(){
console.log('enter mobile');
}
});
ssm.addState({
id: 'tablet',
minWidth: 768,
maxWidth: 1023,
onEnter: function(){
console.log('enter tablet');
}
});
ssm.addState({
id: 'desktop',
minWidth: 1024,
onEnter: function(){
console.log('enter desktop');
}
});</pre>
<p>If you wish to use one command to add multiple states using one command you can use ssm.addStates to which you should pass an array of states.</p>
<pre>ssm.addStates([
{
id: 'mobile',
maxWidth: 767,
onEnter: function(){
console.log('enter mobile');
}
},
{
id: 'tablet',
minWidth: 768,
maxWidth: 1023,
onEnter: function(){
console.log('enter tablet');
}
},
{
id: 'desktop',
minWidth: 1024,
onEnter: function(){
console.log('enter desktop');
}
}
]);</pre>
<h3>Remove States</h3>
<p>Sometimes it may be necessary to remove a state, if we have the <strong>id</strong> for the state we can easily remove the state, to remove the mobile state from our above example we simply use:</p>
<pre>ssm.removeState('mobile');</pre>
<p>Or if you want to remove multiple at the same time</p>
<pre>ssm.removeStates(['tablet', 'mobile']);</pre>
<h3>Ready</h3>
<p>Once you have finished setting up your states you should run <code>ssm.ready()</code> which will setup the states.</p>
<pre>ssm.ready();</pre>
<p>As SSM is chaninable you can fire the <code>ssm.ready()</code> method by simply adding <code>.ready()</code> onto your original command</p>
<pre>ssm.addState({
id: 'mobile',
maxWidth: 767,
onEnter: function(){
document.getElementById('hero').style.backgroundColor = "#daa23e";
}
}).ready();</pre>
<h3>Add a new config option</h3>
<p>In SimpleStateManager options we pass to our states are called config options, we are able to add new config options to SimpleStateManager using <code>ssm.addConfigOption</code></p>
<pre>ssm.addConfigOption({name:"maxWidth", test: function(){
if(typeof this.state.maxWidth === "number" && this.state.maxWidth >= this.browserWidth){
return true;
}
else{
return false;
}
}});</pre>
<p>This is the same method that SimpleStateManager uses to add the maxWidth config option so the example above is taken direct from the SimpleStateManager source. As you will notice we can use <code>this</code> to access the state we are testing to determine whether the test should pass or fail.</p>
<p>Some simple examples of tests that you could add to SimpleStateManager are:</p>
<ul>
<li>Viewport minimum and maximum height tests</li>
<li>Test to see if touch events are avalible</li>
</ul>
<h3>Full API</h3>
<table class="table table-hover table-condensed table-bordered">
<tr>
<th>Method</th>
<th>Description</th>
</tr>
<tr>
<td>ssm.addState</td>
<td>Add a new state, expects an object literal, properties avaliable - id (optional), minWidth (optional), maxWidth (optional), onEnter (optional), onResize (optional), onLeave (optional)</td>
</tr>
<tr>
<td>ssm.updateState</td>
<td>Update an existing state, expects two parameters, firstly the id of the state you wish to update and secondly an object literal of updated settings, properties avaliable - id (optional), minWidth (optional), maxWidth (optional), onEnter (optional), onResize (optional), onLeave (optional)</td>
</tr>
<tr>
<td>ssm.addStates</td>
<td>Add multiple new states, expects an array of object literals, properties avaliable - id (optional), minWidth (optional), maxWidth (optional), onEnter (optional), onResize (optional), onLeave (optional)</td>
</tr>
<tr>
<td>ssm.removeState</td>
<td>Remove a state, expects one property, the id of the state to be removed.</td>
</tr>
<tr>
<td>ssm.removeStates</td>
<td>Remove multiple states, expects an array of strings</td>
</tr>
<tr>
<td>ssm.removeAllStates</td>
<td>Clears all states from SSM</td>
</tr>
<tr>
<td>ssm.getStates</td>
<td>By default <code>ssm.getStates()</code> will return all the states added to SSM however you optionally can pass an array of ID's of the states you want e.g <code>ssm.getStates([ 'mobile' ,'desktop']);</code></td>
</tr>
<tr>
<td>ssm.getCurrentStates</td>
<td>Get the currently applied states</td>
</tr>
<tr>
<td>ssm.isActive</td>
<td>Check if a state is active using the ID you assigned, e.g. <code>ssm.isActive("desktop");</code></td>
</tr>
<tr>
<td>ssm.ready</td>
<td>Tells the page that states have been added and we can fire the onEnter event for the current state/states.</td>
</tr>
<tr>
<td>ssm.getBrowserWidth</td>
<td>Get the current value of the browser width</td>
</tr>
<tr>
<td>ssm.setResizeTimeout</td>
<td>Set the value of the timeout used for the resize debounce</td>
</tr>
<tr>
<td>ssm.getResizeTimeout</td>
<td>Get the current value the resize timeout</td>
</tr>
<tr>
<td>ssm.addConfigOption</td>
<td>SSM allows you to define new rules by which a state can be enabled and disabled using <code>ssm.addConfigOption</code>. The method takes an object with 2 values as the parameter, firstly the name of the config option and secondly the method to test the option. Please note the test must return true or false to allow SSM to know if the test has passed or failed. A typical example of how you can add a test <code>ssm.addConfigOption({name: "minHeight", test: function(){ return true; } });</code></td>
</tr>
</table>
</div>
</section>
<section id="extend">
<div class="container">
<h2>Extend</h2>
<p>One of the core features we integrated into SimpleStateManager 2.x is that we expose a lot more API's to access some of the values that are used everyday in responsive sites. The benefit of this is that it means SSM can be extended with new plugins that add extra functionality with ease.</p>
<p>If you decide to distribute your plugins and you add them to bower, please prefix the name of your plugin with <code>SSM-</code> so that they are easy to find.
<h3>Sample plugin template</h3>
<pre>;(function ( $, window, document, undefined ) {
var pluginName = "defaultPluginName",
defaults = {
propertyName: "value"
};
// The actual plugin constructor
function Plugin ( element, options ) {
this.init();
}
Plugin.prototype = {
init: function(){
}
}
if(!ssm[pluginName]){
ssm[pluginName] = new Plugin();
}
})( jQuery, window, document );</pre>
<h3>Official Plugins</h3>
<p>There are a growing number of official plugins for SimpleStateManager</p>
<ul id="plugins">
<li>Loading plugins...</li>
</ul>
</div>
</section>
<section id="debugger">
<div class="container">
<h2>Debugger</h2>
<p>While working on SSM 2.0 we explored ways in which we could make SSM easier to debug, we started by making a lot more of the SSM variables accessable however we wanted to take it a step further. Due to security restrictions of the browser a Chrome Extension wouldn't work so instead we decided to create a simple bookmarklet which adds a debugger to the page.</p>
<p>The debugger is very much an early alpha build and will be improved over time.</p>
<p>To get started with the SSM 2.0 debugger simply drag the SimpleStateManager Bookmarklet to your bookmarks bar</p>
<p><a href="javascript:(function(){document.body.appendChild(document.createElement('script')).src='http://www.simplestatemanager.com/bookmarklet/debugger.js';})();" class="btn btn-small btn-primary">SimpleStateManager Bookmarklet</a></p>
</div>
</section>
<section id="browsers">
<div class="container">
<h2>Browser Support</h2>
<p>There are a number of browsers that we have tested support, as we test more browsers we will update this list</p>
<ul>
<li>Chrome</li>
<li>Firefox</li>
<li>Internet Explorer 7+</li>
<li>Safari</li>
<li>Opera</li>
</ul>
</div>
</section>
<section id="log">
<div class="container">
<h2>Release Log</h2>
<p>SimpleStateManager follows <a href="http://semver.org/">Semantic Versioning 2.0.0</a></p>
<h3>2.2.6 - June 23, 2014</h3>
<ul>
<li>Fixed issue where you can apply multiple readies</li>
</ul>
<h3>2.2.5 - June 12, 2014</h3>
<ul>
<li>Fixed issue where it didnt work when you zoom the browser</li>
</ul>
<h3>2.2.4 - March 12, 2014</h3>
<ul>
<li>Fixed issue where respond.js would trick SimpleStateManager into thinking the matchMedia API was fully supported.</li>
</ul>
<h3>2.2.3 - February 14, 2014</h3>
<ul>
<li>Fixed issue where the width of the browser would not always match the media query</li>
</ul>
<h3>2.2.2 - February 12, 2014</h3>
<ul>
<li>Fixed issue where config options were required otherwise there would be an error</li>
</ul>
<h3>2.2.1 - January 31, 2014</h3>
<ul>
<li>Fixed build issue</li>
</ul>
<h3>2.2.0 - January 29, 2014</h3>
<ul>
<li>Added ssm.isActive to allow us to test if a state is active</li>
</ul>
<h3>2.1.0 - December 23, 2013</h3>
<ul>
<li>Added config option API which allows you to add your own SimpleStateManager config options along with the test to see if they are valid</li>
<li>Rewrote how testing of minWidth and maxWidth is handled to use the new config option API</li>
<li>Added new unit tests to improve code coverage</li>
</ul>
<h3>2.0.3 - October 7, 2013</h3>
<ul>
<li>Fixed issue where browser width was updated incorrectly</li>
</ul>
<h3>2.0.2 - September 26, 2013</h3>
<ul>
<li>Fixed issue where leave events did not fire correctly</li>
</ul>
<h3>2.0.1 - September 18, 2013</h3>
<ul>
<li>Fixed issue where ssm.js could not be placed in the head of the document</li>
</ul>
<h3>2.0.0 - September 13, 2013</h3>
<ul>
<li>Major API changes to all states mangement methods, please read through the new API documention if upgrading</li>
<li>Ability to overlap your states</li>
<li>Debug mode removed - replaced with a new debug tool (currently early alpha) which will continue to be expanded to allow better responsive debugging</li>
<li>Define min-width and max-width values for each state</li>
<li>Easier to extend SSM (it is now encouraged)</li>
</ul>
<h3>1.3.0 - August 10, 2013</h3>
<ul>
<li>Added .removeStates method</li>
<li>Added unit tests using QUnit</li>
<li>Integrated Travis CI</li>
</ul>
<h3>1.2.0 - August 9, 2013</h3>
<ul>
<li>Added .getState method</li>
</ul>
<h3>1.1.0 - August 9, 2013</h3>
<ul>
<li>Added .removeAllStates method</li>
</ul>
<h3>1.0.2 - August 6, 2013</h3>
<ul>
<li>AMD Support</li>
<li>Performance tweaks</li>
<li>New Site</li>
</ul>
<h3>1.0.1 - June 24, 2013</h3>
<ul>
<li>Added Debounce</li>
</ul>
<h3>1.0.0 - June 22, 2013</h3>
<ul>
<li>Initial release</li>
</ul>
</div>
</section>
<section id="contribute">
<div class="container">
<h2>Contribute</h2>
<p>Anybody is welcome to contribute to this project, this is a community led library and you can get involved in the following ways</p>
<ul>
<li>Create Issues for bugs or new feature requests</li>
<li>Fix any issues you have found and create a pull request</li>
</ul>
<p>Typically master is the latest version of SSM, new features are pushed into branches and when a branch has been fully tested and all the features are complete it will be merged into master. The milestone assigned in GitHub should be used for the branch name.</p>
<h3>Contributors</h3>
<ul>
<li><a href="http://www.jonathanfielding.com">Jonathan Fielding</a></li>
<li><a href="http://www.kevinsweeney.info/">Kevin Sweeney</a></li>
<li><a href="http://koenpasman.nl/">Koen Pasman</a></li>
<li><a href="http://iszak.net/">Iszak Bryan</a></li>
<li><a href="http://mearso.com/">Kevin Mears</a></li>
<li><a href="https://twitter.com/pianomansam">Samuel Oltz</a></li>
</ul>
</div>
</section>
<section id="licence">
<div class="container">
<h2>Licence</h2>
<p>License: MIT (<a href="http://www.opensource.org/licenses/mit-license.php">http://www.opensource.org/licenses/mit-license.php</a>)</p>
<p>The MIT License (MIT)</p>
<p>Copyright (c) 2013 Jonathan Fielding</p>
<p>Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:</p>
<p>The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.</p>
</div>
</section>
<footer>
<div class="container">
<p>Simple State Manager is an Open Source Project licenced under the MIT licence</p>
</div>
</footer>
<script src="src/ssm.js"></script>
<script src="docs/js/vendor/jquery.min.js"></script>
<script src="docs/js/vendor/bootstrap-scrollspy.js"></script>
<script src="docs/js/vendor/bootstrap-collapse.js"></script>
<script src="docs/js/script.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-42981349-1', 'simplestatemanager.com');
ga('send', 'pageview');
</script>
</body>
</html>