PageRenderTime 65ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/admin.js.php

http://github.com/vito/chyrp
PHP | 742 lines | 606 code | 113 blank | 23 comment | 91 complexity | af76514b78c233d20f55a25a13ab2a8d MD5 | raw file
  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/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() + 26,
  136. lineHeight: "15px"
  137. }).autogrow()
  138. })
  139. },
  140. sortable_feathers: function(){
  141. // Make the Feathers sortable
  142. $("#sub-nav").sortable({
  143. axis: "x",
  144. placeholder: "feathers_sort",
  145. opacity: 0.8,
  146. delay: 1,
  147. revert: true,
  148. cancel: "a.no_drag, a[href$=write_page]",
  149. start: function(e, ui) {
  150. $(ui.item).find("a").click(function(){ return false })
  151. $(".feathers_sort").width($(ui.item).width() - 2)
  152. },
  153. update: function(e, ui){
  154. $(ui.item).find("a").unbind("click")
  155. $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php",
  156. "action=reorder_feathers&"+ $("#sub-nav").sortable("serialize"))
  157. }
  158. })
  159. },
  160. prepare_previewer: function() {
  161. if (!$(".preview_me").size())
  162. return
  163. var feather = ($("#feather").size()) ? $("#feather").val() : ""
  164. $(".preview_me").each(function(){
  165. var id = $(this).attr("id")
  166. $(document.createElement("div"))
  167. .css("display", "none")
  168. .attr("id", "preview_"+ id)
  169. .insertBefore("#write_form, #edit_form")
  170. })
  171. $(document.createElement("button"))
  172. .append("<?php echo __("Preview &rarr;"); ?>").attr("accesskey", "p")
  173. .click(function(){
  174. $(".preview_me").each(function(){
  175. var id = $(this).attr("id")
  176. $("#preview_"+ id).load("<?php echo $config->chyrp_url; ?>/includes/ajax.php", {
  177. action: "preview",
  178. content: $("#"+ id).val(),
  179. feather: feather,
  180. field: id
  181. }, function(){
  182. $(this).fadeIn("fast")
  183. })
  184. })
  185. return false
  186. })
  187. .appendTo(".buttons")
  188. },
  189. more_options: function(){
  190. if ($("#more_options").size()) {
  191. if (Cookie.get("show_more_options") == "true")
  192. var more_options_text = "<?php echo __("&uarr; Fewer Options"); ?>";
  193. else
  194. var more_options_text = "<?php echo __("More Options &darr;"); ?>";
  195. $(document.createElement("a")).attr({
  196. id: "more_options_link",
  197. href: "javascript:void(0)"
  198. }).addClass("more_options_link").append(more_options_text).insertBefore(".buttons")
  199. $("#more_options").clone().insertAfter("#more_options_link").removeClass("js_disabled")
  200. $("#more_options").wrap("<div></div>")
  201. if (Cookie.get("show_more_options") == null)
  202. $("#more_options").parent().css("display", "none")
  203. $("#more_options_link").click(function(){
  204. if ($("#more_options").parent().css("display") == "none") {
  205. $(this).empty().append("<?php echo __("&uarr; Fewer Options"); ?>")
  206. Cookie.set("show_more_options", "true", 30)
  207. } else {
  208. $(this).empty().append("<?php echo __("More Options &darr;"); ?>")
  209. Cookie.destroy("show_more_options")
  210. }
  211. $("#more_options").parent().slideToggle()
  212. })
  213. }
  214. },
  215. watch_slug: function(){
  216. $("input#slug").keyup(function(e){
  217. if (/^([a-zA-Z0-9\-\._:]*)$/.test($(this).val()))
  218. $(this).css("background", "")
  219. else
  220. $(this).css("background", "#ffdddd")
  221. })
  222. },
  223. confirm_group: function(msg){
  224. $("form.confirm").submit(function(){
  225. if (!confirm("<?php echo __("You are a member of this group. Are you sure the permissions are as you want them?"); ?>"))
  226. return false
  227. })
  228. }
  229. }
  230. var Manage = {
  231. pages: {
  232. init: function(){
  233. Manage.pages.prepare_reordering()
  234. },
  235. parent_hash: function(){
  236. var parent_hash = ""
  237. $(".sort_pages li").each(function(){
  238. var id = $(this).attr("id").replace(/page_list_/, "")
  239. var parent = $(this).parent().parent() // this > #sort_pages > page_list_(id)
  240. var parent_id = (/page_list_/.test(parent.attr("id"))) ? parent.attr("id").replace(/page_list_/, "") : 0
  241. $(this).attr("parent", parent_id)
  242. parent_hash += "&parent["+id+"]="+parent_id
  243. })
  244. return parent_hash
  245. },
  246. prepare_reordering: function(){
  247. $(".sort_pages li div").css({
  248. background: "#f9f9f9",
  249. padding: ".15em .5em",
  250. marginBottom: ".5em",
  251. border: "1px solid #ddd",
  252. cursor: "move"
  253. })
  254. $("ul.sort_pages").tree({
  255. sortOn: "li",
  256. dropOn: "li:not(.dragging) div",
  257. hoverClass: "sort-hover",
  258. done: function(){
  259. $("#content > form > ul.sort_pages").loader()
  260. $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php",
  261. "action=organize_pages&"+ $("ul.sort_pages").sortable("serialize") + Manage.pages.parent_hash(),
  262. function(){ $("#content > form > ul.sort_pages").loader(true) })
  263. }
  264. })
  265. }
  266. }
  267. }
  268. var Extend = {
  269. init: function(){
  270. this.prepare_info()
  271. this.prepare_draggables()
  272. if (Route.action != "modules")
  273. return
  274. this.draw_conflicts()
  275. this.draw_dependencies()
  276. $(window).resize(function(){
  277. Extend.draw_conflicts()
  278. Extend.draw_dependencies()
  279. })
  280. },
  281. Drop: {
  282. extension: {
  283. classes: [],
  284. name: null,
  285. type: null
  286. },
  287. action: null,
  288. previous: null,
  289. pane: null,
  290. confirmed: null
  291. },
  292. prepare_info: function(){
  293. $(".description:not(.expanded)").wrap("<div></div>").parent().hide()
  294. $(".info_link").click(function(){
  295. $(this).parent().find(".description").parent().slideToggle("normal", Extend.redraw)
  296. return false
  297. })
  298. },
  299. prepare_draggables: function(){
  300. $(".enable h2, .disable h2").append(" <span class=\"sub\"><?php echo __("(drag)"); ?></span>")
  301. $(".disable > ul > li:not(.missing_dependency), .enable > ul > li").draggable({
  302. zIndex: 100,
  303. cancel: "a",
  304. revert: true
  305. })
  306. $(".enable > ul, .disable > ul").droppable({
  307. accept: "ul.extend > li:not(.missing_dependency)",
  308. tolerance: "pointer",
  309. activeClass: "active",
  310. hoverClass: "hover",
  311. drop: Extend.handle_drop
  312. })
  313. $(".enable > ul > li, .disable > ul > li:not(.missing_dependency)").css("cursor", "move")
  314. Extend.equalize_lists()
  315. if ($(".feather").size())
  316. <?php $tip = _f("(tip: drag the tabs on the <a href=\\\"%s\\\">write</a> page to reorder them)",
  317. array(url("/admin/?action=write"))); ?>
  318. $(document.createElement("small")).html("<?php echo $tip; ?>").css({
  319. position: "relative",
  320. bottom: "-1em",
  321. display: "block",
  322. textAlign: "center"
  323. }).appendTo(".tip_here")
  324. },
  325. handle_drop: function(ev, ui) {
  326. var classes = $(this).parent().attr("class").split(" ")
  327. Extend.Drop.pane = $(this)
  328. Extend.Drop.action = classes[0]
  329. Extend.Drop.previous = $(ui.draggable).parent().parent().attr("class").split(" ")[0]
  330. Extend.Drop.extension.classes = $(ui.draggable).attr("class").split(" ")
  331. Extend.Drop.extension.name = Extend.Drop.extension.classes[0]
  332. Extend.Drop.extension.type = classes[1]
  333. Extend.Drop.confirmed = false
  334. if (Extend.Drop.previous == Extend.Drop.action)
  335. return
  336. $.post("<?php echo $config->chyrp_url; ?>/includes/ajax.php", {
  337. action: "check_confirm",
  338. check: Extend.Drop.extension.name,
  339. type: Extend.Drop.extension.type
  340. }, function(data){
  341. if (data != "" && Extend.Drop.action == "disable")
  342. Extend.Drop.confirmed = (confirm(data)) ? 1 : 0
  343. $.ajax({
  344. type: "post",
  345. dataType: "json",
  346. url: "<?php echo $config->chyrp_url; ?>/includes/ajax.php",
  347. data: {
  348. action: Extend.Drop.action + "_" + Extend.Drop.extension.type,
  349. extension: Extend.Drop.extension.name,
  350. confirm: Extend.Drop.confirmed
  351. },
  352. beforeSend: function(){ Extend.Drop.pane.loader() },
  353. success: Extend.finish_drop,
  354. error: function() {
  355. if (Extend.Drop.action == "enable")
  356. alert("<?php echo __("There was an error enabling the extension."); ?>");
  357. else
  358. alert("<?php echo __("There was an error disabling the extension."); ?>");
  359. Extend.Drop.pane.loader(true)
  360. $(ui.draggable).css({ left: 0, right: 0, top: 0, bottom: 0 }).appendTo($(".disable ul"))
  361. Extend.redraw()
  362. }
  363. })
  364. })
  365. $(ui.draggable).css({ left: 0, right: 0, top: 0, bottom: 0 }).appendTo(this)
  366. Extend.redraw()
  367. return true
  368. },
  369. finish_drop: function(json){
  370. if (Extend.Drop.action == "enable") {
  371. var dependees = Extend.Drop.extension.classes.find(/depended_by_(.+)/)
  372. for (i = 0; i < dependees.length; i++) {
  373. var dependee = dependees[i].replace("depended_by", "module")
  374. // The module depending on this one no longer "needs" it
  375. $("#"+ dependee).removeClass("needs_"+ Extend.Drop.extension.name)
  376. // Remove from the dependee's dependency list
  377. $("#"+ dependee +" .dependencies_list ."+ Extend.Drop.extension.name).hide()
  378. if ($("#"+ dependee).attr("class").split(" ").find(/needs_(.+)/).length == 0)
  379. $("#"+ dependee).find(".description").parent().hide().end().end()
  380. .draggable({
  381. zIndex: 100,
  382. cancel: "a",
  383. revert: true
  384. })
  385. .css("cursor", "move")
  386. }
  387. } else if ($(".depends_"+ Extend.Drop.extension.name).size()) {
  388. $(".depends_"+ Extend.Drop.extension.name).find(".description").parent().show()
  389. $(".depends_"+ Extend.Drop.extension.name)
  390. .find(".dependencies_list")
  391. .append($(document.createElement("li")).text(Extend.Drop.extension.name).addClass(Extend.Drop.extension.name))
  392. .show()
  393. .end()
  394. .find(".dependencies_message")
  395. .show()
  396. .end()
  397. .addClass("needs_"+ Extend.Drop.extension.name)
  398. }
  399. Extend.Drop.pane.loader(true)
  400. $(json.notifications).each(function(){
  401. if (this == "") return
  402. alert(this.replace(/<([^>]+)>\n?/gm, ""))
  403. })
  404. Extend.redraw()
  405. },
  406. equalize_lists: function(){
  407. $("ul.extend").height("auto")
  408. $("ul.extend").each(function(){
  409. if ($(".enable ul.extend").height() > $(this).height())
  410. $(this).height($(".enable ul.extend").height())
  411. if ($(".disable ul.extend").height() > $(this).height())
  412. $(this).height($(".disable ul.extend").height())
  413. })
  414. },
  415. redraw: function(){
  416. Extend.equalize_lists()
  417. Extend.draw_conflicts()
  418. Extend.draw_dependencies()
  419. },
  420. draw_conflicts: function(){
  421. if ($.browser.msie ||
  422. Route.action != "modules" ||
  423. (!$(".extend li.depends").size() &&
  424. !($.browser.safari || $.browser.opera || ($.browser.mozilla && $.browser.version >= 1.9))))
  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 ($.browser.msie ||
  518. Route.action != "modules" ||
  519. (!$(".extend li.depends").size() &&
  520. !($.browser.safari || $.browser.opera || ($.browser.mozilla && $.browser.version >= 1.9))))
  521. return false
  522. $("#depends_canvas").remove()
  523. $("#header, #welcome, #sub-nav, #content a.button, .extend li, #footer, h1, h2").css({
  524. position: "relative",
  525. zIndex: 2
  526. })
  527. $("#header ul li a").css({
  528. position: "relative",
  529. zIndex: 3
  530. })
  531. $(document.createElement("canvas")).attr("id", "depends_canvas").prependTo("body")
  532. $("#depends_canvas").css({
  533. position: "absolute",
  534. top: 0,
  535. bottom: 0,
  536. zIndex: 1
  537. }).attr({ width: $(document).width(), height: $(document).height() })
  538. var canvas = document.getElementById("depends_canvas").getContext("2d")
  539. var dependency_displayed = []
  540. $(".extend li.depends").each(function(){
  541. var classes = $(this).attr("class").split(" ")
  542. classes.shift() // Remove the module's safename class
  543. classes.remove(["conflict",
  544. "depends",
  545. "missing_dependency",
  546. /depended_by_(.+)/,
  547. /needs_(.+)/,
  548. /conflict_(.+)/,
  549. /ui-draggable(-dragging)?/])
  550. var gradients = []
  551. for (i = 0; i < classes.length; i++) {
  552. var depend = classes[i].replace("depends_", "module_")
  553. if (dependency_displayed[$(this).attr("id")+" :: "+depend])
  554. continue
  555. canvas.fillStyle = "#e4e3fb"
  556. canvas.lineWidth = 3
  557. var this_status = $(this).parent().parent().attr("class").split(" ")[0] + "d"
  558. var depend_status = $("#"+depend).parent().parent().attr("class").split(" ")[0] + "d"
  559. if (depend_status != this_status) {
  560. var line_from_x = (depend_status == "disabled") ? $("#"+depend).offset().left : $("#"+depend).offset().left + $("#"+depend).outerWidth()
  561. var line_from_y = $("#"+depend).offset().top + 12
  562. var line_to_x = (depend_status == "enabled") ? $(this).offset().left : $(this).offset().left + $(this).outerWidth()
  563. var line_to_y = $(this).offset().top + 12
  564. var height = line_to_y - line_from_y
  565. var width = line_to_x - line_from_x
  566. if (height <= 45)
  567. gradients[i] = canvas.createLinearGradient(line_from_x, 0, line_from_x + width, 0)
  568. else
  569. gradients[i] = canvas.createLinearGradient(0, line_from_y, 0, line_from_y + height)
  570. gradients[i].addColorStop(0, '#0052cc')
  571. gradients[i].addColorStop(1, '#0096ff')
  572. canvas.strokeStyle = gradients[i]
  573. // Line
  574. canvas.moveTo(line_from_x, line_from_y)
  575. canvas.lineTo(line_to_x, line_to_y)
  576. canvas.stroke()
  577. } else if (depend_status == "disabled") {
  578. var line_from_x = $("#"+depend).offset().left + $("#"+depend).outerWidth()
  579. var line_from_y = $("#"+depend).offset().top + 12
  580. var line_to_x = $(this).offset().left + $(this).outerWidth()
  581. var line_to_y = $(this).offset().top + 12
  582. var median = line_from_y + ((line_to_y - line_from_y) / 2)
  583. var height = line_to_y - line_from_y
  584. var curve = line_from_x + 25
  585. gradients[i] = canvas.createLinearGradient(0, line_from_y, 0, line_from_y + height)
  586. gradients[i].addColorStop(0, '#0052cc')
  587. gradients[i].addColorStop(1, '#0096ff')
  588. canvas.strokeStyle = gradients[i]
  589. // Line
  590. canvas.beginPath()
  591. canvas.moveTo(line_from_x, line_from_y)
  592. canvas.quadraticCurveTo(curve, median, line_to_x, line_to_y)
  593. canvas.stroke()
  594. } else if (depend_status == "enabled") {
  595. var line_from_x = $("#"+depend).offset().left
  596. var line_from_y = $("#"+depend).offset().top + 12
  597. var line_to_x = $(this).offset().left
  598. var line_to_y = $(this).offset().top + 12
  599. var median = line_from_y + ((line_to_y - line_from_y) / 2)
  600. var height = line_to_y - line_from_y
  601. var curve = line_from_x - 25
  602. gradients[i] = canvas.createLinearGradient(0, line_from_y, 0, line_from_y + height)
  603. gradients[i].addColorStop(0, '#0052cc')
  604. gradients[i].addColorStop(1, '#0096ff')
  605. canvas.strokeStyle = gradients[i]
  606. // Line
  607. canvas.beginPath()
  608. canvas.moveTo(line_from_x, line_from_y)
  609. canvas.quadraticCurveTo(curve, median, line_to_x, line_to_y)
  610. canvas.stroke()
  611. }
  612. // Beginning circle
  613. canvas.beginPath()
  614. canvas.arc(line_from_x, line_from_y, 5, 0, Math.PI * 2, false)
  615. canvas.fill()
  616. canvas.stroke()
  617. // Ending circle
  618. canvas.beginPath()
  619. canvas.arc(line_to_x, line_to_y, 5, 0, Math.PI * 2, false)
  620. canvas.fill()
  621. canvas.stroke()
  622. dependency_displayed[depend+" :: "+$(this).attr("id")] = true
  623. }
  624. })
  625. return true
  626. }
  627. }
  628. <?php $trigger->call("admin_javascript"); ?>
  629. <!-- --></script>