public
Description: The ultra-lightweight ultra-flexible blogging engine with a fetish for birds and misspellings.
Homepage: http://chyrp.net/
Clone URL: git://github.com/vito/chyrp.git
Click here to lend your support to: chyrp and make a donation at www.pledgie.com !
vito (author)
Mon Oct 05 10:48:26 -0700 2009
commit  6caea733a36320fb66f3ad35eae64e967243ddc5
tree    c1d34eccbb1fd6013b19d04f0b6c94c1e6c4e72e
parent  c41fc068cbe4456f5194d5d925ad88e269646e5f
chyrp / includes / admin.js.php
100644 745 lines (630 sloc) 28.983 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
<?php
    define('JAVASCRIPT', true);
    require_once "common.php";
 
    $route = Route::current(MainController::current());
?>
<!-- --><script>
$(function(){
// Scan AJAX responses for errors.
$(document).ajaxComplete(function(event, request){
var response = request ? request.responseText : null
if (isError(response))
alert(response.replace(/(HEY_JAVASCRIPT_THIS_IS_AN_ERROR_JUST_SO_YOU_KNOW|<([^>]+)>\n?)/gm, ""))
})<?php echo "\n\n\n\n\n"; # Balance out the line numbers in this script and in the output to help debugging. ?>
 
    // Handle typing "\ct" to insert a <tab>
    $("textarea").keyup(function(event){
        if ($(this).val().match(/([^\\]|^)\\ct/gm))
            $(this).val($(this).val().replace(/([^\\]|^)\\ct/gm, " "))
    })
 
    // Automated PNG fixing.
    $.ifixpng("<?php echo $config->chyrp_url; ?>/admin/images/icons/pixel.gif")
    $("img[src$=.png]").ifixpng()
 
    // "Help" links should open in popup windows.
    $(".help").live("click", function(){
        window.open($(this).attr("href"), "help", "status=0, scrollbars=1, location=0, menubar=0, "+
                                                  "toolbar=0, resizable=1, height=450, width=400")
        return false
    })
 
    // Auto-expand input fields
    $(".expand").expand()
 
    // Checkbox toggling.
    togglers()
 
    if ($.browser.safari)
        $("code, .code").each(function(){
            $(this).css({
                fontFamily: "Monaco, monospace",
                fontSize: "9px"
            })
 
            if ($(this).parent().parent().parent().hasClass("split") && $(this).attr("type") == "text") {
                $(this).css("margin-top", "2px")
                $(this).parent().css("margin-top", "-2px")
            }
        })
 
    if (/(edit|write)_/.test(Route.action))
        Write.init()
 
    if (Route.action == "delete_group")
        $("form.confirm").submit(function(){
            if (!confirm("<?php echo __("You are a member of this group. Are you sure you want to delete it?"); ?>"))
                return false
        })
 
    if (Route.action == "manage_pages")
        Manage.pages.init()
 
    if (Route.action == "modules" || Route.action == "feathers")
        Extend.init()
 
    // Remove things that only exist for JS-disabled users.
    $(".js_disabled").remove()
    $(".js_enabled").css("display", "block")
})
 
function togglers() {
    var all_checked = true
 
    $(document.createElement("label")).attr("for", "toggle").text("<?php echo __("Toggle All"); ?>").appendTo("#toggler")
    $(document.createElement("input")).attr({
        type: "checkbox",
        name: "toggle",
        id: "toggle",
        "class": "checkbox"
    }).appendTo("#toggler, .toggler")
 
    $("#toggle").click(function(){
        $("form#new_group, form#group_edit, table").find(":checkbox").not("#toggle").each(function(){
            this.checked = document.getElementById("toggle").checked
        })
 
        $(this).parent().parent().find(":checkbox").not("#toggle").each(function(){
            this.checked = document.getElementById("toggle").checked
        })
    })
 
    // Some checkboxes are already checked when the page is loaded
    $("form#new_group, form#group_edit, table").find(":checkbox").not("#toggle").each(function(){
        if (!all_checked) return
        all_checked = this.checked
    })
 
    $(":checkbox:not(#toggle)").click(function(){
        var action_all_checked = true
 
        $("form#new_group, form#group_edit, table").find(":checkbox").not("#toggle").each(function(){
            if (!action_all_checked) return
            action_all_checked = this.checked
        })
 
        $("#toggle").parent().parent().find(":checkbox").not("#toggle").each(function(){
            if (!action_all_checked) return
            action_all_checked = this.checked
        })
 
        document.getElementById("toggle").checked = action_all_checked
    })
 
 
    if ($("#toggler").size())
        document.getElementById("toggle").checked = all_checked
 
    $("td:has(:checkbox)").click(function(e){
        $(this).find(":checkbox").each(function(){
            if (e.target != this)
                this.checked = !(this.checked)
        })
    })
}
 
