-
-
Notifications
You must be signed in to change notification settings - Fork 8
Several enhancements & new features #5
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
base: main
Are you sure you want to change the base?
Changes from all commits
21494b6
1a93298
fbaa2b1
50dae0b
4b993e8
a50e69f
9a0a9fa
e8925cc
9828757
9c8835e
217617c
37cde6d
e002022
0583818
0128098
784eb9f
69b5037
8f16b01
c38dd8c
bc1fe29
7d69146
44ab26c
833e50f
a5cc6d6
b260ff1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| (function (win, doc) { | ||
| counter = win.counter || {} | ||
| counter.seo = { | ||
| charCountHandler: function(target) { | ||
| $target = $(target); | ||
| let $helpBlock = $target.next('.help-block'); | ||
| let min = $target.data('min'); | ||
| let max = $target.data('max'); | ||
| let count = $target.val().replace(/[{}]/g, "").length; | ||
| $helpBlock.html(`Symbols: <b>${count}</b> of ${min} - ${max} optimal`); | ||
| let $number = $helpBlock.find('b'); | ||
| if (count < max && count > min) { | ||
| $number.css({color: 'lime'}); | ||
| } else if(count < min) { | ||
| $number.css({color: 'darkred'}); | ||
| } else { | ||
| $number.css({color: 'coral'}); | ||
| } | ||
| } | ||
| } | ||
| var listeners = [], | ||
| doc = win.document, | ||
| MutationObserver = win.MutationObserver || win.WebKitMutationObserver, | ||
| observer; | ||
|
|
||
| const ready = (selector, fn) => { | ||
| listeners.push({ | ||
| selector: selector, | ||
| fn: fn | ||
| }); | ||
| if (!observer) { | ||
| observer = new MutationObserver(check); | ||
| observer.observe(doc.documentElement, { | ||
| childList: true, | ||
| subtree: true | ||
| }); | ||
| } | ||
| check(); | ||
| } | ||
|
|
||
| const check = () => { | ||
| for (var i = 0, len = listeners.length, listener, elements; i < len; i++) { | ||
| listener = listeners[i]; | ||
| elements = doc.querySelectorAll(listener.selector); | ||
| for (var j = 0, jLen = elements.length, element; j < jLen; j++) { | ||
| element = elements[j]; | ||
| if (!element.ready) { | ||
| element.ready = true; | ||
| listener.fn.call(element, element); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| win.ready = ready; | ||
| win.counter = counter; | ||
| win.ready('[data-counter]', (el) => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be better to look at rewriting this as a Snowboard.js plugin, see https://github.com/wintercms/winter/blob/develop/modules/backend/formwidgets/iconpicker/assets/js/src/iconpicker.js as an example, specifically the last two lines which enable the use of
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, on second thought with the goal of attaching this to fields using the attributes property on fields this is probably fine as it is, although the indentation still needs to be fixed here.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bennothommo on third thought what do you think about adding support for character counting functionality into the Winter core? It's been asked for a few times and Inetis even created a plugin for it once: https://github.com/inetis-ch/oc-InputCounter-plugin Refs:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bennothommo ping
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kinda feel like that would still be useful as a plugin, unless we have specific fields in core that have limits on length.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have any objections to writing it as a Snowboard plugin that's available in the core (with initial support for the text / textarea / maybe Froala fields)? That way we can use it in this plugin without having to have it only included in this plugin.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll write it as a first party plugin, as I would like to create an example of a plugin that provides Snowboard assets. If you feel afterwards that it should be in core, we can move it.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works for me. Are you going to do it in this plugin?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nah, I'll do it as its own plugin, and just add it as a requirement for this plugin. You never know - there may be other plugins that could use the same feature down the line. |
||
| counter.seo.charCountHandler(el) | ||
| el.oninput = event => counter.seo.charCountHandler(el); | ||
| }); | ||
| })(window, document); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php namespace Winter\SEO\Middleware; | ||
|
|
||
| use Closure; | ||
| use Cache; | ||
| use Illuminate\Http\Request; | ||
|
|
||
| class CompressHTML { | ||
| public function handle (Request $request, Closure $next) | ||
| { | ||
| // Key to store HTML in cache | ||
| $cacheKey = 'winter.seo.minified'.$request->getRequestUri(); | ||
| // Time to live in seconds | ||
| $cacheTTL = 3600; | ||
| // Get cached HTML or compress and save if cache not exists | ||
| $content = Cache::remember($cacheKey, $cacheTTL, function() use ($request, $next) { | ||
| return $this->compress($next($request)->getContent()); | ||
| }); | ||
| return response($content); | ||
| } | ||
|
|
||
| protected function compress($buffer) | ||
| { | ||
| $replace = [ | ||
| // Remove HTML whitespaces | ||
| "/\n([\S])/" => '$1', | ||
| "/\r/" => '', | ||
| "/\n/" => '', | ||
| "/\t/" => '', | ||
| "/ +/" => ' ', | ||
| "/> +</" => '><', | ||
| // Remove HTML comments | ||
| '/<!--[^]><!\[](.*?)[^\]]-->/s' => '', | ||
| // Remove unnecessary url parts | ||
| '/https:/' => '', | ||
| '/http:/' => '', | ||
| // Replace attributes with short notation | ||
| '/ method=("get"|get)/' => '', | ||
| '/ disabled=[^ >]*(.*?)/' => ' disabled', | ||
| '/ selected=[^ >]*(.*?)/' => ' selected', | ||
| ]; | ||
| return preg_replace(array_keys($replace), array_values($replace), $buffer); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.