Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Remote upload
- var char_start = 10;
- var line_limit = 5;
- var index = 0;
- var urls = $('.remote-area');
- var urls_array = [];
- var delay = (function(){
- var timer = 0;
- return function(callback, ms){
- clearTimeout (timer);
- timer = setTimeout(callback, ms);
- };
- })();
- urls.keydown(function(e) {
- new_lines = urls.val().split("\n").length;
- if (e.keyCode == 13 && new_lines >= line_limit)
- {
- display_alert('You reached your maximum number of lines.');
- return false;
- }
- });
- urls.keyup(function(){
- delay(function(){
- if (urls.val().length >= char_start)
- {
- var has_lbrs = /\r|\n/i.test(urls.val());
- if (has_lbrs)
- {
- urls_array = urls.val().split("\n");
- for (var i = 0; i < urls_array.length; i++)
- {
- if (!validate_url(urls_array[i]))
- {
- urls_array.splice(i, 1);
- continue;
- }
- }
- $.ajax({
- type: 'POST',
- url: 'upload.php',
- dataType: 'json',
- data: {
- upload_type: 'remote', // Used to determine the upload type in PHP
- urls: JSON.stringify(urls_array), // Sending the whole array here
- },
- });
- }
- else
- {
- if (!validate_url(urls.val()))
- {
- alert('Invalid URL');
- return;
- }
- $.ajax({
- type: 'POST',
- url: 'upload.php',
- dataType: 'json',
- data: {
- upload_type: 'remote',
- urls: JSON.stringify(urls.val()),
- },
- success: function(response) {
- console.log(response);
- }
- });
- }
- }
- }, 2000); // Delay
- }); // Key up event with Timeout
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement