Permalink
Browse files

Add option to inject jQuery. Probably.

  • Loading branch information...
1 parent 58b1e00 commit aaf907d67ff905a7074c7d7285814c3e353835db @nakajima committed Jun 20, 2010
@@ -11,6 +11,21 @@ def spam?
@body.present? || SpamChecker.new(code).spam?
end
+ def code
+ if jquery?
+ jquery = <<-JS
+ var _jq = document.createElement('script');
+ _jq.src = 'http://code.jquery.com/jquery.js';
+ _jq.type = 'text/javascript';
+ document.getElementsByTagName('head')[0].appendChild(_jq);
+ JS
+ jquery.gsub!(/^\s*/, '')
+ [jquery, self[:code]].join("\n")
+ else
+ self[:code]
+ end
+ end
+
def highlighted_code
self[:highlighted_code] || begin
highlight_code!
@@ -26,7 +41,7 @@ def highlighted_code
def highlight_code!
self.highlighted_code = Net::HTTP.post_form(URI.parse('http://pygments.appspot.com/'), {
'lang' => 'javascript',
- 'code' => code
+ 'code' => self[:code]
}).body
end
@@ -9,26 +9,31 @@
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
-
+
<p>
<%= f.label :password, 'Password (optional, but required to edit)' %><br />
<%= f.text_field :password %>
</p>
-
+
<p>
<%= f.label :code %><br />
<%= f.text_area :code %>
</p>
-
+
<p>
<%= f.label :description, 'Description (optional)' %><br />
<%= f.text_area :description %>
</p>
-
- <p>
- <%= f.submit 'Update Bookmarklet' %>
+
+ <p style="display: inline-block; margin-right: 550px; margin-top: 0">
+ <%= f.check_box :jquery %>
+ <%= f.label :jquery, 'Inject jQuery' %>
+ </p>
+
+ <p style="display: inline-block">
+ <%= f.submit 'Create Bookmarklet' %>
</p>
<% end %>
<%= link_to 'Show', @bookmarklet %> |
-<%= link_to 'Back', bookmarklets_path %>
+<%= link_to 'Back', bookmarklets_path %>
@@ -25,6 +25,15 @@
<%= f.text_area :description %>
</p>
+ <p style="display: inline-block; margin-right: 550px; margin-top: 0">
+ <%= f.check_box :jquery %>
+ <%= f.label :jquery, 'Inject jQuery' %>
+ </p>
+
+ <p style="display: inline-block">
+ <%= f.submit 'Create Bookmarklet' %>
+ </p>
+
<p class="required">
<%= f.label :body, "body" %>
<%= f.text_area :body %>
@@ -35,10 +44,6 @@
$$('p.required').invoke('hide'); // spam protection
});
</script>
-
- <p>
- <%= f.submit 'Create Bookmarklet' %>
- </p>
<% end %>
<%= link_to 'Back', bookmarklets_path %>
@@ -7,7 +7,14 @@ Drag this to your Bookmarks Bar:
<br>
-<blockquote><%= h(@bookmarklet.description) %></blockquote>
+<blockquote>
+<%= h(@bookmarklet.description) %>
+<% if @bookmarklet.jquery? %>
+ <small id="uses-jquery">Includes jQuery</small>
+<% end %>
+</blockquote>
+
+
<%= link_to_function 'View Source', 'showTheCodes(); return false' %>
@@ -21,4 +28,4 @@ Drag this to your Bookmarks Bar:
<p>
<a href="/">Click here to go home.</a>
-</p>
+</p>
@@ -0,0 +1,9 @@
+class AddJqueryToBookmarklets < ActiveRecord::Migration
+ def self.up
+ add_column :bookmarklets, :jquery, :boolean, :default => false
+ end
+
+ def self.down
+ remove_column :bookmarklets, :jquery
+ end
+end
View
@@ -1,4 +1,4 @@
-# This file is auto-generated from the current state of the database. Instead of editing this file,
+# This file is auto-generated from the current state of the database. Instead of editing this file,
# please use the migrations feature of Active Record to incrementally modify your database, and
# then regenerate this schema definition.
#
@@ -9,17 +9,18 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20100522191825) do
+ActiveRecord::Schema.define(:version => 20100620172509) do
create_table "bookmarklets", :force => true do |t|
- t.string "name"
- t.text "code"
- t.integer "count", :default => 0
- t.timestamp "created_at"
- t.timestamp "updated_at"
- t.text "description"
- t.string "password"
- t.text "highlighted_code"
+ t.string "name"
+ t.text "code"
+ t.integer "count", :default => 0
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.text "description"
+ t.string "password"
+ t.text "highlighted_code"
+ t.boolean "jquery", :default => false
end
end
@@ -50,8 +50,11 @@ input[type="submit"] {
textarea {
width: 800px;
+ height: 200px;
font-family: Courier, monospace;
margin-bottom: 2em;
+ padding: 10px;
+ font-size: 16px;
}
#main-title {
@@ -110,3 +113,18 @@ blockquote {
margin: 20px 0;
color: #ccc;
}
+
+blockquote small {
+ font-size: 16px;
+ background: #ffa;
+ padding: 4px 8px;
+ color: #111;
+ margin-right: 10px;
+ margin-top: 0.6em;
+ display: inline-block;
+ -webkit-border-radius: 10px;
+ -moz-border-radius: 10px;
+ border-radius: 10px;
+ float: left;
+ vertical-align: baseline;
+}

0 comments on commit aaf907d

Please sign in to comment.