share.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. function shareArticle(id) {
  2. try {
  3. if (dijit.byId("shareArticleDlg"))
  4. dijit.byId("shareArticleDlg").destroyRecursive();
  5. var query = "backend.php?op=pluginhandler&plugin=share&method=shareArticle&param=" + param_escape(id);
  6. dialog = new dijit.Dialog({
  7. id: "shareArticleDlg",
  8. title: __("Share article by URL"),
  9. style: "width: 600px",
  10. newurl: function() {
  11. var ok = confirm(__("Generate new share URL for this article?"));
  12. if (ok) {
  13. notify_progress("Trying to change URL...", true);
  14. var query = "op=pluginhandler&plugin=share&method=newkey&id=" + param_escape(id);
  15. new Ajax.Request("backend.php", {
  16. parameters: query,
  17. onComplete: function(transport) {
  18. var reply = JSON.parse(transport.responseText);
  19. var new_link = reply.link;
  20. var e = $('gen_article_url');
  21. if (new_link) {
  22. e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
  23. "&key=" + new_link);
  24. e.href = e.href.replace(/\&key=.*$/,
  25. "&key=" + new_link);
  26. new Effect.Highlight(e);
  27. var img = $("SHARE-IMG-" + id);
  28. if (img) img.src = img.src.replace("notshared.png", "share.png");
  29. notify('');
  30. } else {
  31. notify_error("Could not change URL.");
  32. }
  33. } });
  34. }
  35. },
  36. unshare: function() {
  37. var ok = confirm(__("Remove sharing for this article?"));
  38. if (ok) {
  39. notify_progress("Trying to unshare...", true);
  40. var query = "op=pluginhandler&plugin=share&method=unshare&id=" + param_escape(id);
  41. new Ajax.Request("backend.php", {
  42. parameters: query,
  43. onComplete: function(transport) {
  44. notify("Article unshared.");
  45. var img = $("SHARE-IMG-" + id);
  46. if (img) img.src = img.src.replace("share.png", "notshared.png");
  47. dialog.hide();
  48. } });
  49. }
  50. },
  51. href: query});
  52. dialog.show();
  53. var img = $("SHARE-IMG-" + id);
  54. if (img) img.src = img.src.replace("notshared.png", "share.png");
  55. } catch (e) {
  56. exception_error("shareArticle", e);
  57. }
  58. }