mirror of
https://github.com/tabler/tabler.git
synced 2025-12-21 17:34:25 +04:00
capture_once jekyll plugin, autosize fixes
This commit is contained in:
15
js/tabler.js
15
js/tabler.js
@@ -59,21 +59,6 @@ $(document).ready(function() {
|
||||
// $('[data-toggle="tooltip"]').tooltip();
|
||||
// $('[data-toggle="popover"]').popover();
|
||||
|
||||
/*
|
||||
Autosize plugin
|
||||
*/
|
||||
if (window.autosize) {
|
||||
(function() {
|
||||
const elements = document.querySelectorAll('[data-toggle="autosize"]');
|
||||
|
||||
if (elements.length) {
|
||||
elements.forEach(function(element) {
|
||||
autosize(element);
|
||||
});
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
/*
|
||||
Imask plugin
|
||||
*/
|
||||
|
||||
@@ -43,7 +43,7 @@ base:
|
||||
icon: package
|
||||
children:
|
||||
blank:
|
||||
title: Blank page
|
||||
title: Starter page
|
||||
url: blank.html
|
||||
buttons:
|
||||
url: buttons.html
|
||||
@@ -94,7 +94,7 @@ docs:
|
||||
url: docs/index.html
|
||||
children:
|
||||
index:
|
||||
title: index
|
||||
title: Introduction
|
||||
url: docs/index.html
|
||||
alerts:
|
||||
title: Alerts
|
||||
|
||||
@@ -9,5 +9,9 @@ done: true
|
||||
|
||||
{% example html %}
|
||||
<label class="form-label">Autosize example</label>
|
||||
<textarea class="form-control" data-toggle="autosize" placeholder="Typing something…"></textarea>
|
||||
{% include ui/form/textarea-autosize.html %}
|
||||
{% include ui/form/textarea-autosize.html %}
|
||||
{% include ui/form/textarea-autosize.html %}
|
||||
{% include ui/form/textarea-autosize.html %}
|
||||
{% include ui/form/textarea-autosize.html %}
|
||||
{% endexample %}
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
{% removeemptylines %}
|
||||
{{ site.captured_global.scripts }}
|
||||
{% for script in site.captured_global.scripts %}
|
||||
{{ script }}
|
||||
{% endfor %}
|
||||
|
||||
{% for script in site.captured_once.scripts %}
|
||||
{{ script }}
|
||||
{% endfor %}
|
||||
|
||||
{% endremoveemptylines %}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
{% if site.data.libs.js and site.captured_libs %}
|
||||
<!-- Libs JS -->
|
||||
{% for lib in site.data.libs.js %}
|
||||
{% if site.captured_libs contains lib[0] or site.data.libs.global-libs contains lib[0] %}
|
||||
@@ -7,7 +6,6 @@
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<!-- Tabler Core -->
|
||||
<script src="{{ site.base }}/{% if jekyll.environment == 'development' %}tmp-{% endif %}dist/js/tabler{% if jekyll.environment == 'production' %}.min{% endif %}.js?{{ site.time | date: '%s' }}"></script>
|
||||
|
||||
@@ -1,2 +1,19 @@
|
||||
{% append_lib autosize %}
|
||||
|
||||
<textarea class="form-control" data-toggle="autosize" placeholder="{{ include.placeholder | default: 'Typing something…' }}"></textarea>
|
||||
|
||||
{% capture_once scripts %}
|
||||
<script>
|
||||
if (window.autosize) {
|
||||
(function () {
|
||||
const elements = document.querySelectorAll('[data-toggle="autosize"]');
|
||||
|
||||
if (elements.length) {
|
||||
elements.forEach(function (element) {
|
||||
autosize(element);
|
||||
});
|
||||
}
|
||||
})();
|
||||
}
|
||||
</script>
|
||||
{% endcapture_once %}
|
||||
|
||||
@@ -8,10 +8,10 @@ module Jekyll
|
||||
|
||||
def render(context)
|
||||
if $captured_global[@text] === nil
|
||||
$captured_global[@text] = '';
|
||||
$captured_global[@text] = [];
|
||||
end
|
||||
|
||||
$captured_global[@text] += super.strip + "\n\n"
|
||||
$captured_global[@text].push(super.strip)
|
||||
|
||||
''
|
||||
end
|
||||
@@ -31,24 +31,49 @@ module Jekyll
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
class CaptureOnce < Liquid::Block
|
||||
def initialize(tag_name, text, tokens)
|
||||
super
|
||||
@text = text.strip
|
||||
end
|
||||
|
||||
def render(context)
|
||||
if $captured_once[@text] === nil
|
||||
$captured_once[@text] = [];
|
||||
end
|
||||
|
||||
data = super.strip
|
||||
|
||||
unless $captured_once[@text].include?(data)
|
||||
$captured_once[@text].push(data);
|
||||
end
|
||||
|
||||
''
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Jekyll::Hooks.register :site, :after_init do |page, jekyll|
|
||||
$captured_global = {}
|
||||
$captured_libs = []
|
||||
$captured_once = {}
|
||||
end
|
||||
|
||||
Jekyll::Hooks.register :pages, :pre_render do |page, jekyll|
|
||||
jekyll.site['captured_global'] = $captured_global
|
||||
jekyll.site['captured_once'] = $captured_once
|
||||
jekyll.site['captured_libs'] = $captured_libs
|
||||
end
|
||||
|
||||
Jekyll::Hooks.register :pages, :post_render do |page, jekyll|
|
||||
$captured_global = {}
|
||||
$captured_libs = []
|
||||
$captured_once = {}
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_tag('capture_global', Jekyll::Tags::CaptureGlobal)
|
||||
Liquid::Template.register_tag('capture_once', Jekyll::Tags::CaptureOnce)
|
||||
Liquid::Template.register_tag('append_lib', Jekyll::Tags::CaptureScripts)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user