From 54a3dca258501484a25a6fb082d112140de8839c Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 23 Dec 2013 15:48:54 +0800 Subject: [PATCH] MDL-43307 JavaScript: Migrate moodle-mod_assign-history to use Shifter --- .../moodle-mod_assign-history-debug.js | 73 +++++++++++++++++++ .../moodle-mod_assign-history-min.js | 1 + .../moodle-mod_assign-history.js | 73 +++++++++++++++++++ mod/assign/yui/history/history.js | 70 ------------------ mod/assign/yui/src/history/build.json | 10 +++ mod/assign/yui/src/history/js/history.js | 68 +++++++++++++++++ mod/assign/yui/src/history/meta/history.json | 8 ++ 7 files changed, 233 insertions(+), 70 deletions(-) create mode 100644 mod/assign/yui/build/moodle-mod_assign-history/moodle-mod_assign-history-debug.js create mode 100644 mod/assign/yui/build/moodle-mod_assign-history/moodle-mod_assign-history-min.js create mode 100644 mod/assign/yui/build/moodle-mod_assign-history/moodle-mod_assign-history.js delete mode 100644 mod/assign/yui/history/history.js create mode 100644 mod/assign/yui/src/history/build.json create mode 100644 mod/assign/yui/src/history/js/history.js create mode 100644 mod/assign/yui/src/history/meta/history.json diff --git a/mod/assign/yui/build/moodle-mod_assign-history/moodle-mod_assign-history-debug.js b/mod/assign/yui/build/moodle-mod_assign-history/moodle-mod_assign-history-debug.js new file mode 100644 index 00000000000..73c93578fcd --- /dev/null +++ b/mod/assign/yui/build/moodle-mod_assign-history/moodle-mod_assign-history-debug.js @@ -0,0 +1,73 @@ +YUI.add('moodle-mod_assign-history', function (Y, NAME) { + +// Define a function that will run in the context of a +// Node instance: +var CSS = { + LINK: 'mod-assign-history-link', + OPEN: 'mod-assign-history-link-open', + CLOSED: 'mod-assign-history-link-closed', + PANEL: 'mod-assign-history-panel' + }, + COUNT = 0, + TOGGLE = function() { + var id = this.get('for'), + panel = Y.one('#' + id); + if (this.hasClass(CSS.OPEN)) { + this.removeClass(CSS.OPEN); + this.addClass(CSS.CLOSED); + this.setStyle('overflow', 'hidden'); + panel.hide(); + } else { + this.removeClass(CSS.CLOSED); + this.addClass(CSS.OPEN); + panel.show(); + } + }, + HISTORY = function() { + var link = null, + panel = null, + wrapper = null, + container = this; + + // Loop through all the children of this container and turn + // every odd node to a link to open/close the following panel. + this.get('children').each(function () { + if (link) { + COUNT++; + // First convert the link to an anchor. + wrapper = Y.Node.create(''); + panel = this; + container.insertBefore(wrapper, link); + link.remove(false); + wrapper.appendChild(link); + + // Add a for attribute to the link to link to the id of the panel. + if (!panel.get('id')) { + panel.set('id', CSS.PANEL + COUNT); + } + wrapper.set('for', panel.get('id')); + // Add an aria attribute for the live region. + panel.set('aria-live', 'polite'); + + wrapper.addClass(CSS.LINK); + wrapper.addClass(CSS.CLOSED); + panel.addClass(CSS.PANEL); + panel.hide(); + link = null; + } else { + link = this; + } + }); + + // Setup event listeners. + this.delegate('click', TOGGLE, '.' + CSS.LINK); + }; + +// Use addMethod to add history to the Node prototype: +Y.Node.addMethod("history", HISTORY); + +// Extend this functionality to NodeLists. +Y.NodeList.importMethod(Y.Node.prototype, "history"); + + +}, '@VERSION@', {"requires": ["node", "transition"]}); diff --git a/mod/assign/yui/build/moodle-mod_assign-history/moodle-mod_assign-history-min.js b/mod/assign/yui/build/moodle-mod_assign-history/moodle-mod_assign-history-min.js new file mode 100644 index 00000000000..81dd1a95e0e --- /dev/null +++ b/mod/assign/yui/build/moodle-mod_assign-history/moodle-mod_assign-history-min.js @@ -0,0 +1 @@ +YUI.add("moodle-mod_assign-history",function(e,t){var n={LINK:"mod-assign-history-link",OPEN:"mod-assign-history-link-open",CLOSED:"mod-assign-history-link-closed",PANEL:"mod-assign-history-panel"},r=0,i=function(){var t=this.get("for"),r=e.one("#"+t);this.hasClass(n.OPEN)?(this.removeClass(n.OPEN),this.addClass(n.CLOSED),this.setStyle("overflow","hidden"),r.hide()):(this.removeClass(n.CLOSED),this.addClass(n.OPEN),r.show())},s=function(){var t=null,s=null,o=null,u=this;this.get("children").each(function(){t?(r++,o=e.Node.create(""),s=this,u.insertBefore(o,t),t.remove(!1),o.appendChild(t),s.get("id")||s.set("id",n.PANEL+r),o.set("for",s.get("id")),s.set("aria-live","polite"),o.addClass(n.LINK),o.addClass(n.CLOSED),s.addClass(n.PANEL),s.hide(),t=null):t=this}),this.delegate("click",i,"."+n.LINK)};e.Node.addMethod("history",s),e.NodeList.importMethod(e.Node.prototype,"history")},"@VERSION@",{requires:["node","transition"]}); diff --git a/mod/assign/yui/build/moodle-mod_assign-history/moodle-mod_assign-history.js b/mod/assign/yui/build/moodle-mod_assign-history/moodle-mod_assign-history.js new file mode 100644 index 00000000000..73c93578fcd --- /dev/null +++ b/mod/assign/yui/build/moodle-mod_assign-history/moodle-mod_assign-history.js @@ -0,0 +1,73 @@ +YUI.add('moodle-mod_assign-history', function (Y, NAME) { + +// Define a function that will run in the context of a +// Node instance: +var CSS = { + LINK: 'mod-assign-history-link', + OPEN: 'mod-assign-history-link-open', + CLOSED: 'mod-assign-history-link-closed', + PANEL: 'mod-assign-history-panel' + }, + COUNT = 0, + TOGGLE = function() { + var id = this.get('for'), + panel = Y.one('#' + id); + if (this.hasClass(CSS.OPEN)) { + this.removeClass(CSS.OPEN); + this.addClass(CSS.CLOSED); + this.setStyle('overflow', 'hidden'); + panel.hide(); + } else { + this.removeClass(CSS.CLOSED); + this.addClass(CSS.OPEN); + panel.show(); + } + }, + HISTORY = function() { + var link = null, + panel = null, + wrapper = null, + container = this; + + // Loop through all the children of this container and turn + // every odd node to a link to open/close the following panel. + this.get('children').each(function () { + if (link) { + COUNT++; + // First convert the link to an anchor. + wrapper = Y.Node.create(''); + panel = this; + container.insertBefore(wrapper, link); + link.remove(false); + wrapper.appendChild(link); + + // Add a for attribute to the link to link to the id of the panel. + if (!panel.get('id')) { + panel.set('id', CSS.PANEL + COUNT); + } + wrapper.set('for', panel.get('id')); + // Add an aria attribute for the live region. + panel.set('aria-live', 'polite'); + + wrapper.addClass(CSS.LINK); + wrapper.addClass(CSS.CLOSED); + panel.addClass(CSS.PANEL); + panel.hide(); + link = null; + } else { + link = this; + } + }); + + // Setup event listeners. + this.delegate('click', TOGGLE, '.' + CSS.LINK); + }; + +// Use addMethod to add history to the Node prototype: +Y.Node.addMethod("history", HISTORY); + +// Extend this functionality to NodeLists. +Y.NodeList.importMethod(Y.Node.prototype, "history"); + + +}, '@VERSION@', {"requires": ["node", "transition"]}); diff --git a/mod/assign/yui/history/history.js b/mod/assign/yui/history/history.js deleted file mode 100644 index 85ddeb7b6ba..00000000000 --- a/mod/assign/yui/history/history.js +++ /dev/null @@ -1,70 +0,0 @@ -YUI.add('moodle-mod_assign-history', function (Y) { - // Define a function that will run in the context of a - // Node instance: - var CSS = { - LINK: 'mod-assign-history-link', - OPEN: 'mod-assign-history-link-open', - CLOSED: 'mod-assign-history-link-closed', - PANEL: 'mod-assign-history-panel' - }, - COUNT = 0, - TOGGLE = function() { - var id = this.get('for'), - panel = Y.one('#' + id); - if (this.hasClass(CSS.OPEN)) { - this.removeClass(CSS.OPEN); - this.addClass(CSS.CLOSED); - this.setStyle('overflow', 'hidden'); - panel.hide(); - } else { - this.removeClass(CSS.CLOSED); - this.addClass(CSS.OPEN); - panel.show(); - } - }, - HISTORY = function() { - var link = null, - panel = null, - wrapper = null, - container = this; - - // Loop through all the children of this container and turn - // every odd node to a link to open/close the following panel. - this.get('children').each(function () { - if (link) { - COUNT++; - // First convert the link to an anchor. - wrapper = Y.Node.create(''); - panel = this; - container.insertBefore(wrapper, link); - link.remove(false); - wrapper.appendChild(link); - - // Add a for attribute to the link to link to the id of the panel. - if (!panel.get('id')) { - panel.set('id', CSS.PANEL + COUNT); - } - wrapper.set('for', panel.get('id')); - // Add an aria attribute for the live region. - panel.set('aria-live', 'polite'); - - wrapper.addClass(CSS.LINK); - wrapper.addClass(CSS.CLOSED); - panel.addClass(CSS.PANEL); - panel.hide(); - link = null; - } else { - link = this; - } - }); - - // Setup event listeners. - this.delegate('click', TOGGLE, '.' + CSS.LINK); - }; - - // Use addMethod to add history to the Node prototype: - Y.Node.addMethod("history", HISTORY); - - // Extend this functionality to NodeLists. - Y.NodeList.importMethod(Y.Node.prototype, "history"); -}, '@VERSION@', { requires: ['node', 'transition'] }); diff --git a/mod/assign/yui/src/history/build.json b/mod/assign/yui/src/history/build.json new file mode 100644 index 00000000000..e99de89adb2 --- /dev/null +++ b/mod/assign/yui/src/history/build.json @@ -0,0 +1,10 @@ +{ + "name": "moodle-mod_assign-history", + "builds": { + "moodle-mod_assign-history": { + "jsfiles": [ + "history.js" + ] + } + } +} diff --git a/mod/assign/yui/src/history/js/history.js b/mod/assign/yui/src/history/js/history.js new file mode 100644 index 00000000000..9dbafafe0d2 --- /dev/null +++ b/mod/assign/yui/src/history/js/history.js @@ -0,0 +1,68 @@ +// Define a function that will run in the context of a +// Node instance: +var CSS = { + LINK: 'mod-assign-history-link', + OPEN: 'mod-assign-history-link-open', + CLOSED: 'mod-assign-history-link-closed', + PANEL: 'mod-assign-history-panel' + }, + COUNT = 0, + TOGGLE = function() { + var id = this.get('for'), + panel = Y.one('#' + id); + if (this.hasClass(CSS.OPEN)) { + this.removeClass(CSS.OPEN); + this.addClass(CSS.CLOSED); + this.setStyle('overflow', 'hidden'); + panel.hide(); + } else { + this.removeClass(CSS.CLOSED); + this.addClass(CSS.OPEN); + panel.show(); + } + }, + HISTORY = function() { + var link = null, + panel = null, + wrapper = null, + container = this; + + // Loop through all the children of this container and turn + // every odd node to a link to open/close the following panel. + this.get('children').each(function () { + if (link) { + COUNT++; + // First convert the link to an anchor. + wrapper = Y.Node.create(''); + panel = this; + container.insertBefore(wrapper, link); + link.remove(false); + wrapper.appendChild(link); + + // Add a for attribute to the link to link to the id of the panel. + if (!panel.get('id')) { + panel.set('id', CSS.PANEL + COUNT); + } + wrapper.set('for', panel.get('id')); + // Add an aria attribute for the live region. + panel.set('aria-live', 'polite'); + + wrapper.addClass(CSS.LINK); + wrapper.addClass(CSS.CLOSED); + panel.addClass(CSS.PANEL); + panel.hide(); + link = null; + } else { + link = this; + } + }); + + // Setup event listeners. + this.delegate('click', TOGGLE, '.' + CSS.LINK); + }; + +// Use addMethod to add history to the Node prototype: +Y.Node.addMethod("history", HISTORY); + +// Extend this functionality to NodeLists. +Y.NodeList.importMethod(Y.Node.prototype, "history"); diff --git a/mod/assign/yui/src/history/meta/history.json b/mod/assign/yui/src/history/meta/history.json new file mode 100644 index 00000000000..a096c4a642b --- /dev/null +++ b/mod/assign/yui/src/history/meta/history.json @@ -0,0 +1,8 @@ +{ + "moodle-mod_assign-history": { + "requires": [ + "node", + "transition" + ] + } +}