Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ale-latte committed Oct 2, 2019
2 parents 53d975e + b1eca65 commit 61e6233
Show file tree
Hide file tree
Showing 21 changed files with 497 additions and 292 deletions.
48 changes: 25 additions & 23 deletions classes/class-p4ct-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,23 +617,24 @@ protected function set_general_context( &$context ) {
'order' => 'DESC',
],
];

$context['strings'] = [
'issue' => __( 'issue', 'gpea_theme' ),
'topic' => __( 'topic', 'gpea_theme' ),
'posts' => __( 'posts', 'gpea_theme' ),
'advanced_search' => __( 'advanced_search', 'gpea_theme' ),
'filters' => __( 'filters', 'gpea_theme' ),
'none' => __( 'None', 'gpea_theme' ),
'start_typing' => __( 'Start typing', 'gpea_theme' ),
'search_label' => __( 'Search', 'gpea_theme' ),
'reset_filters' => __( 'Reset Filters', 'gpea_theme' ),
'sort_by' => __( 'Sort by', 'gpea_theme' ),
'nothing_found' => __( 'Nothing found, sorry.', 'gpea_theme' ),
'any' => __( 'Any', 'gpea_theme' ),
'any_issue' => __( 'Any issue', 'gpea_theme' ),
'any_topic' => __( 'Any topic', 'gpea_theme' ),
];
$context['is_search_page'] = '1';

// $context['strings'] = [
// 'issue' => __( 'issue', 'gpea_theme' ),
// 'topic' => __( 'topic', 'gpea_theme' ),
// 'posts' => __( 'posts', 'gpea_theme' ),
// 'advanced_search' => __( 'advanced_search', 'gpea_theme' ),
// 'filters' => __( 'filters', 'gpea_theme' ),
// 'none' => __( 'None', 'gpea_theme' ),
// 'start_typing' => __( 'Start typing', 'gpea_theme' ),
// 'search_label' => __( 'Search', 'gpea_theme' ),
// 'reset_filters' => __( 'Reset Filters', 'gpea_theme' ),
// 'sort_by' => __( 'Sort by', 'gpea_theme' ),
// 'nothing_found' => __( 'Nothing found, sorry.', 'gpea_theme' ),
// 'any' => __( 'Any', 'gpea_theme' ),
// 'any_issue' => __( 'Any issue', 'gpea_theme' ),
// 'any_topic' => __( 'Any topic', 'gpea_theme' ),
// ];

