diff options
| author | Teddy Wing | 2013-11-10 06:44:08 -0500 |
|---|---|---|
| committer | Teddy Wing | 2013-11-10 06:44:08 -0500 |
| commit | fd255a3f00b7395aafa68ae65e48b7fe7a09d907 (patch) | |
| tree | af54861b72e242cb21acfbe958095fda04f122e1 | |
| parent | 7aed65d5c8cc01fc554f608d5fed2a16836ae978 (diff) | |
| parent | c4fd8cf89fa7f647c8f97b58812d4e0b0c6d47f6 (diff) | |
| download | clip-play-fd255a3f00b7395aafa68ae65e48b7fe7a09d907.tar.bz2 | |
Merge branch 'validate-url'
| -rw-r--r-- | assets/js/views/sample-add-view.js | 12 | ||||
| -rw-r--r-- | index.html | 6 |
2 files changed, 11 insertions, 7 deletions
diff --git a/assets/js/views/sample-add-view.js b/assets/js/views/sample-add-view.js index 7080c84..8be2fb8 100644 --- a/assets/js/views/sample-add-view.js +++ b/assets/js/views/sample-add-view.js @@ -1,4 +1,8 @@ ClipPlay.Views.SampleAddView = Marionette.View.extend({ + // Copied from + // http://stackoverflow.com/a/10430654 + url_matcher: /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/, + events: { 'click .js-create-sample': 'on_sample_add' }, @@ -19,12 +23,14 @@ ClipPlay.Views.SampleAddView = Marionette.View.extend({ }, on_sample_add: function() { - if (this.$input.val()) { + var input_value = this.$input.val(); + if (input_value + && this.url_matcher.test(input_value)) { this.add_sample_to_collection(); - - this.clear_input(); } + this.clear_input(); + return false; } });
\ No newline at end of file @@ -24,10 +24,8 @@ <div role="main"> <div id="add-sample"> - <form action="" method="get"> - <input type="text" class="url-input js-sample-url" placeholder="http://www.youtube.com/watch?v=_JGaQ3g8WU4" /> - <button type="button" class="button green large js-create-sample">+</button> - </form> + <input type="text" class="url-input js-sample-url" placeholder="http://www.youtube.com/watch?v=_JGaQ3g8WU4" /> + <button type="button" class="button green large js-create-sample">+</button> </div> <div id="samples"></div> |
