Skip to content
This repository was archived by the owner on Mar 26, 2021. It is now read-only.

Commit 932b10e

Browse files
authored
Merge pull request #47 from INN/9-expiration-date-picker
Revisions to the NPR API editor meta box
2 parents 806b3ec + 22af682 commit 932b10e

19 files changed

Lines changed: 1745 additions & 370 deletions

assets/css/jquery-ui.css

Lines changed: 855 additions & 0 deletions
Large diffs are not rendered by default.

assets/css/meta-box.css

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Styles for the NPR Story API meta box
3+
*/
4+
#ds_npr_document_meta ul ul {
5+
margin-top: 6px;
6+
}
7+
#ds_npr_document_meta ul ul ul {
8+
padding-left: 24px;
9+
}
10+
#nprone-expiry {
11+
border-top: 1px solid #eee;
12+
padding-top: 6px;
13+
}
14+
#nprone-expiry-form,
15+
#nprone-expiry-form select,
16+
#nprone-expiry-form input {
17+
font-size: 12px;
18+
padding-left: 0;
19+
padding-right: 0;
20+
}
21+
#nprone-expiry-form .row {
22+
clear: both;
23+
margin-top: 6px;
24+
line-height: 28px;
25+
}
26+
button.link-effect {
27+
border: none;
28+
color: #0073aa;
29+
text-decoration: underline;
30+
}
31+
#nprone-expiry-month {
32+
vertical-align: baseline;
33+
margin: 0;
34+
}
35+
36+
/*
37+
* Minimal Datepicker styles
38+
*/
39+
#ui-datepicker-div {
40+
background: #fff;
41+
border: 1px solid #e5e5e5;
42+
padding: 6px;
43+
box-shadow: 0 3px 5px rgba(0,0,0,.2);
44+
}
45+
.ui-datepicker .ui-datepicker-header {
46+
border: none;
47+
}
48+
.ui-datepicker-calendar .ui-state-default {
49+
text-decoration: none;
50+
background-color: transparent;
51+
}
52+
.ui-datepicker .ui-datepicker-current-day a {
53+
border-color: #0073aa #006799 #006799;
54+
background: #0085ba;
55+
color: #fff;
56+
font-weight: bold;
57+
}
58+
.ui-datepicker .ui-datepicker-today a {
59+
background: #fff;
60+
border: 1px solid #c5c5c5;
61+
font-weight: bold;
62+
color: #000;
63+
}
6.83 KB
Loading
6.82 KB
Loading
4.44 KB
Loading
6.83 KB
Loading
4.44 KB
Loading
6.15 KB
Loading

assets/js/meta-box.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* NPR Story API meta box functions and features
3+
*/
4+
document.addEventListener('DOMContentLoaded', () => {
5+
'use strict';
6+
var $ = jQuery;
7+
8+
// contains the inputs
9+
var $container = $( '#ds-npr-publish-actions' );
10+
11+
// initialize the form
12+
$container.find( 'input' ).on( 'change', li_checking );
13+
14+
// Upon update, do the thing
15+
li_checking.call( $container.find( '#send_to_api' ) );
16+
17+
/*
18+
* If a checkbox in an li gets unchecked, uncheck and disable its child li
19+
* If a checkbox in an li gets checked, enable its child li
20+
*/
21+
function li_checking( event ) {
22+
var checked = $( this ).prop('checked');
23+
var $results = $( this ).closest( 'li' ).children( 'ul' ).children( 'li' ); // Only get the first level of list.
24+
$results.each( function( element ) {
25+
// Triggering the change event on the child does not work.
26+
if ( checked ) {
27+
var recurse = $( this ).children( 'label' ).children( 'input' ).prop( 'disabled', false );
28+
li_checking.call( recurse );
29+
} else {
30+
recurse = $( this ).children( 'label' ).children( 'input' ).prop( 'disabled', true ).prop( 'checked', false );
31+
li_checking.call( recurse );
32+
}
33+
});
34+
}
35+
36+
// edit the time selector
37+
$( '#nprone-expiry-edit' ).on( 'click', function( event ) {
38+
event.preventDefault();
39+
$( '#nprone-expiry-form' ).toggleClass( 'hidden' );
40+
$( this ).toggleClass( 'hidden' );
41+
});
42+
// close the time selector
43+
$( '#nprone-expiry-cancel' ).on( 'click', function( event ) {
44+
event.preventDefault();
45+
$( '#nprone-expiry-form' ).toggleClass( 'hidden' );
46+
$( '#nprone-expiry-edit' ).toggleClass( 'hidden' );
47+
});
48+
// save the time selector
49+
$( '#nprone-expiry-ok' ).on( 'click', function( event ) {
50+
event.preventDefault();
51+
$( '#nprone-expiry-form' ).toggleClass( 'hidden' );
52+
$( '#nprone-expiry-edit' ).toggleClass( 'hidden' );
53+
54+
// but then it needs to update the displayed data in #nprone-expiry-display. How is it to do that?
55+
// This needs to take:
56+
// - the YYYY-MM-DD value of #nprone-expiry-datepicker
57+
// - the HH:MM value of #nprone-expiry-hour
58+
// and output a string in the format Apr 1, 2020 @ 09:01 / Nov 1, 2018 @ 23:59
59+
var d = new Date();
60+
var dateinput = $( '#nprone-expiry-datepicker' ).val().split('-');
61+
var timeinput = $( '#nprone-expiry-hour' ).val().split(':');
62+
63+
d.setFullYear(dateinput[0]);
64+
d.setMonth(dateinput[1] - 1); // because this is zero-indexed?
65+
d.setDate(dateinput[2]);
66+
d.setHours(timeinput[0]);
67+
d.setMinutes(timeinput[1]);
68+
69+
var string = d.toLocaleString("en-us", { month: "short" })
70+
+ " "
71+
+ d.getDate()
72+
+ ", "
73+
+ d.getFullYear()
74+
+ " @ "
75+
+ d.getHours()
76+
+ ":"
77+
+ (d.getMinutes() < 10? '0' : '') + d.getMinutes();
78+
79+
$( '#nprone-expiry-display time' ).text( string );
80+
});
81+
82+
83+
// Activate the date picker, if and only if the browser doesn't have a native datepicker
84+
// @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date#JavaScript
85+
var test = document.createElement( 'input' );
86+
test.type = 'date';
87+
if ( test.type !== 'date' ) {
88+
$( '#nprone-expiry-datepicker' ).attr('type', 'text').css('width', '8em').datepicker({
89+
dateFormat: 'yy-mm-dd'
90+
});
91+
}
92+
});

0 commit comments

Comments
 (0)