Browse Source

Hide show parts based on classes

Greg Turnquist 10 years ago
parent
commit
f910620c6a
1 changed files with 204 additions and 2 deletions
  1. 204
    2
      README.adoc

+ 204
- 2
README.adoc View File

12
 
12
 
13
 This guide walks you through the process of creating a "hello world" link:/understanding/REST[RESTful web service] with Spring.
13
 This guide walks you through the process of creating a "hello world" link:/understanding/REST[RESTful web service] with Spring.
14
 
14
 
15
+++++
16
+<!-- customize code to show and hide different parts -->
17
+<script>
18
+    function forEach(array, callback, scope) {
19
+        for (var i = 0; i < array.length; i++) {
20
+            callback.call(scope, i, array[i]); // passes back stuff we need
21
+        }
22
+    }
23
+
24
+
25
+    var classRx, trimLeadingRx, splitClassNamesRx;
26
+    var body = document.querySelector('body');
27
+    var guidePreferences = '_guide_preferences';
28
+
29
+    classRx = '(\\s+|^)(classNames)(\\b(?![\\-_])|$)';
30
+    trimLeadingRx = /^\s+/;
31
+    splitClassNamesRx = /(\b\s+\b)|(\s+)/g;
32
+
33
+    function addClass (className, str) {
34
+        var newClass;
35
+
36
+        if(!className) {
37
+            return str;
38
+        }
39
+
40
+        newClass = removeClass(className, str);
41
+
42
+        if(newClass && className) {
43
+            newClass += ' ';
44
+        }
45
+
46
+        return newClass + className;
47
+    }
48
+
49
+    function removeClass (removes, tokens) {
50
+        var rx;
51
+
52
+        if (!removes) {
53
+            return tokens;
54
+        }
55
+
56
+        // convert space-delimited tokens with bar-delimited (regexp `or`)
57
+        removes = removes.replace(splitClassNamesRx,
58
+                function (m, inner, edge) {
59
+                    // only replace inner spaces with |
60
+                    return edge ? '' : '|';
61
+                }
62
+        );
63
+
64
+        // create one-pass regexp
65
+        rx = new RegExp(classRx.replace('classNames', removes), 'g');
66
+
67
+        // remove all tokens in one pass (wish we could trim leading
68
+        // spaces in the same pass! at least the trim is not a full
69
+        // scan of the string)
70
+        return tokens.replace(rx, '').replace(trimLeadingRx, '');
71
+    }
72
+
73
+    var docCookies = {
74
+        getItem: function (sKey) {
75
+            return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
76
+        },
77
+        setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {
78
+            if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) { return false; }
79
+            var sExpires = "";
80
+            if (vEnd) {
81
+                switch (vEnd.constructor) {
82
+                    case Number:
83
+                        sExpires = vEnd === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + vEnd;
84
+                        break;
85
+                    case String:
86
+                        sExpires = "; expires=" + vEnd;
87
+                        break;
88
+                    case Date:
89
+                        sExpires = "; expires=" + vEnd.toUTCString();
90
+                        break;
91
+                }
92
+            }
93
+            document.cookie = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : "");
94
+            return true;
95
+        },
96
+        removeItem: function (sKey, sPath, sDomain) {
97
+            if (!sKey || !this.hasItem(sKey)) { return false; }
98
+            document.cookie = encodeURIComponent(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + ( sDomain ? "; domain=" + sDomain : "") + ( sPath ? "; path=" + sPath : "");
99
+            return true;
100
+        },
101
+        hasItem: function (sKey) {
102
+            return (new RegExp("(?:^|;\\s*)" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie);
103
+        },
104
+        keys: /* optional method: you can safely remove it! */ function () {
105
+            var aKeys = document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g, "").split(/\s*(?:\=[^;]*)?;\s*/);
106
+            for (var nIdx = 0; nIdx < aKeys.length; nIdx++) { aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]); }
107
+            return aKeys;
108
+        }
109
+    };
110
+
111
+    function revealGradle() {
112
+        body.className = removeClass("show-gradle show-maven show-sts", body.className);
113
+        body.className = addClass("show-gradle", body.className);
114
+        docCookies.setItem(guidePreferences, 'gradle', Infinity);
115
+
116
+    }
117
+
118
+    function revealMaven() {
119
+        body.className = removeClass("show-gradle show-maven show-sts", body.className);
120
+        body.className = addClass("show-maven", body.className);
121
+        docCookies.setItem(guidePreferences, 'maven', Infinity);
122
+    }
123
+
124
+    function revealSTS() {
125
+        body.className = removeClass("show-gradle show-maven show-sts", body.className);
126
+        body.className = addClass("show-sts", body.className);
127
+        docCookies.setItem(guidePreferences, 'sts', Infinity);
128
+    }
129
+
130
+    function hideBuildSteps() {
131
+        body.className = removeClass("show-gradle show-maven show-sts", body.className);
132
+        docCookies.setItem(guidePreferences, 'none', Infinity);
133
+    }
134
+
135
+    function registerBuildSwitches() {
136
+        document.querySelector('.reveal-gradle').addEventListener('click', revealGradle);
137
+        document.querySelector('.reveal-maven').addEventListener('click', revealMaven);
138
+        document.querySelector('.reveal-sts').addEventListener('click', revealSTS);
139
+
140
+        document.querySelector('.use-gradle').addEventListener('click', hideBuildSteps);
141
+        document.querySelector('.use-maven').addEventListener('click', hideBuildSteps);
142
+        document.querySelector('.use-sts').addEventListener('click', hideBuildSteps);
143
+    }
144
+
145
+    document.addEventListener('DOMContentLoaded', registerBuildSwitches);
146
+</script>
147
+<style>
148
+    .use-gradle {
149
+        display: none;
150
+    }
151
+    .use-maven {
152
+        display: none;
153
+    }
154
+    .use-sts {
155
+        display: none;
156
+    }
157
+
158
+    .reveal-gradle {
159
+        display: inherit;
160
+    }
161
+    .reveal-maven {
162
+        display: inherit;
163
+    }
164
+    .reveal-sts {
165
+        display: inherit;
166
+    }
167
+
168
+    .show-gradle .use-gradle {
169
+        display: inherit;
170
+    }
171
+    .show-maven .use-maven {
172
+        display: inherit;
173
+    }
174
+    .show-sts .use-sts {
175
+        display: inherit;
176
+    }
177
+
178
+    .show-gradle .reveal-gradle {
179
+        display: none;
180
+    }
181
+    .show-maven .reveal-maven {
182
+        display: none;
183
+    }
184
+    .show-sts .reveal-sts {
185
+        display: none;
186
+    }
187
+</style>
188
+++++
189
+
15
 == What you'll build
