(items, $children, counter)
| 1942 | |
| 1943 | // convert <menu> to items object |
| 1944 | function menuChildren(items, $children, counter) { |
| 1945 | if (!counter) { |
| 1946 | counter = 0; |
| 1947 | } |
| 1948 | |
| 1949 | $children.each(function () { |
| 1950 | var $node = $(this), |
| 1951 | node = this, |
| 1952 | nodeName = this.nodeName.toLowerCase(), |
| 1953 | label, |
| 1954 | item; |
| 1955 | |
| 1956 | // extract <label><input> |
| 1957 | if (nodeName === 'label' && $node.find('input, textarea, select').length) { |
| 1958 | label = $node.text(); |
| 1959 | $node = $node.children().first(); |
| 1960 | node = $node.get(0); |
| 1961 | nodeName = node.nodeName.toLowerCase(); |
| 1962 | } |
| 1963 | |
| 1964 | /* |
| 1965 | * <menu> accepts flow-content as children. that means <embed>, <canvas> and such are valid menu items. |
| 1966 | * Not being the sadistic kind, $.contextMenu only accepts: |
| 1967 | * <command>, <menuitem>, <hr>, <span>, <p> <input [text, radio, checkbox]>, <textarea>, <select> and of course <menu>. |
| 1968 | * Everything else will be imported as an html node, which is not interfaced with contextMenu. |
| 1969 | */ |
| 1970 | |
| 1971 | // http://www.whatwg.org/specs/web-apps/current-work/multipage/commands.html#concept-command |
| 1972 | switch (nodeName) { |
| 1973 | // http://www.whatwg.org/specs/web-apps/current-work/multipage/interactive-elements.html#the-menu-element |
| 1974 | case 'menu': |
| 1975 | item = {name: $node.attr('label'), items: {}}; |
| 1976 | counter = menuChildren(item.items, $node.children(), counter); |
| 1977 | break; |
| 1978 | |
| 1979 | // http://www.whatwg.org/specs/web-apps/current-work/multipage/commands.html#using-the-a-element-to-define-a-command |
| 1980 | case 'a': |
| 1981 | // http://www.whatwg.org/specs/web-apps/current-work/multipage/commands.html#using-the-button-element-to-define-a-command |
| 1982 | case 'button': |
| 1983 | item = { |
| 1984 | name: $node.text(), |
| 1985 | disabled: !!$node.attr('disabled'), |
| 1986 | callback: (function () { |
| 1987 | return function () { |
| 1988 | $node.get(0).click(); |
| 1989 | }; |
| 1990 | })() |
| 1991 | }; |
| 1992 | break; |
| 1993 | |
| 1994 | // http://www.whatwg.org/specs/web-apps/current-work/multipage/commands.html#using-the-command-element-to-define-a-command |
| 1995 | case 'menuitem': |
| 1996 | case 'command': |
| 1997 | switch ($node.attr('type')) { |
| 1998 | case undefined: |
| 1999 | case 'command': |
| 2000 | case 'menuitem': |
| 2001 | item = { |
no test coverage detected