/js/widgets/controlgroup.js

https://github.com/forresst/jquery-mobile-fr_FR · JavaScript · 120 lines · 82 code · 18 blank · 20 comment · 4 complexity · e3003fd4ecfdf1eefcb36c97906f0b58 MD5 · raw file

  1. //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
  2. //>>description: Visually groups sets of buttons, checks, radios, etc.
  3. //>>label: Controlgroups
  4. //>>group: Forms
  5. //>>css.structure: ../css/structure/jquery.mobile.controlgroup.css
  6. //>>css.theme: ../css/themes/default/jquery.mobile.theme.css
  7. define( [ "jquery",
  8. "../jquery.mobile.buttonMarkup",
  9. "./addFirstLastClasses",
  10. "../jquery.mobile.widget" ], function( $ ) {
  11. //>>excludeEnd("jqmBuildExclude");
  12. (function( $, undefined ) {
  13. $.widget( "mobile.controlgroup", $.mobile.widget, {
  14. options: {
  15. shadow: false,
  16. corners: true,
  17. excludeInvisible: true,
  18. type: "vertical",
  19. mini: false,
  20. initSelector: ":jqmData(role='controlgroup')"
  21. },
  22. _create: function() {
  23. var $el = this.element,
  24. ui = {
  25. inner: $( "<div class='ui-controlgroup-controls'></div>" ),
  26. legend: $( "<div role='heading' class='ui-controlgroup-label'></div>" )
  27. },
  28. grouplegend = $el.children( "legend" ),
  29. self = this;
  30. // Apply the proto
  31. $el.wrapInner( ui.inner );
  32. if ( grouplegend.length ) {
  33. ui.legend.append( grouplegend ).insertBefore( $el.children( 0 ) );
  34. }
  35. $el.addClass( "ui-corner-all ui-controlgroup" );
  36. $.extend( this, {
  37. _initialRefresh: true
  38. });
  39. $.each( this.options, function( key, value ) {
  40. // Cause initial options to be applied by their handler by temporarily setting the option to undefined
  41. // - the handler then sets it to the initial value
  42. self.options[ key ] = undefined;
  43. self._setOption( key, value, true );
  44. });
  45. },
  46. _init: function() {
  47. this.refresh();
  48. },
  49. _setOption: function( key, value ) {
  50. var setter = "_set" + key.charAt( 0 ).toUpperCase() + key.slice( 1 );
  51. if ( this[ setter ] !== undefined ) {
  52. this[ setter ]( value );
  53. }
  54. this._super( key, value );
  55. this.element.attr( "data-" + ( $.mobile.ns || "" ) + ( key.replace( /([A-Z])/, "-$1" ).toLowerCase() ), value );
  56. },
  57. _setType: function( value ) {
  58. this.element
  59. .removeClass( "ui-controlgroup-horizontal ui-controlgroup-vertical" )
  60. .addClass( "ui-controlgroup-" + value );
  61. this.refresh();
  62. },
  63. _setCorners: function( value ) {
  64. this.element.toggleClass( "ui-corner-all", value );
  65. },
  66. _setShadow: function( value ) {
  67. this.element.toggleClass( "ui-shadow", value );
  68. },
  69. _setMini: function( value ) {
  70. this.element.toggleClass( "ui-mini", value );
  71. },
  72. container: function() {
  73. return this.element.children( ".ui-controlgroup-controls" );
  74. },
  75. refresh: function() {
  76. var els = this.element.find( ".ui-btn" ).not( ".ui-slider-handle" ),
  77. create = this._initialRefresh;
  78. if ( $.mobile.checkboxradio ) {
  79. this.element.find( ":mobile-checkboxradio" ).checkboxradio( "refresh" );
  80. }
  81. this._addFirstLastClasses( els, this.options.excludeInvisible ? this._getVisibles( els, create ) : els, create );
  82. this._initialRefresh = false;
  83. }
  84. });
  85. $.widget( "mobile.controlgroup", $.mobile.controlgroup, $.mobile.behaviors.addFirstLastClasses );
  86. // TODO: Implement a mechanism to allow widgets to become enhanced in the
  87. // correct order when their correct enhancement depends on other widgets in
  88. // the page being correctly enhanced already.
  89. //
  90. // For now, we wait until dom-ready to attach the controlgroup's enhancement
  91. // hook, because by that time, all the other widgets' enhancement hooks should
  92. // already be in place, ensuring that all widgets that need to be grouped will
  93. // already have been enhanced by the time the controlgroup is created.
  94. $( function() {
  95. $.mobile.document.bind( "pagecreate create", function( e ) {
  96. $.mobile.controlgroup.prototype.enhanceWithin( e.target, true );
  97. });
  98. });
  99. })(jQuery);
  100. //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
  101. });
  102. //>>excludeEnd("jqmBuildExclude");