var Route = {
    action: "<?php echo $_GET['action']; ?>"
}
 
var site_url = "<?php echo $config->chyrp_url; ?>"
 
var Write = {
    init: function(){
        this.bookmarklet_link()
        this.auto_expand_fields()
 
        if (!$.browser.msie)
            this.sortable_feathers()
 
        this.prepare_previewer()
        this.more_options()
        this.watch_slug()
 
        if (Route.action == "edit_group")
            this.confirm_group()
    },
    bookmarklet_link: function(){
        // Add the list item
        $(document.createElement("li")).addClass("bookmarklet right").text("Bookmarklet: ").prependTo(".write_post_nav")
 
        // Add the link
        $(document.createElement("a"))
            .text("<?php echo __("Chyrp!"); ?>")
            .addClass("no_drag")
            .attr("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=\'"+site_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=1,status=1,width=450,"+
                          "height=430\'))l.href=u;};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();void(0)")
            .appendTo(".bookmarklet")
    },
    auto_expand_fields: function(){
        $("input.text").expand()
        $("textarea").each(function(){
            $(this).css({
                minHeight: $(this).outerHeight() + 26,
                lineHeight: "15px"
            }).autogrow()
        })
    },
    sortable_feathers: function(){
        // Make the Feathers sortable
        $("#sub-nav").sortable({
            axis: "x",
            placeholder: "feathers_sort",
            opacity: 0.8,
            delay: 1,
            revert: true,
            cancel: "a.no_drag, a[href$=write_page]",
            start: function(e, ui) {
                $(ui.item).find("a").click(function(){ return false })
                $(".feathers_sort").width($(ui.item).width() - 2)
            },
            update: function(e, ui){
                $(ui.item).find("a").unbind("click")
                $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php",
                       "action=reorder_feathers&"+ $("#sub-nav").sortable("serialize"))
            }
        })
    },
    prepare_previewer: function() {
        if (!$(".preview_me").size())
            return
 
        var feather = ($("#feather").size()) ? $("#feather").val() : ""
 
        $(".preview_me").each(function(){
            var id = $(this).attr("id")
            $(document.createElement("div"))
                .css("display", "none")
                .attr("id", "preview_"+ id)
                .insertBefore("#write_form, #edit_form")
        })
 
        $(document.createElement("button"))
            .append("<?php echo __("Preview &#8594;"); ?>").attr("accesskey", "p")
            .click(function(){
                $(".preview_me").each(function(){
                    var id = $(this).attr("id")
                    $("#preview_"+ id).load("<?php echo $config->chyrp_url; ?>/includes/ajax.php", {
                        action: "preview",
                        content: $("#"+ id).val(),
                        feather: feather,
                        field: id
                    }, function(){
                        $(this).fadeIn("fast")
                    })
                })
                return false
            })
            .appendTo(".buttons")
    },
    more_options: function(){
        if ($("#more_options").size()) {
            if (Cookie.get("show_more_options") == "true")
                var more_options_text = "<?php echo __("&#171; Fewer Options"); ?>";
            else
                var more_options_text = "<?php echo __("More Options &#187;"); ?>";
 
            $(document.createElement("a")).attr({
                id: "more_options_link",
                href: "javascript:void(0)"
            }).addClass("more_options_link").append(more_options_text).insertBefore(".buttons")
            $("#more_options").clone().insertAfter("#more_options_link").removeClass("js_disabled")
 
            $("#more_options").wrap("<div></div>")
 
            if (Cookie.get("show_more_options") == null)
                $("#more_options").parent().css("display", "none")
 
            $("#more_options_link").click(function(){
                if ($("#more_options").parent().css("display") == "none") {
                    $(this).empty().append("<?php echo __("&#171; Fewer Options"); ?>")
                    Cookie.set("show_more_options", "true", 30)
                } else {
                    $(this).empty().append("<?php echo __("More Options &#187;"); ?>")
                    Cookie.destroy("show_more_options")
                }
                $("#more_options").parent().slideToggle()
            })
        }
    },
    watch_slug: function(){
        $("input#slug").keyup(function(e){
            if (/^([a-zA-Z0-9\-\._:]*)$/.test($(this).val()))
                $(this).css("background", "")
            else
                $(this).css("background", "#ffdddd")
        })
    },
    confirm_group: function(msg){
        $("form.confirm").submit(function(){
            if (!confirm("<?php echo __("You are a member of this group. Are you sure the permissions are as you want them?"); ?>"))
                return false
        })
    }
}
 
var Manage = {
    pages: {
        init: function(){
            Manage.pages.prepare_reordering()
        },
        parent_hash: function(){
            var parent_hash = ""
            $(".sort_pages li").each(function(){
                var id = $(this).attr("id").replace(/page_list_/, "")
                var parent = $(this).parent().parent() // this > #sort_pages > page_list_(id)
                var parent_id = (/page_list_/.test(parent.attr("id"))) ? parent.attr("id").replace(/page_list_/, "") : 0
                $(this).attr("parent", parent_id)
                parent_hash += "&parent["+id+"]="+parent_id
            })
            return parent_hash
        },
        prepare_reordering: function(){
            $(".sort_pages li").css({
                background: "#f9f9f9",
                padding: ".15em .5em",
                marginBottom: ".5em",
                border: "1px solid #ddd",
                cursor: "move"
            })
 
console.log("Hello?");
 
            $("ul.sort_pages").tree({
                sortOn: "li",
                dropOn: "li:not(.dragging) div",
                hoverClass: "sort_hover",
                done: function(){
                    $("#content > form > ul.sort_pages").loader()
                    $.post("<?php echo $config->url; ?>/includes/ajax.php",
                           "action=organize_pages&"+ $("ul.sort_pages").sortable("serialize") + Manage.pages.parent_hash(),
                           function(){ $("#content > form > ul.sort_pages").loader(true) })
                }
            })
        }
    }
}
 
var Extend = {
    init: function(){
        this.prepare_info()
        this.prepare_draggables()
 
        if (Route.action != "modules")
            return
 
        this.draw_conflicts()
        this.draw_dependencies()
 
        $(window).resize(function(){
            Extend.draw_conflicts()
            Extend.draw_dependencies()
        })
    },
    Drop: {
        extension: {
            classes: [],
            name: null,
            type: null
        },
        action: null,
        previous: null,
        pane: null,
        confirmed: null
    },
    prepare_info: function(){
        $(".description:not(.expanded)").wrap("<div></div>").parent().hide()
        $(".info_link").click(function(){
            $(this).parent().find(".description").parent().slideToggle("normal", Extend.redraw)
            return false
        })
    },
    prepare_draggables: function(){
        $(".enable h2, .disable h2").append(" <span class=\"sub\"><?php echo __("(drag)"); ?></span>")
 
        $(".disable > ul > li:not(.missing_dependency), .enable > ul > li").draggable({
            zIndex: 100,
            cancel: "a",
            revert: true
        })
 
        $(".enable > ul, .disable > ul").droppable({
            accept: "ul.extend > li:not(.missing_dependency)",
            tolerance: "pointer",
            activeClass: "active",
            hoverClass: "hover",
            drop: Extend.handle_drop
        })
 
        $(".enable > ul > li, .disable > ul > li:not(.missing_dependency)").css("cursor", "move")
 
        Extend.equalize_lists()
 
        if ($(".feather").size())
            <?php $tip = _f("(tip: drag the tabs on the <a href=\\\"%s\\\">write</a> page to reorder them)",
                            array(url("/admin/?action=write"))); ?>
$(document.createElement("small")).html("<?php echo $tip; ?>").css({
position: "relative",
bottom: "-1em",
display: "block",
textAlign: "center"
}).appendTo(".tip_here")
},
handle_drop: function(ev, ui) {
var classes = $(this).parent().attr("class").split(" ")
 
Extend.Drop.pane = $(this)
Extend.Drop.action = classes[0]
Extend.Drop.previous = $(ui.draggable).parent().parent().attr("class").split(" ")[0]
Extend.Drop.extension.classes = $(ui.draggable).attr("class").split(" ")
Extend.Drop.extension.name = Extend.Drop.extension.classes[0]
Extend.Drop.extension.type = classes[1]
 
Extend.Drop.confirmed = false
 
if (Extend.Drop.previous == Extend.Drop.action)
return
 
$.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php", {
action: "check_confirm",
check: Extend.Drop.extension.name,
type: Extend.Drop.extension.type
}, function(data){
if (data != "" && Extend.Drop.action == "disable")
Extend.Drop.confirmed = (confirm(data)) ? 1 : 0
 
$.ajax({
type: "post",
dataType: "json",
url: "<?php echo $config->chyrp_url; ?>/includes/ajax.php",
data: {
action: Extend.Drop.action + "_" + Extend.Drop.extension.type,
extension: Extend.Drop.extension.name,
confirm: Extend.Drop.confirmed
},
beforeSend: function(){ Extend.Drop.pane.loader() },
success: Extend.finish_drop,
error: function() {
if (Extend.Drop.action == "enable")
alert("<?php echo __("There was an error enabling the module."); ?>");
else
alert("<?php echo __("There was an error disabling the module."); ?>");
 
Extend.Drop.pane.loader(true)
 
$(ui.draggable).css({ left: 0, right: 0, top: 0, bottom: 0 }).appendTo($(".disable ul"))
 
Extend.redraw()
}
})
})
 
$(ui.draggable).css({ left: 0, right: 0, top: 0, bottom: 0 }).appendTo(this)
 
Extend.redraw()
 
return true
},
finish_drop: function(json){
if (Extend.Drop.action == "enable") {
var dependees = Extend.Drop.extension.classes.find(/depended_by_(.+)/)
for (i = 0; i < dependees.length; i++) {
var dependee = dependees[i].replace("depended_by", "module")
 
// The module depending on this one no longer "needs" it
$("#"+ dependee).removeClass("needs_"+ Extend.Drop.extension.name)
 
// Remove from the dependee's dependency list
$("#"+ dependee +" .dependencies_list ."+ Extend.Drop.extension.name).hide()
 
if ($("#"+ dependee).attr("class").split(" ").find(/needs_(.+)/).length == 0)
$("#"+ dependee).find(".description").parent().hide().end().end()
.draggable({
zIndex: 100,
cancel: "a",
revert: true
})
.css("cursor", "move")
}
} else if ($(".depends_"+ Extend.Drop.extension.name).size()) {
$(".depends_"+ Extend.Drop.extension.name).find(".description").parent().show()
$(".depends_"+ Extend.Drop.extension.name)
.find(".dependencies_list")
.append($(document.createElement("li")).text(Extend.Drop.extension.name).addClass(Extend.Drop.extension.name))
.show()
.end()
.find(".dependencies_message")
.show()
.end()
.addClass("needs_"+ Extend.Drop.extension.name)
}
 
Extend.Drop.pane.loader(true)
$(json.notifications).each(function(){
if (this == "") return
alert(this.replace(/<([^>]+)>\n?/gm, ""))
})
 
Extend.redraw()
},
equalize_lists: function(){
$("ul.extend").height("auto")
$("ul.extend").each(function(){
if ($(".enable ul.extend").height() > $(this).height())
$(this).height($(".enable ul.extend").height())
 
if ($(".disable ul.extend").height() > $(this).height())
$(this).height($(".disable ul.extend").height())
})
},
redraw: function(){
Extend.equalize_lists()
Extend.draw_conflicts()
Extend.draw_dependencies()
},
draw_conflicts: function(){
if ($.browser.msie ||
Route.action != "modules" ||
(!$(".extend li.depends").size() &&
!($.browser.safari || $.browser.opera || ($.browser.mozilla && $.browser.version >= 1.9))))
return false
 
$("#conflicts_canvas").remove()
 
$("#header, #welcome, #sub-nav, #content a.button, .extend li, #footer, h1, h2").css({
position: "relative",
zIndex: 2
})
$("#header ul li a").css({
position: "relative",
zIndex: 3
})
 
$(document.createElement("canvas")).attr("id", "conflicts_canvas").prependTo("body")
$("#conflicts_canvas").css({
position: "absolute",
top: 0,
bottom: 0,
zIndex: 1
}).attr({ width: $(document).width(), height: $(document).height() })
 
var canvas = document.getElementById("conflicts_canvas").getContext("2d")
var conflict_displayed = []
 
$(".extend li.conflict").each(function(){
var classes = $(this).attr("class").split(" ")
classes.shift() // Remove the module's safename class
 
classes.remove(["conflict",
"depends",
"missing_dependency",
/depended_by_(.+)/,
/needs_(.+)/,
/depends_(.+)/,
/ui-draggable(-dragging)?/])
 
for (i = 0; i < classes.length; i++) {
var conflict = classes[i].replace("conflict_", "module_")
 
if (conflict_displayed[$(this).attr("id")+" :: "+conflict])
continue
 
canvas.strokeStyle = "#ef4646"
canvas.fillStyle = "#fbe3e4"
canvas.lineWidth = 3
 
var this_status = $(this).parent().parent().attr("class").split(" ")[0] + "d"
var conflict_status = $("#"+conflict).parent().parent().attr("class").split(" ")[0] + "d"
 
if (conflict_status != this_status) {
var line_from_x = (conflict_status == "disabled") ?
$("#"+conflict).offset().left :
$("#"+conflict).offset().left + $("#"+conflict).outerWidth()
var line_from_y = $("#"+conflict).offset().top + 12
var line_to_x = (conflict_status == "enabled") ?
$(this).offset().left :
$(this).offset().left + $(this).outerWidth()
var line_to_y = $(this).offset().top + 12
 
// Line
canvas.moveTo(line_from_x, line_from_y)
canvas.lineTo(line_to_x, line_to_y)
canvas.stroke()
} else if (conflict_status == "disabled") {
var line_from_x = $("#"+conflict).offset().left
var line_from_y = $("#"+conflict).offset().top + 12
var line_to_x = $(this).offset().left
var line_to_y = $(this).offset().top + 12
var median = line_from_y + ((line_to_y - line_from_y) / 2)
var curve = line_from_x - 25
 
// Line
canvas.beginPath()
canvas.moveTo(line_from_x, line_from_y)
canvas.quadraticCurveTo(curve, median, line_to_x, line_to_y)
canvas.stroke()
} else if (conflict_status == "enabled") {
var line_from_x = $("#"+conflict).offset().left + $("#"+conflict).outerWidth()
var line_from_y = $("#"+conflict).offset().top + 12
var line_to_x = $(this).offset().left + $(this).outerWidth()
var line_to_y = $(this).offset().top + 12
var median = line_from_y + ((line_to_y - line_from_y) / 2)
var curve = line_from_x + 25
 
// Line
canvas.beginPath()
canvas.moveTo(line_from_x, line_from_y)
canvas.quadraticCurveTo(curve, median, line_to_x, line_to_y)
canvas.stroke()
}
 
// Beginning circle
canvas.beginPath()
canvas.arc(line_from_x, line_from_y, 5, 0, Math.PI * 2, false)
canvas.fill()
canvas.stroke()
 
// Ending circle
canvas.beginPath()
canvas.arc(line_to_x, line_to_y, 5, 0, Math.PI * 2, false)
canvas.fill()
canvas.stroke()
 
conflict_displayed[conflict+" :: "+$(this).attr("id")] = true
}
})
 
return true
},
draw_dependencies: function() {
if ($.browser.msie ||
Route.action != "modules" ||
(!$(".extend li.depends").size() &&
!($.browser.safari || $.browser.opera || ($.browser.mozilla && $.browser.version >= 1.9))))
return false
 
$("#depends_canvas").remove()
 
$("#header, #welcome, #sub-nav, #content a.button, .extend li, #footer, h1, h2").css({
position: "relative",
zIndex: 2
})
$("#header ul li a").css({
position: "relative",
zIndex: 3
})
 
$(document.createElement("canvas")).attr("id", "depends_canvas").prependTo("body")
$("#depends_canvas").css({
position: "absolute",
top: 0,
bottom: 0,
zIndex: 1
}).attr({ width: $(document).width(), height: $(document).height() })
 
var canvas = document.getElementById("depends_canvas").getContext("2d")
var dependency_displayed = []
 
$(".extend li.depends").each(function(){
var classes = $(this).attr("class").split(" ")
classes.shift() // Remove the module's safename class
 
classes.remove(["conflict",
"depends",
"missing_dependency",
/depended_by_(.+)/,
/needs_(.+)/,
/conflict_(.+)/,
/ui-draggable(-dragging)?/])
 
var gradients = []
 
for (i = 0; i < classes.length; i++) {
var depend = classes[i].replace("depends_", "module_")
 
if (dependency_displayed[$(this).attr("id")+" :: "+depend])
continue
 
canvas.fillStyle = "#e4e3fb"
canvas.lineWidth = 3
 
var this_status = $(this).parent().parent().attr("class").split(" ")[0] + "d"
var depend_status = $("#"+depend).parent().parent().attr("class").split(" ")[0] + "d"
 
if (depend_status != this_status) {
var line_from_x = (depend_status == "disabled") ? $("#"+depend).offset().left : $("#"+depend).offset().left + $("#"+depend).outerWidth()
var line_from_y = $("#"+depend).offset().top + 12
 
var line_to_x = (depend_status == "enabled") ? $(this).offset().left : $(this).offset().left + $(this).outerWidth()
var line_to_y = $(this).offset().top + 12
var height = line_to_y - line_from_y
var width = line_to_x - line_from_x
 
if (height <= 45)
gradients[i] = canvas.createLinearGradient(line_from_x, 0, line_from_x + width, 0)
else
gradients[i] = canvas.createLinearGradient(0, line_from_y, 0, line_from_y + height)
 
gradients[i].addColorStop(0, '#0052cc')
gradients[i].addColorStop(1, '#0096ff')
 
canvas.strokeStyle = gradients[i]
 
// Line
canvas.moveTo(line_from_x, line_from_y)
canvas.lineTo(line_to_x, line_to_y)
canvas.stroke()
} else if (depend_status == "disabled") {
var line_from_x = $("#"+depend).offset().left + $("#"+depend).outerWidth()
var line_from_y = $("#"+depend).offset().top + 12
var line_to_x = $(this).offset().left + $(this).outerWidth()
var line_to_y = $(this).offset().top + 12
var median = line_from_y + ((line_to_y - line_from_y) / 2)
var height = line_to_y - line_from_y
var curve = line_from_x + 25
 
gradients[i] = canvas.createLinearGradient(0, line_from_y, 0, line_from_y + height)
gradients[i].addColorStop(0, '#0052cc')
gradients[i].addColorStop(1, '#0096ff')
 
canvas.strokeStyle = gradients[i]
 
// Line
canvas.beginPath()
canvas.moveTo(line_from_x, line_from_y)
canvas.quadraticCurveTo(curve, median, line_to_x, line_to_y)
canvas.stroke()
} else if (depend_status == "enabled") {
var line_from_x = $("#"+depend).offset().left
var line_from_y = $("#"+depend).offset().top + 12
var line_to_x = $(this).offset().left
var line_to_y = $(this).offset().top + 12
var median = line_from_y + ((line_to_y - line_from_y) / 2)
var height = line_to_y - line_from_y
var curve = line_from_x - 25
 
gradients[i] = canvas.createLinearGradient(0, line_from_y, 0, line_from_y + height)
gradients[i].addColorStop(0, '#0052cc')
gradients[i].addColorStop(1, '#0096ff')
 
canvas.strokeStyle = gradients[i]
 
// Line
canvas.beginPath()
canvas.moveTo(line_from_x, line_from_y)
canvas.quadraticCurveTo(curve, median, line_to_x, line_to_y)
canvas.stroke()
}
 
// Beginning circle
canvas.beginPath()
canvas.arc(line_from_x, line_from_y, 5, 0, Math.PI * 2, false)
canvas.fill()
canvas.stroke()
 
// Ending circle
canvas.beginPath()
canvas.arc(line_to_x, line_to_y, 5, 0, Math.PI * 2, false)
canvas.fill()
canvas.stroke()
 
dependency_displayed[depend+" :: "+$(this).attr("id")] = true
}
})
 
return true
}
}
 
<?php $trigger->call("admin_javascript"); ?>
<!-- --></script>