@wp-operations/wp-ops 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -27
- package/bin/wp-app.js +2 -0
- package/bin/wp-code.js +2 -0
- package/bin/wp-ide.js +2 -0
- package/package.json +12 -3
- package/src/commands/platform.js +16 -2
- package/src/commands/sandbox.js +3 -3
- package/src/main.js +10 -4
- package/wp-operations/CHANGELOG.md +14 -0
- package/wp-operations/README.md +39 -0
- package/wp-operations/agents/builder/AGENT.md +15 -0
- package/wp-operations/assets/admin.css +631 -0
- package/wp-operations/assets/admin.js +614 -0
- package/wp-operations/assets/app/app.css +1 -0
- package/wp-operations/assets/app/app.js +70 -0
- package/wp-operations/assets/app/fonts/inter-medium.woff +0 -0
- package/wp-operations/assets/app/fonts/inter-regular.woff +0 -0
- package/wp-operations/assets/app/fonts/inter-semibold.woff +0 -0
- package/wp-operations/assets/app/login.css +42 -0
- package/wp-operations/assets/brand/icon.svg +20 -0
- package/wp-operations/assets/brand/mark.svg +19 -0
- package/wp-operations/assets/editors/audiobook.css +311 -0
- package/wp-operations/assets/editors/audiofile.css +286 -0
- package/wp-operations/assets/editors/course.css +701 -0
- package/wp-operations/assets/editors/course.js +698 -0
- package/wp-operations/assets/editors/faq.css +258 -0
- package/wp-operations/assets/editors/faq.js +196 -0
- package/wp-operations/assets/editors/interactive.css +220 -0
- package/wp-operations/assets/editors/interactive.js +378 -0
- package/wp-operations/assets/editors/media-sources.css +3 -0
- package/wp-operations/assets/editors/media-sources.js +40 -0
- package/wp-operations/assets/editors/open-media.css +114 -0
- package/wp-operations/assets/editors/open-media.js +182 -0
- package/wp-operations/assets/editors/thumbnails.css +335 -0
- package/wp-operations/assets/editors/thumbnails.js +447 -0
- package/wp-operations/assets/editors/translator.css +818 -0
- package/wp-operations/functions.php +24 -0
- package/wp-operations/index.php +14 -0
- package/wp-operations/platform.json +1836 -0
- package/wp-operations/skills/ai-development-guardrails/SKILL.md +49 -0
- package/wp-operations/skills/gutenberg-reference/SKILL.md +45 -0
- package/wp-operations/skills/js-tooling-for-themes/SKILL.md +51 -0
- package/wp-operations/skills/tailwind-for-wp/SKILL.md +62 -0
- package/wp-operations/skills/wp-clean-classic-themes/SKILL.md +112 -0
- package/wp-operations/skills/wp-psr4-plugins/SKILL.md +2043 -0
- package/wp-operations/skills/wp-security/SKILL.md +90 -0
- package/wp-operations/src/Admin.php +78 -0
- package/wp-operations/src/App/Access.php +57 -0
- package/wp-operations/src/App/Admin.php +442 -0
- package/wp-operations/src/App/App.php +157 -0
- package/wp-operations/src/App/Apps.php +379 -0
- package/wp-operations/src/App/Bundle.php +111 -0
- package/wp-operations/src/App/Contents.php +676 -0
- package/wp-operations/src/App/Engine.php +554 -0
- package/wp-operations/src/App/Github.php +308 -0
- package/wp-operations/src/App/Module.php +23 -0
- package/wp-operations/src/App/Ops.php +470 -0
- package/wp-operations/src/App/Packages.php +289 -0
- package/wp-operations/src/App/Rest.php +539 -0
- package/wp-operations/src/App/Sandboxes.php +206 -0
- package/wp-operations/src/App/Store.php +104 -0
- package/wp-operations/src/App/Usage.php +268 -0
- package/wp-operations/src/Config.php +249 -0
- package/wp-operations/src/Content/Editor.php +223 -0
- package/wp-operations/src/Content/Fields.php +681 -0
- package/wp-operations/src/Content/Scoring.php +253 -0
- package/wp-operations/src/Content/Structure.php +293 -0
- package/wp-operations/src/Content/Types.php +150 -0
- package/wp-operations/src/Content/Uploads.php +50 -0
- package/wp-operations/src/Editors/AudiobookAuthor.php +61 -0
- package/wp-operations/src/Editors/AudiobookChapters.php +632 -0
- package/wp-operations/src/Editors/AudiobookCover.php +235 -0
- package/wp-operations/src/Editors/Audiofile.php +462 -0
- package/wp-operations/src/Editors/Course.php +784 -0
- package/wp-operations/src/Editors/Ebook.php +242 -0
- package/wp-operations/src/Editors/Editors.php +44 -0
- package/wp-operations/src/Editors/Faq.php +237 -0
- package/wp-operations/src/Editors/Files.php +139 -0
- package/wp-operations/src/Editors/Interactive/Builder.php +103 -0
- package/wp-operations/src/Editors/Interactive/Card.php +76 -0
- package/wp-operations/src/Editors/Interactive/Editor.php +42 -0
- package/wp-operations/src/Editors/Interactive/Field.php +272 -0
- package/wp-operations/src/Editors/Interactive/Map.php +84 -0
- package/wp-operations/src/Editors/Interactive/Models.php +227 -0
- package/wp-operations/src/Editors/Interactive/Report.php +59 -0
- package/wp-operations/src/Editors/Interactive/Save.php +323 -0
- package/wp-operations/src/Editors/Interactive/Scoring.php +244 -0
- package/wp-operations/src/Editors/Interactive/Structure.php +195 -0
- package/wp-operations/src/Editors/Legal.php +235 -0
- package/wp-operations/src/Editors/OpenMedia.php +140 -0
- package/wp-operations/src/Editors/OriginalTitle.php +112 -0
- package/wp-operations/src/Editors/Sources.php +28 -0
- package/wp-operations/src/Editors/Thumbnails/Admin.php +306 -0
- package/wp-operations/src/Editors/Thumbnails/Ajax.php +163 -0
- package/wp-operations/src/Editors/Thumbnails/Box.php +188 -0
- package/wp-operations/src/Editors/Thumbnails/Storage.php +228 -0
- package/wp-operations/src/Editors/Translator/Admin.php +913 -0
- package/wp-operations/src/Editors/Translator/Api.php +63 -0
- package/wp-operations/src/Editors/Translator/Bar.php +83 -0
- package/wp-operations/src/Editors/Translator/Fields.php +273 -0
- package/wp-operations/src/Editors/Translator/Storage.php +131 -0
- package/wp-operations/src/Editors/Translator/Thumbnail.php +215 -0
- package/wp-operations/src/Identity.php +104 -0
- package/wp-operations/src/Languages.php +45 -0
- package/wp-operations/src/Lockdown.php +85 -0
- package/wp-operations/src/Modules/Apps/Admin.php +472 -0
- package/wp-operations/src/Modules/Apps/Api.php +193 -0
- package/wp-operations/src/Modules/Apps/Apps.php +279 -0
- package/wp-operations/src/Modules/Apps/Formatters.php +478 -0
- package/wp-operations/src/Modules/Apps/Schemes.php +248 -0
- package/wp-operations/src/Modules/Apps/Table.php +101 -0
- package/wp-operations/src/Modules/Thumbnails.php +68 -0
- package/wp-operations/src/Modules/Translations.php +133 -0
- package/wp-operations/src/Platform.php +59 -0
- package/wp-operations/src/Setup.php +273 -0
- package/wp-operations/src/Status.php +99 -0
- package/wp-operations/src/Storage/Client.php +168 -0
- package/wp-operations/src/Storage/Offload.php +120 -0
- package/wp-operations/src/Storage/Settings.php +166 -0
- package/wp-operations/src/Storage/Storage.php +35 -0
- package/wp-operations/src/Updates.php +151 -0
- package/wp-operations/style.css +11 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
( function () {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var settings = window.InteractiveCMS || {};
|
|
5
|
+
|
|
6
|
+
function rows( list ) {
|
|
7
|
+
return Array.prototype.filter.call( list.children, function ( node ) {
|
|
8
|
+
return node.classList.contains( 'rep-row' );
|
|
9
|
+
} );
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function setName( field ) {
|
|
13
|
+
var segments = [];
|
|
14
|
+
var prefix = null;
|
|
15
|
+
var node = field.parentElement;
|
|
16
|
+
|
|
17
|
+
while ( node ) {
|
|
18
|
+
if ( node.dataset && node.dataset.prefix ) {
|
|
19
|
+
prefix = node.dataset.prefix;
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if ( node.classList && node.classList.contains( 'rep-row' ) ) {
|
|
24
|
+
var list = node.parentElement;
|
|
25
|
+
segments.unshift( String( rows( list ).indexOf( node ) ) );
|
|
26
|
+
segments.unshift( list.parentElement.dataset.rep );
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
node = node.parentElement;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if ( prefix ) {
|
|
33
|
+
segments.unshift( prefix );
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
segments.push( field.dataset.key );
|
|
37
|
+
|
|
38
|
+
var head = segments.shift();
|
|
39
|
+
|
|
40
|
+
field.name = head + segments.map( function ( segment ) {
|
|
41
|
+
return '[' + segment + ']';
|
|
42
|
+
} ).join( '' );
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function rebuild( scope ) {
|
|
46
|
+
scope.querySelectorAll( '[data-key]' ).forEach( setName );
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function addRow( repeater ) {
|
|
50
|
+
var template = repeater.querySelector( ':scope > .rep-template' );
|
|
51
|
+
var list = repeater.querySelector( ':scope > .rep-list' );
|
|
52
|
+
|
|
53
|
+
if ( ! template || ! list ) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
var source = template.content.firstElementChild;
|
|
58
|
+
|
|
59
|
+
if ( ! source ) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
var row = source.cloneNode( true );
|
|
64
|
+
|
|
65
|
+
list.appendChild( row );
|
|
66
|
+
rebuild( repeater );
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function sortable( list, onDrop ) {
|
|
70
|
+
var dragging = null;
|
|
71
|
+
|
|
72
|
+
list.addEventListener( 'mousedown', function ( event ) {
|
|
73
|
+
var handle = event.target.closest( '.rep-handle' );
|
|
74
|
+
|
|
75
|
+
if ( ! handle ) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var row = handle.closest( '.rep-row, .child' );
|
|
80
|
+
|
|
81
|
+
if ( row && row.parentElement === list ) {
|
|
82
|
+
row.draggable = true;
|
|
83
|
+
}
|
|
84
|
+
} );
|
|
85
|
+
|
|
86
|
+
list.addEventListener( 'dragstart', function ( event ) {
|
|
87
|
+
if ( event.target.parentElement !== list ) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
dragging = event.target;
|
|
92
|
+
dragging.classList.add( 'is-dragging' );
|
|
93
|
+
event.dataTransfer.effectAllowed = 'move';
|
|
94
|
+
} );
|
|
95
|
+
|
|
96
|
+
list.addEventListener( 'dragover', function ( event ) {
|
|
97
|
+
if ( ! dragging ) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
|
|
103
|
+
var over = event.target.closest( '.rep-row, .child' );
|
|
104
|
+
|
|
105
|
+
if ( ! over || over === dragging || over.parentElement !== list ) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var bounds = over.getBoundingClientRect();
|
|
110
|
+
var after = event.clientY > bounds.top + bounds.height / 2;
|
|
111
|
+
|
|
112
|
+
list.insertBefore( dragging, after ? over.nextSibling : over );
|
|
113
|
+
} );
|
|
114
|
+
|
|
115
|
+
list.addEventListener( 'dragend', function () {
|
|
116
|
+
if ( ! dragging ) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
dragging.classList.remove( 'is-dragging' );
|
|
121
|
+
dragging.draggable = false;
|
|
122
|
+
dragging = null;
|
|
123
|
+
|
|
124
|
+
if ( onDrop ) {
|
|
125
|
+
onDrop( list );
|
|
126
|
+
}
|
|
127
|
+
} );
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function bindRepeaters( scope ) {
|
|
131
|
+
scope.querySelectorAll( '.rep' ).forEach( function ( repeater ) {
|
|
132
|
+
if ( repeater.dataset.bound ) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
repeater.dataset.bound = '1';
|
|
137
|
+
|
|
138
|
+
var list = repeater.querySelector( ':scope > .rep-list' );
|
|
139
|
+
|
|
140
|
+
if ( list ) {
|
|
141
|
+
sortable( list, function () {
|
|
142
|
+
rebuild( repeater );
|
|
143
|
+
} );
|
|
144
|
+
}
|
|
145
|
+
} );
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function request( action, data ) {
|
|
149
|
+
var body = new FormData();
|
|
150
|
+
|
|
151
|
+
body.append( 'action', action );
|
|
152
|
+
body.append( 'nonce', settings.nonce );
|
|
153
|
+
|
|
154
|
+
Object.keys( data ).forEach( function ( key ) {
|
|
155
|
+
var value = data[ key ];
|
|
156
|
+
|
|
157
|
+
if ( Array.isArray( value ) ) {
|
|
158
|
+
value.forEach( function ( entry ) {
|
|
159
|
+
body.append( key + '[]', entry );
|
|
160
|
+
} );
|
|
161
|
+
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
body.append( key, value );
|
|
166
|
+
} );
|
|
167
|
+
|
|
168
|
+
return fetch( settings.ajaxUrl, {
|
|
169
|
+
method: 'POST',
|
|
170
|
+
credentials: 'same-origin',
|
|
171
|
+
body: body
|
|
172
|
+
} ).then( function ( response ) {
|
|
173
|
+
return response.json();
|
|
174
|
+
} );
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function childOrder( list ) {
|
|
178
|
+
return Array.prototype.map.call( list.querySelectorAll( ':scope > .child' ), function ( child ) {
|
|
179
|
+
return child.dataset.id;
|
|
180
|
+
} );
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function applyModel() {
|
|
184
|
+
var select = document.querySelector( '.model-select' );
|
|
185
|
+
|
|
186
|
+
if ( ! select ) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
var model = settings.models ? settings.models[ select.value ] : null;
|
|
191
|
+
var uses = model ? model.uses : [];
|
|
192
|
+
|
|
193
|
+
var summary = document.querySelector( '.model-summary' );
|
|
194
|
+
var examples = document.querySelector( '.model-examples' );
|
|
195
|
+
|
|
196
|
+
if ( summary ) {
|
|
197
|
+
summary.textContent = model ? model.summary : '';
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if ( examples ) {
|
|
201
|
+
examples.textContent = model ? model.examples : '';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
document.querySelectorAll( '.model-params' ).forEach( function ( panel ) {
|
|
205
|
+
panel.hidden = panel.dataset.model !== select.value;
|
|
206
|
+
} );
|
|
207
|
+
|
|
208
|
+
document.querySelectorAll( '[data-need]' ).forEach( function ( element ) {
|
|
209
|
+
element.hidden = uses.indexOf( element.dataset.need ) === -1;
|
|
210
|
+
} );
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function refreshList( id, repeaterKey ) {
|
|
214
|
+
var datalist = document.getElementById( id );
|
|
215
|
+
var repeater = document.querySelector( '.rep[data-rep="' + repeaterKey + '"]' );
|
|
216
|
+
|
|
217
|
+
if ( ! datalist || ! repeater ) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
var values = [];
|
|
222
|
+
|
|
223
|
+
repeater.querySelectorAll( '.rep-row [data-key="key"]' ).forEach( function ( field ) {
|
|
224
|
+
if ( field.value && values.indexOf( field.value ) === -1 ) {
|
|
225
|
+
values.push( field.value );
|
|
226
|
+
}
|
|
227
|
+
} );
|
|
228
|
+
|
|
229
|
+
datalist.innerHTML = values.map( function ( value ) {
|
|
230
|
+
return '<option value="' + value.replace( /"/g, '"' ) + '"></option>';
|
|
231
|
+
} ).join( '' );
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function refreshLists() {
|
|
235
|
+
refreshList( 'subscale-keys', '_subscales' );
|
|
236
|
+
refreshList( 'scale-keys', '_scales' );
|
|
237
|
+
refreshList( 'outcome-keys', '_outcomes' );
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function countItems( child ) {
|
|
241
|
+
var counter = child.querySelector( '.child-count' );
|
|
242
|
+
var repeater = child.querySelector( '.rep[data-rep="items"] > .rep-list' );
|
|
243
|
+
|
|
244
|
+
if ( ! counter || ! repeater ) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
counter.textContent = rows( repeater ).length;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
document.addEventListener( 'click', function ( event ) {
|
|
252
|
+
var add = event.target.closest( '.rep-add' );
|
|
253
|
+
|
|
254
|
+
if ( add ) {
|
|
255
|
+
event.preventDefault();
|
|
256
|
+
addRow( add.closest( '.rep' ) );
|
|
257
|
+
bindRepeaters( add.closest( '.rep' ) );
|
|
258
|
+
applyModel();
|
|
259
|
+
|
|
260
|
+
var host = add.closest( '.child' );
|
|
261
|
+
|
|
262
|
+
if ( host ) {
|
|
263
|
+
countItems( host );
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
var remove = event.target.closest( '.rep-remove' );
|
|
270
|
+
|
|
271
|
+
if ( remove ) {
|
|
272
|
+
event.preventDefault();
|
|
273
|
+
|
|
274
|
+
if ( ! window.confirm( settings.confirmRow ) ) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
var row = remove.closest( '.rep-row' );
|
|
279
|
+
var repeater = row.closest( '.rep' );
|
|
280
|
+
var parentChild = row.closest( '.child' );
|
|
281
|
+
|
|
282
|
+
row.remove();
|
|
283
|
+
rebuild( repeater );
|
|
284
|
+
|
|
285
|
+
if ( parentChild ) {
|
|
286
|
+
countItems( parentChild );
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
var toggle = event.target.closest( '.child-toggle' );
|
|
293
|
+
|
|
294
|
+
if ( toggle ) {
|
|
295
|
+
event.preventDefault();
|
|
296
|
+
toggle.closest( '.child' ).classList.toggle( 'is-open' );
|
|
297
|
+
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
var remove_child = event.target.closest( '.child-delete' );
|
|
302
|
+
|
|
303
|
+
if ( remove_child ) {
|
|
304
|
+
event.preventDefault();
|
|
305
|
+
|
|
306
|
+
if ( ! window.confirm( settings.confirmAll ) ) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
var child = remove_child.closest( '.child' );
|
|
311
|
+
|
|
312
|
+
request( 'interactive_delete_child', { child: child.dataset.id } ).then( function () {
|
|
313
|
+
child.remove();
|
|
314
|
+
} );
|
|
315
|
+
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
var addChild = event.target.closest( '.child-add' );
|
|
320
|
+
|
|
321
|
+
if ( addChild ) {
|
|
322
|
+
event.preventDefault();
|
|
323
|
+
addChild.disabled = true;
|
|
324
|
+
|
|
325
|
+
request( 'interactive_add_child', {
|
|
326
|
+
parent: addChild.dataset.parent,
|
|
327
|
+
type: addChild.dataset.type
|
|
328
|
+
} ).then( function ( response ) {
|
|
329
|
+
addChild.disabled = false;
|
|
330
|
+
|
|
331
|
+
if ( ! response || ! response.success ) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
var list = document.querySelector( '.child-list' );
|
|
336
|
+
var holder = document.createElement( 'div' );
|
|
337
|
+
|
|
338
|
+
holder.innerHTML = response.data.html.trim();
|
|
339
|
+
|
|
340
|
+
var child = holder.firstElementChild;
|
|
341
|
+
|
|
342
|
+
list.appendChild( child );
|
|
343
|
+
child.classList.add( 'is-open' );
|
|
344
|
+
bindRepeaters( child );
|
|
345
|
+
applyModel();
|
|
346
|
+
} );
|
|
347
|
+
}
|
|
348
|
+
} );
|
|
349
|
+
|
|
350
|
+
document.addEventListener( 'change', function ( event ) {
|
|
351
|
+
if ( event.target.classList.contains( 'model-select' ) ) {
|
|
352
|
+
applyModel();
|
|
353
|
+
}
|
|
354
|
+
} );
|
|
355
|
+
|
|
356
|
+
document.addEventListener( 'input', function ( event ) {
|
|
357
|
+
if ( event.target.dataset && event.target.dataset.key === 'key' ) {
|
|
358
|
+
refreshLists();
|
|
359
|
+
}
|
|
360
|
+
} );
|
|
361
|
+
|
|
362
|
+
document.addEventListener( 'DOMContentLoaded', function () {
|
|
363
|
+
bindRepeaters( document );
|
|
364
|
+
|
|
365
|
+
var childList = document.querySelector( '.child-list' );
|
|
366
|
+
|
|
367
|
+
if ( childList ) {
|
|
368
|
+
sortable( childList, function ( list ) {
|
|
369
|
+
request( 'interactive_sort_children', { order: childOrder( list ) } );
|
|
370
|
+
} );
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
applyModel();
|
|
374
|
+
refreshLists();
|
|
375
|
+
|
|
376
|
+
document.querySelectorAll( '.child' ).forEach( countItems );
|
|
377
|
+
} );
|
|
378
|
+
} )();
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
.course-video-input-wrap[data-type="external_url"], .course-video-input-wrap { position: relative; }
|
|
2
|
+
input.pms-video-input { width: calc(100% - 150px) !important; display: inline-block !important; vertical-align: middle; }
|
|
3
|
+
.pms-video { margin-left: 8px !important; vertical-align: middle; }
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
(function ($) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
function attach(root) {
|
|
5
|
+
$(root).find('input.course-video-source-field[data-type="external_url"]').addBack('input.course-video-source-field[data-type="external_url"]').each(function () {
|
|
6
|
+
var $input = $(this);
|
|
7
|
+
|
|
8
|
+
if ($input.next('.pms-video').length) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
var $button = $('<button type="button" class="button pms-video">Upload or choose</button>');
|
|
13
|
+
$input.addClass('pms-video-input').after($button);
|
|
14
|
+
$button.on('click', function () {
|
|
15
|
+
var frame = wp.media({ title: 'Choose a video', library: { type: 'video' }, button: { text: 'Use this video' }, multiple: false });
|
|
16
|
+
frame.on('select', function () {
|
|
17
|
+
$input.val(frame.state().get('selection').first().toJSON().url).trigger('input').trigger('change');
|
|
18
|
+
});
|
|
19
|
+
frame.open();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
$(function () {
|
|
25
|
+
if (typeof wp === 'undefined' || !wp.media) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
attach(document.body);
|
|
30
|
+
new MutationObserver(function (records) {
|
|
31
|
+
records.forEach(function (record) {
|
|
32
|
+
record.addedNodes.forEach(function (node) {
|
|
33
|
+
if (node.nodeType === 1) {
|
|
34
|
+
attach(node);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}).observe(document.body, { childList: true, subtree: true });
|
|
39
|
+
});
|
|
40
|
+
}(jQuery));
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
.opm-wrap {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
padding: 16px;
|
|
5
|
+
box-sizing: border-box;
|
|
6
|
+
height: 100%;
|
|
7
|
+
overflow-y: auto;
|
|
8
|
+
background: #f0f0f1;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.opm-bar {
|
|
12
|
+
display: flex;
|
|
13
|
+
gap: 8px;
|
|
14
|
+
margin-bottom: 8px;
|
|
15
|
+
flex-shrink: 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.opm-q {
|
|
19
|
+
flex: 1;
|
|
20
|
+
height: 36px;
|
|
21
|
+
padding: 0 10px;
|
|
22
|
+
border: 1px solid #8c8f94;
|
|
23
|
+
border-radius: 3px;
|
|
24
|
+
font-size: 14px;
|
|
25
|
+
background: #fff;
|
|
26
|
+
box-shadow: inset 0 1px 2px rgba(0,0,0,.07);
|
|
27
|
+
outline: none;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.opm-q:focus {
|
|
31
|
+
border-color: #2271b1;
|
|
32
|
+
box-shadow: 0 0 0 1px #2271b1;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.opm-btn.button-primary {
|
|
36
|
+
height: 36px;
|
|
37
|
+
padding: 0 16px;
|
|
38
|
+
flex-shrink: 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.opm-msg {
|
|
42
|
+
margin: 0 0 10px;
|
|
43
|
+
font-size: 12px;
|
|
44
|
+
color: #646970;
|
|
45
|
+
min-height: 18px;
|
|
46
|
+
flex-shrink: 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.opm-grid {
|
|
50
|
+
display: grid;
|
|
51
|
+
grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
|
|
52
|
+
gap: 5px;
|
|
53
|
+
align-content: start;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.opm-item {
|
|
57
|
+
position: relative;
|
|
58
|
+
aspect-ratio: 1;
|
|
59
|
+
overflow: hidden;
|
|
60
|
+
border-radius: 3px;
|
|
61
|
+
cursor: pointer;
|
|
62
|
+
background: #dcdcde;
|
|
63
|
+
border: 2px solid transparent;
|
|
64
|
+
transition: border-color .15s, transform .1s;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.opm-item:hover {
|
|
68
|
+
border-color: #2271b1;
|
|
69
|
+
transform: scale(1.02);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.opm-item img {
|
|
73
|
+
width: 100%;
|
|
74
|
+
height: 100%;
|
|
75
|
+
object-fit: cover;
|
|
76
|
+
display: block;
|
|
77
|
+
transition: opacity .2s;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.opm-item:hover img {
|
|
81
|
+
opacity: .85;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.opm-footer {
|
|
85
|
+
margin-top: 12px;
|
|
86
|
+
text-align: center;
|
|
87
|
+
flex-shrink: 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.opm-more {
|
|
91
|
+
padding: 6px 24px;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.opm-item.opm-busy::after {
|
|
95
|
+
content: '';
|
|
96
|
+
position: absolute;
|
|
97
|
+
inset: 0;
|
|
98
|
+
background:
|
|
99
|
+
rgba(255,255,255,.65)
|
|
100
|
+
url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 50 50'%3E%3Ccircle cx='25' cy='25' r='18' fill='none' stroke='%232271b1' stroke-width='5' stroke-dasharray='28 57'%3E%3CanimateTransform attributeName='transform' type='rotate' from='0 25 25' to='360 25 25' dur='.65s' repeatCount='indefinite'/%3E%3C/circle%3E%3C/svg%3E")
|
|
101
|
+
center / 32px no-repeat;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.opm-item.opm-done::after {
|
|
105
|
+
content: '\2713';
|
|
106
|
+
position: absolute;
|
|
107
|
+
inset: 0;
|
|
108
|
+
display: flex;
|
|
109
|
+
align-items: center;
|
|
110
|
+
justify-content: center;
|
|
111
|
+
font-size: 32px;
|
|
112
|
+
color: #00a32a;
|
|
113
|
+
background: rgba(255,255,255,.75);
|
|
114
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/* global jQuery, wp, opm */
|
|
2
|
+
(function ($, wp, cfg) {
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
if (!wp || !wp.media || !wp.media.view) return;
|
|
6
|
+
|
|
7
|
+
function toAscii(str) {
|
|
8
|
+
return String(str || '').replace(/[^\x20-\x7E]/g, '').trim();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* ── View ─────────────────────────────────────────── */
|
|
12
|
+
var OpmView = wp.media.View.extend({
|
|
13
|
+
className: 'opm-wrap',
|
|
14
|
+
|
|
15
|
+
events: {
|
|
16
|
+
'keydown .opm-q': 'onKey',
|
|
17
|
+
'click .opm-btn': 'run',
|
|
18
|
+
'click .opm-item': 'pick',
|
|
19
|
+
'click .opm-more': 'loadMore',
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
initialize: function () {
|
|
23
|
+
this.page = 1;
|
|
24
|
+
this.query = '';
|
|
25
|
+
this.busy = false;
|
|
26
|
+
this.total = 0;
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
render: function () {
|
|
30
|
+
this.$el.html(
|
|
31
|
+
'<div class="opm-bar">' +
|
|
32
|
+
'<input class="opm-q" type="text" placeholder="Search images\u2026" autofocus />' +
|
|
33
|
+
'<button class="opm-btn button button-primary">Search</button>' +
|
|
34
|
+
'</div>' +
|
|
35
|
+
'<p class="opm-msg"></p>' +
|
|
36
|
+
'<div class="opm-grid"></div>' +
|
|
37
|
+
'<div class="opm-footer"></div>'
|
|
38
|
+
);
|
|
39
|
+
return this;
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
onKey: function (e) { if (13 === e.which) this.run(); },
|
|
43
|
+
|
|
44
|
+
run: function () {
|
|
45
|
+
var q = this.$('.opm-q').val().trim();
|
|
46
|
+
if (!q || this.busy) return;
|
|
47
|
+
this.query = q;
|
|
48
|
+
this.page = 1;
|
|
49
|
+
this.total = 0;
|
|
50
|
+
this.$('.opm-grid').empty();
|
|
51
|
+
this.$('.opm-footer').empty();
|
|
52
|
+
this.fetch();
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
loadMore: function () {
|
|
56
|
+
if (this.busy) return;
|
|
57
|
+
this.page++;
|
|
58
|
+
this.fetch();
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
fetch: function () {
|
|
62
|
+
var self = this;
|
|
63
|
+
this.busy = true;
|
|
64
|
+
this.$('.opm-more').prop('disabled', true).text('Loading\u2026');
|
|
65
|
+
if (this.page === 1) this.msg('Searching\u2026');
|
|
66
|
+
|
|
67
|
+
$.ajax({
|
|
68
|
+
url: cfg.root + '/search',
|
|
69
|
+
data: { q: self.query, page: self.page },
|
|
70
|
+
beforeSend: function (xhr) {
|
|
71
|
+
xhr.setRequestHeader('X-WP-Nonce', cfg.nonce);
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
.done(function (res) {
|
|
75
|
+
self.busy = false;
|
|
76
|
+
self.total = res.count || 0;
|
|
77
|
+
var loaded = (self.page - 1) * 20 + (res.results || []).length;
|
|
78
|
+
self.msg(self.total + ' results \u2014 showing ' + loaded);
|
|
79
|
+
self.paint(res.results || []);
|
|
80
|
+
self.updateFooter(loaded);
|
|
81
|
+
})
|
|
82
|
+
.fail(function (xhr) {
|
|
83
|
+
self.busy = false;
|
|
84
|
+
var msg = xhr.responseJSON && xhr.responseJSON.message
|
|
85
|
+
? xhr.responseJSON.message
|
|
86
|
+
: 'Search failed (HTTP ' + xhr.status + ')';
|
|
87
|
+
self.msg(msg);
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
paint: function (items) {
|
|
92
|
+
var $g = this.$('.opm-grid');
|
|
93
|
+
if (!items.length && this.page === 1) { this.msg('No results found.'); return; }
|
|
94
|
+
items.forEach(function (img) {
|
|
95
|
+
$g.append(
|
|
96
|
+
'<div class="opm-item"' +
|
|
97
|
+
' data-url="' + img.url + '"' +
|
|
98
|
+
' data-title="' + (img.title || '').replace(/"/g, '"') + '"' +
|
|
99
|
+
' data-creator="' + (img.creator || '').replace(/"/g, '"') + '">' +
|
|
100
|
+
'<img src="' + img.thumb + '" alt="" loading="lazy" />' +
|
|
101
|
+
'</div>'
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
updateFooter: function (loaded) {
|
|
107
|
+
this.$('.opm-footer').empty();
|
|
108
|
+
if (loaded < this.total) {
|
|
109
|
+
this.$('.opm-footer').html('<button class="opm-more button">Load more</button>');
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
pick: function (e) {
|
|
114
|
+
var self = this;
|
|
115
|
+
var $item = $(e.currentTarget);
|
|
116
|
+
if ($item.hasClass('opm-busy') || $item.hasClass('opm-done')) return;
|
|
117
|
+
|
|
118
|
+
$item.addClass('opm-busy');
|
|
119
|
+
self.msg('Downloading\u2026');
|
|
120
|
+
|
|
121
|
+
$.ajax({
|
|
122
|
+
url: cfg.root + '/download',
|
|
123
|
+
method: 'POST',
|
|
124
|
+
contentType: 'application/json',
|
|
125
|
+
data: JSON.stringify({
|
|
126
|
+
url: $item.data('url'),
|
|
127
|
+
title: toAscii( String($item.data('title') || '') ),
|
|
128
|
+
creator: toAscii( String($item.data('creator') || '') ),
|
|
129
|
+
}),
|
|
130
|
+
beforeSend: function (xhr) {
|
|
131
|
+
xhr.setRequestHeader('X-WP-Nonce', cfg.nonce);
|
|
132
|
+
},
|
|
133
|
+
})
|
|
134
|
+
.done(function (att) {
|
|
135
|
+
$item.removeClass('opm-busy').addClass('opm-done');
|
|
136
|
+
self.msg('Added to media library.');
|
|
137
|
+
self.select(att);
|
|
138
|
+
})
|
|
139
|
+
.fail(function (xhr) {
|
|
140
|
+
$item.removeClass('opm-busy');
|
|
141
|
+
var msg = xhr.responseJSON && xhr.responseJSON.message
|
|
142
|
+
? xhr.responseJSON.message
|
|
143
|
+
: 'Download failed (HTTP ' + xhr.status + ')';
|
|
144
|
+
self.msg(msg);
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
/* wp_prepare_attachment_for_js returns the exact backbone format */
|
|
149
|
+
select: function (data) {
|
|
150
|
+
var frame = this.controller;
|
|
151
|
+
try {
|
|
152
|
+
var model = new wp.media.model.Attachment(data);
|
|
153
|
+
model.set(data);
|
|
154
|
+
frame.state('library').get('selection').reset([model]);
|
|
155
|
+
frame.setState('library');
|
|
156
|
+
} catch (e) {
|
|
157
|
+
frame.close();
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
msg: function (text) { this.$('.opm-msg').text(text); },
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
/* ── Router tab injection ─────────────────────────── */
|
|
165
|
+
function inject(frame) {
|
|
166
|
+
frame.on('router:render:browse', function (view) {
|
|
167
|
+
view.set({ opm: { text: 'Open Media', priority: 60 } });
|
|
168
|
+
});
|
|
169
|
+
frame.on('content:render:opm', function () {
|
|
170
|
+
var v = new OpmView({ controller: frame });
|
|
171
|
+
v.render();
|
|
172
|
+
frame.content.set(v);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
var origInit = wp.media.view.MediaFrame.prototype.initialize;
|
|
177
|
+
wp.media.view.MediaFrame.prototype.initialize = function () {
|
|
178
|
+
origInit.apply(this, arguments);
|
|
179
|
+
inject(this);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
}(jQuery, window.wp, window.opm));
|