Permalink
Fetching contributors…
Cannot retrieve contributors at this time
112 lines (97 sloc) 5.01 KB
<!--
Copyright (C) 2015 Orbeon, Inc.
This program is free software; you can redistribute it and/or modify it under the terms of the
GNU Lesser General Public License as published by the Free Software Foundation; either version
2.1 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
-->
<xbl:xbl xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:xbl="http://www.w3.org/ns/xbl"
xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:oxf="http://www.orbeon.com/oxf/processors">
<xbl:binding
id="fr-character-counter"
element="
fr|character-counter,
xf|input[appearance ~= character-counter],
xf|textarea[appearance ~= character-counter],
xf|secret[appearance ~= character-counter],
fr|tinymce[appearance ~= character-counter]"
xxbl:mode="binding lhha value"
xxbl:label-for="field"
xxbl:container="span">
<metadata xmlns="http://orbeon.org/oxf/xml/form-builder">
<display-name lang="en">With Character Counter</display-name>
<display-name lang="es">Con Contador de Caracteres</display-name>
<display-name lang="fi" todo="true">[With Character Counter]</display-name>
<display-name lang="fr">Avec compteur de charactères</display-name>
<display-name lang="ru" todo="true">[With Character Counter]</display-name>
<display-name lang="de">Mit Zeichenzähler</display-name>
<display-name lang="it" todo="true">[With Character Counter]</display-name>
<display-name lang="nl" todo="true">[With Character Counter]</display-name>
<display-name lang="sv">Med teckenräknare</display-name>
<display-name lang="pt" todo="true">[With Character Counter]</display-name>
<toolbox show="false"/>
<icon>
<small-icon>/apps/fr/style/images/other/140-skylt-16.png</small-icon>
<large-icon>/apps/fr/style/images/other/140-skylt-16.png</large-icon>
</icon>
<templates>
<!-- Provide a view template for Form Builder so that CSS resources are loaded -->
<view>
<xf:input id="" ref="" appearance="character-counter" xmlns="">
<xf:label ref=""/>
<xf:hint ref=""/>
<xf:help ref=""/>
<xf:alert ref=""/>
</xf:input>
</view>
</templates>
</metadata>
<xbl:resources>
<xbl:style src="/xbl/orbeon/character-counter/character-counter.css"/>
</xbl:resources>
<xbl:template xxbl:transform="oxf:xslt">
<xh:span xsl:version="2.0" class="fr-charcounter-wrapper">
<xf:var
name="binding"
value="xxf:binding('fr-character-counter')"/>
<xf:var
name="current"
value="string-length(string($binding))"/>
<xf:var
name="remaining"
value="xs:integer(xxf:custom-mip($binding, 'max-length')[. castable as xs:integer]) - $current"/>
<xsl:element name="{name(/*)}">
<xsl:attribute name="id" select="'field'"/>
<xsl:attribute name="ref" select="'$binding'"/>
<xsl:attribute name="incremental" select="'true'"/>
<xsl:attribute name="appearance" select="tokenize(/*/@appearance, '\s+')[. != 'character-counter']"/>
<xsl:copy-of select="/*/@mediatype"/>
</xsl:element>
<!-- Will appear below field for IE < 11 -->
<xh:span class="fr-charcounter-count">
<xf:output
value="if (empty($remaining)) then $current else abs($remaining)"
class="label fr-charcounter-{{
if (empty($remaining)) then
'current'
else if ($remaining ge 0) then
'remaining'
else
'over label-important'
}}">
</xf:output>
</xh:span>
</xh:span>
</xbl:template>
</xbl:binding>
</xbl:xbl>