Commit 9460cdc2e4351849227a7e501a138d0e777d7362

auto suggest a project slug

Commit diff

app/views/projects/_form.html.erb

 
22 <%= form.label :title -%><br />
33 <%= form.text_field :title, :class => "text" -%>
44</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 -%>
914<p>
1015 <%= form.label :description -%><br />
1116 <%= form.text_area :description, :class => "text medium" -%>
toggle raw diff

public/javascripts/application.js

 
1// Place your application-specific JavaScript functions and classes here
2// This file is automatically included by javascript_include_tag :defaults
1var 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