Skip to content

Commit 6c566dc

Browse files
committed
feat: Added media browser JS and fixed css font sizes
Also bumped version from `1.3.19` to `1.4.0`.
1 parent 5bb28d4 commit 6c566dc

5 files changed

Lines changed: 144 additions & 30 deletions

File tree

css/admin.css

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,13 @@
182182
--cs-font-family-default: 'Roboto', Tahoma, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
183183
--cs-font-size-default: .8125rem;
184184
--cs-font-size-small: .75rem;
185+
--cs-font-size-smaller: .688rem;
185186
--cs-font-size-h1: 1.438rem;
186-
--cs-font-size-h2: var(--cs-font-size-h1);
187-
--cs-font-size-h3: 1.438rem;
188-
--cs-font-size-h4: var(--cs-font-size-default);
189-
--cs-font-size-h5: .688rem;
190-
--cs-font-size-h6: .562rem;
187+
--cs-font-size-h2: 1.25rem;
188+
--cs-font-size-h3: 1.087rem;
189+
--cs-font-size-h4: .945rem;
190+
--cs-font-size-h5: .822rem;
191+
--cs-font-size-h6: .715rem;
191192
}
192193

193194
/* Arabic and Persian */
@@ -273,34 +274,40 @@ h6 {
273274
font-weight: 400;
274275
}
275276

