Commit 9460cdc2e4351849227a7e501a138d0e777d7362
- Date: Sun Dec 16 17:52:54 +0000 2007
- Committer: Johan Sørensen (johan@johansorensen.com)
- Author: Johan Sørensen (johan@johansorensen.com)
- Commit SHA1: 9460cdc2e4351849227a7e501a138d0e777d7362
- Tree SHA1: 5616362e39c41e24744b046f92c82dd3c5b3766a
auto suggest a project slug
Commit diff
| |   |
| 2 | 2 | <%= form.label :title -%><br /> |
| 3 | 3 | <%= form.text_field :title, :class => "text" -%> |
| 4 | 4 | </p> |
| 5 | | <p> |
| 6 | | <%= form.label :slug, "Slug (for urls etc)" -%><br /> |
| 7 | | <%= form.text_field :slug, :class => "text" -%> |
| 8 | | </p> |
| 5 | <% unless ["edit", "update"].include?(controller.action_name) -%> |
| 6 | <p> |
| 7 | <%= form.label :slug, "Slug (for urls etc)" -%><br /> |
| 8 | <%= form.text_field :slug, :class => "text" -%> |
| 9 | </p> |
| 10 | <script type="text/javascript" charset="utf-8"> |
| 11 | var slugger = new ProjectSluggorizer("project_title", "project_slug"); |
| 12 | </script> |
| 13 | <% end -%> |
| 9 | 14 | <p> |
| 10 | 15 | <%= form.label :description -%><br /> |
| 11 | 16 | <%= form.text_area :description, :class => "text medium" -%> |
| toggle raw diff |
--- a/app/views/projects/_form.html.erb
+++ b/app/views/projects/_form.html.erb
@@ -2,10 +2,15 @@
<%= form.label :title -%><br />
<%= form.text_field :title, :class => "text" -%>
</p>
-<p>
- <%= form.label :slug, "Slug (for urls etc)" -%><br />
- <%= form.text_field :slug, :class => "text" -%>
-</p>
+<% unless ["edit", "update"].include?(controller.action_name) -%>
+ <p>
+ <%= form.label :slug, "Slug (for urls etc)" -%><br />
+ <%= form.text_field :slug, :class => "text" -%>
+ </p>
+ <script type="text/javascript" charset="utf-8">
+ var slugger = new ProjectSluggorizer("project_title", "project_slug");
+ </script>
+<% end -%>
<p>
<%= form.label :description -%><br />
<%= form.text_area :description, :class => "text medium" -%> |
| |   |
| 1 | | // Place your application-specific JavaScript functions and classes here |
| 2 | | // This file is automatically included by javascript_include_tag :defaults |
| 1 | var ProjectSluggorizer = Class.create({ |
| 2 | initialize: function(source, target) { |
| 3 | this.source = $(source); |
| 4 | this.target = $(target); |
| 5 | new Form.Element.Observer( |
| 6 | this.source, |
| 7 | 0.8, |
| 8 | function(el, value){ |
| 9 | this.target.value = this._lintedName(value); |
| 10 | }.bind(this) |
| 11 | ) |
| 12 | }, |
| 13 | |
| 14 | _lintedName: function(val) { |
| 15 | var linted = val.gsub(/\W+/, ' ') |
| 16 | linted = linted.gsub(/\ +/, '-') |
| 17 | linted = linted.toLowerCase(); |
| 18 | linted = linted.gsub(/\-+$/, '') |
| 19 | return linted; |
| 20 | } |
| 21 | }); |
| toggle raw diff |
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -1,2 +1,21 @@
-// Place your application-specific JavaScript functions and classes here
-// This file is automatically included by javascript_include_tag :defaults
+var ProjectSluggorizer = Class.create({
+ initialize: function(source, target) {
+ this.source = $(source);
+ this.target = $(target);
+ new Form.Element.Observer(
+ this.source,
+ 0.8,
+ function(el, value){
+ this.target.value = this._lintedName(value);
+ }.bind(this)
+ )
+ },
+
+ _lintedName: function(val) {
+ var linted = val.gsub(/\W+/, ' ')
+ linted = linted.gsub(/\ +/, '-')
+ linted = linted.toLowerCase();
+ linted = linted.gsub(/\-+$/, '')
+ return linted;
+ }
+}); |