Pārlūkot izejas kodu

Show/hide instructions toggle

master
Chris Smith 12 gadus atpakaļ
vecāks
revīzija
9ee2d4a207
4 mainītis faili ar 86 papildinājumiem un 0 dzēšanām
  1. 5
    0
      index.html
  2. 47
    0
      res/js/jquery.cookie.js
  3. 19
    0
      res/js/viewer.js
  4. 15
    0
      res/style.less

+ 5
- 0
index.html Parādīt failu

@@ -3,6 +3,7 @@
3 3
  <head>
4 4
   <title>Dungeon Defenders Viewer</title>
5 5
   <script src="res/js/jquery-1.7.1.min.js" type="text/javascript"></script>
6
+  <script src="res/js/jquery.cookie.js" type="text/javascript"></script>
6 7
   <script src="res/js/jquery-ui-1.8.17.custom.min.js" type="text/javascript"></script>
7 8
   <script src="res/data/levels.js" type="text/javascript"></script>
8 9
   <script src="res/data/towers.js" type="text/javascript"></script>
@@ -15,6 +16,7 @@
15 16
   <div id="header">
16 17
    <h1><img src="res/images/dd-logo.png" alt="Dungeon Defenders"><span>Layout Editor</span></h1>
17 18
    <div id="buttons">
19
+    <button id="showinstructions" class="initiallyhidden">Show Instructions</button>
18 20
     <button id="savelayout">Save this layout</button>
19 21
     <button id="createlayout">Create new layout</button>
20 22
    </div>
@@ -41,6 +43,9 @@
41 43
      Shift+click to rotate a tower.
42 44
      Double click to remove a tower.
43 45
     </p>
46
+    <button id="hideinstructions">
47
+     Hide instructions
48
+    </button>
44 49
    </div>
45 50
    <div id="mapcontainer"></div>
46 51
   </div>

+ 47
- 0
res/js/jquery.cookie.js Parādīt failu

@@ -0,0 +1,47 @@
1
+/**
2
+ * jQuery Cookie plugin
3
+ *
4
+ * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
5
+ * Dual licensed under the MIT and GPL licenses:
6
+ * http://www.opensource.org/licenses/mit-license.php
7
+ * http://www.gnu.org/licenses/gpl.html
8
+ *
9
+ */
10
+(function($) {
11
+    $.cookie = function(key, value, options) {
12
+
13
+        // key and at least value given, set cookie...
14
+        if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value === null || value === undefined)) {
15
+            options = $.extend({}, options);
16
+
17
+            if (value === null || value === undefined) {
18
+                options.expires = -1;
19
+            }
20
+
21
+            if (typeof options.expires === 'number') {
22
+                var days = options.expires, t = options.expires = new Date();
23
+                t.setDate(t.getDate() + days);
24
+            }
25
+
26
+            value = String(value);
27
+
28
+            return (document.cookie = [
29
+                encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
30
+                options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
31
+                options.path    ? '; path=' + options.path : '',
32
+                options.domain  ? '; domain=' + options.domain : '',
33
+                options.secure  ? '; secure' : ''
34
+            ].join(''));
35
+        }
36
+
37
+        // key and possibly options given, get cookie...
38
+        options = value || {};
39
+        var decode = options.raw ? function(s) { return s; } : decodeURIComponent;
40
+
41
+        var pairs = document.cookie.split('; ');
42
+        for (var i = 0, pair; pair = pairs[i] && pairs[i].split('='); i++) {
43
+            if (decode(pair[0]) === key) return decode(pair[1] || ''); // IE saves cookies with empty string as "c; ", e.g. without "=" as opposed to EOMB, thus pair[1] may be undefined
44
+        }
45
+        return null;
46
+    };
47
+})(jQuery);

+ 19
- 0
res/js/viewer.js Parādīt failu

@@ -268,6 +268,25 @@ $(function() {
268 268
   }
269 269
  }
270 270
 
271
+ function showInstructions() {
272
+  $.cookie('hideinstructions', null);
273
+  $('#instructions').show();
274
+  $('#showinstructions').hide();
275
+ }
276
+
277
+ function hideInstructions() {
278
+  $.cookie('hideinstructions', 1, { expires: 365 });
279
+  $('#instructions').hide();
280
+  $('#showinstructions').show();
281
+ }
282
+
283
+ $('#hideinstructions').click(hideInstructions);
284
+ $('#showinstructions').click(showInstructions);
285
+
271 286
  $(window).bind('hashchange', updateFromHash);
272 287
  updateFromHash();
288
+
289
+ if ($.cookie('hideinstructions')) {
290
+  hideInstructions();
291
+ }
273 292
 });

+ 15
- 0
res/style.less Parādīt failu

@@ -8,6 +8,7 @@
8 8
 
9 9
 @create-color: @heading-color;
10 10
 @save-color: #030;
11
+@instructions-color: #003;
11 12
 
12 13
 @border-color: @gradient-start-color;
13 14
 @border: 1px solid @border-color;
@@ -65,9 +66,14 @@ body {
65 66
   }
66 67
 
67 68
   #savelayout {
69
+   margin-left: 20px;
68 70
    color: @save-color;
69 71
   }
70 72
 
73
+  #showinstructions {
74
+   color: @instructions-color;
75
+  }
76
+
71 77
   button {
72 78
    font-variant: small-caps;
73 79
    font-weight: bold;
@@ -223,4 +229,13 @@ body .tower.ui-draggable-dragging { z-index: 101; }
223 229
  h2 {
224 230
   padding-left: 20px;
225 231
  }
232
+
233
+ button {
234
+  margin-left: 20px;
235
+  opacity: 0.6;
236
+
237
+  &:hover {
238
+   opacity: 1;
239
+  }
240
+ }
226 241
 }

Notiek ielāde…
Atcelt
Saglabāt