-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-media-api.js
52 lines (45 loc) · 1.75 KB
/
wp-media-api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
window.onload = () =>{
const wpMediaShow = (text, callback) =>{
let uploader = false;
if(uploader) return uploader.open();
uploader = wp.media({
title: text+"の選択",
library: {
type: "image"
},
button: {
text: "選択"
},
multiple: false
});
uploader.on("select", () =>{
(uploader.state().get("selection")).each((data) =>{
const url = data.attributes.url;
callback(url);
});
});
uploader.open();
}
document.querySelector("#media_upload_btn_logo").onclick = () =>{
wpMediaShow("ロゴ", () =>{
document.getElementById("media_logo_url").value = url;
document.getElementById("media_logo_img").src = url;
document.getElementById("media_logo_img").style.display = "";
});
}
document.querySelector("#media_upload_btn_bg").onclick = () =>{
wpMediaShow("背景画像", () =>{
document.getElementById("media_bg_url").value = url;
document.getElementById("media_bg_img").src = url;
document.getElementById("media_bg_img").style.display = "";
});
}
document.getElementById("media_logo_url").onchange = () =>{
document.getElementById("media_logo_img").src = document.getElementById("media_logo_url").value;
document.getElementById("media_logo_img").style.display = "";
};
document.getElementById("media_bg_url").onchange = () =>{
document.getElementById("media_bg_img").src = document.getElementById("media_logo_url").value;
document.getElementById("media_bg_img").style.display = "";
};
}