diff options
Diffstat (limited to 'snakeplan/templates/media/js/application.js')
-rw-r--r-- | snakeplan/templates/media/js/application.js | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/snakeplan/templates/media/js/application.js b/snakeplan/templates/media/js/application.js new file mode 100644 index 0000000..95b5c92 --- /dev/null +++ b/snakeplan/templates/media/js/application.js | |||
@@ -0,0 +1,184 @@ | |||
1 | /********************************************************************* | ||
2 | * Main SnakePlan Application * | ||
3 | *********************************************************************/ | ||
4 | (function() { | ||
5 | |||
6 | var URLS = { | ||
7 | project: "/api/project", | ||
8 | projectStories: "/api/project/{0}/stories" | ||
9 | }; | ||
10 | |||
11 | window.simpleTemplate = simpleTemplate; | ||
12 | |||
13 | $(document).ready(function() | ||
14 | { | ||
15 | $.getJSON(URLS.project, loadProjectSelector); | ||
16 | |||
17 | $("#project-select").change(function() | ||
18 | { | ||
19 | $.getJSON(URLS.projectStories.replace("{0}", getCurrentProjectId()), loadTaskList); | ||
20 | }); | ||
21 | }); | ||
22 | |||
23 | |||
24 | function getCurrentProjectId() | ||
25 | { | ||
26 | return $("#project-select").val(); | ||
27 | } | ||
28 | |||
29 | |||
30 | function loadProjectSelector(json) | ||
31 | { | ||
32 | $.each(json, function(i, item) | ||
33 | { | ||
34 | $("#project-select").append(new Option(item.name, item.id)); | ||
35 | }); | ||
36 | } | ||
37 | |||
38 | |||
39 | function loadTaskList(json) | ||
40 | { | ||
41 | var taskList = $("#task-table"); | ||
42 | taskList.empty(); | ||
43 | |||
44 | $.each(json, function(i, item) | ||
45 | { | ||
46 | $("<li/>").text(item.name).attr("class", "ui-state-default").appendTo(taskList); | ||
47 | }); | ||
48 | |||
49 | $("#task-table").sortable({ | ||
50 | placeholder: 'ui-state-highlight' | ||
51 | }); | ||
52 | $("#task-table").disableSelection(); | ||
53 | } | ||
54 | |||
55 | })(); | ||
56 | |||
57 | |||
58 | /********************************************************************* | ||
59 | * Centering Plugin * | ||
60 | *********************************************************************/ | ||
61 | (function($){ | ||
62 | $.fn.extend({ | ||
63 | center: function (options) { | ||
64 | var options = $.extend({ | ||
65 | inside: window, | ||
66 | transition: 0, | ||
67 | minX: 0, | ||
68 | minY: 0, | ||
69 | withScrolling: true, | ||
70 | vertical: true, | ||
71 | horizontal: true | ||
72 | }, options); | ||
73 | |||
74 | return this.each(function() { | ||
75 | var props = {position:'absolute'}; | ||
76 | if (options.vertical) { | ||
77 | var top = ($(options.inside).height() - $(this).outerHeight()) / 3; | ||
78 | if (options.withScrolling) { | ||
79 | top += $(options.inside).scrollTop() || 0; | ||
80 | } | ||
81 | top = (top > options.minY ? top : options.minY); | ||
82 | $.extend(props, {top: top+'px'}); | ||
83 | } | ||
84 | |||
85 | if (options.horizontal) { | ||
86 | var left = ($(options.inside).width() - $(this).outerWidth()) / 3; | ||
87 | if (options.withScrolling) { | ||
88 | left += $(options.inside).scrollLeft() || 0; | ||
89 | } | ||
90 | left = (left > options.minX ? left : options.minX); | ||
91 | $.extend(props, {left: left+'px'}); | ||
92 | } | ||
93 | |||
94 | if (options.transition > 0) { | ||
95 | $(this).animate(props, options.transition); | ||
96 | } else { | ||
97 | $(this).css(props); | ||
98 | } | ||
99 | |||
100 | return $(this); | ||
101 | }); | ||
102 | } | ||
103 | }); | ||
104 | })(jQuery); | ||
105 | |||
106 | |||
107 | /********************************************************************* | ||
108 | * Hitch Plugin * | ||
109 | *********************************************************************/ | ||
110 | (function($) { | ||
111 | $.fn.hitch = function(ev, fn, scope) { | ||
112 | return this.bind(ev, function() { | ||
113 | return fn.apply(scope || this, Array.prototype.slice.call(arguments)); | ||
114 | }); | ||
115 | }; | ||
116 | })(jQuery); | ||
117 | |||
118 | |||
119 | /********************************************************************* | ||
120 | * Overlay Plugin * | ||
121 | * * | ||
122 | * WARNING: Here be dragons! * | ||
123 | * * | ||
124 | * This needs some love still. I really want to make this into a * | ||
125 | * decent overlay so that it can be used for async form loading but * | ||
126 | * don't yet know how to properly extend jQuery. * | ||
127 | * * | ||
128 | *********************************************************************/ | ||
129 | (function($) { | ||
130 | window.overlay = $("#overlay"); | ||
131 | window.overlay.close = function() { | ||
132 | $(this).fadeOut("slow"); | ||
133 | }; | ||
134 | window.overlay.show = function() { | ||
135 | $(this).fadeIn("slow"); | ||
136 | }; | ||
137 | |||
138 | Overlay = function(height, width) | ||
139 | { | ||
140 | this.height = height; | ||
141 | this.width = width; | ||
142 | |||
143 | this.overlayBox = $("#overlay-display-box").clone().attr("id", ""); | ||
144 | this.overlayBox.appendTo(overlay); | ||
145 | }; | ||
146 | Overlay.prototype = { | ||
147 | |||
148 | open: function() | ||
149 | { | ||
150 | this.overlayBox.css({ | ||
151 | width: this.width + "px", | ||
152 | height: this.height + "px", | ||
153 | }).center().draggable(); | ||
154 | |||
155 | this.overlayBox.find(".overlay-background").css({ | ||
156 | width: this.width + "px", | ||
157 | height: this.height + "px" | ||
158 | }); | ||
159 | |||
160 | this.overlayBox.find(".overlay-foreground").css({ | ||
161 | width: (this.width - 22) + "px", | ||
162 | height: (this.height - 22) + "px" | ||
163 | }); | ||
164 | |||
165 | this.overlayBox.find(".overlay-close").hitch("click", function() { | ||
166 | this.destroy(); | ||
167 | }, this); | ||
168 | |||
169 | this.overlayBox.fadeIn("slow"); | ||
170 | overlay.show(); | ||
171 | }, | ||
172 | |||
173 | close: function() { | ||
174 | this.overlayBox.fadeOut("slow"); | ||
175 | overlay.close(); | ||
176 | }, | ||
177 | |||
178 | destroy: function() { | ||
179 | this.close(); | ||
180 | this.overlayBox.remove(); | ||
181 | } | ||
182 | |||
183 | }; | ||
184 | })(jQuery); | ||