From 27e64f1dc6cc43b40592337eed360bdf7e3d7a59 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 27 Nov 2008 06:14:32 +0000 Subject: Move javascript from default theme to appropriate modules --- modules/comment/helpers/comment_block.php | 5 ++++ modules/comment/js/comment.js | 19 ++++++++++++++++ modules/user/helpers/user_block.php | 5 +++- modules/user/js/user.js | 38 +++++++++++++++++++++++++++++++ themes/default/js/comment.js | 19 ---------------- themes/default/js/user.js | 38 ------------------------------- themes/default/views/page.html.php | 2 -- 7 files changed, 66 insertions(+), 60 deletions(-) create mode 100644 modules/comment/js/comment.js create mode 100644 modules/user/js/user.js delete mode 100644 themes/default/js/comment.js delete mode 100644 themes/default/js/user.js diff --git a/modules/comment/helpers/comment_block.php b/modules/comment/helpers/comment_block.php index 58a1a416..ee05a383 100644 --- a/modules/comment/helpers/comment_block.php +++ b/modules/comment/helpers/comment_block.php @@ -19,6 +19,11 @@ */ class comment_block_Core { + public static function head($theme) { + $url = url::file("modules/comment/js/comment.js"); + return "\n"; + } + public static function photo_bottom($theme) { return comment::block($theme, true); } diff --git a/modules/comment/js/comment.js b/modules/comment/js/comment.js new file mode 100644 index 00000000..259b4826 --- /dev/null +++ b/modules/comment/js/comment.js @@ -0,0 +1,19 @@ +$("document").ready(function() { + ajaxify_comment_form(); +}); + +function ajaxify_comment_form() { + $("#gComments form").ajaxForm({ + complete: function(xhr, statusText) { + $("#gComments form").replaceWith(xhr.responseText); + if (xhr.status == 201) { + $.get(xhr.getResponseHeader("Location"), function(data, textStatus) { + $("#gComments .gBlockContent ul:first").append("
  • "+data+"
  • "); + $("#gComments .gBlockContent ul:first li:last").hide().slideDown(); + }); + $("#gComments form").clearForm(); + } + ajaxify_comment_form(); + } + }); +} diff --git a/modules/user/helpers/user_block.php b/modules/user/helpers/user_block.php index 225ff82e..5146cc9f 100644 --- a/modules/user/helpers/user_block.php +++ b/modules/user/helpers/user_block.php @@ -19,9 +19,12 @@ */ class user_block_Core { public static function head($theme) { + $url = url::file("modules/user/js/user.js"); + $script[] = ""; $user = Session::instance()->get('user', null); $url = url::file("lib/jquery.jeditable.js"); - return empty($user) ? "" : ""; + $script[] = empty($user) ? "" : ""; + return implode("\n", $script); } public static function header_top($theme) { diff --git a/modules/user/js/user.js b/modules/user/js/user.js new file mode 100644 index 00000000..8ee543bf --- /dev/null +++ b/modules/user/js/user.js @@ -0,0 +1,38 @@ +/** + * @todo preventDefault() not working in IE 6 and 7 + * @todo Close link should be reusable + */ + +$("document").ready(function() { + $("#gLoginLink").click(function(event){ + event.preventDefault(); + var url = $("#gLoginLink a").attr("href"); + $.get(url, function(data) { + $('#gLoginLink').hide(); + $("#gLoginMenu").append('
  • X
  • '); + $("#gLoginMenu li:last").addClass("gClose").show(); + $("#gLoginMenu .gClose a").click(function(){ + $("#gLoginForm").remove(); + $("#gLoginMenu .gClose").remove(); + $("#gLoginLink").show(); + $("input#gUsername").val(""); + $("input#gPassword").val(""); + }); + $("#gLoginFormContainer").html(data).hide().fadeIn(); + ajaxify_login_form(); + }); + }); +}); + +function ajaxify_login_form() { + $("form#gLoginForm").ajaxForm({ + target: "#gLoginFormContainer", + success: function(responseText, statusText) { + if (!responseText) { + window.location.reload(); + } else { + ajaxify_login_form(); + } + } + }); +} diff --git a/themes/default/js/comment.js b/themes/default/js/comment.js deleted file mode 100644 index 259b4826..00000000 --- a/themes/default/js/comment.js +++ /dev/null @@ -1,19 +0,0 @@ -$("document").ready(function() { - ajaxify_comment_form(); -}); - -function ajaxify_comment_form() { - $("#gComments form").ajaxForm({ - complete: function(xhr, statusText) { - $("#gComments form").replaceWith(xhr.responseText); - if (xhr.status == 201) { - $.get(xhr.getResponseHeader("Location"), function(data, textStatus) { - $("#gComments .gBlockContent ul:first").append("
  • "+data+"
  • "); - $("#gComments .gBlockContent ul:first li:last").hide().slideDown(); - }); - $("#gComments form").clearForm(); - } - ajaxify_comment_form(); - } - }); -} diff --git a/themes/default/js/user.js b/themes/default/js/user.js deleted file mode 100644 index 8ee543bf..00000000 --- a/themes/default/js/user.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * @todo preventDefault() not working in IE 6 and 7 - * @todo Close link should be reusable - */ - -$("document").ready(function() { - $("#gLoginLink").click(function(event){ - event.preventDefault(); - var url = $("#gLoginLink a").attr("href"); - $.get(url, function(data) { - $('#gLoginLink').hide(); - $("#gLoginMenu").append('
  • X
  • '); - $("#gLoginMenu li:last").addClass("gClose").show(); - $("#gLoginMenu .gClose a").click(function(){ - $("#gLoginForm").remove(); - $("#gLoginMenu .gClose").remove(); - $("#gLoginLink").show(); - $("input#gUsername").val(""); - $("input#gPassword").val(""); - }); - $("#gLoginFormContainer").html(data).hide().fadeIn(); - ajaxify_login_form(); - }); - }); -}); - -function ajaxify_login_form() { - $("form#gLoginForm").ajaxForm({ - target: "#gLoginFormContainer", - success: function(responseText, statusText) { - if (!responseText) { - window.location.reload(); - } else { - ajaxify_login_form(); - } - } - }); -} diff --git a/themes/default/views/page.html.php b/themes/default/views/page.html.php index 702595a6..e3da147c 100644 --- a/themes/default/views/page.html.php +++ b/themes/default/views/page.html.php @@ -17,8 +17,6 @@ media="screen,print,projection" /> - - " media="screen,print,projection" /> -- cgit v1.2.3