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