KXStudio Website https://kx.studio/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

admin.js.php 28KB

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