File Coverage

blib/lib/JQuery/Mobile.pm
Criterion Covered Total %
statement 401 486 82.5
branch 106 212 50.0
condition 55 126 43.6
subroutine 35 37 94.5
pod 22 22 100.0
total 619 883 70.1


' . "\n" . ' ' . "\n"; ' . "\n" . ' ' . "\n"; '. "\n"; ' . "\n" . join("\n", map ({' '} @{$row})) . "\n" . ' ' . "\n"; ';
line stmt bran cond sub pod time code
1             package JQuery::Mobile;
2 2     2   45361 use strict;
  2         14  
  2         89  
3 2     2   12 use warnings;
  2         4  
  2         95  
4 2     2   10 no warnings 'uninitialized';
  2         8  
  2         91  
5 2     2   11 use Exporter 'import';
  2         3  
  2         275  
6             our @EXPORT_OK = qw(new head header footer table panel popup page pages form listview collapsible collapsible_set navbar button controlgroup input rangeslider select checkbox radio textarea);
7              
8 2     2   4469 use Clone qw(clone);
  2         14536  
  2         215  
9 2     2   3454 use HTML::Entities qw(encode_entities);
  2         25114  
  2         32977  
10              
11             our $VERSION = 0.03;
12             # 54.4
13              
14             sub new {
15 1     1 1 3439 my ($class, %args) = (@_);
16 1         3 my $self = bless {}, $class;
17 1   50     6 $args{config} ||= {};
18            
19             $self->{config} = {
20             'head' => 1, # include , , and tag when rendering a page
21             'viewport' => 'width=device-width, initial-scale=1', # default viewport
22             'apple-mobile-web-app-capable' => 1, # enable as apple web app
23             'apple-touch-icon' => '', # path to apple web app icon image
24             'apple-touch-icon-72' => '', # path to apple web app icon image (72x72 pixels)
25             'apple-touch-icon-114' => '', # path to apple web app icon image (114x114 pixels)
26             'apple-touch-startup-image' => '', # path to apple web app startup image
27             'jquery-mobile-css' => 'http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css',
28             'jquery-mobile-js' => 'http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js',
29             'jquery' => 'http://code.jquery.com/jquery-1.9.1.min.js',
30             'app-css' => [], # global application CSS files
31             'app-js' => [], # global application JS files
32             'app-inline-css' => ' span.invalid{color:#F00000;line-height: 1.5;}', # inline CSS code
33             'app-inline-js' => '', # inline JS code
34             'app-title' => '', # in <head> </td> </tr> <tr> <td class="h" > <a name="35">35</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> # a list of default allowed HTML and data-* attributes for UI components (Reference: http://api.jquerymobile.com/data-attribute/) </td> </tr> <tr> <td class="h" > <a name="36">36</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'header-footer-html-attribute' => ['id', 'class'], </td> </tr> <tr> <td class="h" > <a name="37">37</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'header-footer-data-attribute' => ['id', 'fullscreen', 'position', 'theme'], </td> </tr> <tr> <td class="h" > <a name="38">38</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'navbar-html-attribute' => ['id', 'class'], </td> </tr> <tr> <td class="h" > <a name="39">39</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'navbar-data-attribute' => ['disable-page-zoom', 'enhance', 'fullscreen', 'iconpos', 'tap-toggle', 'theme', 'transition', 'update-page-padding', 'visible-on-page-show'], </td> </tr> <tr> <td class="h" > <a name="40">40</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'navbar-item-html-attribute' => ['id', 'class', 'target'], </td> </tr> <tr> <td class="h" > <a name="41">41</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'navbar-item-data-attribute' => ['ajax', 'icon', 'iconpos', 'iconshadow','prefetch', 'theme'], </td> </tr> <tr> <td class="h" > <a name="42">42</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'page-html-attribute' => ['id', 'class'], </td> </tr> <tr> <td class="h" > <a name="43">43</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> # combine data-attributes for page and dialog </td> </tr> <tr> <td class="h" > <a name="44">44</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'page-data-attribute' => ['add-back-btn', 'back-btn-text', 'back-btn-theme', 'close-btn', 'close-btn-text', 'corners', 'dom-cache', 'enhance', 'overlay-theme', 'role', 'shadow','theme', 'title', 'tolerance', 'url'], </td> </tr> <tr> <td class="h" > <a name="45">45</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'table-html-attribute' => ['id', 'class'], </td> </tr> <tr> <td class="h" > <a name="46">46</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'table-data-attribute' => ['mode'], </td> </tr> <tr> <td class="h" > <a name="47">47</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'table-head-html-attribute' => ['id', 'class'], </td> </tr> <tr> <td class="h" > <a name="48">48</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'table-head-data-attribute' => ['priority'], </td> </tr> <tr> <td class="h" > <a name="49">49</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'panel-html-attribute' => ['id', 'class'], </td> </tr> <tr> <td class="h" > <a name="50">50</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'panel-data-attribute' => ['corners', 'overlay-theme', 'shadow', 'theme', 'tolerance', 'position-to', 'rel', 'role', 'transition'], </td> </tr> <tr> <td class="h" > <a name="51">51</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'popup-html-attribute' => ['id', 'class'], </td> </tr> <tr> <td class="h" > <a name="52">52</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'popup-data-attribute' => ['animate', 'dismissible', 'display', 'position', 'position-fixed', 'swipe-close', 'role', 'theme'], </td> </tr> <tr> <td class="h" > <a name="53">53</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'listview-html-attribute' => ['id', 'class'], </td> </tr> <tr> <td class="h" > <a name="54">54</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'listview-data-attribute' => ['autodividers', 'count-theme', 'divider-theme', 'enhance', 'filter', 'filter-placeholder', 'filter-reveal', 'filter-theme', 'filtertext', 'header-theme', 'inset', 'split-icon', 'split-theme', 'theme'], </td> </tr> <tr> <td class="h" > <a name="55">55</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'listview-item-html-attribute' => ['id', 'class'], </td> </tr> <tr> <td class="h" > <a name="56">56</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'listview-item-data-attribute' => ['ajax', 'mini', 'rel', 'theme', 'transition'], </td> </tr> <tr> <td class="h" > <a name="57">57</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'collapsible-html-attribute' => ['id', 'class'], </td> </tr> <tr> <td class="h" > <a name="58">58</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'collapsible-data-attribute' => ['collapsed', 'collapsed-icon', 'content-theme', 'expanded-icon', 'iconpos', 'inset', 'mini', 'theme'], </td> </tr> <tr> <td class="h" > <a name="59">59</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'collapsible-set-html-attribute' => ['id', 'class'], </td> </tr> <tr> <td class="h" > <a name="60">60</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'collapsible-set-data-attribute' => ['collapsed-icon', 'content-theme', 'expanded-icon', 'iconpos', 'inset', 'mini', 'theme'], </td> </tr> <tr> <td class="h" > <a name="61">61</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'controlgroup-html-attribute' => ['id', 'class'], </td> </tr> <tr> <td class="h" > <a name="62">62</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'controlgroup-data-attribute' => ['enhance', 'iconpos', 'mini', 'theme', 'type'], </td> </tr> <tr> <td class="h" > <a name="63">63</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'button-html-attribute' => ['id', 'name', 'class', 'maxlength', 'size', 'type', 'value'], </td> </tr> <tr> <td class="h" > <a name="64">64</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'button-html-anchor-attribute' => ['id', 'class', 'href', 'target'], </td> </tr> <tr> <td class="h" > <a name="65">65</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'button-data-attribute' => ['ajax', 'corners', 'dialog', 'direction', 'dom-cache', 'external', 'icon', 'iconpos', 'iconshadow', 'inline', 'mini', 'position-to', 'prefetch', 'rel', 'role', 'shadow', 'theme', 'transition'], </td> </tr> <tr> <td class="h" > <a name="66">66</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'form-html-attribute' => ['id', 'action', 'class', 'enctype', 'method'], </td> </tr> <tr> <td class="h" > <a name="67">67</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'form-data-attribute' => ['enhance', 'theme', 'ajax'], </td> </tr> <tr> <td class="h" > <a name="68">68</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'input-html-attribute' => ['id', 'class', 'disabled', 'max', 'maxlength', 'min', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'size', 'type', 'value', 'accept', 'capture'], </td> </tr> <tr> <td class="h" > <a name="69">69</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'input-data-attribute' => ['clear-btn', 'clear-btn-text', 'corners', 'highlight', 'icon', 'iconpos', 'iconshadow', 'inline', 'mini', 'shadow', 'theme', 'track-theme'], </td> </tr> <tr> <td class="h" > <a name="70">70</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'textarea-html-attribute' => ['id', 'name', 'class', 'rows', 'cols', 'readonly', 'disabled', 'title', 'required', 'placeholder', 'title', 'pattern'], </td> </tr> <tr> <td class="h" > <a name="71">71</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'textarea-data-attribute' => ['clear-btn', 'clear-btn-text', 'mini', 'theme'], </td> </tr> <tr> <td class="h" > <a name="72">72</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'select-html-attribute' => ['id', 'class', 'size', 'maxlength', 'readonly', 'disabled', 'title', 'required', 'placeholder', 'title', 'pattern', 'multiple'], </td> </tr> <tr> <td class="h" > <a name="73">73</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'select-data-attribute' => ['icon', 'iconpos', 'inline', 'mini', 'native-menu', 'overlay-theme', 'theme', 'role'], </td> </tr> <tr> <td class="h" > <a name="74">74</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'radio-checkbox-html-attribute' => ['id', 'class', 'readonly', 'disabled', 'title', 'required', 'placeholder', 'title', 'pattern', 'value'], </td> </tr> <tr> <td class="h" > <a name="75">75</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'radio-checkbox-data-attribute' => ['mini', 'theme'], </td> </tr> <tr> <td class="h" > <a name="76">76</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'rangeslider-html-attribute' => ['id', 'name', 'class'], </td> </tr> <tr> <td class="h" > <a name="77">77</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'rangeslider-data-attribute' => ['highlight', 'mini', 'theme', 'track-theme'], </td> </tr> <tr> <td class="h" > <a name="78">78</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'label' => sub { </td> </tr> <tr> <td class="h" > <a name="79">79</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td class="c0" > <a href="blib-lib-JQuery-Mobile-pm--subroutine.html#79-1"> 0 </a> </td> <td >   </td> <td > 0 </td> <td class="s"> my $args = shift; </td> </tr> <tr> <td class="h" > <a name="80">80</a> </td> <td class="c0" > 0 </td> <td class="c0" > <a href="blib-lib-JQuery-Mobile-pm--branch.html#80-1"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td > 0 </td> <td class="s"> return '<strong>' . $args->{label} . '</strong>' if $args->{required}; </td> </tr> <tr> <td class="h" > <a name="81">81</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td > 0 </td> <td class="s"> return $args->{label}; </td> </tr> <tr> <td class="h" > <a name="82">82</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> }, </td> </tr> <tr> <td class="h" > <a name="83">83</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'invalid' => sub { </td> </tr> <tr> <td class="h" > <a name="84">84</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td class="c0" > <a href="blib-lib-JQuery-Mobile-pm--subroutine.html#84-1"> 0 </a> </td> <td >   </td> <td > 0 </td> <td class="s"> my $args = shift; </td> </tr> <tr> <td class="h" > <a name="85">85</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td > 0 </td> <td class="s"> my $message = $args->{message}; </td> </tr> <tr> <td class="h" > <a name="86">86</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="87">87</a> </td> <td class="c0" > 0 </td> <td class="c0" > <a href="blib-lib-JQuery-Mobile-pm--branch.html#87-1"> 0 </a> </td> <td class="c0" > <a href="blib-lib-JQuery-Mobile-pm--condition.html#87-1"> 0 </a> </td> <td >   </td> <td >   </td> <td > 0 </td> <td class="s"> if (! $message && $args->{type}) { </td> </tr> <tr> <td class="h" > <a name="88">88</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td > 0 </td> <td class="s"> $message = { </td> </tr> <tr> <td class="h" > <a name="89">89</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'input' => 'Enter "%FIELDNAME%"', </td> </tr> <tr> <td class="h" > <a name="90">90</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'checkbox' => 'Check one or more "%FIELDNAME%"', </td> </tr> <tr> <td class="h" > <a name="91">91</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'radio' => 'Choose "%FIELDNAME%"', </td> </tr> <tr> <td class="h" > <a name="92">92</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'select' => 'Select an option from "%FIELDNAME%"', </td> </tr> <tr> <td class="h" > <a name="93">93</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> 'textarea' => 'Fill in the "%FIELDNAME%"' </td> </tr> <tr> <td class="h" > <a name="94">94</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> }->{$args->{type}}; </td> </tr> <tr> <td class="h" > <a name="95">95</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> } </td> </tr> <tr> <td class="h" > <a name="96">96</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="97">97</a> </td> <td class="c0" > 0 </td> <td >   </td> <td class="c0" > <a href="blib-lib-JQuery-Mobile-pm--condition.html#97-1"> 0 </a> </td> <td >   </td> <td >   </td> <td > 0 </td> <td class="s"> $message ||= 'Enter "%FIELDNAME%"'; </td> </tr> <tr> <td class="h" > <a name="98">98</a> </td> <td class="c0" > 0 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td > 0 </td> <td class="s"> $message =~ s/\%FIELDNAME\%/$args->{label}/g; </td> </tr> <tr> <td class="h" > <a name="99">99</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="100">100</a> </td> <td class="c0" > 0 </td> <td class="c0" > <a href="blib-lib-JQuery-Mobile-pm--branch.html#100-1"> 0 </a> </td> <td >   </td> <td >   </td> <td >   </td> <td > 0 </td> <td class="s"> return '<span class="invalid">' . $message . '</span>' if $args->{invalid}; </td> </tr> <tr> <td class="h" > <a name="101">101</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> }, </td> </tr> <tr> <td class="h" > <a name="102">102</a> </td> <td class="c3" > 1 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td > 53 </td> <td class="s"> %{$args{config}}, </td> </tr> <tr> <td class="h" > <a > </a> </td> <td class="c3" > 1 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td > 39 </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="103">103</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> }; </td> </tr> <tr> <td class="h" > <a name="104">104</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="105">105</a> </td> <td class="c3" > 1 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td > 8 </td> <td class="s"> return $self; </td> </tr> <tr> <td class="h" > <a name="106">106</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> } </td> </tr> <tr> <td class="h" > <a name="107">107</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="108">108</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s"> sub head { </td> </tr> <tr> <td class="h" > <a name="109">109</a> </td> <td class="c3" > 2 </td> <td >   </td> <td >   </td> <td class="c3" > <a href="blib-lib-JQuery-Mobile-pm--subroutine.html#109-1"> 2 </a> </td> <td class="c3" > <a href="blib-lib-JQuery-Mobile-pm--subroutine.html#109-1"> 1 </a> </td> <td > 5 </td> <td class="s"> my ($self, %args) = @_; </td> </tr> <tr> <td class="h" > <a name="110">110</a> </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td class="s">   </td> </tr> <tr> <td class="h" > <a name="111">111</a> </td> <td class="c3" > 2 </td> <td >   </td> <td >   </td> <td >   </td> <td >   </td> <td > 14 </td> <td class="s"> my $head = ' <head>' . "\n" . ' <title>' . $self->{config}->{'app-title'} . '' . "\n" .
112             ' ' . "\n";
113             # apple icons, startup image
114 2 50       29 $head .= ' ' . "\n" if $self->{config}->{'apple-mobile-web-app-capable'};
115 2 50       14 $head .= ' ' . "\n" if $self->{config}->{'apple-touch-icon'};
116 2 50       6 $head .= ' ' . "\n" if $self->{config}->{'apple-touch-icon-72'};
117 2 50       7 $head .= ' ' . "\n" if $self->{config}->{'apple-touch-icon-114'};
118 2 50       7 $head .= ' ' . "\n" if $self->{config}->{'apple-touch-startup-image'};
119              
120 2         38 my $css_sources = [$self->{config}->{'jquery-mobile-css'}];
121 2 50       4 push @{$css_sources}, @{$self->{config}->{'app-css'}}, if @{$self->{config}->{'app-css'}};
  0         0  
  0         0  
  2         9  
122              
123 2         5 foreach my $css (@{$css_sources}) {
  2         4  
124 2         11 $head .= ' ' . "\n";
125             }
126              
127 2         11 my $js_sources = [$self->{config}->{'jquery'}, $self->{config}->{'jquery-mobile-js'}];
128 2 50       4 push @{$js_sources}, @{$self->{config}->{'app-js'}}, if @{$self->{config}->{'app-js'}};
  2         3  
  2         5  
  2         9  
129              
130 2         4 foreach my $js (@{$js_sources}) {
  2         4  
131 6 50       30 $head .= ' ' . "\n" if $js;
132             }
133              
134 2 50       13 $head .= ' ' . "\n" if $self->{config}->{'app-inline-css'};
135 2 50       14 $head .= ' ' . "\n" if $self->{config}->{'app-inline-js'};
136              
137 2         3 $head .= ' ' . "\n";
138 2         52 return $head;
139             }
140              
141             sub header {
142 5     5 1 1117 my ($self, %args) = @_;
143              
144 5   0     14 $args{content} ||= '

' . ($self->{config}->{'app-title'} || 'Header Content') . '

';
      33        
145            
146 5         16 my $attributes = $self->_header_footer_attribute('header', \%args);
147 5         10 my $header = '
' . "\n";
148 5         11 $header .= $args{content} . "\n";
149 5         36 $header .= ' ' . "\n";
150 5         25 return $header;
151             }
152              
153             sub footer {
154 2     2 1 1850 my ($self, %args) = @_;
155              
156 2   50     8 $args{content} ||= '

Footer Content

';
157              
158 2         7 my $attributes = $self->_header_footer_attribute('footer', \%args);
159 2         5 my $footer = '
' . "\n";
160 2         4 $footer .= $args{content} . "\n";
161 2         4 $footer .= ' ' . "\n";
162 2         7 return $footer;
163             }
164              
165             sub navbar {
166 1     1 1 1030 my ($self, %args) = @_;
167              
168              
169 1         6 my $attributes = _html_attribute('', $self->{config}->{'navbar-html-attribute'}, \%args);
170 1         5 $attributes = _data_attribute($attributes, $self->{config}->{'navbar-data-attribute'}, \%args);
171              
172 1         4 my $navbar = '
' . "\n";
173 1         3 $navbar .= '
    ' . "\n";
174              
175 1         2 foreach my $item (@{$args{items}}) {
  1         3  
176 3         10 my $item_attributes = _data_attribute ('', $self->{config}->{'navbar-item-data-attribute'}, $item);
177              
178 3         6 my $item_class = '';
179              
180 3 50       13 if ($args{active}) {
    100          
181 0 0       0 if ($item->{$args{active}->{option}} eq $args{active}->{value}) {
182 0 0       0 if ($item->{class}) {
183 0         0 $item->{class} .= ' ui-btn-active';
184 0 0       0 $item->{class} .= ' ui-btn-persist' if $args{persist};
185             }
186             else {
187 0         0 $item->{class} = 'ui-btn-active';
188 0 0       0 $item->{class} .= ' ui-btn-persist' if $args{persist};
189             }
190             }
191             }
192             elsif ($item->{active}) {
193 1 50       3 if ($item->{class}) {
194 0         0 $item->{class} .= ' ui-btn-active';
195 0 0       0 $item->{class} .= ' ui-btn-persist' if $item->{persist};
196             }
197             else {
198 1         3 $item->{class} = 'ui-btn-active';
199 1 50       4 $item->{class} .= ' ui-btn-persist' if $item->{persist};
200             }
201             }
202              
203 3         8 $item_attributes = _html_attribute ($item_attributes, $self->{config}->{'navbar-item-html-attribute'}, $item);
204              
205 3         13 $navbar .= '
  • ' . $item->{value} . '
  • ' . "\n";
    206              
    207             }
    208 1         4 $navbar .= ' ' . "\n";
    209 1         2 $navbar .= ' ';
    210 1         4 return $navbar;
    211             }
    212              
    213             sub panel {
    214 1     1 1 1077 my ($self, %args) = @_;
    215              
    216 1   50     8 $args{content} ||= '

    Panel Content

    ';
    217 1         3 $args{role} = 'panel';
    218              
    219 1         5 my $attributes = _html_attribute('', $self->{config}->{'panel-html-attribute'}, \%args);
    220 1         5 $attributes = _data_attribute($attributes, $self->{config}->{'panel-data-attribute'}, \%args);
    221              
    222 1         4 my $panel = ' ' . "\n";
    223 1         3 $panel .= $args{content} . "\n";
    224 1         3 $panel .= ' ' . "\n";
    225              
    226 1         5 return $panel;
    227             }
    228              
    229             sub table {
    230 1     1 1 3235 my ($self, %args) = @_;
    231              
    232 1 50       5 unless ($args{content}) {
    233              
    234 1         4 $args{content} = '
    235 1         2 foreach my $header (@{$args{headers}}) {
      1         4  
    236              
    237 4         5 my $head_attributes = '';
    238 4 50 33     45 if ($args{th} && exists $args{th}->{$header}) {
    239 4         12 $head_attributes = _html_attribute($head_attributes, $self->{config}->{'table-head-html-attribute'}, $args{th}->{$header});
    240 4         13 $head_attributes = _data_attribute($head_attributes, $self->{config}->{'table-head-data-attribute'}, $args{th}->{$header});
    241             }
    242              
    243 4         13 $args{content} .= ' ' . $header . '' . "\n";
    244             }
    245 1         3 $args{content} .= '
    246              
    247 1         2 $args{content} .= '
    248 1         2 foreach my $row (@{$args{rows}}) {
      1         3  
    249 2         4 $args{content} .= '
    ' . $_ . '
      8         22  
      2         3  
    250             }
    251 1         3 $args{content} .= '
    252             }
    253              
    254 1         4 my $attributes = _html_attribute('', $self->{config}->{'table-html-attribute'}, \%args);
    255 1         3 $attributes = _data_attribute($attributes, $self->{config}->{'table-data-attribute'}, \%args);
    256              
    257 1         17 my $table = ' ' . "\n" . $args{content} . "\n" . '
    ' . "\n";
    258 1         5 return $table;
    259             }
    260              
    261             sub popup {
    262 1     1 1 1367 my ($self, %args) = @_;
    263              
    264 1   50     5 $args{content} ||= '

    Popup Content

    ';
    265 1         2 $args{role} = 'popup';
    266              
    267 1         4 my $attributes = _html_attribute('', $self->{config}->{'popup-html-attribute'}, \%args);
    268 1         3 $attributes = _data_attribute($attributes, $self->{config}->{'popup-data-attribute'}, \%args);
    269              
    270 1         3 my $popup = ' ' . "\n";
    271 1         3 $popup .= $args{content} . "\n";
    272 1         5 $popup .= ' ' . "\n";
    273              
    274 1         4 return $popup;
    275             }
    276              
    277             sub page {
    278 3     3 1 11 my ($self, %args) = @_;
    279              
    280 3   50     10 $args{content} ||= '

    Page Content

    ';
    281 3   50     16 $args{role} ||= 'page';
    282              
    283 3         16 my $attributes = _html_attribute('', $self->{config}->{'page-html-attribute'}, \%args);
    284 3         37 $attributes = _data_attribute($attributes, $self->{config}->{'page-data-attribute'}, \%args);
    285              
    286 3         7 my $page = ' ' . "\n";
    287 3 50       10 $page .= $self->header(%{$args{header}}) if $args{header};
      3         15  
    288 3 50       9 $page .= $self->panel(%{$args{panel}}) if $args{panel};
      0         0  
    289 3         10 $page .= '
    ' . "\n" . $args{content} . "\n" . '
    ' . "\n";
    290 3 50       8 $page .= $args{after} if $args{after};
    291 3 100       9 $page .= $self->footer(%{$args{footer}}) if $args{footer};
      1         5  
    292 3         6 $page .= ' ' . "\n";
    293              
    294 3 100 66     42 return $page if (exists $args{head} && ! $args{head}) || ! $self->{config}->{'head'};
          66        
    295 1         5 return "\n\n" . $self->head() . " \n" . $page . " \n";
    296             }
    297              
    298             sub pages {
    299 1     1 1 31 my ($self, %args) = @_;
    300              
    301 1         3 my $pages = '';
    302              
    303 1         2 foreach my $page (@{$args{pages}}) {
      1         4  
    304 2         4 $page->{head} = 0;
    305 2         4 $pages .= $self->page(%{$page});
      2         16  
    306             }
    307              
    308 1   50     5 $pages ||= '

    Multiple Pages

    ';
    309              
    310 1 50 33     11 return $pages if (exists $args{head} && ! $args{head}) || ! $self->{config}->{'head'};
          33        
    311 1         5 return "\n\n" . $self->head() . " \n" . $pages . " \n";
    312             }
    313              
    314             sub collapsible_set {
    315 2     2 1 3066 my ($self, %args) = @_;
    316              
    317 2 50 33     11 if ($args{collapsibles} && @{$args{collapsibles}}) {
      2         12  
    318 2         3 foreach my $collapsible (@{$args{collapsibles}}) {
      2         5  
    319 4 100 66     19 if ($args{active} && ! exists $collapsible->{active}) {
    320 2         4 $collapsible->{active} = $args{active};
    321             }
    322              
    323 4         6 $args{content} .= $self->collapsible(%{$collapsible});
      4         16  
    324             }
    325             }
    326             else {
    327 0   0     0 $args{content} ||= '

    Collapsible Set Content

    ';
    328             }
    329              
    330 2         6 my $attributes = _html_attribute('', $self->{config}->{'collapsible-set-html-attribute'}, \%args);
    331 2         6 $attributes = _data_attribute($attributes, $self->{config}->{'collapsible-set-data-attribute'}, \%args);
    332              
    333 2         17 my $collapsible_set = '
    ' . "\n" . $args{content} . "\n" . '
    ' . "\n";
    334 2         9 return $collapsible_set;
    335             }
    336              
    337             sub collapsible {
    338 4     4 1 9 my ($self, %args) = @_;
    339              
    340 4 100       9 if ($args{listview}) {
    341 2 50 33     13 if ($args{active} && ! exists $args{listview}->{active}) {
    342 2         6 $args{listview}->{active} = $args{active};
    343             }
    344              
    345 2   50     6 $args{title} ||= 'Title';
    346 2         5 $args{content} = '

    ' . $args{title} . '

    ' . "\n" . $self->listview(%{$args{listview}});
      2         19  
    347 2 100 66     22 $args{collapsed} = 'false' if ! exists $args{collapsed} && $args{content} =~ /ui-btn-active/;
    348             }
    349             else {
    350 2   50     8 $args{content} ||= '

    Collapsible Title

    Collapsible Content

    ';
    351             }
    352              
    353 4         14 my $attributes = _html_attribute('', $self->{config}->{'collapsible-html-attribute'}, \%args);
    354 4         18 $attributes = _data_attribute($attributes, $self->{config}->{'collapsible-data-attribute'}, \%args);
    355              
    356 4         14 my $collapsible = '
    ' . "\n" . $args{content} . "\n" . '
    ' . "\n";
    357 4         16 return $collapsible;
    358             }
    359              
    360             sub listview {
    361 4     4 1 12642 my ($self, %args) = @_;
    362              
    363 4         19 my $attributes = _html_attribute('', $self->{config}->{'listview-html-attribute'}, \%args);
    364 4         14 $attributes = _data_attribute($attributes, $self->{config}->{'listview-data-attribute'}, \%args);
    365              
    366 4         7 my $anchor_attributes = '';
    367 4 100 66     14 if ($args{anchor} && %{$args{anchor}}) {
      2         15  
    368 2         7 $anchor_attributes = _html_attribute($anchor_attributes, $self->{config}->{'button-html-anchor-attribute'}, $args{anchor});
    369 2         7 $anchor_attributes = _data_attribute($anchor_attributes, $self->{config}->{'button-data-attribute'}, $args{anchor});
    370             }
    371              
    372 4         8 my $split_anchor_attributes = '';
    373 4 100 66     26 if ($args{split_anchor} && %{$args{split_anchor}}) {
      1         8  
    374 1         7 $split_anchor_attributes = _html_attribute($split_anchor_attributes, $self->{config}->{'button-html-anchor-attribute'}, $args{split_anchor});
    375 1         6 $split_anchor_attributes = _data_attribute($split_anchor_attributes, $self->{config}->{'button-data-attribute'}, $args{split_anchor});
    376             }
    377              
    378 4         5 my $list_tag;
    379 4 50       10 if ($args{numbered}) {
    380 0         0 $list_tag = 'ol';
    381             }
    382             else {
    383 4         6 $list_tag = 'ul';
    384             }
    385              
    386 4         11 my $list = ' <' . $list_tag . ' data-role="listview"' . $attributes . '>' . "\n";
    387            
    388 4         6 my $divider = '';
    389              
    390 4         4 foreach my $item (@{$args{items}}) {
      4         8  
    391              
    392 11 100       23 if ($item->{divider}) {
    393 1         3 $list .= '
  • ' . $item->{value} . '
  • ' . "\n";
    394 1         2 next;
    395             }
    396              
    397 10         29 my $item_attributes = _data_attribute ('', $self->{config}->{'listview-item-data-attribute'}, $item);
    398 10 100       37 if ($args{active}) {
        50          
    399 4 100       14 if ($item->{$args{active}->{option}} eq $args{active}->{value}) {
    400 1 50       4 if ($item->{class}) {
    401 0         0 $item->{class} .= ' ui-btn-active';
    402             }
    403             else {
    404 1         4 $item->{class} = 'ui-btn-active';
    405             }
    406             }
    407             }
    408             elsif ($item->{active}) {
    409 0 0       0 if ($item->{class}) {
    410 0         0 $item->{class} .= ' ui-btn-active';
    411             }
    412             else {
    413 0         0 $item->{class} = 'ui-btn-active';
    414             }
    415             }
    416              
    417 10         27 $item_attributes = _html_attribute ($item_attributes, $self->{config}->{'listview-item-html-attribute'}, $item);
    418              
    419 10         12 my $value = '';
    420              
    421 10 50       31 if (defined $item->{content}) {
        50          
    422 0         0 $value = $item->{content};
    423             }
    424             elsif (defined $item->{value}) {
    425 0         0 $value = '

    ' . $item->{value} . '

    ';
    426             }
    427              
    428 10 50       21 if (defined $item->{title}) {
    429 10         21 $value = '

    ' . $item->{title} . '

    ' . $value;
    430             }
    431              
    432 10 100       21 if (defined $item->{count}) {
    433 3         5 $value .= '' . $item->{count} . '';
    434             }
    435              
    436 10 100       55 if (defined $item->{aside}) {
    437 3         5 $value .= '

    ' . $item->{aside} . '

    ';
    438             }
    439              
    440 10 50       36 if ($item->{divider}) {
        50          
        50          
        0          
    441 0         0 $list .= ' ' . $value . '' . "\n";
    442             }
    443             elsif (defined $item->{list}) {
    444 0         0 $list .= '' . $value . "\n" . $item->{list} . '' . "\n";
    445             }
    446             elsif (defined $item->{href}) {
    447 10 100       35 $value = '' . $value if defined $item->{image};
    448 10         24 $value = '' . $value . '';
    449              
    450 10 100       22 if (defined $item->{split}) {
    451 3   33     9 my $split_value = $item->{split_value} || $args{split_value};
    452 3         10 $value .= '' . $split_value . '';
    453             }
    454              
    455 10         35 $list .= ' ' . $value . '' . "\n";
    456             }
    457             elsif (defined $item->{image}) {
    458 0         0 $list .= ' ' . $value . '' . "\n";
    459             }
    460             else {
    461 0         0 $list .= ' ' . $value . '' . "\n";
    462             }
    463             }
    464 4         11 $list .= ' ' . "\n";
    465 4         19 return $list;
    466             }
    467              
    468             sub controlgroup {
    469 4     4 1 652 my ($self, %args) = @_;
    470              
    471 4         16 my $attributes = _html_attribute('', $self->{config}->{'controlgroup-html-attribute'}, \%args);
    472 4         16 $attributes = _data_attribute($attributes, $self->{config}->{'controlgroup-data-attribute'}, \%args);
    473              
    474 4 100       14 my $element = $args{fieldset} ? 'fieldset' : 'div';
    475              
    476 4         14 my $controlgroup = ' <' . $element . ' data-role="controlgroup"'. $attributes . '>' . "\n";
    477 4         12 $controlgroup .= ' ' . $args{content} . "\n";
    478 4         12 $controlgroup .= ' ' . "\n";
    479 4         86 return $controlgroup;
    480             }
    481              
    482             sub button {
    483 7     7 1 8454 my ($self, %args) = @_;
    484              
    485 7 50 66     45 unless (exists $args{role} && $args{role} eq 'none') {
    486 7         16 $args{role} = 'button';
    487             }
    488              
    489 7         30 my $attributes = _data_attribute('', $self->{config}->{'button-data-attribute'}, \%args);
    490              
    491 7 100 66     56 if ($args{type} && $args{type} =~ /^(button|submit|reset)$/) {
    492 2         10 $attributes = _html_attribute($attributes, $self->{config}->{'button-html-attribute'}, \%args);
    493 2         13 return ' ' . "\n";
    494             }
    495             else {
    496 5         23 $attributes = _html_attribute($attributes, $self->{config}->{'button-html-anchor-attribute'}, \%args);
    497 5         170 return ' ' . $args{value} . '' . "\n";
    498             }
    499             }
    500              
    501             sub form {
    502 1     1 1 1557 my ($self, %args) = @_;
    503              
    504 1   50     12 $args{method} ||= 'post';
    505              
    506 1         5 my $attributes = _html_attribute('', $self->{config}->{'form-html-attribute'}, \%args);
    507 1         4 $attributes = _data_attribute($attributes, $self->{config}->{'form-data-attribute'}, \%args);
    508              
    509 1         2 my $content = '';
    510              
    511 1 50       4 if ($args{fields}) {
    512 1         2 foreach my $field (@{$args{fields}}) {
      1         2  
    513 10 100 100     109 if ($field->{type} && $field->{type} =~ /^(select|radio|checkbox|textarea|rangeslider)$/) {
    514 5         13 my $type = delete $field->{type};
    515 5         12 $content .= $self->$type(%{$field});
      5         36  
    516             }
    517             else {
    518 5         6 $content .= $self->input(%{$field});
      5         19  
    519             }
    520             }
    521             }
    522              
    523 1         3 my $buttons = '';
    524              
    525 1 50       5 if ($args{buttons}) {
    526 1         2 foreach my $button (@{$args{buttons}}) {
      1         3  
    527 2         4 $buttons .= $self->button(%{$button});
      2         10  
    528             }
    529              
    530 1 50       7 if ($args{controlgroup}) {
    531 1         2 my $controlgroup;
    532 1 50       5 if (ref $args{controlgroup} eq 'HASH') {
    533 1         3 $controlgroup = $args{controlgroup};
    534 1         26 $controlgroup->{content} = $buttons;
    535             }
    536             else {
    537 0         0 $controlgroup = {content => $buttons};
    538             }
    539 1         5 $content .= $self->controlgroup(%{$controlgroup});
      1         7  
    540             }
    541             else {
    542 0         0 $content .= $buttons;
    543             }
    544             }
    545              
    546 1         6 my $form = ' ' . "\n";
    547 1 50       10 $form .= '

    ' . $args{title} . "

    \n" if $args{title};
    548 1 50       7 $form .= '

    ' . $args{description} . "

    \n" if $args{description};
    549 1         11 $form .= $content;
    550 1         3 $form .= ' ' . "\n";
    551 1         8 return $form;
    552             }
    553              
    554             sub rangeslider {
    555 1     1 1 5 my ($self, %args) = @_;
    556              
    557 1         4 my $attributes = _html_attribute('', $self->{config}->{'rangeslider-html-attribute'}, \%args);
    558 1         5 $attributes = _data_attribute($attributes, $self->{config}->{'rangeslider-data-attribute'}, \%args);
    559              
    560 1         5 $args{from}->{type} = 'range';
    561 1         2 $args{to}->{type} = 'range';
    562 1         3 my $from = ' ' . $self->_input(%{$args{from}}) . "\n";
      1         7  
    563 1         21 my $to = ' ' . $self->_input(%{$args{to}});
      1         6  
    564              
    565 1   50     25 $args{container_role} ||= 'fieldcontain';
    566 1 50       5 my $invalid = $args{invalid} ? $self->{config}->{invalid}->(\%args) : '';
    567              
    568 1         4 my $rangeslider = '
    ' . "\n" . '
    ' . "\n";
    569 1         3 $rangeslider .= $from . $to . $invalid . "\n";
    570 1         4 $rangeslider .= " \n \n";
    571              
    572 1         18 return $rangeslider;
    573             }
    574              
    575             sub _input {
    576 7     7   36 my ($self, %args) = @_;
    577 7   100     23 $args{type} ||= 'text';
    578 7   33     35 $args{id} ||= $args{name};
    579 7   66     34 $args{label} ||= _label($args{name});
    580              
    581 7         32 $args{value} = encode_entities($args{value});
    582              
    583 7         50 my $attributes = _html_attribute('', $self->{config}->{'input-html-attribute'}, \%args);
    584 7         24 $attributes = _data_attribute($attributes, $self->{config}->{'input-data-attribute'}, \%args);
    585              
    586 7 50       27 return ' ' . "\n" if $args{type} eq 'hidden';
    587 7         70 return '';
    588             }
    589              
    590             sub input {
    591 5     5 1 14 my ($self, %args) = @_;
    592              
    593 5         15 my $input = $self->_input(%args);
    594 5 50       55 return $input if $args{type} eq 'hidden';
    595              
    596 5   50     22 $args{container_role} ||= 'fieldcontain';
    597 5 50       11 my $invalid = $args{invalid} ? $self->{config}->{invalid}->(\%args) : '';
    598 5         37 return '
    ' . $input . $invalid . '
    ' . "\n";
    599             }
    600              
    601             sub textarea {
    602 1     1 1 3 my ($self, %args) = @_;
    603              
    604 1   33     8 $args{id} ||= $args{name};
    605 1   33     7 $args{label} ||= _label($args{name});
    606              
    607 1   50     24 $args{cols} ||= 40;
    608 1   50     15 $args{rows} ||= 8;
    609 1         5 $args{value} = encode_entities($args{value});
    610              
    611 1         11 my $attributes = _html_attribute('', $self->{config}->{'textarea-html-attribute'}, \%args);
    612 1         4 $attributes = _data_attribute($attributes, $self->{config}->{'textarea-data-attribute'}, \%args);
    613              
    614 1   50     7 $args{container_role} ||= 'fieldcontain';
    615 1 50       6 my $invalid = $args{invalid} ? $self->{config}->{invalid}->(\%args) : '';
    616 1         6 return '
    ' . $args{value} . '' . $invalid . '
    ' . "\n";
    617             }
    618              
    619             sub select {
    620 1     1 1 8 my ($self, %args) = @_;
    621              
    622 1   33     11 $args{id} ||= $args{name};
    623 1   33     6 $args{label} ||= _label($args{name});
    624              
    625 1 50       7 if ($args{multiple}) {
    626 0   0     0 $args{'native-menu'} ||= 'false';
    627             }
    628              
    629 1         6 my $attributes = _html_attribute('', $self->{config}->{'select-html-attribute'}, \%args);
    630 1         6 $attributes = _data_attribute($attributes, $self->{config}->{'select-data-attribute'}, \%args);
    631              
    632 1         3 my $options = '';
    633 1         3 my $placeholder_text = $args{placeholder_text};
    634              
    635 1 50       11 if (ref $args{options} eq 'HASH') {
        50          
    636              
    637 0         0 my @keys;
    638 0         0 my $sort_options = $args{sort_options};
    639 0 0 0     0 if ($sort_options && $sort_options eq 'key') {
    640 0         0 @keys = sort keys %{$args{options}};
      0         0  
    641             }
    642             else {
    643 0         0 @keys = sort {$args{options}->{$a} cmp $args{options}->{$b}} keys %{$args{options}};
      0         0  
      0         0  
    644             }
    645              
    646 0         0 foreach my $key (@keys) {
    647 0         0 my $selected = '';
    648              
    649 0 0       0 if (defined $args{value}) {
    650              
    651 0 0       0 if (ref $args{value} eq 'HASH') {
        0          
    652 0         0 foreach my $value_key (keys %{$args{value}}) {
      0         0  
    653 0 0       0 if ($key eq $value_key) {
    654 0         0 $selected = 'selected="selected"';
    655 0         0 last;
    656             }
    657             }
    658             }
    659             elsif ($key eq $args{value}) {
    660 0         0 $selected = 'selected="selected"';
    661             }
    662             }
    663              
    664 0         0 $options .= '';
    665             }
    666              
    667 0 0       0 if (defined $placeholder_text) {
    668 0         0 $options = '' . $options;
    669             }
    670             }
    671             elsif (ref $args{options} eq 'ARRAY') {
    672 1         3 foreach my $option (@{$args{options}}) {
      1         3  
    673 5         64 my $selected = '';
    674              
    675 5 50       14 if (defined $args{value}) {
    676              
    677 0 0       0 if (ref $args{value} eq 'ARRAY') {
        0          
    678 0         0 foreach my $element (@{$args{value}}) {
      0         0  
    679 0 0       0 if ($option eq $element) {
    680 0         0 $selected = 'selected="selected"';
    681 0         0 last;
    682             }
    683             }
    684             }
    685             elsif ($option eq $args{value}) {
    686 0         0 $selected = 'selected="selected"';
    687             }
    688             }
    689              
    690 5         19 $options .= '';
    691             }
    692              
    693 1 50       16 if (defined $placeholder_text) {
    694 0         0 $options = '' . $options;
    695             }
    696             }
    697             else {
    698 0         0 $options = $args{options};
    699             }
    700              
    701 1   50     8 $args{container_role} ||= 'fieldcontain';
    702 1 50       14 my $invalid = $args{invalid} ? $self->{config}->{invalid}->(\%args) : '';
    703 1         9 return '
    ' . $invalid . '
    ' . "\n";
    704             }
    705              
    706             sub radio {
    707 1     1 1 4 my ($self, %args) = @_;
    708              
    709 1         4 $args{type} = 'radio';
    710 1         6 return $self->_radio_checkbox(%args);
    711             }
    712              
    713             sub checkbox {
    714 1     1 1 3 my ($self, %args) = @_;
    715              
    716 1         3 $args{type} = 'checkbox';
    717 1         3 return $self->_radio_checkbox(%args);
    718             }
    719              
    720             sub _radio_checkbox {
    721 2     2   6 my ($self, %args) = @_;
    722              
    723 2   33     10 $args{id} ||= $args{name};
    724 2   33     10 $args{label} ||= _label($args{name});
    725              
    726 2         7 my $data_attributes = _data_attribute('', $self->{config}->{'radio-checkbox-data-attribute'}, \%args);
    727 2         55 my $cloned_args = clone(\%args);
    728 2         5 my $options = '';
    729              
    730 2 100       8 if (ref $args{options} eq 'HASH') {
        50          
    731              
    732 1         2 my @keys;
    733 1         2 my $sort_options = $args{sort_options};
    734 1 50 33     5 if ($sort_options && $sort_options eq 'key') {
    735 0         0 @keys = sort keys %{$args{options}};
      0         0  
    736             }
    737             else {
    738 1         1 @keys = sort {$args{options}->{$a} cmp $args{options}->{$b}} keys %{$args{options}};
      1         6  
      1         7  
    739             }
    740              
    741 1         3 foreach my $key (@keys) {
    742 2         13 $cloned_args->{id} = $args{name} . '-' . _id($key);
    743 2         3 $cloned_args->{value} = $key;
    744 2         9 my $html_attributes = _html_attribute('', $self->{config}->{'radio-checkbox-html-attribute'}, $cloned_args);
    745              
    746 2         4 my $checked = '';
    747              
    748 2 50       6 if (defined $args{value}) {
    749              
    750 2 50       11 if (ref $args{value} eq 'HASH') {
        100          
    751 0         0 foreach my $value_key (keys %{$args{value}}) {
      0         0  
    752 0 0       0 if ($key eq $value_key) {
    753 0         0 $checked = ' checked="checked"';
    754 0         0 last;
    755             }
    756             }
    757             }
    758             elsif ($key eq $args{value}) {
    759 1         2 $checked = ' checked="checked"';
    760             }
    761             }
    762              
    763 2         14 $options .= '';
    764             }
    765             }
    766             elsif (ref $args{options} eq 'ARRAY') {
    767 1         2 foreach my $key (@{$args{options}}) {
      1         2  
    768 2         6 $cloned_args->{id} = $args{name} . '-' . _id($key);
    769 2         4 $cloned_args->{value} = $key;
    770 2         9 my $html_attributes = _html_attribute('', $self->{config}->{'radio-checkbox-html-attribute'}, $cloned_args);
    771              
    772 2         4 my $checked = '';
    773              
    774 2 50       6 if (defined $args{value}) {
    775              
    776 0 0       0 if (ref $args{value} eq 'ARRAY') {
        0          
    777 0         0 foreach my $element (@{$args{value}}) {
      0         0  
    778 0 0       0 if ($key eq $element) {
    779 0         0 $checked = ' checked="checked"';
    780 0         0 last;
    781             }
    782             }
    783             }
    784             elsif ($key eq $args{value}) {
    785 0         0 $checked = ' checked="checked"';
    786             }
    787             }
    788              
    789 2         12 $options .= '';
    790             }
    791             }
    792             else {
    793 0         0 $options = $args{options};
    794             }
    795              
    796 2 50       7 my $invalid = $args{invalid} ? $self->{config}->{invalid}->(\%args) : '';
    797            
    798 2         21 my $controlgroup = clone ($args{controlgroup});
    799 2         7 $controlgroup->{fieldset} = 1;
    800 2   33     21 $controlgroup->{content} ||= ' ' . $self->{config}->{label}->(\%args) . ':' . $options . $invalid;
    801              
    802 2         56 return $self->controlgroup(%{$controlgroup});
      2         11  
    803             }
    804              
    805             sub _header_footer_attribute {
    806 7     7   11 my ($self, $type, $args) = @_;
    807 7         12 my $attributes = '';
    808              
    809 7 50       31 if (exists $args->{'fixed'}) {
        50          
    810 0 0       0 if ($args->{'fixed'}) {
    811 0         0 $attributes = ' data-position="fixed"';
    812             }
    813             }
    814             elsif ($self->{config}->{$type . '-fixed'}) {
    815 0         0 $attributes = ' data-position="fixed"';
    816             }
    817              
    818 7 100       28 if (exists $args->{'fullscreen'}) {
        50          
    819 1 50       4 if ($args->{'fullscreen'}) {
    820 1         2 $attributes .= ' data-fullscreen="true"';
    821             }
    822             }
    823             elsif ($self->{config}->{$type . '-fullscreen'}) {
    824 0         0 $attributes .= ' data-fullscreen="true"';
    825             }
    826              
    827 7         21 $attributes = _html_attribute($attributes, $self->{config}->{'header-footer-html-attribute'}, $args);
    828 7         21 $attributes = _data_attribute($attributes, $self->{config}->{'header-footer-data-attribute'}, $args);
    829              
    830 7         17 return $attributes;
    831             }
    832              
    833             sub _html_attribute {
    834 70     70   124 my ($attributes, $options, $args) = @_;
    835              
    836 70         86 foreach my $option (@{$options}) {
      70         136  
    837 323 100       865 if (exists $args->{$option}) {
    838 70         210 $attributes .= ' ' . $option . '="' . $args->{$option} . '"';
    839             }
    840             }
    841              
    842 70         177 return $attributes;
    843             }
    844              
    845             sub _data_attribute {
    846 68     68   109 my ($attributes, $options, $args) = @_;
    847 68         74 foreach my $option (@{$options}) {
      68         225  
    848 581 100       2143 if (exists $args->{'data-' . $option}) {
        100          
    849 1         4 $attributes .= ' data-' . $option . '="' . $args->{'data-' . $option} . '"';
    850             }
    851             elsif (exists $args->{$option}) {
    852 48         149 $attributes .= ' data-' . $option . '="' . $args->{$option} . '"';
    853             }
    854             }
    855 68         168 return $attributes;
    856             }
    857              
    858             sub _label {
    859 8     8   9 my $string = shift;
    860 8         17 $string =~ s/_/ /g;
    861 8         57 $string =~ s/\b(\w)/\u$1/gx;
    862 8         34 return $string;
    863             }
    864              
    865             sub _id {
    866 4     4   5 my $text = shift;
    867 4         5 $text =~ s/&/and/g;
    868 4         5 $text =~ s/\//-/g;
    869 4         8 $text =~ s/[^0-9A-Za-z\-_.:]//g;
    870 4         12 return lc($text);
    871             }
    872              
    873             1;
    874              
    875             __END__