[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/editor/atto/plugins/collapse/yui/build/moodle-atto_collapse-button/ -> moodle-atto_collapse-button-debug.js (source)

   1  YUI.add('moodle-atto_collapse-button', function (Y, NAME) {
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /*
  19   * @package    atto_collapse
  20   * @copyright  2013 Damyon Wiese  <damyon@moodle.com>
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  /**
  25   * @module moodle-atto_collapse-button
  26   */
  27  
  28  /**
  29   * Atto text editor collapse plugin.
  30   *
  31   * @namespace M.atto_collapse
  32   * @class button
  33   * @extends M.editor_atto.EditorPlugin
  34   */
  35  
  36  var PLUGINNAME = 'atto_collapse',
  37      ATTRSHOWGROUPS = 'showgroups',
  38      COLLAPSE = 'collapse',
  39      COLLAPSED = 'collapsed',
  40      GROUPS = '.atto_group';
  41  
  42  Y.namespace('M.atto_collapse').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {
  43      initializer: function() {
  44          var toolbarGroupCount = Y.Object.size(this.get('host').get('plugins'));
  45          if (toolbarGroupCount <= 1 + parseInt(this.get(ATTRSHOWGROUPS), 10)) {
  46              Y.log("There are not enough groups to require toggling - not adding the button",
  47                  'debug', 'moodle-atto_collapse');
  48              return;
  49          }
  50  
  51          if (this.toolbar.all(GROUPS).size() > this.get(ATTRSHOWGROUPS)) {
  52              Y.log("The collapse plugin is shown after it's cut-off - not adding the button",
  53                  'debug', 'moodle-atto_collapse');
  54              return;
  55          }
  56  
  57          var button = this.addButton({
  58              icon: 'icon',
  59              iconComponent: PLUGINNAME,
  60              callback: this._toggle
  61          });
  62  
  63          // Perform a toggle after all plugins have been loaded for the first time.
  64          this.get('host').on('pluginsloaded', function(e, button) {
  65              this._setVisibility(button);
  66  
  67              // Set the toolbar to break after the initial those displayed by default.
  68              var firstGroup = this.toolbar.all(GROUPS).item(this.get(ATTRSHOWGROUPS));
  69              firstGroup.insert('<div class="toolbarbreak"></div>', 'before');
  70          }, this, button);
  71      },
  72  
  73      /**
  74       * Toggle the visibility of the extra groups in the toolbar.
  75       *
  76       * @method _toggle
  77       * @param {EventFacade} e
  78       * @private
  79       */
  80      _toggle: function(e) {
  81          e.preventDefault();
  82          var button = this.buttons[COLLAPSE];
  83  
  84          if (button.getData(COLLAPSED)) {
  85              this.highlightButtons(COLLAPSE);
  86              this._setVisibility(button, true);
  87          } else {
  88              this.unHighlightButtons(COLLAPSE);
  89              this._setVisibility(button);
  90          }
  91  
  92          this.buttons[this.name].focus();
  93      },
  94  
  95      /**
  96       * Set the visibility of the toolbar groups.
  97       *
  98       * @method _setVisibility
  99       * @param {Node} button The collapse button
 100       * @param {Booelan} visibility Whether the groups should be made visible
 101       * @private
 102       */
 103      _setVisibility: function(button, visibility) {
 104          var groups = this.toolbar.all(GROUPS).slice(this.get(ATTRSHOWGROUPS));
 105  
 106          if (visibility) {
 107              button.set('title', M.util.get_string('showfewer', PLUGINNAME));
 108              groups.show();
 109              button.setData(COLLAPSED, false);
 110          } else {
 111              button.set('title', M.util.get_string('showmore', PLUGINNAME));
 112              groups.hide();
 113              button.setData(COLLAPSED, true);
 114          }
 115  
 116      }
 117  }, {
 118      ATTRS: {
 119          /**
 120           * How many groups to show when collapsed.
 121           *
 122           * @attribute showgroups
 123           * @type Number
 124           * @default 3
 125           */
 126          showgroups: {
 127              value: 3
 128          }
 129      }
 130  });
 131  
 132  
 133  }, '@VERSION@', {"requires": ["moodle-editor_atto-plugin"]});


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1