Browse files

cleaning up javascript

  • Loading branch information...
1 parent 7aaa99a commit ca8d091026fd5c7f63c828322e8c2f4cbe9cb5c6 @ryanb committed Sep 5, 2009
Showing with 45 additions and 80 deletions.
  1. +0 −43 public/javascripts/edit_stamp.js
  2. +45 −37 public/javascripts/stamp.js
View
43 public/javascripts/edit_stamp.js
@@ -12,14 +12,6 @@ jQuery.fn.change_color = function(color) {
return this;
};
-jQuery.fn.submit_with_ajax = function() {
- this.submit(function() {
- $.post(this.action, $(this).serialize(), null, "script");
- return false;
- })
- return this;
-};
-
$(function() {
$("#colors input").click(function() {
$("#stamp_images img").change_color(this.value);
@@ -30,39 +22,4 @@ $(function() {
}
return false;
});
- // $("#new_stamp_image_link").click(function() {
- // $.getScript(this.href);
- // return false;
- // });
});
-
-function modal_dialog(content) {
- var overlay = $("<div id='modal_overlay'></div>");
- var window = $("<div id='modal_window'></div>");
- $("body").append(overlay.click(function() {
- modal_hide();
- })).append(window);
- overlay.css("opacity", 0.8);
- overlay.fadeIn(150);
- window.css({
- "margin-left": -300,
- "margin-top": -200
- }).html(content).fadeIn(150);
- $("#modal_window form").submit_with_ajax();
- $(document).keydown(handle_escape);
-}
-
-function modal_hide() {
- $(document).unbind("keydown", handle_escape)
- var remove = function() {
- $(this).remove();
- }
- $("#modal_window").fadeOut(remove);
- $("#modal_overlay").fadeOut(remove);
-}
-
-function handle_escape(e) {
- if (e.keyCode == 27) {
- modal_hide();
- }
-}
View
82 public/javascripts/stamp.js
@@ -16,6 +16,50 @@ function next_instructions() {
$("#instructions").attr("src", "/images/instructions/instruction" + instruction_level + ".gif");
}
+function pick_up_stamp(click_event) {
+ if (instruction_level == 1) {
+ next_instructions();
+ }
+ $("#stamper a img").change_image("ink.png");
+ $("#stamp_cursor").change_image("holding.png").show().css({
+ left: (click_event.pageX - 40) + 'px',
+ top: (click_event.pageY - 45) + 'px'
+ }).click(function(event) {
+ stamp_down(event);
+ });
+ $("body").mousemove(function(event) {
+ $("#stamp_cursor").css({
+ left: (event.pageX - 40) + 'px',
+ top: (event.pageY - 45) + 'px'
+ });
+ });
+}
+
+function stamp_down(event) {
+ $("body").unbind("mousemove");
+ $("#stamp_cursor").unbind("click").hide();
+ if (!document.elementFromPoint) {
+ alert("Please upgrade your browser to use this feature.");
+ }
+ if (navigator.userAgent.indexOf("Firefox") != -1) {
+ var element = document.elementFromPoint(event.pageX - window.pageXOffset, event.pageY - window.pageYOffset);
+ } else {
+ var element = document.elementFromPoint(event.pageX, event.pageY);
+ }
+ if (element.id.search(/day_/) != -1 && $(element).children("a.mark_link").length > 0 && $(element).children("img").length == 0) {
+ if (instruction_level == 2) {
+ next_instructions();
+ }
+ $("#stamp_cursor").change_image("stamping.png").show();
+ var p = $(element).position();
+ var x = (event.pageX - p.left);
+ var y = (event.pageY - p.top);
+ $.post($(element).children("a.mark_link").attr("href"), { x: x, y: y }, null, "script");
+ } else {
+ $("#stamper a img").change_image("ready.png");
+ }
+}
+
$(function() {
$("#owner #calendar td").live("click", function(event) {
if ($(this).children("a.mark_link").length > 0) {
@@ -43,43 +87,7 @@ $(function() {
});
$("#owner #stamper a").click(function(click_event) {
- if (instruction_level == 1) {
- next_instructions();
- }
- $("#stamper a img").change_image("ink.png");
- $("#stamp_cursor").change_image("holding.png").show().css({
- left: (click_event.pageX - 40) + 'px',
- top: (click_event.pageY - 45) + 'px'
- }).click(function(event) {
- $("body").unbind("mousemove");
- $("#stamp_cursor").unbind("click").hide();
- if (!document.elementFromPoint) {
- alert("Please upgrade your browser to use this feature.");
- }
- if (navigator.userAgent.indexOf("Firefox") != -1) {
- var element = document.elementFromPoint(event.pageX - window.pageXOffset, event.pageY - window.pageYOffset);
- } else {
- var element = document.elementFromPoint(event.pageX, event.pageY);
- }
- if (element.id.search(/day_/) != -1 && $(element).children("a.mark_link").length > 0 && $(element).children("img").length == 0) {
- if (instruction_level == 2) {
- next_instructions();
- }
- $("#stamp_cursor").change_image("stamping.png").show();
- var p = $(element).position();
- var x = (event.pageX - p.left);
- var y = (event.pageY - p.top);
- $.post($(element).children("a.mark_link").attr("href"), { x: x, y: y }, null, "script");
- } else {
- $("#stamper a img").change_image("ready.png");
- }
- });
- $("body").mousemove(function(event) {
- $("#stamp_cursor").css({
- left: (event.pageX - 40) + 'px',
- top: (event.pageY - 45) + 'px'
- });
- });
+ pick_up_stamp(click_event);
return false;
});

0 comments on commit ca8d091

Please sign in to comment.