mirror of
https://github.com/tabler/tabler.git
synced 2025-12-22 01:44: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="tooltip"]').tooltip();
|
||||||
// $('[data-toggle="popover"]').popover();
|
// $('[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
|
Imask plugin
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ base:
|
|||||||
icon: package
|
icon: package
|
||||||
children:
|
children:
|
||||||
blank:
|
blank:
|
||||||
title: Blank page
|
title: Starter page
|
||||||
url: blank.html
|
url: blank.html
|
||||||
buttons:
|
buttons:
|
||||||
url: buttons.html
|
url: buttons.html
|
||||||
@@ -94,7 +94,7 @@ docs:
|
|||||||
url: docs/index.html
|
url: docs/index.html
|
||||||
children:
|
children:
|
||||||
index:
|
index:
|
||||||
title: index
|
title: Introduction
|
||||||
url: docs/index.html
|
url: docs/index.html
|
||||||
alerts:
|
alerts:
|
||||||
title: Alerts
|
title: Alerts
|
||||||
|
|||||||
@@ -9,5 +9,9 @@ done: true
|
|||||||
|
|
||||||
{% example html %}
|
{% example html %}
|
||||||
<label class="form-label">Autosize example</label>
|
<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 %}
|
{% endexample %}
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
{% removeemptylines %}
|
{% removeemptylines %}
|
||||||
{{ site.captured_global.scripts }}
|
{% for script in site.captured_global.scripts %}
|
||||||
|
{{ script }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for script in site.captured_once.scripts %}
|
||||||
|
{{ script }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
{% endremoveemptylines %}
|
{% endremoveemptylines %}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
{% if site.data.libs.js and site.captured_libs %}
|
|
||||||
<!-- Libs JS -->
|
<!-- Libs JS -->
|
||||||
{% for lib in site.data.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] %}
|
{% if site.captured_libs contains lib[0] or site.data.libs.global-libs contains lib[0] %}
|
||||||
@@ -7,7 +6,6 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<!-- Tabler Core -->
|
<!-- 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>
|
<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 %}
|
{% append_lib autosize %}
|
||||||
|
|
||||||
<textarea class="form-control" data-toggle="autosize" placeholder="{{ include.placeholder | default: 'Typing something…' }}"></textarea>
|
<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)
|
def render(context)
|
||||||
if $captured_global[@text] === nil
|
if $captured_global[@text] === nil
|
||||||
$captured_global[@text] = '';
|
$captured_global[@text] = [];
|
||||||
end
|
end
|
||||||
|
|
||||||
$captured_global[@text] += super.strip + "\n\n"
|
$captured_global[@text].push(super.strip)
|
||||||
|
|
||||||
''
|
''
|
||||||
end
|
end
|
||||||
@@ -31,24 +31,49 @@ module Jekyll
|
|||||||
''
|
''
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
Jekyll::Hooks.register :site, :after_init do |page, jekyll|
|
Jekyll::Hooks.register :site, :after_init do |page, jekyll|
|
||||||
$captured_global = {}
|
$captured_global = {}
|
||||||
$captured_libs = []
|
$captured_libs = []
|
||||||
|
$captured_once = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
Jekyll::Hooks.register :pages, :pre_render do |page, jekyll|
|
Jekyll::Hooks.register :pages, :pre_render do |page, jekyll|
|
||||||
jekyll.site['captured_global'] = $captured_global
|
jekyll.site['captured_global'] = $captured_global
|
||||||
|
jekyll.site['captured_once'] = $captured_once
|
||||||
jekyll.site['captured_libs'] = $captured_libs
|
jekyll.site['captured_libs'] = $captured_libs
|
||||||
end
|
end
|
||||||
|
|
||||||
Jekyll::Hooks.register :pages, :post_render do |page, jekyll|
|
Jekyll::Hooks.register :pages, :post_render do |page, jekyll|
|
||||||
$captured_global = {}
|
$captured_global = {}
|
||||||
$captured_libs = []
|
$captured_libs = []
|
||||||
|
$captured_once = {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Liquid::Template.register_tag('capture_global', Jekyll::Tags::CaptureGlobal)
|
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)
|
Liquid::Template.register_tag('append_lib', Jekyll::Tags::CaptureScripts)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user