Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional template locations #64

Merged
merged 18 commits into from
Aug 6, 2017
Merged

Additional template locations #64

merged 18 commits into from
Aug 6, 2017

Conversation

senky
Copy link
Contributor

@senky senky commented Aug 2, 2017

@@ -21,4 +21,6 @@
$lang = array_merge($lang, array(
'ADBLOCKER_TITLE' => 'Ad blocker detected',
'ADBLOCKER_MESSAGE' => 'Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker on our website.',

'POP_UP_TITLE' => 'ADVERTISEMENT',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead call this key ADVERTISEMENT. Then make the translation Advertisement (not all caps). This may come in handy in other places. We can make it uppercase with Twig in the template.


$this->template->assign_vars(array(
'POP_UP_COOKIE_NAME' => $this->config['cookie_name'] . '_pop_up',
'POP_UP_COOKIE_EXPIRES' => gmdate('D, d M Y H:i:s T', time() + 86400),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this more readable:

gmdate('D, d M Y H:i:s T', strtotime('+1 day')),

* @param \phpbb\language\language $language Language object
* @param \phpbb\request\request $request Request object
* @param \phpbb\config\config $config Config object
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing template from doc

@@ -0,0 +1,14 @@
{% if AD_POP_UP %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be safe should probably also add AD_POP_UP_ID to this conditional


$(window).on('load', function() {
document.cookie = '{{ POP_UP_COOKIE_NAME }}=true; expires={{ POP_UP_COOKIE_EXPIRES }}; path={{ POP_UP_COOKIE_PATH }}';
phpbb.alert('{{ lang('POP_UP_TITLE') }}', `{% include '@phpbb_ads/phpbb_ads_default.html' %}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where you can easily uppercase this string like this:

{{ lang('POP_UP_TITLE')|upper }}

@senky
Copy link
Contributor Author

senky commented Aug 2, 2017

!set WIP

@phpbb-user phpbb-user added the WIP label Aug 2, 2017
'use strict';

$(window).on('scroll', function() {
var page_footer = $('#page-footer');
Copy link
Contributor

@iMattPro iMattPro Aug 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when storing an jquery object in a var it's a good practice to name those vars with $, ie: $page_footer

Also for JS lets use camelCase, ie: $pageFooter

$(window).on('scroll', function() {
var page_footer = $('#page-footer');
if (page_footer.offset().top - $(window).scrollTop() < $(window).height()) {
$('#phpbbad-slide-up').css({bottom: 0});
Copy link
Contributor

@iMattPro iMattPro Aug 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets also add something that hides/slides the ad back down when the user scrolls back up from the bottom, so it goes away.

May be as simple as

if (page_footer.offset().top - $(window).scrollTop() > $(window).height()) {
	$('#phpbbad-slide-up').css({bottom: '-1000px'});
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something along these lines seems to work... could maybe use a little more finesse though:

$(window).on('scroll', function() {
	var $pageFooter = $('#page-footer'),
		$slider = $('#phpbbad-slide-up'),
		position = $pageFooter.offset().top - $(window).scrollTop();
	if (position < $(window).height()) {
		$slider.css({bottom: 0});
	}
	if (position > $(window).height()) {
		$slider.css({bottom: '-1000px'});
	}
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That video is with the code above ;)

#phpbbad-slide-up {
position: fixed;
right: 0;
bottom: -100%;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a much bigger offset...in case of large ads..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh just noticed it's 100%... Maybe go 200% lol ???

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we must find real solution. Otherwise animation will not work as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transform works fine.


#phpbbad-slide-up {
position: fixed;
right: 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably remove this and just use width: 100%; for centering ads.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VSEphpbb to be honest, I didn't want this type of location to go that way. I always wanted to have it right aligned, shrank to the minimum space. I see your point now, as you posted a video. Right align won't look good on small screens. The only problem I have with 100% width is that content behind will be visible in some cases, but not clickable.

@senky
Copy link
Contributor Author

senky commented Aug 6, 2017

!unset WIP

@phpbb-user phpbb-user removed the WIP label Aug 6, 2017
@iMattPro
Copy link
Contributor

iMattPro commented Aug 6, 2017 via email

})(jQuery);
</script>
{% endif %}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets clean this up a little using the new includes folder and moving the actual ad code to their own dedicated files so this file may look more like:

{% if AD_POP_UP and AD_POP_UP_ID %}
	{% set PHPBB_ADS_STYLE = '' %}
	{% set PHPBB_ADS_CODE, PHPBB_ADS_ID = AD_POP_UP, AD_POP_UP_ID %}
	{% include '@phpbb_ads/includes/phpbb_ads_pop_up.html' %}
{% endif %}

{% if AD_SLIDE_UP and AD_SLIDE_UP_ID %}
	{% set PHPBB_ADS_STYLE = '' %}
	{% set PHPBB_ADS_CODE, PHPBB_ADS_ID = AD_SLIDE_UP, AD_SLIDE_UP_ID %}
	{% include '@phpbb_ads/includes/phpbb_ads_slide_up.html' %}
{% endif %}

You'll probably need to merge the master branch into your branch here to get it up to date and have the new include folder.

var $pageFooter = $('#page-footer'),
$slider = $('#phpbbad-slide-up'),
position = $pageFooter.offset().top - $(window).scrollTop(),
is_high_enough = $('body').height() > $(window).height() + $slider.height();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing some unextepted behavior. For example, I have one ad on apge that scrolls only a little, and the ad never appears because it's height is greater than the amount to scroll (due to + $slider.height()).

Also I notice that because you use $page-footer as part of the equation when a page loads that already displays some of the footer (but not all) you can either have 2 outcomes: Scroll to bottom reveals no ad...or there is enough scroll to reveal the ad, but scroll back up does not disappear the ad (because some of page-footer is still visible on the whole page).

Is that by design, because my expectation was that the ad would appear when you reach the bottom of a page scroll and imediately go away the instant you scroll back up a bit?

@@ -0,0 +1,10 @@
<script>
(function($) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets protect window and document, like:

(function($, window, document, undefined) {
....
})(jQuery, document, window);

</div>

<script>
(function($) {
Copy link
Contributor

@iMattPro iMattPro Aug 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here, lets protect the window and document

if ($(window).scrollTop() + $(window).height() >= $(document).height()) {
$slider.css({transform: 'translateY(0)'});
}
else {
Copy link
Contributor

@iMattPro iMattPro Aug 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else should go on previous line, like: } else {

var $slider = $('#phpbbad-slide-up');

$(window).on('scroll', function() {
if ($(window).scrollTop() + $(window).height() >= $(document).height()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(window) in here can technically be replaced with $(this)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but it's easier to read that way.

}
});

$('.phpbbad-slide-up-icon').on('click', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a name more like phpbb-slide-up-close

});

$('.phpbbad-slide-up-icon').on('click', function() {
$slider.css({transform: 'translateY(100%)'});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to have dedicated functions for this: hideSlider and showSlider so that it makes perfect sens in their usages above which is showing it and which is hiding it. Or perhaps a jQuery function we create called $fn.toggleSlider() that accepts the args hide|show ??

@@ -0,0 +1,25 @@
<div id="phpbbad-slide-up">
<div class="phpbbad-slide-up-hide"><i class="phpbbad-slide-up-icon icon fa-chevron-down"></i></div>
Copy link
Contributor

@iMattPro iMattPro Aug 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add a title to the icon so a mouse-over says "Hide advertisement"

@iMattPro iMattPro merged commit 86a220b into phpbb-extensions:master Aug 6, 2017
@senky senky deleted the more-locations branch August 6, 2017 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Events to add
3 participants