276-
h1 {
277+
h1,
278+
.h1 {
277279
font-size: var(--cs-font-size-h1);
278-
line-height: 1.8125rem;
280+
line-height: 1.1;
279281
}
280282

281-
h2 {
283+
h2,
284+
.h2 {
282285
font-size: var(--cs-font-size-h2);
283-
line-height: 1.8125rem;
286+
line-height: 1.1;
284287
}
285288

286-
h3 {
289+
h3,
290+
.h3 {
287291
font-size: var(--cs-font-size-h3);
288-
line-height: 1.125rem;
292+
line-height: 1.2;
289293
}
290294

291-
h4 {
295+
h4,
296+
.h4 {
292297
font-size: var(--cs-font-size-h4);
293-
line-height: 1.125rem;
298+
line-height: 1.2;
294299
}
295300

296-
h5 {
301+
h5,
302+
.h5 {
297303
font-size: var(--cs-font-size-h5);
298-
line-height: 1.125rem;
304+
line-height: 1.2;
299305
}
300306

301-
h6 {
307+
h6,
308+
.h6 {
302309
font-size: var(--cs-font-size-h6);
303-
line-height: 1.125rem;
310+
line-height: 1.2;
304311
}
305312

306313
a:not(.btn, :hover, :focus, :active),
@@ -450,7 +457,7 @@ textarea {
450457

451458
.smaller,
452459
.text-small {
453-
font-size: .685rem !important;
460+
font-size: var(--cs-font-size-smaller) !important;
454461
}
455462

456463
.overflow-initial {
@@ -481,15 +488,15 @@ textarea {
481488
inline-size: 10% !important;
482489
}
483490

484-
.w-125 {
491+
.w-13 {
485492
inline-size: 12.5% !important;
486493
}
487494

488495
.w-15 {
489496
inline-size: 15% !important;
490497
}
491498

492-
.w-175 {
499+
.w-18 {
493500
inline-size: 17.5% !important;
494501
}
495502

@@ -1988,7 +1995,7 @@ textarea {
19881995

19891996
table th {
19901997
text-transform: uppercase;
1991-
font-size: var(--cs-font-size-h5);
1998+
font-size: var(--cs-font-size-smaller);
19921999
}
19932000

19942001
table th>input[type="checkbox"],
@@ -2158,8 +2165,8 @@ table td>input[type="checkbox"] {
21582165
}
21592166

21602167
.header .page-title {
2161-
font-size: 1.25rem;
2162-
line-height: 2.25rem;
2168+
font-size: var(--cs-font-size-h2);
2169+
line-height: 1.75;
21632170
color: var(--bs-white);
21642171
display: inline-block;
21652172
margin: 0;
@@ -2462,7 +2469,7 @@ body.csk-clean .footer .skeleton-footer-logo {
24622469
}
24632470

24642471
.note-btn-group .note-btn {
2465-
font-size: var(--cs-font-size-h5);
2472+
font-size: var(--cs-font-size-smaller);
24662473
padding: .25rem .5rem;
24672474
}
24682475

css/admin.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/admin.js

Lines changed: 110 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,30 @@
171171
window.attachEvent("on" + event, callback);
172172
}
173173
},
174+
/**
175+
* Adds a delegated event listener to the document.
176+
*
177+
* This allows event handling for elements that may not exist when
178+
* the listener is registered (similar to jQuery's '.on()').
179+
* It listens for the specified event type on the entire document,
180+
* and when the event bubbles up, checks if the event target (or one
181+
* of its ancestors) matches the provided CSS selector.
182+
*
183+
* @function delegate
184+
* @memberof csk.ui
185+
* @param {string} event - The name of the event to listen for.
186+
* @param {string} selector - A CSS selector to match the event target or its ancestors.
187+
* @param {Function} handler - The callback function to execute when a match is found.
188+
* @return {void}
189+
*/
190+
delegate: function(event, selector, handler) {
191+
document.addEventListener(event, function(e) {
192+
const target = e.target.closest(selector);
193+
if (target) {
194+
handler.call(target, e);
195+
}
196+
});
197+
},
174198
/**
175199
* Lazy load images.
176200
* @since 2.0
@@ -596,10 +620,9 @@
596620
};
597621

598622
/**
599-
* SKeleton Ping.
623+
* Skeleton Ping.
600624
* @since 2.100
601625
*/
602-
603626
csk.ping = {
604627
init : function(options) {
605628
var defaults = {
@@ -624,6 +647,90 @@
624647
}
625648
};
626649

650+
/**
651+
* Media Browser
652+
* @since 3.10.2
653+
*/
654+
csk.media = {
655+
/**
656+
* Currently selected editor for the opened media browser.
657+
* @type {HTMLElement}
658+
*/
659+
editor: null,
660+
661+
/**
662+
* Opens Media browser.
663+
* @param {HTMLElement} editor Summernote editor note.
664+
* @return {void}
665+
*/
666+
browse: function(editor) {
667+
csk.media.editor = editor;
668+
const $modal = $("#media-modal");
669+
const $browser = $("#media-browser");
670+
const $insert = $("#media-insert-btn");
671+
672+
$browser.html('<div class="text-center py-5 text-muted">'+csk.i18n.default.loading+'...</div>');
673+
$insert.prop('disabled', true);
674+
675+
// Load existing media
676+
csk.ajax.request(csk.config.adminURL + '/ajax/media', {
677+
type: 'GET',
678+
success: function(response) {
679+
if (response.results && response.results.length) {
680+
let html = '';
681+
response.results.forEach(file => {
682+
var source = document.getElementById("media-template").innerHTML,
683+
template = Handlebars.compile(source);
684+
html += template(file);
685+
});
686+
687+
$browser.html(html);
688+
} else {
689+
$browser.html('<div class="text-center py-5 text-muted">'+csk.i18n.default.no_data+'</div>');
690+
}
691+
}
692+
});
693+
694+
$modal.modal('show');
695+
},
696+
697+
/**
698+
* Handles media file selection.
699+
* @return {void}
700+
*/
701+
select: function() {
702+
$('#media-modal .media-item').removeClass('selected');
703+
$(this).addClass('selected');
704+
$('#media-modal #media-insert-btn').prop('disabled', false);
705+
},
706+
707+
/**
708+
* Handles inserting media into Summernote editor.
709+
* @return {void}
710+
*/
711+
insert: function() {
712+
const selected = $('#media-modal .media-item.selected');
713+
if (!selected.length || !csk.media.editor) return;
714+
715+
const $editor = $(csk.media.editor);
716+
if (!$editor.hasClass('summernote')) {
717+
console.warn('Invalid editor reference:', $editor);
718+
return;
719+
}
720+
721+
const url = selected.data('url');
722+
$editor.summernote('insertImage', url);
723+
$('#media-modal').modal('hide');
724+
},
725+
726+
init: function () {
727+
if (csk.media._initialized) return;
728+
csk.ui.delegate('click', '#media-modal .media-item', csk.media.select);
729+
csk.ui.delegate('click', '#media-modal #media-insert-btn', csk.media.insert);
730+
csk.media._initialized = true;
731+
}
732+
};
733+
627734
/** Things to do when the page is ready! */
628735
$(document).ready(function() {
629736
/**
@@ -1243,7 +1350,7 @@
12431350
if (typeof file !== "object") {
12441351
return false;
12451352
}
1246-
var source = document.getElementById("attachment-template").innerHTML,
1353+
var source = document.getElementById("media-template").innerHTML,
12471354
template = Handlebars.compile(source),
12481355
html = template(file);
12491356
$(html).hide().prependTo(".dropZone").fadeIn("slow");

0 commit comments

Comments
 (0)