Skip to content

Commit

Permalink
## 1.0.2 - 2018-12-06
Browse files Browse the repository at this point in the history
- Refactored javascript to use native JS over jQuery
  • Loading branch information
reganlawton committed Dec 6, 2018
1 parent 5cddc92 commit 077faba
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 31 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# oEmbed Changelog

## 1.0.2 - 2018-12-06

### Updated
- Refactored javascript to use native JS over jQuery

## 1.0.1 - 2018-11-26

### Updated
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wrav/oembed",
"description": "A simple plugin to extract media information from websites, like youtube videos, twitter statuses or blog articles.",
"type": "craft-plugin",
"version": "1.0.1",
"version": "1.0.2",
"keywords": [
"craft",
"cms",
Expand Down
8 changes: 8 additions & 0 deletions releases.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
[
{
"version": "1.0.2",
"downloadUrl": "https://github.com/wrav/oembed/archive/master.zip",
"date": "2018-12-06:00:00+10:30",
"notes": [
"[Updated] Refactored javascript to your native JS over jQuery"
]
},
{
"version": "1.0.1",
"downloadUrl": "https://github.com/wrav/oembed/archive/master.zip",
Expand Down
72 changes: 42 additions & 30 deletions src/assetbundles/oembed/dist/js/oembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,49 @@
*/

var oembedOnChangeTimeout = null;
var oembedFields = document.querySelector('input.oembed-field');
var errorMessage = '<p class="error">Please check your URL.</p>';

$('input.oembed-field').on('keyup blur change', function () {
var that = $(this);

if (oembedOnChangeTimeout != null) {
clearTimeout(oembedOnChangeTimeout);
}

oembedOnChangeTimeout = setTimeout(function() {
oembedOnChangeTimeout = null;

var val = that.val();

if(val) {
$.ajax({
type: "GET",
url: "/admin/oembed/preview?url=" + val + "&options[]=",
async: true
}).done(function (res) {
var preview = that.parent().find('.oembed-preview');
preview.html('');

if (res) {
preview.html(res);
} else {
preview.html(
'<p class="error">Please check your URL.</p>'
);
}
});
['keyup', 'change'].forEach(function(event) {
oembedFields.addEventListener(event, function (e) {
var elem = e.target;

if (oembedOnChangeTimeout != null) {
clearTimeout(oembedOnChangeTimeout);
}

}, 500);
oembedOnChangeTimeout = setTimeout(function() {
oembedOnChangeTimeout = null;

var val = elem.value;

if(val) {
var preview = elem.parentNode.querySelector('.oembed-preview');
var request = new XMLHttpRequest();
request.open('GET', '/admin/oembed/preview?url=' + val + '&options[]=', true);

request.onload = function() {

if (request.status >= 200 && request.status < 400) {
var res = request.responseText;
preview.innerHTML = '';

if (res) {
preview.innerHTML = res;
} else {
preview.innerHTML = errorMessage;
}
} else {
preview.innerHTML = errorMessage;
}
};

request.onerror = function() {
preview.innerHTML = errorMessage;
};

request.send();
}
}, 500);
});
});

0 comments on commit 077faba

Please sign in to comment.