vito / chyrp

The ultra-lightweight ultra-flexible blogging engine with a fetish for birds and misspellings.

This URL has Read+Write access

chyrp / includes / admin.js.php
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 1 <?php
2 define('JAVASCRIPT', true);
05fcaa5c » vito 2008-05-10 * Restructuring of JS libra... 3 require_once "common.php";
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 4 ?>
6b9a84a8 » vito 2008-06-10 * Changed a few .js_disable... 5 <!-- --><script>
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 6 $(function(){
7 // Scan AJAX responses for errors.
a2df500e » vito 2008-07-18 JavaScript renovations 8 $(document).ajaxComplete(function(event, request){
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 9 var response = request.responseText
10 if (isError(response))
3a2de031 » vito 2008-06-10 Implemented AJAX page reord... 11 alert(response.replace(/(HEY_JAVASCRIPT_THIS_IS_AN_ERROR_JUST_SO_YOU_KNOW|<([^>]+)>\n?)/gm, ""))
a2df500e » vito 2008-07-18 JavaScript renovations 12 })<?php echo "\n\n\n\n\n"; # Balance out the line numbers in this script and in the output to help debugging. ?>
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 13
a2df500e » vito 2008-07-18 JavaScript renovations 14 // Handle typing "\ct" to insert a <tab>
68132d2d » vito 2008-06-18 * Made textareas in the Adm... 15 $("textarea").keyup(function(event){
734d486a » vito 2008-06-30 Allow commenting on the tab... 16 if ($(this).val().match(/([^\\]|^)\\ct/gm))
17 $(this).val($(this).val().replace(/([^\\]|^)\\ct/gm, " "))
68132d2d » vito 2008-06-18 * Made textareas in the Adm... 18 })
19
20dce947 » vito 2008-05-10 More JS updates. 20 // Automated PNG fixing.
b19d812c » vito 2008-06-03 Renamed file_url to chyrp_url 21 $.ifixpng("<?php echo $config->chyrp_url; ?>/admin/images/icons/pixel.gif")
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 22 $("img[@src$=.png]").ifixpng()
23
24 // "Help" links should open in popup windows.
25 $(".help").click(function(){
26 window.open($(this).attr("href"), "help", "status=0, height=350, width=300")
27 return false;
28 })
29
30 // Checkbox toggling.
3a2de031 » vito 2008-06-10 Implemented AJAX page reord... 31 togglers()
32
e6175ce9 » vito 2008-07-06 Minor bugfixes. 33 if ($.browser.safari)
fc1bc194 » vito 2008-07-06 * Added an awesome Flash cl... 34 $("code").each(function(){
35 $(this).css({
36 fontFamily: "Monaco, monospace",
37 fontSize: "9px"
38 })
3a2de031 » vito 2008-06-10 Implemented AJAX page reord... 39 })
40
a2df500e » vito 2008-07-18 JavaScript renovations 41 if (/(edit|write)_/.test(Route.action))
42 Write.init()
d87af098 » vito 2008-06-12 * Added AJAX sorting of Fea... 43
a2df500e » vito 2008-07-18 JavaScript renovations 44 if (Route.action == "manage_pages")
45 Manage.pages.init()
46
47 if (Route.action == "modules" || Route.action == "feathers")
48 Extend.init()
49
50 // Remove things that only exist for JS-disabled users.
51 $(".js_disabled").remove()
52 $(".js_enabled").css("display", "block")
53 })
d87af098 » vito 2008-06-12 * Added AJAX sorting of Fea... 54
3a2de031 » vito 2008-06-10 Implemented AJAX page reord... 55 function togglers() {
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 56 var all_checked = true
a2df500e » vito 2008-07-18 JavaScript renovations 57
9f40ccdf » vito 2008-07-17 l10n fixes. [#164 state:res... 58 $("#toggler").html('<label for="toggle"><?php echo __("Toggle All"); ?></label><input class="checkbox" type="checkbox" name="toggle" id="toggle" />')
a2df500e » vito 2008-07-18 JavaScript renovations 59
523339b3 » vito 2008-06-09 * Updated jQuery UI 60 $(".toggler").html('<input class="checkbox" type="checkbox" name="toggle" id="toggle" />')
a2df500e » vito 2008-07-18 JavaScript renovations 61
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 62 $("#toggle").click(function(){
523339b3 » vito 2008-06-09 * Updated jQuery UI 63 $("form#new_group, form#group_edit, table").find(":checkbox").not("#toggle").each(function(){
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 64 this.checked = document.getElementById("toggle").checked
65 })
66 })
a2df500e » vito 2008-07-18 JavaScript renovations 67
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 68 $("form#new_group, form#group_edit").find(":checkbox").not("#toggle").each(function(){
69 if (!all_checked) return
70 all_checked = this.checked
71 })
a2df500e » vito 2008-07-18 JavaScript renovations 72
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 73 if ($("#toggler").size())
74 document.getElementById("toggle").checked = all_checked
3a2de031 » vito 2008-06-10 Implemented AJAX page reord... 75 }
05fcaa5c » vito 2008-05-10 * Restructuring of JS libra... 76
065c0612 » vito 2008-07-17 * Re-implemented (incomplet... 77 Array.prototype.indicesOf = function(value) {
78 var results = []
79
80 for (var j = 0; j < this.length; j++)
81 if (typeof value != "string") {
82 if (value.test(this[j]))
83 results.push(j)
84 } else if (this[j] == value)
85 results.push(j)
86
87 return results
88 }
89
90 Array.prototype.find = function(match) {
91 var matches = []
92
93 for (var f = 0; f < this.length; f++)
94 if (match.test(this[f]))
95 matches.push(this[f])
96
97 return matches
98 }
99
100 Array.prototype.remove = function(value) {
a2df500e » vito 2008-07-18 JavaScript renovations 101 if (value instanceof Array) {
065c0612 » vito 2008-07-17 * Re-implemented (incomplet... 102 for (var r = 0; r < value.length; r++)
103 this.remove(value[r])
104
105 return
106 }
107
108 var indices = this.indicesOf(value)
109
110 if (indices.length == 0)
111 return
112
113 for (var h = 0; h < indices.length; h++)
114 this.splice(indices[h] - h, 1)
115
116 return this
3a2de031 » vito 2008-06-10 Implemented AJAX page reord... 117 }
f194e03d » vito 2008-05-22 Re-implemented module confl... 118
a2df500e » vito 2008-07-18 JavaScript renovations 119 var Route = {
120 action: "<?php echo $_GET['action']; ?>"
121 }
3a2de031 » vito 2008-06-10 Implemented AJAX page reord... 122
a2df500e » vito 2008-07-18 JavaScript renovations 123 var Write = {
124 init: function(){
125 this.bookmarklet_link()
126 this.auto_expand_fields()
127 this.sortable_feathers()
128 this.prepare_previewer()
129 this.more_options()
130 },
131 bookmarklet_link: function(){
08245434 » vito 2008-07-18 Relocated the Bookmarklet t... 132 $(document.createElement("li")).addClass("bookmarklet right").html("<?php echo _f("Bookmarklet: %s", array('<a class=\"no_drag\" href=\"javascript:var%20d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f=\''.$config->chyrp_url.'/admin/?action=bookmarklet\',l=d.location,e=encodeURIComponent,p=\'&url=\'+e(l.href)+\'&title=\'+e(d.title)+\'&selection=\'+e(s),u=f+p;a=function(){if(!w.open(u,\'t\',\'toolbar=0,resizable=0,status=1,width=450,height=430\'))l.href=u;};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();void(0)\">Chyrp!</a>')); ?>").prependTo(".write_post_nav")
a2df500e » vito 2008-07-18 JavaScript renovations 133 },
134 auto_expand_fields: function(){
135 $("input.text").each(function(){
136 if ($(this).parent().parent().attr("class") == "more_options") return
137 $(this).css("min-width", $(this).outerWidth()).Autoexpand()
138 })
139 $("textarea").each(function(){
140 $(this).css({
141 lineHeight: "15px"
142 }).autogrow()
143 })
144 },
145 sortable_feathers: function(){
146 // Make the Feathers sortable
147 $("#sub-nav").sortable({
148 axis: "x",
149 placeholder: "feathers_sort",
150 opacity: 0.8,
151 delay: 1,
152 revert: true,
153 cancel: "a.no_drag, a[href$=write_page]",
154 update: function(){
155 $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php", "action=reorder_feathers&"+$("#sub-nav").sortable("serialize"))
065c0612 » vito 2008-07-17 * Re-implemented (incomplet... 156 }
a2df500e » vito 2008-07-18 JavaScript renovations 157 })
158 },
159 prepare_previewer: function() {
160 if ($(".preview_me").length > 0) {
161 var feather = ($("#write_feather").size()) ? $("#write_feather").val() : ""
162 var feather = ($("#edit_feather").size()) ? $("#edit_feather").val() : feather
163 $(document.createElement("div")).css("display", "none").attr("id", "preview").insertBefore("#write_form, #edit_form")
164 $(document.createElement("button")).html("<?php echo __("Preview &rarr;"); ?>").attr({ "type": "submit", "accesskey": "p" }).click(function(){
165 $("#preview").load("<?php echo $config->chyrp_url; ?>/includes/ajax.php", { action: "preview", content: $(".preview_me").val(), feather: feather }, function(){
166 $(this).fadeIn("fast")
167 })
168 return false
169 }).appendTo(".buttons")
170 }
171 },
172 more_options: function(){
173 if ($("#more_options").size()) {
174 if (Cookie.get("show_more_options") == "true")
175 var more_options_text = "<?php echo __("&laquo; Fewer Options"); ?>";
176 else
177 var more_options_text = "<?php echo __("More Options &raquo;"); ?>";
178
179 $(document.createElement("a")).attr({
180 id: "more_options_link",
181 href: "javascript:void(0)"
182 }).addClass("more_options_link").html(more_options_text).insertBefore(".buttons")
183 $("#more_options").clone().insertAfter("#more_options_link").removeClass("js_disabled")
184
185 if (Cookie.get("show_more_options") == null)
186 $("#more_options").css("display", "none")
187
188 $("#more_options_link").click(function(){
189 if ($("#more_options").css("display") == "none") {
190 $(this).html("<?php echo __("&laquo; Fewer Options"); ?>")
191 Cookie.set("show_more_options", "true", 30)
192 } else {
193 $(this).html("<?php echo __("More Options &raquo;"); ?>")
194 Cookie.destroy("show_more_options")
195 }
196 $("#more_options").slideToggle()
197 })
198 }
199 }
200 }
065c0612 » vito 2008-07-17 * Re-implemented (incomplet... 201
a2df500e » vito 2008-07-18 JavaScript renovations 202 var Manage = {
203 pages: {
204 init: function(){
205 Manage.pages.prepare_reordering()
206 },
207 parent_hash: function(){
208 var parent_hash = ""
209 $(".sort_pages li").each(function(){
210 var id = $(this).attr("id").replace(/page_list_/, "")
211 var parent = $(this).parent().parent() // this > #sort_pages > page_list_(id)
212 var parent_id = (/page_list_/.test(parent.attr("id"))) ? parent.attr("id").replace(/page_list_/, "") : 0
213 $(this).attr("parent", parent_id)
214 parent_hash += "&parent["+id+"]="+parent_id
215 })
216 return parent_hash
217 },
218 prepare_reordering: function(){
219 $(".sort_pages li").css({
220 background: "#f9f9f9",
221 padding: ".15em .5em",
222 marginBottom: ".5em",
223 border: "1px solid #ddd"
224 })
225
226 $(".sort_pages li, .page-item").css("cursor", "move")
065c0612 » vito 2008-07-17 * Re-implemented (incomplet... 227
a2df500e » vito 2008-07-18 JavaScript renovations 228 $(".sort_pages input, form#reorder_pages .buttons").remove()
229
230 $("ul.sort_pages").attr("id", "sort_pages").NestedSortable({
231 accept: "page-item",
232 opacity: 0.8,
233 nestingPxSpace: 5,
234 onStop: function(){
235 $("#content > form > ul.sort_pages").loader()
236 $.post("<?php echo $config->url; ?>/includes/ajax.php",
237 "action=organize_pages&"+ $.SortSerialize("sort_pages").hash + Manage.pages.parent_hash(),
238 function(){ $("#content > form > ul.sort_pages").loader(true) })
239 }
240 })
241 }
242 }
065c0612 » vito 2008-07-17 * Re-implemented (incomplet... 243 }
244
a2df500e » vito 2008-07-18 JavaScript renovations 245 var Extend = {
246 init: function(){
247 this.prepare_draggables()
065c0612 » vito 2008-07-17 * Re-implemented (incomplet... 248
a2df500e » vito 2008-07-18 JavaScript renovations 249 if (Route.action != "modules")
250 return
065c0612 » vito 2008-07-17 * Re-implemented (incomplet... 251
a2df500e » vito 2008-07-18 JavaScript renovations 252 this.draw_conflicts()
253 this.draw_dependencies()
254
255 $(window).resize(function(){
256 Extend.draw_conflicts()
257 Extend.draw_dependencies()
258 })
259 },
260 Drop: {
261 extension: {
262 classes: [],
263 name: null,
264 type: null
265 },
266 action: null,
267 previous: null,
268 pane: null,
269 confirmed: null
270 },
271 prepare_draggables: function(){
272 $(".enable h2, .disable h2").append(" <span class=\"sub\"><?php echo __("(drag)"); ?></span>")
273
4ee04a34 » vito 2008-07-18 Improvements to the depende... 274 $(".disable > ul > li:not(.missing_dependency), .enable > ul > li").draggable({
a2df500e » vito 2008-07-18 JavaScript renovations 275 zIndex: 100,
276 cancel: "a",
277 revert: true
278 })
279
4ee04a34 » vito 2008-07-18 Improvements to the depende... 280 $(".enable > ul, .disable > ul").droppable({
a2df500e » vito 2008-07-18 JavaScript renovations 281 accept: "ul.extend > li:not(.missing_dependency)",
282 tolerance: "pointer",
283 activeClass: "active",
284 hoverClass: "hover",
285 drop: Extend.handle_drop
286 })
287
288 $(".info_link").click(function(){
289 $(this).parent().find(".description").toggle("blind", {}, null, Extend.redraw)
290 return false
291 })
292
4ee04a34 » vito 2008-07-18 Improvements to the depende... 293 $(".enable > ul > li, .disable > ul > li:not(.missing_dependency)").css("cursor", "move")
a2df500e » vito 2008-07-18 JavaScript renovations 294 $("ul.extend li .description:not(.expanded)").css("display", "none")
295
296 Extend.equalize_lists()
297
298 if ($(".feather").size())
998c6b01 » vito 2008-07-19 url("/foo") now acts like r... 299 <?php $tip = _f("(tip: drag the tabs on the <a href=\\\"%s\\\">write</a> page to reorder them)", array(url("/admin/?action=write"))); ?>
300 $(document.createElement("small")).html("<?php echo $tip; ?>").css({
a2df500e » vito 2008-07-18 JavaScript renovations 301 position: "relative",
302 bottom: "-1em",
303 display: "block",
304 textAlign: "center"
305 }).appendTo(".tip_here")
306 },
307 handle_drop: function(ev, ui) {
308 var classes = $(this).parent().attr("class").split(" ")
309
310 Extend.Drop.pane = $(this)
311 Extend.Drop.action = classes[0]
312 Extend.Drop.previous = $(ui.draggable).parent().parent().attr("class").split(" ")[0]
313 Extend.Drop.extension.classes = $(ui.draggable).attr("class").split(" ")
314 Extend.Drop.extension.name = Extend.Drop.extension.classes[0]
315 Extend.Drop.extension.type = classes[1]
316
317 Extend.Drop.confirmed = false
318
319 if (Extend.Drop.previous == Extend.Drop.action)
320 return
321
322 $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php", {
323 action: "check_confirm",
324 check: Extend.Drop.extension.name,
325 type: Extend.Drop.extension.type
326 }, function(data){
78e15e45 » vito 2008-07-19 * gettext.rb improvements 327 if (data != "" && Extend.Drop.action == "disable")
a2df500e » vito 2008-07-18 JavaScript renovations 328 Extend.Drop.confirmed = (confirm(data)) ? 1 : 0
329
330 $.ajax({
331 type: "post",
332 dataType: "json",
333 url: "<?php echo $config->chyrp_url; ?>/includes/ajax.php",
334 data: {
335 action: Extend.Drop.action + "_" + Extend.Drop.extension.type,
336 extension: Extend.Drop.extension.name,
337 confirm: Extend.Drop.confirmed
338 },
4ee04a34 » vito 2008-07-18 Improvements to the depende... 339 beforeSend: function(){ Extend.Drop.pane.loader() },
a2df500e » vito 2008-07-18 JavaScript renovations 340 success: Extend.finish_drop
341 })
342 })
343
344 $(ui.draggable).css({ left: 0, right: 0, top: 0, bottom: 0 }).appendTo(this)
345
4ee04a34 » vito 2008-07-18 Improvements to the depende... 346 Extend.redraw()
347
a2df500e » vito 2008-07-18 JavaScript renovations 348 return true
349 },
350 finish_drop: function(json){
351 if (Extend.Drop.action == "enable") {
352 var dependees = Extend.Drop.extension.classes.find(/depended_by_(.+)/)
353 for (i = 0; i < dependees.length; i++) {
354 var dependee = dependees[i].replace("depended_by", "module")
355
356 // The module depending on this one no longer "needs" it
357 $("#"+ dependee).removeClass("needs_"+ Extend.Drop.extension.name)
358
359 // Remove from the dependee's dependency list
360 $("#"+ dependee +" .dependencies_list ."+ Extend.Drop.extension.name).hide()
361
362 if ($("#"+ dependee).attr("class").split(" ").find(/needs_(.+)/).length == 0)
363 $("#"+ dependee).find(".dependencies_message, .dependencies_list, .description").hide().end()
364 .draggable({
365 zIndex: 100,
366 cancel: "a",
367 revert: true
368 })
369 .css("cursor", "move")
370 }
4ee04a34 » vito 2008-07-18 Improvements to the depende... 371 } else {
372 $(".depends_"+ Extend.Drop.extension.name).find(".dependencies_message, .dependencies_list, .description").show()
373 $(".depends_"+ Extend.Drop.extension.name)
374 .find(".dependencies_list")
375 .append($(document.createElement("li")).html(Extend.Drop.extension.name).addClass(Extend.Drop.extension.name))
376 .end()
377 .addClass("needs_"+ Extend.Drop.extension.name)
a2df500e » vito 2008-07-18 JavaScript renovations 378 }
379
380 Extend.Drop.pane.loader(true)
381 $(json.notifications).each(function(){
382 if (this == "") return
383 alert(this.replace(/<([^>]+)>\n?/gm, ""))
384 })
4ee04a34 » vito 2008-07-18 Improvements to the depende... 385
386 Extend.redraw()
a2df500e » vito 2008-07-18 JavaScript renovations 387 },
388 equalize_lists: function(){
389 $("ul.extend").height("auto")
390 $("ul.extend").each(function(){
391 if ($(".enable ul.extend").height() > $(this).height())
392 $(this).height($(".enable ul.extend").height())
393
394 if ($(".disable ul.extend").height() > $(this).height())
395 $(this).height($(".disable ul.extend").height())
396 })
397 },
398 redraw: function(){
399 Extend.equalize_lists()
400 Extend.draw_conflicts()
401 Extend.draw_dependencies()
402 },
403 draw_conflicts: function(){
404 if (!$(".extend li.conflict").size() && !($.browser.safari || $.browser.opera || ($.browser.mozilla && $.browser.version >= 1.9)))
405 return false
406
407 $("#conflicts_canvas").remove()
408
409 $("#header, #welcome, #sub-nav, #content a.button, .extend li, #footer, h1, h2").css({
410 position: "relative",
411 zIndex: 2
412 })
413 $("#header ul li a").css({
414 position: "relative",
415 zIndex: 3
416 })
417
418 $(document.createElement("canvas")).attr("id", "conflicts_canvas").prependTo("body")
419 $("#conflicts_canvas").css({
420 position: "absolute",
421 top: 0,
422 bottom: 0,
423 zIndex: 1
424 }).attr({ width: $(document).width(), height: $(document).height() })
425
426 var canvas = document.getElementById("conflicts_canvas").getContext("2d")
427 var conflict_displayed = []
428
429 $(".extend li.conflict").each(function(){
430 var classes = $(this).attr("class").split(" ")
431 classes.shift() // Remove the module's safename class
432
433 classes.remove(["conflict",
434 "depends",
435 "missing_dependency",
436 /depended_by_(.+)/,
437 /needs_(.+)/,
438 /depends_(.+)/,
439 /ui-draggable(-dragging)?/])
440
441 for (i = 0; i < classes.length; i++) {
442 var conflict = classes[i].replace("conflict_", "module_")
443
444 if (conflict_displayed[$(this).attr("id")+" :: "+conflict])
445 continue;
446
447 canvas.strokeStyle = "#ef4646"
448 canvas.fillStyle = "#fbe3e4"
449 canvas.lineWidth = 3
450
451 var this_status = $(this).parent().parent().attr("class").split(" ")[0] + "d"
452 var conflict_status = $("#"+conflict).parent().parent().attr("class").split(" ")[0] + "d"
453
454 if (conflict_status != this_status) {
455 var line_from_x = (conflict_status == "disabled") ? $("#"+conflict).offset().left : $("#"+conflict).offset().left + $("#"+conflict).outerWidth()
456 var line_from_y = $("#"+conflict).offset().top + 12
457 var line_to_x = (conflict_status == "enabled") ? $(this).offset().left : $(this).offset().left + $(this).outerWidth()
458 var line_to_y = $(this).offset().top + 12
459
460 // Line
461 canvas.moveTo(line_from_x, line_from_y)
462 canvas.lineTo(line_to_x, line_to_y)
463 canvas.stroke()
464
465 // Beginning circle
466 canvas.beginPath()
467 if (conflict_status == "disabled")
468 canvas.arc(line_from_x, line_from_y, 5, 1.35, -1.35, false)
469 else
470 canvas.arc(line_from_x, line_from_y, 5, -1.35, 1.35, false)
471 canvas.fill()
472 canvas.stroke()
473
474 // Ending circle
475 canvas.beginPath()
476 if (conflict_status == "disabled")
477 canvas.arc(line_to_x, line_to_y, 5, -1.75, 1.75, false)
478 else
479 canvas.arc(line_to_x, line_to_y, 5, 1.75, -1.75, false)
480 canvas.fill()
481 canvas.stroke()
482 } else if (conflict_status == "disabled") {
483 var line_from_x = $("#"+conflict).offset().left
484 var line_from_y = $("#"+conflict).offset().top + 12
485 var line_to_x = $(this).offset().left
486 var line_to_y = $(this).offset().top + 12
487 var median = line_from_y + ((line_to_y - line_from_y) / 2)
488 var curve = line_from_x - 25
489
490 // Line
491 canvas.beginPath();
492 canvas.moveTo(line_from_x, line_from_y)
493 canvas.quadraticCurveTo(curve, median, line_to_x, line_to_y);
494 canvas.stroke();
495
496 // Beginning circle
497 canvas.beginPath()
b0d38b13 » vito 2008-06-12 Fixed wonky conflict lines. 498 canvas.arc(line_from_x, line_from_y, 5, 1.35, -1.35, false)
a2df500e » vito 2008-07-18 JavaScript renovations 499 canvas.fill()
500 canvas.stroke()
501
502 // Ending circle
503 canvas.beginPath()
504 canvas.arc(line_to_x, line_to_y, 5, 1.35, -1.35, false)
505 canvas.fill()
506 canvas.stroke()
507 } else if (conflict_status == "enabled") {
508 var line_from_x = $("#"+conflict).offset().left + $("#"+conflict).outerWidth()
509 var line_from_y = $("#"+conflict).offset().top + 12
510 var line_to_x = $(this).offset().left + $(this).outerWidth()
511 var line_to_y = $(this).offset().top + 12
512 var median = line_from_y + ((line_to_y - line_from_y) / 2)
513 var curve = line_from_x + 25
514
515 // Line
516 canvas.beginPath();
517 canvas.moveTo(line_from_x, line_from_y)
518 canvas.quadraticCurveTo(curve, median, line_to_x, line_to_y);
519 canvas.stroke();
520
521 // Beginning circle
522 canvas.beginPath()
523 canvas.arc(line_from_x, line_from_y, 5, -1.75, 1.75, false)
524 canvas.fill()
525 canvas.stroke()
526
527 // Ending circle
528 canvas.beginPath()
b0d38b13 » vito 2008-06-12 Fixed wonky conflict lines. 529 canvas.arc(line_to_x, line_to_y, 5, -1.75, 1.75, false)
a2df500e » vito 2008-07-18 JavaScript renovations 530 canvas.fill()
531 canvas.stroke()
532 }
533
534 conflict_displayed[conflict+" :: "+$(this).attr("id")] = true
3a2de031 » vito 2008-06-10 Implemented AJAX page reord... 535 }
a2df500e » vito 2008-07-18 JavaScript renovations 536 })
3a2de031 » vito 2008-06-10 Implemented AJAX page reord... 537
a2df500e » vito 2008-07-18 JavaScript renovations 538 return true
539 },
540 draw_dependencies: function() {
541 if (!$(".extend li.depends").size() && !($.browser.safari || $.browser.opera || ($.browser.mozilla && $.browser.version >= 1.9)))
542 return false
6b9a84a8 » vito 2008-06-10 * Changed a few .js_disable... 543
a2df500e » vito 2008-07-18 JavaScript renovations 544 $("#depends_canvas").remove()
545
546 $(document.createElement("canvas")).attr("id", "depends_canvas").prependTo("body")
547 $("#depends_canvas").css({
548 position: "absolute",
549 top: 0,
550 bottom: 0,
551 zIndex: 1
552 }).attr({ width: $(document).width(), height: $(document).height() })
553
554 var canvas = document.getElementById("depends_canvas").getContext("2d")
555 var dependency_displayed = []
556
557 $(".extend li.depends").each(function(){
558 var classes = $(this).attr("class").split(" ")
559 classes.shift() // Remove the module's safename class
560
561 classes.remove(["conflict",
562 "depends",
563 "missing_dependency",
564 /depended_by_(.+)/,
565 /needs_(.+)/,
566 /conflict_(.+)/,
567 /ui-draggable(-dragging)?/])
568
91c3c4b2 » vito 2008-07-19 Added gradients to the depe... 569 var gradients = []
570
a2df500e » vito 2008-07-18 JavaScript renovations 571 for (i = 0; i < classes.length; i++) {
572 var conflict = classes[i].replace("depends_", "module_")
573
574 if (dependency_displayed[$(this).attr("id")+" :: "+conflict])
575 continue;
576
577 canvas.fillStyle = "#e4e3fb"
578 canvas.lineWidth = 3
579
580 var this_status = $(this).parent().parent().attr("class").split(" ")[0] + "d"
581 var conflict_status = $("#"+conflict).parent().parent().attr("class").split(" ")[0] + "d"
582
583 if (conflict_status != this_status) {
584 var line_from_x = (conflict_status == "disabled") ? $("#"+conflict).offset().left : $("#"+conflict).offset().left + $("#"+conflict).outerWidth()
585 var line_from_y = $("#"+conflict).offset().top + 12
586
587 var line_to_x = (conflict_status == "enabled") ? $(this).offset().left : $(this).offset().left + $(this).outerWidth()
588 var line_to_y = $(this).offset().top + 12
91c3c4b2 » vito 2008-07-19 Added gradients to the depe... 589 var height = line_to_y - line_from_y
590 var width = line_to_x - line_from_x
591
78e15e45 » vito 2008-07-19 * gettext.rb improvements 592 if (height <= 45)
91c3c4b2 » vito 2008-07-19 Added gradients to the depe... 593 gradients[i] = canvas.createLinearGradient(line_from_x, 0, line_from_x + width, 0)
594 else
595 gradients[i] = canvas.createLinearGradient(0, line_from_y, 0, line_from_y + height)
596
597 gradients[i].addColorStop(0, '#0052cc');
598 gradients[i].addColorStop(1, '#0096ff');
599
600 canvas.strokeStyle = gradients[i]
a2df500e » vito 2008-07-18 JavaScript renovations 601
602 // Line
603 canvas.moveTo(line_from_x, line_from_y)
604 canvas.lineTo(line_to_x, line_to_y)
605 canvas.stroke()
606
607 // Beginning circle
608 canvas.beginPath()
609 if (conflict_status == "disabled")
610 canvas.arc(line_from_x, line_from_y, 5, 1.35, -1.35, false)
611 else
612 canvas.arc(line_from_x, line_from_y, 5, -1.35, 1.35, false)
613 canvas.fill()
614 canvas.stroke()
615
616 // Ending circle
617 canvas.beginPath()
618 if (conflict_status == "disabled")
619 canvas.arc(line_to_x, line_to_y, 5, -1.75, 1.75, false)
620 else
621 canvas.arc(line_to_x, line_to_y, 5, 1.75, -1.75, false)
622 canvas.fill()
623 canvas.stroke()
624 } else if (conflict_status == "disabled") {
f0905f8f » vito 2008-07-19 * Display equal-status (cur... 625 var line_from_x = $("#"+conflict).offset().left + $("#"+conflict).outerWidth()
a2df500e » vito 2008-07-18 JavaScript renovations 626 var line_from_y = $("#"+conflict).offset().top + 12
f0905f8f » vito 2008-07-19 * Display equal-status (cur... 627 var line_to_x = $(this).offset().left + $(this).outerWidth()
a2df500e » vito 2008-07-18 JavaScript renovations 628 var line_to_y = $(this).offset().top + 12
629 var median = line_from_y + ((line_to_y - line_from_y) / 2)
91c3c4b2 » vito 2008-07-19 Added gradients to the depe... 630 var height = line_to_y - line_from_y
f0905f8f » vito 2008-07-19 * Display equal-status (cur... 631 var curve = line_from_x + 25
a2df500e » vito 2008-07-18 JavaScript renovations 632
91c3c4b2 » vito 2008-07-19 Added gradients to the depe... 633 gradients[i] = canvas.createLinearGradient(0, line_from_y, 0, line_from_y + height);
634 gradients[i].addColorStop(0, '#0052cc');
635 gradients[i].addColorStop(1, '#0096ff');
636
637 canvas.strokeStyle = gradients[i]
638
a2df500e » vito 2008-07-18 JavaScript renovations 639 // Line
640 canvas.beginPath();
641 canvas.moveTo(line_from_x, line_from_y)
642 canvas.quadraticCurveTo(curve, median, line_to_x, line_to_y);
643 canvas.stroke();
644
645 // Beginning circle
646 canvas.beginPath()
f0905f8f » vito 2008-07-19 * Display equal-status (cur... 647 canvas.arc(line_from_x, line_from_y, 5, -1.75, 1.75, false)
a2df500e » vito 2008-07-18 JavaScript renovations 648 canvas.fill()
649 canvas.stroke()
650
651 // Ending circle
652 canvas.beginPath()
f0905f8f » vito 2008-07-19 * Display equal-status (cur... 653 canvas.arc(line_to_x, line_to_y, 5, -1.75, 1.75, false)
a2df500e » vito 2008-07-18 JavaScript renovations 654 canvas.fill()
655 canvas.stroke()
656 } else if (conflict_status == "enabled") {
f0905f8f » vito 2008-07-19 * Display equal-status (cur... 657 var line_from_x = $("#"+conflict).offset().left
a2df500e » vito 2008-07-18 JavaScript renovations 658 var line_from_y = $("#"+conflict).offset().top + 12
f0905f8f » vito 2008-07-19 * Display equal-status (cur... 659 var line_to_x = $(this).offset().left
a2df500e » vito 2008-07-18 JavaScript renovations 660 var line_to_y = $(this).offset().top + 12
661 var median = line_from_y + ((line_to_y - line_from_y) / 2)
91c3c4b2 » vito 2008-07-19 Added gradients to the depe... 662 var height = line_to_y - line_from_y
f0905f8f » vito 2008-07-19 * Display equal-status (cur... 663 var curve = line_from_x - 25
a2df500e » vito 2008-07-18 JavaScript renovations 664
91c3c4b2 » vito 2008-07-19 Added gradients to the depe... 665 gradients[i] = canvas.createLinearGradient(0, line_from_y, 0, line_from_y + height);
666 gradients[i].addColorStop(0, '#0052cc');
667 gradients[i].addColorStop(1, '#0096ff');
668
669 canvas.strokeStyle = gradients[i]
670
a2df500e » vito 2008-07-18 JavaScript renovations 671 // Line
672 canvas.beginPath();
673 canvas.moveTo(line_from_x, line_from_y)
674 canvas.quadraticCurveTo(curve, median, line_to_x, line_to_y);
675 canvas.stroke();
676
677 // Beginning circle
678 canvas.beginPath()
f0905f8f » vito 2008-07-19 * Display equal-status (cur... 679 canvas.arc(line_from_x, line_from_y, 5, 1.35, -1.35, false)
a2df500e » vito 2008-07-18 JavaScript renovations 680 canvas.fill()
681 canvas.stroke()
682
683 // Ending circle
684 canvas.beginPath()
f0905f8f » vito 2008-07-19 * Display equal-status (cur... 685 canvas.arc(line_to_x, line_to_y, 5, 1.35, -1.35, false)
a2df500e » vito 2008-07-18 JavaScript renovations 686 canvas.fill()
687 canvas.stroke()
688 }
689
690 dependency_displayed[conflict+" :: "+$(this).attr("id")] = true
691 }
692 })
693
694 return true
695 }
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 696 }
697
698 // "Loading..." overlay.
699 $.fn.loader = function(remove) {
700 if (remove) {
701 $(this).next().remove()
702 return this
703 }
704
705 var offset = $(this).offset()
05fcaa5c » vito 2008-05-10 * Restructuring of JS libra... 706 var loading_top = ($(this).outerHeight() / 2) - 11
707 var loading_left = ($(this).outerWidth() / 2) - 63
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 708
b19d812c » vito 2008-06-03 Renamed file_url to chyrp_url 709 $(this).after("<div class=\"load_overlay\"><img src=\"<?php echo $config->chyrp_url; ?>/includes/close.png\" style=\"display: none\" class=\"close\" /><img src=\"<?php echo $config->chyrp_url; ?>/includes/loading.gif\" style=\"display: none\" class=\"loading\" /></div>")
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 710
711 $(".load_overlay .loading").css({
712 position: "absolute",
713 top: loading_top+"px",
714 left: loading_left+"px",
715 display: "inline"
716 })
717
718 $(".load_overlay .close").css({
719 position: "absolute",
720 top: "3px",
721 right: "3px",
722 color: "#fff",
723 cursor: "pointer",
724 display: "inline"
725 }).click(function(){ $(this).parent().remove() })
726
727 $(".load_overlay").css({
728 position: "absolute",
729 top: offset.top,
730 left: offset.left,
731 zIndex: 100,
05fcaa5c » vito 2008-05-10 * Restructuring of JS libra... 732 width: $(this).outerWidth(),
733 height: $(this).outerHeight(),
b19d812c » vito 2008-06-03 Renamed file_url to chyrp_url 734 background: ($.browser.msie) ? "transparent" : "transparent url('<?php echo $config->chyrp_url; ?>/includes/trans.png')",
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 735 textAlign: "center",
b19d812c » vito 2008-06-03 Renamed file_url to chyrp_url 736 filter: ($.browser.msie) ? "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='<?php echo $config->chyrp_url; ?>/includes/trans.png');" : ""
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 737 })
738
739 return this
740 }
741
a2df500e » vito 2008-07-18 JavaScript renovations 742 // Originally from http://livepipe.net/extra/cookie
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 743 var Cookie = {
a2df500e » vito 2008-07-18 JavaScript renovations 744 set: function (name, value, days) {
745 if (days) {
746 var d = new Date();
747 d.setTime(d.getTime() + (days * 1000 * 60 * 60 * 24));
748 var expiry = "; expires=" + d.toGMTString();
749 } else
750 var expiry = "";
751
752 document.cookie = name + "=" + value + expiry + "; path=/";
753 },
754 get: function(name){
755 var nameEQ = name + "=";
756 var ca = document.cookie.split(';');
757 for (var i = 0; i < ca.length; i++) {
758 var c = ca[i];
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 759
a2df500e » vito 2008-07-18 JavaScript renovations 760 while(c.charAt(0) == " ")
761 c = c.substring(1,c.length);
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 762
a2df500e » vito 2008-07-18 JavaScript renovations 763 if(c.indexOf(nameEQ) == 0)
764 return c.substring(nameEQ.length,c.length);
765 }
766 return null;
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 767 },
a2df500e » vito 2008-07-18 JavaScript renovations 768 destroy: function(name){
769 Cookie.set(name, "", -1);
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 770 }
771 }
772
773 // Used to check if AJAX responses are errors.
774 function isError(text) {
2eb4675e » vito 2008-05-24 * Only recycle the session ... 775 return /HEY_JAVASCRIPT_THIS_IS_AN_ERROR_JUST_SO_YOU_KNOW/m.test(text);
2ee66832 » vito 2008-05-04 Reorganizing some Admin stu... 776 }
777
778 <?php $trigger->call("admin_javascript"); ?>
6b9a84a8 » vito 2008-06-10 * Changed a few .js_disable... 779 <!-- --></script>