blob: 2d3372e1e28499fcb0d448d168bc28c095ecc3ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
ClipPlay.Views.SampleAddView = Marionette.View.extend({
// Copied from
// http://daringfireball.net/2010/07/improved_regex_for_matching_urls
// http://stackoverflow.com/questions/6927719/url-regex-does-not-work-in-javascript
url_matcher: /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i,
events: {
'click .js-create-sample': 'on_sample_add'
},
initialize: function(options) {
this.setElement(options.el);
this.$input = this.$('.js-sample-url');
},
add_sample_to_collection: function() {
this.collection.add({
url: this.$input.val()
});
},
clear_input: function() {
this.$input.val('');
},
on_sample_add: function() {
var input_value = this.$input.val();
if (input_value
&& this.url_matcher.test(input_value)) {
this.add_sample_to_collection();
}
this.clear_input();
return false;
}
});
|