Created
August 3, 2016 15:27
-
-
Save onigetoc/3a4346daa3213257fb85cc7a05cad126 to your computer and use it in GitHub Desktop.
Better - on Paste, keyup, input, submit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function($) { | |
var $input = $('#get_url'); | |
$input.data('curr_val', $input.val()); //sets initial value | |
var count = 0; | |
setInterval(function() { | |
if ($input.data('curr_val') == $input.val()) //if it still has same value | |
return false; //returns false | |
$input.data('curr_val', $input.val()); //if val is !=, updates it and | |
//do your stuff | |
oembed(); | |
}, 100); //100 = interval in miliseconds | |
/*********/ | |
$('#show-embed').on("submit", function() { | |
oembed(); | |
return false; | |
}); | |
/******************************/ | |
function oembed() { | |
if ($('#get_url').val()) { | |
$("#result").html(''); | |
$('#code-loading').show(); | |
$.getJSON("http://example.com/api.php?url=" + $("#get_url").val(), function(data, status, xhr) { | |
if (status == "success") { | |
$("#result").html(data.html); | |
$('#code-loading').hide(); | |
$("iframe.wp-oembed-all-content").load(function() { | |
$(this).height($(this).contents().find("html").height()); | |
}); | |
} | |
}); | |
} | |
} | |
}); // jquery function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment