1: <?php
2: /**
3: * Triggered when the menu loses focus.
4: *
5: * * event Type: Event
6: *
7: * * ui Type: Object
8: *
9: * * item Type: jQuery The currently active menu item.
10: *
11: */
12: class QMenu_BlurEvent extends QJqUiEvent {
13: const EventName = 'menublur';
14: }
15: /**
16: * Triggered when the menu is created.
17: *
18: * * event Type: Event
19: * * ui Type: Object
20: *
21: * _Note: The ui object is empty but included for consistency with other
22: * events._ */
23: class QMenu_CreateEvent extends QJqUiEvent {
24: const EventName = 'menucreate';
25: }
26: /**
27: * Triggered when a menu gains focus or when any menu item is activated.
28: *
29: * * event Type: Event
30: *
31: * * ui Type: Object
32: *
33: * * item Type: jQuery The currently active menu item.
34: *
35: */
36: class QMenu_FocusEvent extends QJqUiEvent {
37: const EventName = 'menufocus';
38: }
39: /**
40: * Triggered when a menu item is selected.
41: *
42: * * event Type: Event
43: *
44: * * ui Type: Object
45: *
46: * * item Type: jQuery The currently active menu item.
47: *
48: */
49: class QMenu_SelectEvent extends QJqUiEvent {
50: const EventName = 'menuselect';
51: }
52:
53: /* Custom "property" event classes for this control */
54:
55: /**
56: * Generated QMenuGen class.
57: *
58: * This is the QMenuGen class which is automatically generated
59: * by scraping the JQuery UI documentation website. As such, it includes all the options
60: * as listed by the JQuery UI website, which may or may not be appropriate for QCubed. See
61: * the QMenuBase class for any glue code to make this class more
62: * usable in QCubed.
63: *
64: * @see QMenuBase
65: * @package Controls\Base
66: * @property boolean $Disabled
67: * Disables the menu if set to true.
68: *
69: * @property mixed $Icons
70: * Icons to use for submenus, matching an icon provided by the jQuery UI
71: * CSS Framework.
72: *
73: * * submenu (string, default: "ui-icon-carat-1-e")
74: *
75:
76: *
77: * @property string $Items
78: * Selector for the elements that serve as the menu items. Note: The
79: * items option should not be changed after initialization. (version
80: * added: 1.11.0)
81: *
82: * @property string $Menus
83: * Selector for the elements that serve as the menu container, including
84: * sub-menus. Note: The menus option should not be changed after
85: * initialization. Existing submenus will not be updated.
86: *
87: * @property mixed $Position
88: * Identifies the position of submenus in relation to the associated
89: * parent menu item. The of option defaults to the parent menu item, but
90: * you can specify another element to position against. You can refer to
91: * the jQuery UI Position utility for more details about the various
92: * options.
93: *
94: * @property string $Role
95: * Customize the ARIA roles used for the menu and menu items. The default
96: * uses "menuitem" for items. Setting the role option to "listbox" will
97: * use "option" for items. If set to null, no roles will be set, which is
98: * useful if the menu is being controlled by another element that is
99: * maintaining focus. Note: The role option should not be changed after
100: * initialization. Existing (sub)menus and menu items will not be
101: * updated.
102: *
103: */
104:
105: class QMenuGen extends QPanel {
106: protected $strJavaScripts = __JQUERY_EFFECTS__;
107: protected $strStyleSheets = __JQUERY_CSS__;
108: /** @var boolean */
109: protected $blnDisabled = null;
110: /** @var mixed */
111: protected $mixIcons = null;
112: /** @var string */
113: protected $strItems = null;
114: /** @var string */
115: protected $strMenus = null;
116: /** @var mixed */
117: protected $mixPosition = null;
118: /** @var string */
119: protected $strRole = null;
120:
121: /**
122: * Builds the option array to be sent to the widget constructor.
123: *
124: * @return array key=>value array of options
125: */
126: protected function MakeJqOptions() {
127: $jqOptions = null;
128: if (!is_null($val = $this->Disabled)) {$jqOptions['disabled'] = $val;}
129: if (!is_null($val = $this->Icons)) {$jqOptions['icons'] = $val;}
130: if (!is_null($val = $this->Items)) {$jqOptions['items'] = $val;}
131: if (!is_null($val = $this->Menus)) {$jqOptions['menus'] = $val;}
132: if (!is_null($val = $this->Position)) {$jqOptions['position'] = $val;}
133: if (!is_null($val = $this->Role)) {$jqOptions['role'] = $val;}
134: return $jqOptions;
135: }
136:
137: /**
138: * Return the JavaScript function to call to associate the widget with the control.
139: *
140: * @return string
141: */
142: public function GetJqSetupFunction() {
143: return 'menu';
144: }
145:
146: /**
147: * Returns the script that attaches the JQueryUI widget to the html object.
148: *
149: * @return string
150: */
151: public function GetEndScript() {
152: $strId = $this->GetJqControlId();
153: $jqOptions = $this->makeJqOptions();
154: $strFunc = $this->getJqSetupFunction();
155:
156: if ($strId !== $this->ControlId && QApplication::$RequestMode == QRequestMode::Ajax) {
157: // If events are not attached to the actual object being drawn, then the old events will not get
158: // deleted during redraw. We delete the old events here. This must happen before any other event processing code.
159: QApplication::ExecuteControlCommand($strId, 'off', QJsPriority::High);
160: }
161:
162: // Attach the javascript widget to the html object
163: if (empty($jqOptions)) {
164: QApplication::ExecuteControlCommand($strId, $strFunc, QJsPriority::High);
165: } else {
166: QApplication::ExecuteControlCommand($strId, $strFunc, $jqOptions, QJsPriority::High);
167: }
168:
169: return parent::GetEndScript();
170: }
171:
172: /**
173: * Removes focus from a menu, resets any active element styles and
174: * triggers the menus blur event.
175: *
176: * * event Type: Event What triggered the menu to blur.
177: * @param $event
178: */
179: public function Blur($event = null) {
180: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "blur", $event, QJsPriority::Low);
181: }
182: /**
183: * Closes the currently active sub-menu.
184: *
185: * * event Type: Event What triggered the menu to collapse.
186: * @param $event
187: */
188: public function Collapse($event = null) {
189: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "collapse", $event, QJsPriority::Low);
190: }
191: /**
192: * Closes all open sub-menus.
193: *
194: * * event Type: Event What triggered the menu to collapse.
195: * * all Type: Boolean Indicates whether all sub-menus should be closed
196: * or only sub-menus below and including the menu that is or contains the
197: * target of the triggering event.
198: * @param $event
199: * @param $all
200: */
201: public function CollapseAll($event = null, $all = null) {
202: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "collapseAll", $event, $all, QJsPriority::Low);
203: }
204: /**
205: * Removes the menu functionality completely. This will return the
206: * element back to its pre-init state.
207: *
208: * * This method does not accept any arguments.
209: */
210: public function Destroy() {
211: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "destroy", QJsPriority::Low);
212: }
213: /**
214: * Disables the menu.
215: *
216: * * This method does not accept any arguments.
217: */
218: public function Disable() {
219: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "disable", QJsPriority::Low);
220: }
221: /**
222: * Enables the menu.
223: *
224: * * This method does not accept any arguments.
225: */
226: public function Enable() {
227: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "enable", QJsPriority::Low);
228: }
229: /**
230: * Opens the sub-menu below the currently active item, if one exists.
231: *
232: * * event Type: Event What triggered the menu to expand.
233: * @param $event
234: */
235: public function Expand($event = null) {
236: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "expand", $event, QJsPriority::Low);
237: }
238: /**
239: * Activates a particular menu item, begins opening any sub-menu if
240: * present and triggers the menus focus event.
241: *
242: * * event Type: Event What triggered the menu item to gain focus.
243: * * item Type: jQuery The menu item to focus/activate.
244: * @param $item
245: * @param $event
246: */
247: public function Focus($event = null, $item) {
248: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "focus", $item, $event, QJsPriority::Low);
249: }
250: /**
251: * Retrieves the menus instance object. If the element does not have an
252: * associated instance, undefined is returned.
253: *
254: * Unlike other widget methods, instance() is safe to call on any element
255: * after the menu plugin has loaded.
256: *
257: * * This method does not accept any arguments.
258: */
259: public function Instance() {
260: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "instance", QJsPriority::Low);
261: }
262: /**
263: * Returns a boolean value stating whether or not the currently active
264: * item is the first item in the menu.
265: *
266: * * This method does not accept any arguments.
267: */
268: public function IsFirstItem() {
269: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "isFirstItem", QJsPriority::Low);
270: }
271: /**
272: * Returns a boolean value stating whether or not the currently active
273: * item is the last item in the menu.
274: *
275: * * This method does not accept any arguments.
276: */
277: public function IsLastItem() {
278: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "isLastItem", QJsPriority::Low);
279: }
280: /**
281: * Moves active state to next menu item.
282: *
283: * * event Type: Event What triggered the focus to move.
284: * @param $event
285: */
286: public function Next($event = null) {
287: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "next", $event, QJsPriority::Low);
288: }
289: /**
290: * Moves active state to first menu item below the bottom of a scrollable
291: * menu or the last item if not scrollable.
292: *
293: * * event Type: Event What triggered the focus to move.
294: * @param $event
295: */
296: public function NextPage($event = null) {
297: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "nextPage", $event, QJsPriority::Low);
298: }
299: /**
300: * Gets the value currently associated with the specified optionName.
301: *
302: * Note: For options that have objects as their value, you can get the
303: * value of a specific key by using dot notation. For example, "foo.bar"
304: * would get the value of the bar property on the foo option.
305: *
306: * * optionName Type: String The name of the option to get.
307: * @param $optionName
308: */
309: public function Option($optionName) {
310: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, QJsPriority::Low);
311: }
312: /**
313: * Gets an object containing key/value pairs representing the current
314: * menu options hash.
315: *
316: * * This signature does not accept any arguments.
317: */
318: public function Option1() {
319: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", QJsPriority::Low);
320: }
321: /**
322: * Sets the value of the menu option associated with the specified
323: * optionName.
324: *
325: * Note: For options that have objects as their value, you can set the
326: * value of just one property by using dot notation for optionName. For
327: * example, "foo.bar" would update only the bar property of the foo
328: * option.
329: *
330: * * optionName Type: String The name of the option to set.
331: * * value Type: Object A value to set for the option.
332: * @param $optionName
333: * @param $value
334: */
335: public function Option2($optionName, $value) {
336: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, $value, QJsPriority::Low);
337: }
338: /**
339: * Sets one or more options for the menu.
340: *
341: * * options Type: Object A map of option-value pairs to set.
342: * @param $options
343: */
344: public function Option3($options) {
345: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $options, QJsPriority::Low);
346: }
347: /**
348: * Moves active state to previous menu item.
349: *
350: * * event Type: Event What triggered the focus to move.
351: * @param $event
352: */
353: public function Previous($event = null) {
354: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "previous", $event, QJsPriority::Low);
355: }
356: /**
357: * Moves active state to first menu item above the top of a scrollable
358: * menu or the first item if not scrollable.
359: *
360: * * event Type: Event What triggered the focus to move.
361: * @param $event
362: */
363: public function PreviousPage($event = null) {
364: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "previousPage", $event, QJsPriority::Low);
365: }
366: /**
367: * Initializes sub-menus and menu items that have not already been
368: * initialized. New menu items, including sub-menus can be added to the
369: * menu or all of the contents of the menu can be replaced and then
370: * initialized with the refresh() method.
371: *
372: * * This method does not accept any arguments.
373: */
374: public function Refresh() {
375: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "refresh", QJsPriority::Low);
376: }
377: /**
378: * Selects the currently active menu item, collapses all sub-menus and
379: * triggers the menus select event.
380: *
381: * * event Type: Event What triggered the selection.
382: * @param $event
383: */
384: public function Select($event = null) {
385: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "select", $event, QJsPriority::Low);
386: }
387:
388:
389: public function __get($strName) {
390: switch ($strName) {
391: case 'Disabled': return $this->blnDisabled;
392: case 'Icons': return $this->mixIcons;
393: case 'Items': return $this->strItems;
394: case 'Menus': return $this->strMenus;
395: case 'Position': return $this->mixPosition;
396: case 'Role': return $this->strRole;
397: default:
398: try {
399: return parent::__get($strName);
400: } catch (QCallerException $objExc) {
401: $objExc->IncrementOffset();
402: throw $objExc;
403: }
404: }
405: }
406:
407: public function __set($strName, $mixValue) {
408: switch ($strName) {
409: case 'Disabled':
410: try {
411: $this->blnDisabled = QType::Cast($mixValue, QType::Boolean);
412: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'disabled', $this->blnDisabled);
413: break;
414: } catch (QInvalidCastException $objExc) {
415: $objExc->IncrementOffset();
416: throw $objExc;
417: }
418:
419: case 'Icons':
420: $this->mixIcons = $mixValue;
421: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'icons', $mixValue);
422: break;
423:
424: case 'Items':
425: try {
426: $this->strItems = QType::Cast($mixValue, QType::String);
427: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'items', $this->strItems);
428: break;
429: } catch (QInvalidCastException $objExc) {
430: $objExc->IncrementOffset();
431: throw $objExc;
432: }
433:
434: case 'Menus':
435: try {
436: $this->strMenus = QType::Cast($mixValue, QType::String);
437: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'menus', $this->strMenus);
438: break;
439: } catch (QInvalidCastException $objExc) {
440: $objExc->IncrementOffset();
441: throw $objExc;
442: }
443:
444: case 'Position':
445: $this->mixPosition = $mixValue;
446: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'position', $mixValue);
447: break;
448:
449: case 'Role':
450: try {
451: $this->strRole = QType::Cast($mixValue, QType::String);
452: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'role', $this->strRole);
453: break;
454: } catch (QInvalidCastException $objExc) {
455: $objExc->IncrementOffset();
456: throw $objExc;
457: }
458:
459:
460: case 'Enabled':
461: $this->Disabled = !$mixValue; // Tie in standard QCubed functionality
462: parent::__set($strName, $mixValue);
463: break;
464:
465: default:
466: try {
467: parent::__set($strName, $mixValue);
468: break;
469: } catch (QCallerException $objExc) {
470: $objExc->IncrementOffset();
471: throw $objExc;
472: }
473: }
474: }
475:
476: /**
477: * If this control is attachable to a codegenerated control in a ModelConnector, this function will be
478: * used by the ModelConnector designer dialog to display a list of options for the control.
479: * @return QModelConnectorParam[]
480: **/
481: public static function GetModelConnectorParams() {
482: return array_merge(parent::GetModelConnectorParams(), array(
483: new QModelConnectorParam (get_called_class(), 'Disabled', 'Disables the menu if set to true.', QType::Boolean),
484: new QModelConnectorParam (get_called_class(), 'Items', 'Selector for the elements that serve as the menu items. Note: Theitems option should not be changed after initialization. (versionadded: 1.11.0)', QType::String),
485: new QModelConnectorParam (get_called_class(), 'Menus', 'Selector for the elements that serve as the menu container, includingsub-menus. Note: The menus option should not be changed afterinitialization. Existing submenus will not be updated.', QType::String),
486: new QModelConnectorParam (get_called_class(), 'Role', 'Customize the ARIA roles used for the menu and menu items. The defaultuses \"menuitem\" for items. Setting the role option to \"listbox\" willuse \"option\" for items. If set to null, no roles will be set, which isuseful if the menu is being controlled by another element that ismaintaining focus. Note: The role option should not be changed afterinitialization. Existing (sub)menus and menu items will not beupdated.', QType::String),
487: ));
488: }
489: }