Parcourir la source

Fixes #425: Ignore leading and trailing periods when generating a slug

Jeremy Stretch il y a 8 ans
Parent
commit
6184eb6664
1 fichiers modifiés avec 5 ajouts et 5 suppressions
  1. 5 5
      netbox/project-static/js/forms.js

+ 5 - 5
netbox/project-static/js/forms.js

@@ -13,11 +13,11 @@ $(document).ready(function() {
 
     // Slugify
     function slugify(s, num_chars) {
-        s = s.replace(/[^\-\.\w\s]/g, '');   // Remove unneeded chars
-        s = s.replace(/^\s+|\s+$/g, '');     // Trim leading/trailing spaces
-        s = s.replace(/[\-\.\s]+/g, '-');    // Convert spaces and decimals to hyphens
-        s = s.toLowerCase();                 // Convert to lowercase
-        return s.substring(0, num_chars);    // Trim to first num_chars chars
+        s = s.replace(/[^\-\.\w\s]/g, '');          // Remove unneeded chars
+        s = s.replace(/^[\s\.]+|[\s\.]+$/g, '');    // Trim leading/trailing spaces
+        s = s.replace(/[\-\.\s]+/g, '-');           // Convert spaces and decimals to hyphens
+        s = s.toLowerCase();                        // Convert to lowercase
+        return s.substring(0, num_chars);           // Trim to first num_chars chars
     }
     var slug_field = $('#id_slug');
     slug_field.change(function() {