if ( $this->search_query ) {
$context['page_title'] = sprintf(
Expand Down Expand Up @@ -941,15 +942,16 @@ function( $issue ) {

/**
* Load assets only on the search page.
* Update 8/9/2019: on ALL pages -> moved to class-p4ct-site.php
*/
public function enqueue_public_assets() {
if ( is_search() ) {
$js_creation = filectime( get_stylesheet_directory() . '/static/js/search.js' );
// if ( is_search() ) {
// $js_creation = filectime( get_stylesheet_directory() . '/static/js/search.js' );

wp_register_script( 'search-script', get_stylesheet_directory_uri() . '/static/js/search.js', [], $js_creation, true );
wp_localize_script( 'search-script', 'localizations', $this->localizations );
wp_enqueue_script( 'search-script' );
}
// wp_register_script( 'search-script', get_stylesheet_directory_uri() . '/static/js/search.js', [], $js_creation, true );
// wp_localize_script( 'search-script', 'localizations', $this->localizations );
// wp_enqueue_script( 'search-script' );
// }
}
}
}
31 changes: 30 additions & 1 deletion classes/class-p4ct-site.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class P4CT_Site {
*/
protected $services;

const SHOW_SCROLL_TIMES = 2;

/**
* P4CT_Site constructor.
*
Expand Down Expand Up @@ -87,7 +89,7 @@ protected function hooks() {
remove_action( 'wp_ajax_get_paged_posts', [ 'P4MT\P4_ElasticSearch', 'get_paged_posts' ] );
remove_action( 'wp_ajax_nopriv_get_paged_posts', [ 'P4MT\P4_ElasticSearch', 'get_paged_posts' ] );
add_action( 'wp_ajax_get_paged_posts', [ 'P4CT_ElasticSearch', 'get_paged_posts' ] );
add_action( 'wp_ajax_nopriv_get_paged_posts', [ 'P4CT_ElasticSearch', 'get_paged_posts' ] );
add_action( 'wp_ajax_nopriv_get_paged_posts', [ 'P4CT_ElasticSearch', 'get_paged_posts' ] );

}

Expand Down Expand Up @@ -223,6 +225,25 @@ public function add_to_context( $context ) {
'my_preferences' => __( 'My Preferences', 'gpea_theme' ),
];

$context['search_strings'] = [
'issue' => __( 'issue', 'gpea_theme' ),
'topic' => __( 'topic', 'gpea_theme' ),
'posts' => __( 'posts', 'gpea_theme' ),
'advanced_search' => __( 'advanced_search', 'gpea_theme' ),
'filters' => __( 'filters', 'gpea_theme' ),
'none' => __( 'None', 'gpea_theme' ),
'start_typing' => __( 'Start typing', 'gpea_theme' ),
'search_label' => __( 'Search', 'gpea_theme' ),
'reset_filters' => __( 'Reset Filters', 'gpea_theme' ),
'sort_by' => __( 'Sort by', 'gpea_theme' ),
'nothing_found' => __( 'Nothing found, sorry.', 'gpea_theme' ),
'any' => __( 'Any', 'gpea_theme' ),
'any_issue' => __( 'Any issue', 'gpea_theme' ),
'any_topic' => __( 'Any topic', 'gpea_theme' ),
];



return $context;
}

Expand Down Expand Up @@ -293,6 +314,7 @@ public function enqueue_admin_assets( $hook ) {
public function enqueue_public_assets( $hook ) {
$css_creation = filectime( get_stylesheet_directory() . '/static/css/style.css' );
$js_creation = filectime( get_stylesheet_directory() . '/static/js/script.js' );
$search_js_creation = filectime( get_stylesheet_directory() . '/static/js/search.js' );

$css_fonts = gpea_get_option( 'gpea_css_fonts' ) ? gpea_get_option( 'gpea_css_fonts' ) : 'hk-fonts.css';
wp_enqueue_style( 'child-style-fonts', get_stylesheet_directory_uri() . '/static/css/' . $css_fonts, [], $css_creation );
Expand All @@ -301,6 +323,13 @@ public function enqueue_public_assets( $hook ) {
wp_localize_script( 'child-script', 'localizations', [
'ajaxurl' => admin_url( 'admin-ajax.php' ),
]);

wp_register_script( 'search-script', get_stylesheet_directory_uri() . '/static/js/search.js', [], $search_js_creation, true );
wp_localize_script( 'search-script', 'localizations', [
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'show_scroll_times' => self::SHOW_SCROLL_TIMES,
] );
wp_enqueue_script( 'search-script' );
}

/**
Expand Down
6 changes: 6 additions & 0 deletions frontend/js/Donation/geo-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,8 @@ jQuery(document).on('change',".js-country-select", function(){
});
regexPhone = window.NRO_PROPERTIES['HK'].regex.phone;
regexPhoneMessage = window.NRO_PROPERTIES['HK'].validation.format_phone;
jQuery('.en__field--NOT_TAGGED_34').hide();
jQuery('.enform').removeClass('extra-padding-bottom');
// citySelect.append(citySelectOptions);

} else if ( this.value == 'TW' ) {
Expand All @@ -979,6 +981,8 @@ jQuery(document).on('change',".js-country-select", function(){
regexPhone = window.NRO_PROPERTIES['TW'].regex.phone;
regexPhoneMessage = window.NRO_PROPERTIES['TW'].validation.format_phone;
// citySelect.append(citySelectOptions);
jQuery('.en__field--NOT_TAGGED_34').show();
jQuery('.enform').addClass('extra-padding-bottom');

} else {
jQuery('input[name="supporter.city"]').val('-');
Expand All @@ -995,6 +999,8 @@ jQuery(document).on('change',".js-country-select", function(){
jQuery('.js-region-select').html(o2);
regexPhone = window.NRO_PROPERTIES[NRO].regex.phone_general;
regexPhoneMessage = window.NRO_PROPERTIES[NRO].validation.format_phone_general;
jQuery('.en__field--NOT_TAGGED_34').hide();
jQuery('.enform').removeClass('extra-padding-bottom');
}
});

Expand Down
3 changes: 3 additions & 0 deletions frontend/js/Donation/lexicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export default function() {
jQuery('label[for="en__field_supporter_NOT_TAGGED_311"]').html(window.NRO_PROPERTIES[NRO].gift.type.recurring);
jQuery('label[for="en__field_supporter_NOT_TAGGED_310"]').html(window.NRO_PROPERTIES[NRO].gift.type.single);

// national id
jQuery('label[for="en__field_supporter_NOT_TAGGED_34"]').html(window.NRO_PROPERTIES[NRO].form.labels.national_id);

jQuery('label[for="en__field_transaction_ccnumber"]').html(window.NRO_PROPERTIES[NRO].form.labels.card_number);
jQuery('label[for="en__field_transaction_ccexpire"]').html(window.NRO_PROPERTIES[NRO].form.labels.expiry);
jQuery('label[for="en__field_transaction_ccvv"]').html(window.NRO_PROPERTIES[NRO].form.labels.cvv);
Expand Down
26 changes: 25 additions & 1 deletion frontend/js/Donation/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ const required = {
message: requiredMessage,
};

validate.validators.validateTwNationalId = function(id, options, key, attributes){
// console.log(id);
// leave it optional?
if (!id) return;
const cityValidation = new Array(1,10,19,28,37,46,55,64,39,73,82, 2,11,20,48,29,38,47,56,65,74,83,21, 3,12,30)
id = id.toUpperCase();
if (id.search(/^[A-Z](1|2)\d{8}$/i) == -1) {
return window.NRO_PROPERTIES[NRO].validation.format_id;
} else {
id = id.split('');
var total = cityValidation[id[0].charCodeAt(0)-65];
for(var i=1; i<=8; i++){
total += eval(id[i]) * (9 - i);
}
total += eval(id[9]);
if ((total%10 !== 0 )) return window.NRO_PROPERTIES[NRO].validation.format_id;
else return;
}
};

const amountConstraintsRecurring = {
['en__field--donationAmt']: {
presence: required,
Expand Down Expand Up @@ -81,6 +101,9 @@ const dataConstraints = {
presence: required,
length: { maximum: 255 },
},
['en__field--NOT_TAGGED_34']: {
validateTwNationalId: {},
},
// ['en__field--NOT_TAGGED_33']: {
// presence: false,
// format: {
Expand Down Expand Up @@ -141,8 +164,9 @@ const allConstraints = Object.assign(
);

function prepareFormForValidation(form) {
for (const name in allConstraints) {
for (const name in allConstraints) {
if (allConstraints.hasOwnProperty(name)) {
console.log(name);
// const options = allConstraints[name];
let input = form.querySelector('.' + name + ' input');
if (!input) input = form.querySelector('.' + name + ' select');
Expand Down
28 changes: 28 additions & 0 deletions frontend/js/components/dynamic-search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const $ = jQuery;
window.over_sb = null; // fix issue with jQuery autoComplete v1.0.7

export default function() {
const $dynamicSearch = $('.dynamic-search');
const $dynamicSearchTrigger = $('.js-dynamic-search');
const $dynamicSearchClose = $('.js-close-dynamic-search');

$dynamicSearchTrigger.on('click', function(e) {
if ($dynamicSearch.length) {
$dynamicSearch.toggleClass('is-visible');
$(document.body).toggleClass('has-open-dynamic-search');
}

setTimeout(() => {
$('#search_input').focus();
}, 100);

e.preventDefault();
});

$dynamicSearchClose.on('click', function(e) {
$('#search_input').blur();
$dynamicSearch.removeClass('is-visible');
$(document.body).removeClass('has-open-dynamic-search');
e.preventDefault();
});
}
7 changes: 6 additions & 1 deletion frontend/js/donation-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ function initDonation(Swiper, Scroll) {
// Quit if we aren't in a donation page
if (!document.querySelector('.page-template-donation')) return;

// show national id if taiwan
if ( 'TW' === NRO ) {
jQuery('.en__field--NOT_TAGGED_34').show();
}

// activate dollar handles if any
dollarHandles();

Expand Down Expand Up @@ -212,7 +217,7 @@ function initDonation(Swiper, Scroll) {
// var pageJsonReplicated = pageJson;
pageJsonReplicated.amount = amountSent;
pageJsonReplicated.country = jQuery("input[name='supporter.country']").val();
pageJsonReplicated.currency = window.NRO_PROPERTIES['HK'].currency;
pageJsonReplicated.currency = window.NRO_PROPERTIES[NRO].currency;
pageJsonReplicated.pageNumber = 2;
pageJsonReplicated.recurring = ( jQuery("input[name='supporter.NOT_TAGGED_31']:checked").val() == 'N' ) ? 'false' : 'true';
pageJsonReplicated.paymentType = jQuery("input[name='transaction.paymenttype']").val();
Expand Down
3 changes: 3 additions & 0 deletions frontend/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import parallax from './components/parallax';
import scrollWay from './components/scroll-way';
import articleList from './components/article-list';
import facebookVideo from './components/facebook-video';
import dynamicSearch from './components/dynamic-search';

import petitionThankyou from './petition-thankyou';

Expand Down Expand Up @@ -97,6 +98,8 @@ document.addEventListener('DOMContentLoaded', function(event) {

facebookVideo();

dynamicSearch();

AOS.init({
easing: 'ease-in-out-cubic',
once: true,
Expand Down
9 changes: 9 additions & 0 deletions frontend/scss/_general.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ body {
overflow: hidden;
}
}

&.has-open-dynamic-search {
overflow: hidden;
}
}

h1,
Expand Down Expand Up @@ -210,3 +214,8 @@ body.is-loading .body-spinner {
margin-left: -32px;
}
}

/* remove stuff from mater */
svg.external_link {
display: none;
}
61 changes: 60 additions & 1 deletion frontend/scss/_page-search.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
body.search {
body.search,
.dynamic-search {
.live-search,
.advanced-search {
padding: 20px 0;
Expand Down Expand Up @@ -133,3 +134,61 @@ body.search {
}
}
}

.dynamic-search {
position: fixed;
top: 96px; // see _header.scss
bottom: 0;
left: 0;
right: 0;
z-index: 3;
background: rgba(0, 0, 0, 0.7);
visibility: hidden;
opacity: 0;
transition: opacity 200ms linear, visibility 0ms linear 240ms;

&.is-visible {
visibility: visible;
opacity: 1;
transition: opacity 200ms linear, visibility 0ms linear 0ms;
}

@include greaterThan('sm') {
top: 50px; // see _header.scss
}

.live-search {
max-height: 100%;
// overflow-y: scroll;
overflow-y: auto;
transform: translateY(-20px);
transition: transform 140ms ease-in-out;

@include lessThan('sm') {
.ct-container {
position: relative;
}
}
}

&.is-visible .live-search {
transform: translateY(0);
}

.close-dynamic-search-button {
position: absolute;
top: 0px;
right: 20px;
margin: 0;
padding: 5px;
border: none;
background: transparent;
font-size: 24px;
z-index: 4;
cursor: pointer;

@include greaterThan('sm') {
top: 14px;
}
}
}
10 changes: 10 additions & 0 deletions frontend/scss/_template-donation-engaging.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
transition-delay: .1s;
transition-timing-function: linear;

&.extra-padding-bottom {
padding-bottom: 75px;
}

.en__field__element {
width: 100%;
}
Expand Down Expand Up @@ -244,6 +248,12 @@
font-size: 14px;
color: $color-grey;
}

// hide national id field for taiwan
.en__field--NOT_TAGGED_34 {
display: none;
}

}

/* steps visible here */
Expand Down
2 changes: 1 addition & 1 deletion static/css/style.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/css/style.css.map

Large diffs are not rendered by default.

Loading

0 comments on commit 61e6233

Please sign in to comment.