Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing identation

  • Loading branch information...
commit 5149c941c10af00818730aad08db094e274362f8 1 parent 4a18be5
Mohamed Magdy authored
Showing with 100 additions and 98 deletions.
  1. +83 −81 Javascript/jquery.link.detector.js
  2. +17 −17 Javascript/strings.js
164 Javascript/jquery.link.detector.js
View
@@ -2,91 +2,93 @@
This plugin is used to detect urls in a text field/area and submits the url to the server.
It can be used to fetch the url metadata as Facebook does
*/
-(function($) {
- $.fn.extend({
- 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);
- });
-
- // actual function to do the character counting and notification
- function check() {
- var url = detectedUrl($this.val());
+(function ($) {
+ $.fn.extend({
+ 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);
- 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
- });
- },
- success: function(data, textStatus, jqXHR) {
- if(options.successCallback != '')
- options.successCallback(data);
- },
- error: function(jqXHR, textStatus, data) {
- if(options.errorCallback != '')
- options.errorCallback(data);
- },
- complete: function(jqXHR, textStatus) {
- $(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();
- });
- }
- });
+ 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());
+
+ 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
+ });
+ },
+ success: function (data, textStatus, jqXHR) {
+ if (options.successCallback != '')
+ options.successCallback(data);
+ },
+ error: function (jqXHR, textStatus, data) {
+ if (options.errorCallback != '')
+ options.errorCallback(data);
+ },
+ complete: function (jqXHR, textStatus) {
+ $(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();
+ });
+ }
+ });
})(jQuery);
// Example usage
$('.js-BlabContent').detector({
- apiURL: $('.js-BlabContent').data('url'),
- beforeSendCallback: disableBlabPostTrigger,
- successCallback: showURLFetchMeta, // Embeding the url meta into the page
- saveUrlTo: '.js-BlabURL' // Save the url in the HTML DOM
-});
+ apiURL: $('.js-BlabContent').data('url'),
+ beforeSendCallback: disableBlabPostTrigger,
+ successCallback: showURLFetchMeta, // Embeding the url meta into the page
+ saveUrlTo: '.js-BlabURL' // Save the url in the HTML DOM
+});
34 Javascript/strings.js
View
@@ -1,25 +1,25 @@
// This will add a function named "titleize" to the JavaScript strings
-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);
-
- return titleize;
+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);
+
+ return titleize;
}
// This method capitalize a given string and remove all non alphanumeric characters
-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;
+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;
}
// Replace all occurrence of a value in a string
-String.prototype.replaceAll = function(target, replacement) {
+String.prototype.replaceAll = function (target, replacement) {
return this.split(target).join(replacement);
-};
+};
Please sign in to comment.
Something went wrong with that request. Please try again.