Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing identation

  • Loading branch information...
commit 06a9443cfe83bc8713ffae52e31f4b7c0958ab87 1 parent 4a18be5
Mohamed Magdy authored
Showing with 59 additions and 59 deletions.
  1. +53 −53 Javascript/jquery.link.detector.js
  2. +6 −6 Javascript/strings.js
View
106 Javascript/jquery.link.detector.js
@@ -7,52 +7,51 @@
detector: function(givenOptions) {
return this.each(function() {
var $this = $(this);
- var options = $.extend({
- interval: 750,
- beforeSendCallback: '',
- successCallback: '',
- errorCallback: '',
- apiURL: $this.data('url'),
- saveUrlTo: '',
- spinClass: '.spinner'
- },
- givenOptions);
- var interval;
- var sentUrls = [];
-
- $this
- .bind('keyup', check)
- .bind('focus blur', function(event) {
- if ( event.type == 'blur' ) clearInterval(checker);
- if ( event.type == 'focus' && !interval ) checker = setInterval(check, options.interval);
- });
-
+ var options = $.extend({
+ interval: 750,
+ beforeSendCallback: '',
+ successCallback: '',
+ errorCallback: '',
+ apiURL: $this.data('url'),
+ saveUrlTo: '',
+ spinClass: '.spinner'
+ }, givenOptions);
+
+ var interval;
+ var sentUrls = [];
+
+ $this.bind('keyup', check)
+ .bind('focus blur', function(event) {
+ if ( event.type == 'blur' ) clearInterval(checker);
+ if ( event.type == 'focus' && !interval ) checker = setInterval(check, options.interval);
+ });
+
// actual function to do the character counting and notification
- function check() {
- var url = detectedUrl($this.val());
+ function check() {
+ var url = detectedUrl($this.val());
+
+ if(url && sentUrls.indexOf(url) == -1) {
+ $(options.saveUrlTo).val(url); // Saving the url
+ sentUrls.push(url); // Pushing the url to the sent urls
- if(url && sentUrls.indexOf(url) == -1) {
- $(options.saveUrlTo).val(url); // Saving the url
- sentUrls.push(url); // Pushing the url to the sent urls
-
$.ajax({
- url: options.apiURL,
- data: { url: url },
- beforeSend: function(jqXHR, settings) {
- if(options.beforeSendCallback != '')
- options.beforeSendCallback();
-
- $(options.spinClass).spin({
- radius: 5,
- rotate: 0,
- width: 2,
- lines: 13
- });
+ url: options.apiURL,
+ data: { url: url },
+ beforeSend: function(jqXHR, settings) {
+ if(options.beforeSendCallback != '')
+ options.beforeSendCallback();
+
+ $(options.spinClass).spin({
+ radius: 5,
+ rotate: 0,
+ width: 2,
+ lines: 13
+ });
},
success: function(data, textStatus, jqXHR) {
if(options.successCallback != '')
options.successCallback(data);
- },
+ },
error: function(jqXHR, textStatus, data) {
if(options.errorCallback != '')
options.errorCallback(data);
@@ -61,21 +60,22 @@
$(options.spinClass).html('');
}
});
- }
+ }
};
-
- function detectedUrl(text) {
- var urls = text.match(/(https?:\/\/[^\s]+)/g);
- return(urls ? urls[0] : false);
- };
-
- function initialize() {
- var url = detectedUrl($this.val());
- if(url)
- sentUrls.push(url)
- };
- // run an initial check
- initialize();
+
+ function detectedUrl(text) {
+ var urls = text.match(/(https?:\/\/[^\s]+)/g);
+ return(urls ? urls[0] : false);
+ };
+
+ function initialize() {
+ var url = detectedUrl($this.val());
+ if(url)
+ sentUrls.push(url)
+ };
+
+ // run an initial check
+ initialize();
});
}
});
View
12 Javascript/strings.js
@@ -1,21 +1,21 @@
// This will add a function named "titleize" to the JavaScript strings
-String.prototype.titleize = function() {
+String.prototype.titleize = function() {
var words = this.replaceAll(/[^A-Za-z0-9]/, ' ').split(' ');
var titleize = '';
-
+
for(word in words)
- titleize += words[word].charAt(0).toUpperCase() + words[word].slice(1);
-
+ titleize += words[word].charAt(0).toUpperCase() + words[word].slice(1);
+
return titleize;
}
// This method capitalize a given string and remove all non alphanumeric characters
-String.prototype.capitalize = function() {
+String.prototype.capitalize = function() {
var words = this.replaceAll(/[^A-Za-z0-9]/, ' ').split(' ');
var capitalized = words[0].charAt(0).toUpperCase() + words[0].slice(1);
words.splice(0, 1);
capitalized += ' ' + words.join(' ');
-
+
return capitalized;
}
Please sign in to comment.
Something went wrong with that request. Please try again.