Skip to content

Commit

Permalink
load helpers correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
tanthammar committed Feb 16, 2022
1 parent 5037607 commit 25ae66e
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 103 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
.env
.phpunit.result.cache
.phpunit.result.cache
/.idea
99 changes: 99 additions & 0 deletions src/Helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

if (!function_exists('windowWidthLessThan')) {
function windowWidthLessThan(int $value): bool
{
return session('windowW') < $value;
}
}

if (!function_exists('windowWidthGreaterThan')) {
function windowWidthGreaterThan(int $value): bool
{
return session('windowW') > $value;
}
}

if (!function_exists('windowWidthBetween')) {
function windowWidthBetween(int $expression): bool
{
$between = collect(explode(',', $expression));
$w = session('windowW');
return ($w > $between->first()) && ($w < $between->last());
}
}

if (!function_exists('windowHeightLessThan')) {
function windowHeightLessThan(int $value): bool
{
return session('windowH') < $value;
}
}

if (!function_exists('windowHeightGreaterThan')) {
function windowHeightGreaterThan(int $value): bool
{
return session('windowH') > $value;
}
}

if (!function_exists('windowHeightBetween')) {
function windowHeightBetween(int $expression): bool
{
$between = collect(explode(',', $expression));
$h = session('windowH');
return ($h > $between->first()) && ($h < $between->last());
}
}

if (!function_exists('windowXs')) {
function windowXs(): bool
{
$w = session('windowW');
return ($w > 0) &&
($w < config('breakpoints.window-width.Xs', 640));
}
}

if (!function_exists('windowSm')) {
function windowSm(): bool
{
$w = session('windowW');
return ($w >= config('breakpoints.window-width.Sm', 640))
&& ($w < config('breakpoints.window-width.Md', 768));
}
}

if (!function_exists('windowMd')) {
function windowMd(): bool
{
$w = session('windowW');
return ($w >= config('breakpoints.window-width.Md', 768))
&& ($w < config('breakpoints.window-width.Lg', 1024));
}
}

if (!function_exists('windowLg')) {
function windowLg(): bool
{
$w = session('windowW');
return ($w >= config('breakpoints.window-width.Lg', 1024))
&& ($w < config('breakpoints.window-width.Xl', 1280));
}
}

if (!function_exists('windowXl')) {
function windowXl(): bool
{
$w = session('windowW');
return ($w >= config('breakpoints.window-width.Xl', 1280))
&& ($w < config('breakpoints.window-width.2xl', 1536));
}
}

if (!function_exists('window2xl')) {
function window2xl(): bool
{
return session('windowW') >= config('breakpoints.window-width.2xl', 1536);
}
}
104 changes: 2 additions & 102 deletions src/LaravelWindowSizeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Tanthammar\LaravelWindowSize;

include_once('Helpers.php');

use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\RateLimiter;
Expand Down Expand Up @@ -30,7 +32,6 @@ public function boot()
$this->publishes([__DIR__ . '/../config/breakpoints.php' => config_path('breakpoints.php')], 'laravel-window-size');
$this->loadRoutesFrom(__DIR__ . '/../routes/web.php');
$this->loadViewsFrom(__DIR__ . '/../resources/', 'window-size');
$this->registerHelpers();
$this->bladeDirectives();
}

Expand Down Expand Up @@ -84,105 +85,4 @@ protected function bladeDirectives()
return window2xl();
});
}

protected function registerHelpers()
{
if (!function_exists('windowWidthLessThan')) {
function windowWidthLessThan(int $value): bool
{
return session('windowW') < $value;
}
}

if (!function_exists('windowWidthGreaterThan')) {
function windowWidthGreaterThan(int $value): bool
{
return session('windowW') > $value;
}
}

if (!function_exists('windowWidthBetween')) {
function windowWidthBetween(int $expression): bool
{
$between = collect(explode(',', $expression));
$w = session('windowW');
return ($w > $between->first()) && ($w < $between->last());
}
}

if (!function_exists('windowHeightLessThan')) {
function windowHeightLessThan(int $value): bool
{
return session('windowH') < $value;
}
}

if (!function_exists('windowHeightGreaterThan')) {
function windowHeightGreaterThan(int $value): bool
{
return session('windowH') > $value;
}
}

if (!function_exists('windowHeightBetween')) {
function windowHeightBetween(int $expression): bool
{
$between = collect(explode(',', $expression));
$h = session('windowH');
return ($h > $between->first()) && ($h < $between->last());
}
}

if (!function_exists('windowXs')) {
function windowXs(): bool
{
$w = session('windowW');
return ($w > 0) &&
($w < config('breakpoints.window-width.Xs', 640));
}
}

if (!function_exists('windowSm')) {
function windowSm(): bool
{
$w = session('windowW');
return ($w >= config('breakpoints.window-width.Sm', 640))
&& ($w < config('breakpoints.window-width.Md', 768));
}
}

if (!function_exists('windowMd')) {
function windowMd(): bool
{
$w = session('windowW');
return ($w >= config('breakpoints.window-width.Md', 768))
&& ($w < config('breakpoints.window-width.Lg', 1024));
}
}

if (!function_exists('windowLg')) {
function windowLg(): bool
{
$w = session('windowW');
return ($w >= config('breakpoints.window-width.Lg', 1024))
&& ($w < config('breakpoints.window-width.Xl', 1280));
}
}

if (!function_exists('windowXl')) {
function windowXl(): bool
{
$w = session('windowW');
return ($w >= config('breakpoints.window-width.Xl', 1280))
&& ($w < config('breakpoints.window-width.2xl', 1536));
}
}

if (!function_exists('window2xl')) {
function window2xl(): bool
{
return session('windowW') >= config('breakpoints.window-width.2xl', 1536);
}
}
}
}

0 comments on commit 25ae66e

Please sign in to comment.