livingstyleguide 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,75 @@
|
|
1
|
+
;(function(win) {
|
2
|
+
|
3
|
+
getCookie = function(name) {
|
4
|
+
var regexp = new RegExp('(?:^|;)\\s*' + name + '\\s*=(.+?)(?:;|$)'),
|
5
|
+
match = document.cookie.match(regexp);
|
6
|
+
if (match) {
|
7
|
+
return escape(match[1]);
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
setCookie = function(name, value, expireDays) {
|
12
|
+
var cookie = name + '=' + escape(value);
|
13
|
+
if (expireDays) {
|
14
|
+
var expireDate = new Date();
|
15
|
+
expireDate.setDate(expireDate.getDate() + expireDays);
|
16
|
+
cookie += '; expires=' + expireDate.toUTCString();
|
17
|
+
}
|
18
|
+
document.cookie = cookie;
|
19
|
+
}
|
20
|
+
|
21
|
+
getClasses = function(el) {
|
22
|
+
return el.className.split(/\s+/g);
|
23
|
+
};
|
24
|
+
|
25
|
+
addClass = function(el, name) {
|
26
|
+
var classList = getClasses(el);
|
27
|
+
if (classList.indexOf(name) == -1) {
|
28
|
+
classList.push(name);
|
29
|
+
el.className = classList.join(' ');
|
30
|
+
}
|
31
|
+
};
|
32
|
+
|
33
|
+
removeClass = function(el, name) {
|
34
|
+
var classList = getClasses(el);
|
35
|
+
classList[classList.indexOf(name)] = null;
|
36
|
+
el.className = classList.join(' ');
|
37
|
+
};
|
38
|
+
|
39
|
+
toggleClass = function(el, name) {
|
40
|
+
var classList = getClasses(el);
|
41
|
+
if (classList.indexOf(name) == -1) {
|
42
|
+
addClass(el, name);
|
43
|
+
return true;
|
44
|
+
}
|
45
|
+
else {
|
46
|
+
removeClass(el, name);
|
47
|
+
return false;
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
51
|
+
var html = document.getElementsByTagName('HTML')[0];
|
52
|
+
|
53
|
+
// Hide/show code
|
54
|
+
|
55
|
+
var codeOpenedClass = 'show-code';
|
56
|
+
|
57
|
+
if (getCookie(codeOpenedClass) != 'false') {
|
58
|
+
addClass(html, codeOpenedClass);
|
59
|
+
}
|
60
|
+
|
61
|
+
function toggleCode(event) {
|
62
|
+
event.preventDefault();
|
63
|
+
showCode = toggleClass(html, codeOpenedClass);
|
64
|
+
setCookie(codeOpenedClass, showCode, 365);
|
65
|
+
}
|
66
|
+
|
67
|
+
document.addEventListener('DOMContentLoaded', function() {
|
68
|
+
var switches = document.getElementsByClassName('livingstyleguide--code-switch');
|
69
|
+
for (var i = 0; i < switches.length; i++) {
|
70
|
+
switches[i].addEventListener('click', toggleCode);
|
71
|
+
}
|
72
|
+
});
|
73
|
+
|
74
|
+
})(window);
|
75
|
+
|
@@ -45,10 +45,13 @@
|
|
45
45
|
}
|
46
46
|
|
47
47
|
.livingstyleguide--code-block {
|
48
|
-
display:
|
48
|
+
display: none;
|
49
49
|
line-height: $livingstyleguide--code-line-height;
|
50
50
|
padding: 3px 6px;
|
51
51
|
width: $livingstyleguide--width - 2 * 6px;
|
52
|
+
.show-code & {
|
53
|
+
display: block;
|
54
|
+
}
|
52
55
|
}
|
53
56
|
|
54
57
|
.livingstyleguide--example + .livingstyleguide--code-block {
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: livingstyleguide
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minisyntax
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- LICENSE.txt
|
120
120
|
- README.md
|
121
121
|
- Rakefile
|
122
|
+
- assets/javascripts/livingstyleguide.js
|
122
123
|
- lib/livingstyleguide.rb
|
123
124
|
- lib/livingstyleguide/markdown_extensions.rb
|
124
125
|
- lib/livingstyleguide/sass_extensions.rb
|
@@ -162,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
163
|
version: '0'
|
163
164
|
segments:
|
164
165
|
- 0
|
165
|
-
hash:
|
166
|
+
hash: 3032285374060806348
|
166
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
168
|
none: false
|
168
169
|
requirements:
|
@@ -171,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
172
|
version: '0'
|
172
173
|
segments:
|
173
174
|
- 0
|
174
|
-
hash:
|
175
|
+
hash: 3032285374060806348
|
175
176
|
requirements: []
|
176
177
|
rubyforge_project:
|
177
178
|
rubygems_version: 1.8.23
|