190
 == What you'll build
16
 
191
 
17
 You'll build a service that will accept HTTP GET requests at:
192
 You'll build a service that will accept HTTP GET requests at:
49
 include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/how_to_complete_this_guide.adoc[]
224
 include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/how_to_complete_this_guide.adoc[]
50
 
225
 
51
 
226
 
227
+[.reveal-gradle]
228
+== Build with Gradle
229
+
52
 [[scratch]]
230
 [[scratch]]
53
-== Set up the project
231
+[.use-gradle]
232
+== Build with Gradle
54
 
233
 
55
 include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/build_system_intro.adoc[]
234
 include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/build_system_intro.adoc[]
56
 
235
 
57
 include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/create_directory_structure_hello.adoc[]
236
 include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/create_directory_structure_hello.adoc[]
58
 
237
 
59
-
60
 include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/create_both_builds.adoc[]
238
 include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/create_both_builds.adoc[]
239
+
61
 `build.gradle`
240
 `build.gradle`
62
 // AsciiDoc source formatting doesn't support groovy, so using java instead
241
 // AsciiDoc source formatting doesn't support groovy, so using java instead
63
 [source,java]
242
 [source,java]
67
 
246
 
68
 include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/spring-boot-gradle-plugin.adoc[]
247
 include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/spring-boot-gradle-plugin.adoc[]
69
 
248
 
249
+[.reveal-maven] 
250
+== Build with Maven
251
+
252
+[.use-maven]
253
+== Build with Maven
254
+
255
+include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/build_system_intro_maven.adoc[]
256
+
257
+include::https://raw.githubusercontent.com/spring-guides/getting-started-macros/master/create_directory_structure_hello.adoc[]
258
+
259
+`pom.xml`
260
+[source,xml]
261
+----
262
+include::initial/pom.xml[]
263
+----
264
+
265
+[.reveal-sts]
266
+== Build with Spring Tool Suite
267
+
268
+[.use-sts]
269
+== Build with Spring Tool Suite
270
+
271
+If you have Spring Tool Suite, then you can simply link:/guides/gs/sts/[import this guide directly].
70
 
272
 
71
 [[initial]]
273
 [[initial]]
72
 == Create a resource representation class
274
 == Create a resource representation class