Advertisement
DEATHMETALGORE

Untitled

Dec 9th, 2013
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     // Remote upload
  2.     var char_start  = 10;
  3.     var line_limit  = 5;
  4.     var index   = 0;
  5.     var urls    = $('.remote-area');
  6.     var urls_array  = [];
  7.    
  8.     var delay = (function(){
  9.     var timer = 0;
  10.         return function(callback, ms){
  11.             clearTimeout (timer);
  12.             timer = setTimeout(callback, ms);
  13.         };
  14.     })();
  15.    
  16.     urls.keydown(function(e) {
  17.         new_lines = urls.val().split("\n").length;
  18.        
  19.         if (e.keyCode == 13 && new_lines >= line_limit)
  20.         {
  21.             display_alert('You reached your maximum number of lines.');
  22.             return false;
  23.         }
  24.     });
  25.    
  26.     urls.keyup(function(){
  27.        
  28.         delay(function(){
  29.            
  30.             if (urls.val().length >= char_start)
  31.             {          
  32.                 var has_lbrs = /\r|\n/i.test(urls.val());
  33.                
  34.                 if (has_lbrs)
  35.                 {
  36.                     urls_array = urls.val().split("\n");
  37.                    
  38.                     for (var i = 0; i < urls_array.length; i++)
  39.                     {
  40.                         if (!validate_url(urls_array[i]))
  41.                         {
  42.                             urls_array.splice(i, 1);
  43.                             continue;  
  44.                         }      
  45.                     }
  46.                    
  47.                     $.ajax({
  48.                         type: 'POST',
  49.                         url: 'upload.php',
  50.                         dataType: 'json',
  51.                         data: {
  52.                             upload_type: 'remote', // Used to determine the upload type in PHP
  53.                             urls: JSON.stringify(urls_array), // Sending the whole array here
  54.                         },
  55.                     });
  56.                 }
  57.                 else
  58.                 {
  59.                     if (!validate_url(urls.val()))
  60.                     {
  61.                         alert('Invalid URL');
  62.                         return;
  63.                     }
  64.                    
  65.                     $.ajax({
  66.                         type: 'POST',
  67.                         url: 'upload.php',
  68.                         dataType: 'json',
  69.                         data: {
  70.                             upload_type: 'remote',
  71.                             urls: JSON.stringify(urls.val()),  
  72.                         },
  73.                         success: function(response) {
  74.                             console.log(response); 
  75.                         }
  76.                     });
  77.                 }
  78.             }
  79.            
  80.         }, 2000); // Delay
  81.     }); // Key up event with Timeout
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement