From f3e0cd0b30d880b5d7f8cb9ab0af524d07c5bc7e Mon Sep 17 00:00:00 2001
From: Zach Copley <zach@status.net>
Date: Sun, 17 Apr 2011 18:37:51 -0700
Subject: [PATCH] Some special .js for the bookmark plugin, so we can control
 the form in the second step

---
 plugins/Bookmark/BookmarkPlugin.php |  5 ++++
 plugins/Bookmark/js/bookmark.js     | 37 +++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
 create mode 100644 plugins/Bookmark/js/bookmark.js

diff --git a/plugins/Bookmark/BookmarkPlugin.php b/plugins/Bookmark/BookmarkPlugin.php
index c6fe987dc7..9d92fd61a3 100644
--- a/plugins/Bookmark/BookmarkPlugin.php
+++ b/plugins/Bookmark/BookmarkPlugin.php
@@ -130,6 +130,11 @@ class BookmarkPlugin extends MicroAppPlugin
         return true;
     }
 
+    function onEndShowScripts($action)
+    {
+        $action->script($this->path('js/bookmark.js'));
+        return true;
+    }
     /**
      * Load related modules when needed
      *
diff --git a/plugins/Bookmark/js/bookmark.js b/plugins/Bookmark/js/bookmark.js
new file mode 100644
index 0000000000..c56587c188
--- /dev/null
+++ b/plugins/Bookmark/js/bookmark.js
@@ -0,0 +1,37 @@
+var Bookmark = {
+
+    // Special XHR that sends in some code to be run
+    // when the full bookmark form gets loaded
+    BookmarkXHR: function(form)
+    {
+        SN.U.FormXHR(form, Bookmark.InitBookmarkForm);
+        return false;
+    },
+
+    // Special initialization function just for the
+    // second step in the bookmarking workflow
+    InitBookmarkForm: function() {
+        alert('Gar!');
+
+        // Put fancy stuff here
+
+    }
+}
+
+$(document).ready(function() {
+
+    // Stop normal live event stuff
+    $('form.ajax').die();
+    $('form.ajax input[type=submit]').die();
+
+    // Make the bookmark submit super special
+    $('#form_initial_bookmark').bind('submit', function(e) {
+        Bookmark.BookmarkXHR($(this));
+        e.stopPropagation();
+        return false;
+    });
+
+    // Restore live event stuff to other forms & submit buttions
+    SN.Init.AjaxForms();
+
+});
-- 
2.39.5