diff options
author | shadlaws <shad@shadlaws.com> | 2013-03-12 10:10:47 +0100 |
---|---|---|
committer | shadlaws <shad@shadlaws.com> | 2013-03-12 10:10:47 +0100 |
commit | b3984f975a328efcd6bee9870213476ea295a238 (patch) | |
tree | 03b7642ddb3a5aef1c811201e6af4d8e658deee9 | |
parent | cb8a63bb483742e86af9afd4e931b36638131317 (diff) |
#2054 - Revise albums_form_add.js: update for new jQuery, refactor.
- changed "change" event to "input" to catch cut'n'paste
- kept "keyup" event for old IE compatibility
- removed code duplication by using $(this) and combining events using .on()
- replaced attr("value",...) with val()
- added quotes around input names
-rw-r--r-- | modules/gallery/js/albums_form_add.js | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/modules/gallery/js/albums_form_add.js b/modules/gallery/js/albums_form_add.js index a568f35d..55ad8ce6 100644 --- a/modules/gallery/js/albums_form_add.js +++ b/modules/gallery/js/albums_form_add.js @@ -1,23 +1,6 @@ -$("#g-add-album-form input[name=title]").change( - function() { - $("#g-add-album-form input[name=name]").attr( - "value", $("#g-add-album-form input[name=title]").attr("value") - .replace(/[\s\/]+/g, "-").replace(/\.+$/, "")); - $("#g-add-album-form input[name=slug]").attr( - "value", $("#g-add-album-form input[name=title]").attr("value") - .replace(/[^A-Za-z0-9-_]+/g, "-") - .replace(/^-+/, "") - .replace(/-+$/, "")); - }); -$("#g-add-album-form input[name=title]").keyup( - function() { - $("#g-add-album-form input[name=name]").attr( - "value", $("#g-add-album-form input[name=title]").attr("value") - .replace(/[\s\/]+/g, "-") - .replace(/\.+$/, "")); - $("#g-add-album-form input[name=slug]").attr( - "value", $("#g-add-album-form input[name=title]").attr("value") - .replace(/[^A-Za-z0-9-_]+/g, "-") - .replace(/^-+/, "") - .replace(/-+$/, "")); - }); +$("#g-add-album-form input[name='title']").on("input keyup", function() { + $("#g-add-album-form input[name='name']").val( + $(this).val().replace(/[\s\/\\]+/g, "-").replace(/\.+$/, "")); + $("#g-add-album-form input[name='slug']").val( + $(this).val().replace(/[^A-Za-z0-9-_]+/g, "-").replace(/^-+/, "").replace(/-+$/, "")); +}); |