From da8426112fed9be59bbe9a57c80ac44b8cdff197 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Tue, 17 Mar 2020 12:42:11 +0100 Subject: [PATCH 1/2] MDL-68116 filter_h5p: remove h5p.org from allowed sources h5p.org has to be removed as default value for the allowedsources in the "Display H5P" filter because H5P is going to close it down completely so that only the author can see the test content. --- filter/displayh5p/db/upgrade.php | 12 ++++++++++++ filter/displayh5p/lang/en/filter_displayh5p.php | 6 +++++- filter/displayh5p/settings.php | 2 +- filter/displayh5p/version.php | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/filter/displayh5p/db/upgrade.php b/filter/displayh5p/db/upgrade.php index 97c4a3b8191..734f1c19b17 100644 --- a/filter/displayh5p/db/upgrade.php +++ b/filter/displayh5p/db/upgrade.php @@ -45,5 +45,17 @@ function xmldb_filter_displayh5p_upgrade($oldversion) { // Automatically generated Moodle v3.8.0 release upgrade line. // Put any upgrade step following this. + if ($oldversion < 2020031700) { + // References to h5p.org has to be removed as default value for the allowedsources in the filter because H5P is going + // to close it down completely so that only the author can see the test content. + $h5porgurl = 'https://h5p.org/h5p/embed/[id]'; + $config = get_config('filter_displayh5p', 'allowedsources'); + if (strpos($config, $h5porgurl) !== false) { + set_config('allowedsources', str_replace($h5porgurl, '', $config), 'filter_displayh5p'); + } + + upgrade_plugin_savepoint(true, 2020031700, 'filter', 'displayh5p'); + } + return true; } diff --git a/filter/displayh5p/lang/en/filter_displayh5p.php b/filter/displayh5p/lang/en/filter_displayh5p.php index dfb1f12c938..d8fc4313d10 100644 --- a/filter/displayh5p/lang/en/filter_displayh5p.php +++ b/filter/displayh5p/lang/en/filter_displayh5p.php @@ -27,6 +27,10 @@ defined('MOODLE_INTERNAL') || die; $string['allowedsourceslist'] = 'Allowed sources'; $string['allowedsourceslistdesc'] = 'A list of URLs from which users can embed H5P content. If none are specified, all URLs will remain as links and not be displayed as embedded H5P content. -\'[id]\' is a placeholder for the H5P content ID in the external source.'; +\'[id]\' is a placeholder for the H5P content ID in the external source. +For example: + +- H5P.com: https://[xxxxxx].h5p.com/content/[id] +- Wordpress: http://myserver/wp-admin/admin-ajax.php?action=h5p_embed&id=[id]'; $string['filtername'] = 'Display H5P'; $string['privacy:metadata'] = 'The display H5P filter does not store any personal data.'; diff --git a/filter/displayh5p/settings.php b/filter/displayh5p/settings.php index 3bed622ac2e..329155a6b73 100644 --- a/filter/displayh5p/settings.php +++ b/filter/displayh5p/settings.php @@ -30,5 +30,5 @@ if ($ADMIN->fulltree) { get_string('allowedsourceslist', 'filter_displayh5p'), get_string('allowedsourceslistdesc', 'filter_displayh5p'), - "https://h5p.org/h5p/embed/[id]")); + '')); } diff --git a/filter/displayh5p/version.php b/filter/displayh5p/version.php index 88a30383656..e936737a100 100644 --- a/filter/displayh5p/version.php +++ b/filter/displayh5p/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die; -$plugin->version = 2019111800; +$plugin->version = 2020031700; $plugin->requires = 2019111200; $plugin->component = 'filter_displayh5p'; From d9c9c01f262163c8b47a8ad2811d98649776fa05 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Wed, 18 Mar 2020 14:11:31 +0100 Subject: [PATCH 2/2] MDL-68116 atto_h5p: simplify fields to add H5P content The embed section has been removed in order to simplify this screen. It was added to make easier include content coming from h5p.org but, as soon users won't be able to use it, it makes no sense. Users will still be able to use the "HTML" button to paste the embed code. --- .../atto/plugins/h5p/lang/en/atto_h5p.php | 3 +- lib/editor/atto/plugins/h5p/lib.php | 5 +- .../atto/plugins/h5p/tests/behat/h5p.feature | 40 ++- .../moodle-atto_h5p-button-debug.js | 238 ++++++++---------- .../moodle-atto_h5p-button-min.js | 4 +- .../moodle-atto_h5p-button.js | 238 ++++++++---------- .../plugins/h5p/yui/src/button/js/button.js | 238 ++++++++---------- 7 files changed, 334 insertions(+), 432 deletions(-) diff --git a/lib/editor/atto/plugins/h5p/lang/en/atto_h5p.php b/lib/editor/atto/plugins/h5p/lang/en/atto_h5p.php index feefb27e26a..0469ddca5b7 100644 --- a/lib/editor/atto/plugins/h5p/lang/en/atto_h5p.php +++ b/lib/editor/atto/plugins/h5p/lang/en/atto_h5p.php @@ -30,11 +30,12 @@ $string['embedbutton'] = 'Embed button'; $string['enterurl'] = 'URL or embed code'; $string['h5p:addembed'] = 'Add embedded H5P'; $string['h5pfile'] = 'H5P file upload'; +$string['h5pfileorurl'] = 'H5P URL or file upload'; $string['h5poptions'] = 'H5P options'; $string['h5pproperties'] = 'H5P properties'; $string['h5purl'] = 'H5P URL'; $string['invalidh5purl'] = 'Invalid URL'; -$string['instructions'] = 'You can insert H5P content by either entering a URL or embed code from an external H5P site or by uploading an H5P file.'; +$string['instructions'] = 'You can insert H5P content by either entering a URL or by uploading an H5P file.'; $string['noh5pcontent'] = 'No H5P content added'; $string['pluginname'] = 'Insert H5P'; $string['privacy:metadata'] = 'The atto_h5p plugin does not store any personal data.'; diff --git a/lib/editor/atto/plugins/h5p/lib.php b/lib/editor/atto/plugins/h5p/lib.php index 60b34e7c604..174d420b8a3 100644 --- a/lib/editor/atto/plugins/h5p/lib.php +++ b/lib/editor/atto/plugins/h5p/lib.php @@ -67,16 +67,13 @@ function atto_h5p_strings_for_js() { 'copyrightbutton', 'downloadbutton', 'instructions', - 'either', 'embedbutton', - 'enterurl', 'h5pfile', 'h5poptions', - 'h5pproperties', 'h5purl', + 'h5pfileorurl', 'invalidh5purl', 'noh5pcontent', - 'or', 'pluginname' ); diff --git a/lib/editor/atto/plugins/h5p/tests/behat/h5p.feature b/lib/editor/atto/plugins/h5p/tests/behat/h5p.feature index 4ea2e13b538..d0da200c851 100644 --- a/lib/editor/atto/plugins/h5p/tests/behat/h5p.feature +++ b/lib/editor/atto/plugins/h5p/tests/behat/h5p.feature @@ -17,7 +17,7 @@ Feature: Add h5ps to Atto | page | PageName1 | PageDesc1 | 1 | C1 | H5Ptest | 1 | 1 | And the "displayh5p" filter is "on" And the following config values are set as admin: - | allowedsources | https://moodle.h5p.com/content/[id]/embed | filter_displayh5p | + | allowedsources | https://moodle.h5p.com/content/[id] | filter_displayh5p | @javascript @external Scenario: Insert an embedded h5p @@ -27,7 +27,7 @@ Feature: Add h5ps to Atto And I follow "PageName1" And I navigate to "Edit settings" in current page administration And I click on "Insert H5P" "button" in the "#fitem_id_page" "css_element" - And I set the field with xpath "//textarea[@data-region='h5purl']" to "https://moodle.h5p.com/content/1290772960722742119/embed" + And I set the field with xpath "//input[@data-region='h5pfile']" to "https://moodle.h5p.com/content/1290772960722742119" And I click on "Insert H5P" "button" in the "Insert H5P" "dialogue" And I wait until the page is ready When I click on "Save and display" "button" @@ -64,7 +64,7 @@ Feature: Add h5ps to Atto And I navigate to "Edit settings" in current page administration And I click on "Insert H5P" "button" in the "#fitem_id_page" "css_element" # This is not a real external URL, so this scenario shouldn't be labeled as external. - And I set the field with xpath "//textarea[@data-region='h5purl']" to "ftp://moodle.h5p.com/content/1290772960722742119/embed" + And I set the field with xpath "//input[@data-region='h5pfile']" to "ftp://moodle.h5p.com/content/1290772960722742119" When I click on "Insert H5P" "button" in the "Insert H5P" "dialogue" And I wait until the page is ready Then I should see "Invalid URL" in the "Insert H5P" "dialogue" @@ -91,7 +91,9 @@ Feature: Add h5ps to Atto And I follow "PageName1" When I navigate to "Edit settings" in current page administration And I click on "Insert H5P" "button" - Then I should not see "URL or embed code" in the "Insert H5P" "dialogue" + Then I should not see "H5P URL" in the "Insert H5P" "dialogue" + And I should see "H5P file upload" in the "Insert H5P" "dialogue" + And I should see "H5P options" in the "Insert H5P" "dialogue" @javascript Scenario: No upload h5p capabilities @@ -104,6 +106,8 @@ Feature: Add h5ps to Atto When I navigate to "Edit settings" in current page administration And I click on "Insert H5P" "button" Then I should not see "H5P file upload" in the "Insert H5P" "dialogue" + And I should see "H5P URL" in the "Insert H5P" "dialogue" + And I should not see "H5P options" in the "Insert H5P" "dialogue" @javascript @external Scenario: Edit H5P content @@ -132,7 +136,7 @@ Feature: Add h5ps to Atto And I click on ".h5p-placeholder" "css_element" And I click on "Insert H5P" "button" in the "#fitem_id_page" "css_element" # External URL - And I set the field with xpath "//textarea[@data-region='h5purl']" to "https://moodle.h5p.com/content/1290772960722742119/embed" + And I set the field with xpath "//input[@data-region='h5pfile']" to "https://moodle.h5p.com/content/1290772960722742119" And I click on "Insert H5P" "button" in the "Insert H5P" "dialogue" And I wait until the page is ready And I click on "Save and display" "button" @@ -199,6 +203,32 @@ Feature: Add h5ps to Atto And I should see "Embed" And I should see "Rights of use" + @javascript @external + Scenario: H5P options are ignored for H5P URLs + Given I log in as "admin" + And I change window size to "large" + And I am on "Course 1" course homepage + And I follow "PageName1" + And I navigate to "Edit settings" in current page administration + And I click on "Insert H5P" "button" in the "#fitem_id_page" "css_element" + And I set the field with xpath "//input[@data-region='h5pfile']" to "https://moodle.h5p.com/content/1290752078589054689" + And I click on "H5P options" "link" + And I click on "Embed button" "checkbox" + And I click on "Insert H5P" "button" in the "Insert H5P" "dialogue" + And I wait until the page is ready + When I click on "Save and display" "button" + Then ".h5p-placeholder" "css_element" should exist + And I wait until the page is ready + And I switch to "h5pcontent" iframe + And I should see "History of strawberries" + And I should not see "Embed" + And I switch to the main frame + And I navigate to "Edit settings" in current page administration + And I click on ".h5p-placeholder" "css_element" + And I click on "Insert H5P" "button" in the "#fitem_id_page" "css_element" + And I click on "H5P options" "link" + And "input[aria-label=\"Embed button\"]:not([checked=checked])" "css_element" should exist + @javascript Scenario: Private H5P files are shown to students Given the following "users" exist: diff --git a/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-debug.js b/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-debug.js index 29ed69b26e7..98d1d42fbac 100644 --- a/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-debug.js +++ b/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-debug.js @@ -38,7 +38,6 @@ var CSS = { H5PBROWSER: 'openh5pbrowser', INPUTALT: 'atto_h5p_altentry', INPUTH5PFILE: 'atto_h5p_file', - INPUTH5PURL: 'atto_h5p_url', INPUTSUBMIT: 'atto_h5p_urlentrysubmit', OPTION_DOWNLOAD_BUTTON: 'atto_h5p_option_download_button', OPTION_COPYRIGHT_BUTTON: 'atto_h5p_option_copyright_button', @@ -49,7 +48,6 @@ var CSS = { CONTENTWARNING: '.' + CSS.CONTENTWARNING, H5PBROWSER: '.' + CSS.H5PBROWSER, INPUTH5PFILE: '.' + CSS.INPUTH5PFILE, - INPUTH5PURL: '.' + CSS.INPUTH5PURL, INPUTSUBMIT: '.' + CSS.INPUTSUBMIT, OPTION_DOWNLOAD_BUTTON: '.' + CSS.OPTION_DOWNLOAD_BUTTON, OPTION_COPYRIGHT_BUTTON: '.' + CSS.OPTION_COPYRIGHT_BUTTON, @@ -64,65 +62,71 @@ var CSS = { '' + - '{{#if canUploadAndEmbed}}' + - '
{{{get_string "instructions" component}}}
' + - '
{{get_string "either" component}}
' + - '{{/if}}' + - '{{#if canEmbed}}' + - '
' + - '' + - '' + - '' + + '' + - '{{/if}}' + '{{#if canUploadAndEmbed}}' + - '
{{get_string "or" component}}
' + + '
{{{get_string "instructions" component}}}
' + '{{/if}}' + - '{{#if canUpload}}' + '
' + - '' + + '' + '
' + '' + - '' + - '' + - '' + + 'id="{{elementid}}_{{CSS.INPUTH5PFILE}}" data-region="h5pfile" size="32"/>' + + '{{#if canUpload}}' + + '' + + '' + + '' + + '{{/if}}' + '
' + - '
' + - '{{get_string "h5poptions" component}}' + - '
' + + '' + + '{{/if}}' + '
' + - '{{/if}}' + '
' + '' + @@ -270,9 +274,9 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito */ _getPermissions: function() { var permissions = { + 'canEmbed': false, 'canUpload': false, - 'canUploadAndEbmed': false, - 'canEmbed': false + 'canUploadAndEmbed': false }; if (this.get('host').canShowFilepicker('h5p')) { @@ -304,7 +308,6 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito var permissions = this._getPermissions(); var fileURL, - embedURL, optionDownloadButton, optionEmbedButton, optionCopyrightButton, @@ -334,7 +337,7 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito } } } else { - embedURL = H5PURL; + fileURL = H5PURL; } } @@ -345,10 +348,9 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito component: COMPONENTNAME, canUpload: permissions.canUpload, canEmbed: permissions.canEmbed, - fileURL: fileURL, - embedURL: embedURL, canUploadAndEmbed: permissions.canUploadAndEmbed, collapseOptions: collapseOptions, + fileURL: fileURL, optionDownloadButton: optionDownloadButton, optionEmbedButton: optionEmbedButton, optionCopyrightButton: optionCopyrightButton @@ -374,7 +376,6 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito if (params.url !== '') { var input = this._form.one(SELECTORS.INPUTH5PFILE); input.set('value', params.url); - this._form.one(SELECTORS.INPUTH5PURL).set('value', ''); this._removeWarnings(); } }, @@ -399,11 +400,6 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito if (permissions.canUploadAndEmbed) { form.one(SELECTORS.INPUTH5PFILE).on('change', function() { - form.one(SELECTORS.INPUTH5PURL).set('value', ''); - this._removeWarnings(); - }, this); - form.one(SELECTORS.INPUTH5PURL).on('change', function() { - form.one(SELECTORS.INPUTH5PFILE).set('value', ''); this._removeWarnings(); }, this); } @@ -423,7 +419,6 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito /** * Update the h5p in the contenteditable. - * * @method _setH5P * @param {EventFacade} e @@ -431,20 +426,11 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito */ _setH5P: function(e) { var form = this._form, - url = form.one(SELECTORS.INPUTH5PURL).get('value'), h5phtml, host = this.get('host'), - h5pfile, + h5pfile = form.one(SELECTORS.INPUTH5PFILE).get('value'), permissions = this._getPermissions(); - if (permissions.canEmbed) { - url = form.one(SELECTORS.INPUTH5PURL).get('value'); - } - - if (permissions.canUpload) { - h5pfile = form.one(SELECTORS.INPUTH5PFILE).get('value'); - } - e.preventDefault(); // Check if there are any issues. @@ -464,68 +450,49 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito addParagraphs = false; } - if (url !== '') { - + if (h5pfile !== '') { host.setSelection(this._currentSelection); - if (this._validEmbed(url)) { - var embedtemplate = Y.Handlebars.compile(H5PTEMPLATE); - var regex = //; - var src = url.match(regex)[1]; + if (h5pfile.startsWith(M.cfg.wwwroot)) { + // It's a local file. + var params = ''; + if (permissions.canUpload) { + var options = {}; + if (form.one(SELECTORS.OPTION_DOWNLOAD_BUTTON).get('checked')) { + options['export'] = '1'; + } + if (form.one(SELECTORS.OPTION_EMBED_BUTTON).get('checked')) { + options.embed = '1'; + } + if (form.one(SELECTORS.OPTION_COPYRIGHT_BUTTON).get('checked')) { + options.copyright = '1'; + } - // In case a local H5P embed code is used we need get the url - // param form the src and decode it. - if (src.startsWith(M.cfg.wwwroot + '/h5p/embed.php')) { - src = decodeURIComponent(src.split("url=")[1]); + for (var opt in options) { + if (params === "" && (h5pfile.indexOf("?") === -1)) { + params += "?"; + } else { + params += "&"; + } + params += opt + "=" + options[opt]; + } } - h5phtml = embedtemplate({ - url: src + var h5ptemplate = Y.Handlebars.compile(H5PTEMPLATE); + + h5phtml = h5ptemplate({ + url: h5pfile + params, + addParagraphs: addParagraphs }); } else { + // It's a URL. var urltemplate = Y.Handlebars.compile(H5PTEMPLATE); h5phtml = urltemplate({ - url: url + url: h5pfile }); } - this.get('host').insertContentAtFocusPoint(h5phtml); - - this.markUpdated(); - } else if (h5pfile !== '') { - - host.setSelection(this._currentSelection); - - var options = {}; - - if (form.one(SELECTORS.OPTION_DOWNLOAD_BUTTON).get('checked')) { - options['export'] = '1'; - } - if (form.one(SELECTORS.OPTION_EMBED_BUTTON).get('checked')) { - options.embed = '1'; - } - if (form.one(SELECTORS.OPTION_COPYRIGHT_BUTTON).get('checked')) { - options.copyright = '1'; - } - - var params = ""; - for (var opt in options) { - if (params === "" && (h5pfile.indexOf("?") === -1)) { - params += "?"; - } else { - params += "&"; - } - params += opt + "=" + options[opt]; - } - - var h5ptemplate = Y.Handlebars.compile(H5PTEMPLATE); - - h5phtml = h5ptemplate({ - url: h5pfile + params, - addParagraphs: addParagraphs - }); - - this.get('host').insertContentAtFocusPoint(h5phtml); + host.insertContentAtFocusPoint(h5phtml); this.markUpdated(); } @@ -574,30 +541,21 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito _updateWarning: function() { var form = this._form, state = true, - url, h5pfile, permissions = this._getPermissions(); - - if (permissions.canEmbed) { - url = form.one(SELECTORS.INPUTH5PURL).get('value'); - if (url !== '') { - if (this._validURL(url) || this._validEmbed(url)) { + if (permissions.canUpload || permissions.canEmbed) { + h5pfile = form.one(SELECTORS.INPUTH5PFILE).get('value'); + if (h5pfile !== '') { + form.one(SELECTORS.CONTENTWARNING).setStyle('display', 'none'); + if (h5pfile.startsWith(M.cfg.wwwroot) || this._validURL(h5pfile)) { + // Only external URLs have to be validated. form.one(SELECTORS.URLWARNING).setStyle('display', 'none'); state = false; } else { form.one(SELECTORS.URLWARNING).setStyle('display', 'block'); state = true; } - return state; - } - } - - if (permissions.canUpload) { - h5pfile = form.one(SELECTORS.INPUTH5PFILE).get('value'); - if (h5pfile !== '') { - form.one(SELECTORS.CONTENTWARNING).setStyle('display', 'none'); - state = false; } else { form.one(SELECTORS.CONTENTWARNING).setStyle('display', 'block'); state = true; diff --git a/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-min.js b/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-min.js index 41c5f75d7f6..7fe48a7f627 100644 --- a/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-min.js +++ b/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button-min.js @@ -1,2 +1,2 @@ -YUI.add("moodle-atto_h5p-button",function(e,t){var n={CONTENTWARNING:"att_h5p_contentwarning",H5PBROWSER:"openh5pbrowser",INPUTALT:"atto_h5p_altentry",INPUTH5PFILE:"atto_h5p_file",INPUTH5PURL:"atto_h5p_url",INPUTSUBMIT:"atto_h5p_urlentrysubmit",OPTION_DOWNLOAD_BUTTON:"atto_h5p_option_download_button",OPTION_COPYRIGHT_BUTTON:"atto_h5p_option_copyright_button",OPTION_EMBED_BUTTON:"atto_h5p_option_embed_button",URLWARNING:"atto_h5p_warning"},r={CONTENTWARNING:"."+n.CONTENTWARNING,H5PBROWSER:"."+n.H5PBROWSER,INPUTH5PFILE:"."+n.INPUTH5PFILE,INPUTH5PURL:"."+n.INPUTH5PURL,INPUTSUBMIT:"."+n.INPUTSUBMIT,OPTION_DOWNLOAD_BUTTON:"."+n.OPTION_DOWNLOAD_BUTTON,OPTION_COPYRIGHT_BUTTON:"."+n.OPTION_COPYRIGHT_BUTTON,OPTION_EMBED_BUTTON:"."+n.OPTION_EMBED_BUTTON,URLWARNING:"."+n.URLWARNING},i="atto_h5p",s='
{{#if canUploadAndEmbed}}
{{{get_string "instructions" component}}}
{{get_string "either" component}}
{{/if}}{{#if canEmbed}}
{{/if}}{{#if canUploadAndEmbed}}
{{get_string "or" component}}
{{/if}}{{#if canUpload}}
{{get_string "h5poptions" component}}
{{/if}}
',o='{{#if addParagraphs}}


{{/if}}
{{{url}}}
{{#if addParagraphs}}


{{/if}}';e.namespace("M.atto_h5p").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_form:null,_H5PDiv:null,_allowedmethods:"none",initializer:function(){this._allowedmethods=this.get("allowedmethods");if(this._allowedmethods==="none")return;this.addButton({icon:"icon",iconComponent:"atto_h5p",callback:this._displayDialogue,tags:".h5p-placeholder",tagMatchRequiresAll:!1}),this.editor.all(".h5p-placeholder").setAttribute("contenteditable","false"),this.editor.delegate("dblclick",this._handleDblClick,".h5p-placeholder",this),this.editor.delegate("click",this._handleClick,".h5p-placeholder",this)},_handleDblClick:function(){this._displayDialogue()},_handleClick:function(e){var t=this.get("host").getSelectionFromNode(e.target);this.get("host").getSelection()!==t&&this.get("host").setSelection(t)},_displayDialogue:function(){this._currentSelection=this.get("host").getSelection();if(this._currentSelection===!1)return;this._getH5PDiv();var e=this.getDialogue({headerContent:M.util.get_string("pluginname",i),width:"auto",focusAfterHide:!0});e.set("bodyContent",this._getDialogueContent()).show(),M.form.shortforms({formid:this.get("host").get("elementid")+"_atto_h5p_form"})},_getH5PDiv:function(){var e=this.get("host").getSelectedNodes(),t=null;e.each(function(e){e.hasClass("h5p-placeholder")&&(t=e)}),this._H5PDiv=t},_getPermissions:function(){var e={canUpload:!1,canUploadAndEbmed:!1,canEmbed:!1};this.get("host").canShowFilepicker("h5p")&&(this._allowedmethods==="both"?(e.canUploadAndEmbed=!0,e.canUpload=!0):this._allowedmethods==="upload"&&(e.canUpload=!0));if(this._allowedmethods==="both"||this._allowedmethods==="embed")e.canEmbed=!0;return e},_getDialogueContent:function(){var t=this._getPermissions(),r,o,u,a,f,l=!0;if(this._H5PDiv){var c=this._H5PDiv.get("innerHTML"),h=M.cfg.wwwroot+"/draftfile.php";if(h==c.substring(0,h.length)){r=c.split("?")[0];var p=c.split("?")[1];p&&(p.match(/export=1/)&&(u="checked",l=!1),p.match(/embed=1/)&&(a="checked",l=!1),p.match(/copyright=1/)&&(f="checked",l=!1))}else o=c}var d=e.Handlebars.compile(s),v=e.Node.create(d({elementid:this.get("host").get("elementid"),CSS:n,component:i,canUpload:t.canUpload,canEmbed:t.canEmbed,fileURL:r,embedURL:o,canUploadAndEmbed:t.canUploadAndEmbed,collapseOptions:l,optionDownloadButton:u,optionEmbedButton:a,optionCopyrightButton:f}));return this -._form=v,this._setEventListeners(),v},_filepickerCallback:function(e){if(e.url!==""){var t=this._form.one(r.INPUTH5PFILE);t.set("value",e.url),this._form.one(r.INPUTH5PURL).set("value",""),this._removeWarnings()}},_setEventListeners:function(){var e=this._form,t=this._getPermissions();e.one(r.INPUTSUBMIT).on("click",this._setH5P,this),t.canUpload&&e.one(r.H5PBROWSER).on("click",function(){this.get("host").showFilepicker("h5p",this._filepickerCallback,this)},this),t.canUploadAndEmbed&&(e.one(r.INPUTH5PFILE).on("change",function(){e.one(r.INPUTH5PURL).set("value",""),this._removeWarnings()},this),e.one(r.INPUTH5PURL).on("change",function(){e.one(r.INPUTH5PFILE).set("value",""),this._removeWarnings()},this))},_removeWarnings:function(){var e=this._form;e.one(r.URLWARNING).setStyle("display","none"),e.one(r.CONTENTWARNING).setStyle("display","none")},_setH5P:function(t){var n=this._form,i=n.one(r.INPUTH5PURL).get("value"),s,u=this.get("host"),a,f=this._getPermissions();f.canEmbed&&(i=n.one(r.INPUTH5PURL).get("value")),f.canUpload&&(a=n.one(r.INPUTH5PFILE).get("value")),t.preventDefault();if(this._updateWarning())return;u.focus();var l=!0;this._H5PDiv&&(this._H5PDiv.remove(),l=!1);if(i!==""){u.setSelection(this._currentSelection);if(this._validEmbed(i)){var c=e.Handlebars.compile(o),h=//,p=i.match(h)[1];p.startsWith(M.cfg.wwwroot+"/h5p/embed.php")&&(p=decodeURIComponent(p.split("url=")[1])),s=c({url:p})}else{var d=e.Handlebars.compile(o);s=d({url:i})}this.get("host").insertContentAtFocusPoint(s),this.markUpdated()}else if(a!==""){u.setSelection(this._currentSelection);var v={};n.one(r.OPTION_DOWNLOAD_BUTTON).get("checked")&&(v["export"]="1"),n.one(r.OPTION_EMBED_BUTTON).get("checked")&&(v.embed="1"),n.one(r.OPTION_COPYRIGHT_BUTTON).get("checked")&&(v.copyright="1");var m="";for(var g in v)m===""&&a.indexOf("?")===-1?m+="?":m+="&",m+=g+"="+v[g];var y=e.Handlebars.compile(o);s=y({url:a+m,addParagraphs:l}),this.get("host").insertContentAtFocusPoint(s),this.markUpdated()}this.getDialogue({focusAfterHide:null}).hide()},_validEmbed:function(e){var t=new RegExp("^()");return!!t.test(e)},_validURL:function(e){var t=new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*");return!!t.test(e)},_updateWarning:function(){var e=this._form,t=!0,n,i,s=this._getPermissions();if(s.canEmbed){n=e.one(r.INPUTH5PURL).get("value");if(n!=="")return this._validURL(n)||this._validEmbed(n)?(e.one(r.URLWARNING).setStyle("display","none"),t=!1):(e.one(r.URLWARNING).setStyle("display","block"),t=!0),t}return s.canUpload&&(i=e.one(r.INPUTH5PFILE).get("value"),i!==""?(e.one(r.CONTENTWARNING).setStyle("display","none"),t=!1):(e.one(r.CONTENTWARNING).setStyle("display","block"),t=!0)),t}},{ATTRS:{allowedmethods:{value:null}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]}); +YUI.add("moodle-atto_h5p-button",function(e,t){var n={CONTENTWARNING:"att_h5p_contentwarning",H5PBROWSER:"openh5pbrowser",INPUTALT:"atto_h5p_altentry",INPUTH5PFILE:"atto_h5p_file",INPUTSUBMIT:"atto_h5p_urlentrysubmit",OPTION_DOWNLOAD_BUTTON:"atto_h5p_option_download_button",OPTION_COPYRIGHT_BUTTON:"atto_h5p_option_copyright_button",OPTION_EMBED_BUTTON:"atto_h5p_option_embed_button",URLWARNING:"atto_h5p_warning"},r={CONTENTWARNING:"."+n.CONTENTWARNING,H5PBROWSER:"."+n.H5PBROWSER,INPUTH5PFILE:"."+n.INPUTH5PFILE,INPUTSUBMIT:"."+n.INPUTSUBMIT,OPTION_DOWNLOAD_BUTTON:"."+n.OPTION_DOWNLOAD_BUTTON,OPTION_COPYRIGHT_BUTTON:"."+n.OPTION_COPYRIGHT_BUTTON,OPTION_EMBED_BUTTON:"."+n.OPTION_EMBED_BUTTON,URLWARNING:"."+n.URLWARNING},i="atto_h5p",s='
{{#if canUploadAndEmbed}}
{{{get_string "instructions" component}}}
{{/if}}
{{#if canUpload}}{{/if}}
{{#if canUpload}}
{{get_string "h5poptions" component}}
{{/if}}
',o='{{#if addParagraphs}}


{{/if}}
{{{url}}}
{{#if addParagraphs}}


{{/if}}';e.namespace("M.atto_h5p").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_form:null,_H5PDiv:null,_allowedmethods:"none",initializer:function(){this._allowedmethods=this.get("allowedmethods");if(this._allowedmethods==="none")return;this.addButton({icon:"icon",iconComponent:"atto_h5p",callback:this._displayDialogue,tags:".h5p-placeholder",tagMatchRequiresAll:!1}),this.editor.all(".h5p-placeholder").setAttribute("contenteditable","false"),this.editor.delegate("dblclick",this._handleDblClick,".h5p-placeholder",this),this.editor.delegate("click",this._handleClick,".h5p-placeholder",this)},_handleDblClick:function(){this._displayDialogue()},_handleClick:function(e){var t=this.get("host").getSelectionFromNode(e.target);this.get("host").getSelection()!==t&&this.get("host").setSelection(t)},_displayDialogue:function(){this._currentSelection=this.get("host").getSelection();if(this._currentSelection===!1)return;this._getH5PDiv();var e=this.getDialogue({headerContent:M.util.get_string("pluginname",i),width:"auto",focusAfterHide:!0});e.set("bodyContent",this._getDialogueContent()).show(),M.form.shortforms({formid:this.get("host").get("elementid")+"_atto_h5p_form"})},_getH5PDiv:function(){var e=this.get("host").getSelectedNodes(),t=null;e.each(function(e){e.hasClass("h5p-placeholder")&&(t=e)}),this._H5PDiv=t},_getPermissions:function(){var e={canEmbed:!1,canUpload:!1,canUploadAndEmbed:!1};this.get("host").canShowFilepicker("h5p")&&(this._allowedmethods==="both"?(e.canUploadAndEmbed=!0,e.canUpload=!0):this._allowedmethods==="upload"&&(e.canUpload=!0));if(this._allowedmethods==="both"||this._allowedmethods==="embed")e.canEmbed=!0;return e},_getDialogueContent:function(){var t=this._getPermissions(),r,o,u,a,f=!0;if(this._H5PDiv){var l=this._H5PDiv.get("innerHTML"),c=M.cfg.wwwroot+"/draftfile.php";if(c==l.substring(0,c.length)){r=l.split("?")[0];var h=l.split("?")[1];h&&(h.match(/export=1/)&&(o="checked",f=!1),h.match(/embed=1/)&&(u="checked",f=!1),h.match(/copyright=1/)&&(a="checked",f=!1))}else r=l}var p=e.Handlebars.compile(s),d=e.Node.create(p({elementid:this.get("host").get("elementid"),CSS:n,component:i,canUpload:t.canUpload,canEmbed:t.canEmbed,canUploadAndEmbed:t.canUploadAndEmbed,collapseOptions:f,fileURL:r,optionDownloadButton:o,optionEmbedButton:u,optionCopyrightButton:a}));return this._form=d,this._setEventListeners(),d},_filepickerCallback:function(e){if(e.url!==""){var t=this._form.one(r.INPUTH5PFILE);t.set("value" +,e.url),this._removeWarnings()}},_setEventListeners:function(){var e=this._form,t=this._getPermissions();e.one(r.INPUTSUBMIT).on("click",this._setH5P,this),t.canUpload&&e.one(r.H5PBROWSER).on("click",function(){this.get("host").showFilepicker("h5p",this._filepickerCallback,this)},this),t.canUploadAndEmbed&&e.one(r.INPUTH5PFILE).on("change",function(){this._removeWarnings()},this)},_removeWarnings:function(){var e=this._form;e.one(r.URLWARNING).setStyle("display","none"),e.one(r.CONTENTWARNING).setStyle("display","none")},_setH5P:function(t){var n=this._form,i,s=this.get("host"),u=n.one(r.INPUTH5PFILE).get("value"),a=this._getPermissions();t.preventDefault();if(this._updateWarning())return;s.focus();var f=!0;this._H5PDiv&&(this._H5PDiv.remove(),f=!1);if(u!==""){s.setSelection(this._currentSelection);if(u.startsWith(M.cfg.wwwroot)){var l="";if(a.canUpload){var c={};n.one(r.OPTION_DOWNLOAD_BUTTON).get("checked")&&(c["export"]="1"),n.one(r.OPTION_EMBED_BUTTON).get("checked")&&(c.embed="1"),n.one(r.OPTION_COPYRIGHT_BUTTON).get("checked")&&(c.copyright="1");for(var h in c)l===""&&u.indexOf("?")===-1?l+="?":l+="&",l+=h+"="+c[h]}var p=e.Handlebars.compile(o);i=p({url:u+l,addParagraphs:f})}else{var d=e.Handlebars.compile(o);i=d({url:u})}s.insertContentAtFocusPoint(i),this.markUpdated()}this.getDialogue({focusAfterHide:null}).hide()},_validEmbed:function(e){var t=new RegExp("^()");return!!t.test(e)},_validURL:function(e){var t=new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*");return!!t.test(e)},_updateWarning:function(){var e=this._form,t=!0,n,i=this._getPermissions();if(i.canUpload||i.canEmbed)n=e.one(r.INPUTH5PFILE).get("value"),n!==""?(e.one(r.CONTENTWARNING).setStyle("display","none"),n.startsWith(M.cfg.wwwroot)||this._validURL(n)?(e.one(r.URLWARNING).setStyle("display","none"),t=!1):(e.one(r.URLWARNING).setStyle("display","block"),t=!0)):(e.one(r.CONTENTWARNING).setStyle("display","block"),t=!0);return t}},{ATTRS:{allowedmethods:{value:null}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin"]}); diff --git a/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button.js b/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button.js index 29ed69b26e7..98d1d42fbac 100644 --- a/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button.js +++ b/lib/editor/atto/plugins/h5p/yui/build/moodle-atto_h5p-button/moodle-atto_h5p-button.js @@ -38,7 +38,6 @@ var CSS = { H5PBROWSER: 'openh5pbrowser', INPUTALT: 'atto_h5p_altentry', INPUTH5PFILE: 'atto_h5p_file', - INPUTH5PURL: 'atto_h5p_url', INPUTSUBMIT: 'atto_h5p_urlentrysubmit', OPTION_DOWNLOAD_BUTTON: 'atto_h5p_option_download_button', OPTION_COPYRIGHT_BUTTON: 'atto_h5p_option_copyright_button', @@ -49,7 +48,6 @@ var CSS = { CONTENTWARNING: '.' + CSS.CONTENTWARNING, H5PBROWSER: '.' + CSS.H5PBROWSER, INPUTH5PFILE: '.' + CSS.INPUTH5PFILE, - INPUTH5PURL: '.' + CSS.INPUTH5PURL, INPUTSUBMIT: '.' + CSS.INPUTSUBMIT, OPTION_DOWNLOAD_BUTTON: '.' + CSS.OPTION_DOWNLOAD_BUTTON, OPTION_COPYRIGHT_BUTTON: '.' + CSS.OPTION_COPYRIGHT_BUTTON, @@ -64,65 +62,71 @@ var CSS = { '' + - '{{#if canUploadAndEmbed}}' + - '
{{{get_string "instructions" component}}}
' + - '
{{get_string "either" component}}
' + - '{{/if}}' + - '{{#if canEmbed}}' + - '
' + - '' + - '' + - '' + + '' + - '{{/if}}' + '{{#if canUploadAndEmbed}}' + - '
{{get_string "or" component}}
' + + '
{{{get_string "instructions" component}}}
' + '{{/if}}' + - '{{#if canUpload}}' + '
' + - '' + + '' + '
' + '' + - '' + - '' + - '' + + 'id="{{elementid}}_{{CSS.INPUTH5PFILE}}" data-region="h5pfile" size="32"/>' + + '{{#if canUpload}}' + + '' + + '' + + '' + + '{{/if}}' + '
' + - '
' + - '{{get_string "h5poptions" component}}' + - '
' + + '' + + '{{/if}}' + '
' + - '{{/if}}' + '
' + '' + @@ -270,9 +274,9 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito */ _getPermissions: function() { var permissions = { + 'canEmbed': false, 'canUpload': false, - 'canUploadAndEbmed': false, - 'canEmbed': false + 'canUploadAndEmbed': false }; if (this.get('host').canShowFilepicker('h5p')) { @@ -304,7 +308,6 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito var permissions = this._getPermissions(); var fileURL, - embedURL, optionDownloadButton, optionEmbedButton, optionCopyrightButton, @@ -334,7 +337,7 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito } } } else { - embedURL = H5PURL; + fileURL = H5PURL; } } @@ -345,10 +348,9 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito component: COMPONENTNAME, canUpload: permissions.canUpload, canEmbed: permissions.canEmbed, - fileURL: fileURL, - embedURL: embedURL, canUploadAndEmbed: permissions.canUploadAndEmbed, collapseOptions: collapseOptions, + fileURL: fileURL, optionDownloadButton: optionDownloadButton, optionEmbedButton: optionEmbedButton, optionCopyrightButton: optionCopyrightButton @@ -374,7 +376,6 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito if (params.url !== '') { var input = this._form.one(SELECTORS.INPUTH5PFILE); input.set('value', params.url); - this._form.one(SELECTORS.INPUTH5PURL).set('value', ''); this._removeWarnings(); } }, @@ -399,11 +400,6 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito if (permissions.canUploadAndEmbed) { form.one(SELECTORS.INPUTH5PFILE).on('change', function() { - form.one(SELECTORS.INPUTH5PURL).set('value', ''); - this._removeWarnings(); - }, this); - form.one(SELECTORS.INPUTH5PURL).on('change', function() { - form.one(SELECTORS.INPUTH5PFILE).set('value', ''); this._removeWarnings(); }, this); } @@ -423,7 +419,6 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito /** * Update the h5p in the contenteditable. - * * @method _setH5P * @param {EventFacade} e @@ -431,20 +426,11 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito */ _setH5P: function(e) { var form = this._form, - url = form.one(SELECTORS.INPUTH5PURL).get('value'), h5phtml, host = this.get('host'), - h5pfile, + h5pfile = form.one(SELECTORS.INPUTH5PFILE).get('value'), permissions = this._getPermissions(); - if (permissions.canEmbed) { - url = form.one(SELECTORS.INPUTH5PURL).get('value'); - } - - if (permissions.canUpload) { - h5pfile = form.one(SELECTORS.INPUTH5PFILE).get('value'); - } - e.preventDefault(); // Check if there are any issues. @@ -464,68 +450,49 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito addParagraphs = false; } - if (url !== '') { - + if (h5pfile !== '') { host.setSelection(this._currentSelection); - if (this._validEmbed(url)) { - var embedtemplate = Y.Handlebars.compile(H5PTEMPLATE); - var regex = //; - var src = url.match(regex)[1]; + if (h5pfile.startsWith(M.cfg.wwwroot)) { + // It's a local file. + var params = ''; + if (permissions.canUpload) { + var options = {}; + if (form.one(SELECTORS.OPTION_DOWNLOAD_BUTTON).get('checked')) { + options['export'] = '1'; + } + if (form.one(SELECTORS.OPTION_EMBED_BUTTON).get('checked')) { + options.embed = '1'; + } + if (form.one(SELECTORS.OPTION_COPYRIGHT_BUTTON).get('checked')) { + options.copyright = '1'; + } - // In case a local H5P embed code is used we need get the url - // param form the src and decode it. - if (src.startsWith(M.cfg.wwwroot + '/h5p/embed.php')) { - src = decodeURIComponent(src.split("url=")[1]); + for (var opt in options) { + if (params === "" && (h5pfile.indexOf("?") === -1)) { + params += "?"; + } else { + params += "&"; + } + params += opt + "=" + options[opt]; + } } - h5phtml = embedtemplate({ - url: src + var h5ptemplate = Y.Handlebars.compile(H5PTEMPLATE); + + h5phtml = h5ptemplate({ + url: h5pfile + params, + addParagraphs: addParagraphs }); } else { + // It's a URL. var urltemplate = Y.Handlebars.compile(H5PTEMPLATE); h5phtml = urltemplate({ - url: url + url: h5pfile }); } - this.get('host').insertContentAtFocusPoint(h5phtml); - - this.markUpdated(); - } else if (h5pfile !== '') { - - host.setSelection(this._currentSelection); - - var options = {}; - - if (form.one(SELECTORS.OPTION_DOWNLOAD_BUTTON).get('checked')) { - options['export'] = '1'; - } - if (form.one(SELECTORS.OPTION_EMBED_BUTTON).get('checked')) { - options.embed = '1'; - } - if (form.one(SELECTORS.OPTION_COPYRIGHT_BUTTON).get('checked')) { - options.copyright = '1'; - } - - var params = ""; - for (var opt in options) { - if (params === "" && (h5pfile.indexOf("?") === -1)) { - params += "?"; - } else { - params += "&"; - } - params += opt + "=" + options[opt]; - } - - var h5ptemplate = Y.Handlebars.compile(H5PTEMPLATE); - - h5phtml = h5ptemplate({ - url: h5pfile + params, - addParagraphs: addParagraphs - }); - - this.get('host').insertContentAtFocusPoint(h5phtml); + host.insertContentAtFocusPoint(h5phtml); this.markUpdated(); } @@ -574,30 +541,21 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito _updateWarning: function() { var form = this._form, state = true, - url, h5pfile, permissions = this._getPermissions(); - - if (permissions.canEmbed) { - url = form.one(SELECTORS.INPUTH5PURL).get('value'); - if (url !== '') { - if (this._validURL(url) || this._validEmbed(url)) { + if (permissions.canUpload || permissions.canEmbed) { + h5pfile = form.one(SELECTORS.INPUTH5PFILE).get('value'); + if (h5pfile !== '') { + form.one(SELECTORS.CONTENTWARNING).setStyle('display', 'none'); + if (h5pfile.startsWith(M.cfg.wwwroot) || this._validURL(h5pfile)) { + // Only external URLs have to be validated. form.one(SELECTORS.URLWARNING).setStyle('display', 'none'); state = false; } else { form.one(SELECTORS.URLWARNING).setStyle('display', 'block'); state = true; } - return state; - } - } - - if (permissions.canUpload) { - h5pfile = form.one(SELECTORS.INPUTH5PFILE).get('value'); - if (h5pfile !== '') { - form.one(SELECTORS.CONTENTWARNING).setStyle('display', 'none'); - state = false; } else { form.one(SELECTORS.CONTENTWARNING).setStyle('display', 'block'); state = true; diff --git a/lib/editor/atto/plugins/h5p/yui/src/button/js/button.js b/lib/editor/atto/plugins/h5p/yui/src/button/js/button.js index 4b753baf780..2906734e42a 100644 --- a/lib/editor/atto/plugins/h5p/yui/src/button/js/button.js +++ b/lib/editor/atto/plugins/h5p/yui/src/button/js/button.js @@ -36,7 +36,6 @@ var CSS = { H5PBROWSER: 'openh5pbrowser', INPUTALT: 'atto_h5p_altentry', INPUTH5PFILE: 'atto_h5p_file', - INPUTH5PURL: 'atto_h5p_url', INPUTSUBMIT: 'atto_h5p_urlentrysubmit', OPTION_DOWNLOAD_BUTTON: 'atto_h5p_option_download_button', OPTION_COPYRIGHT_BUTTON: 'atto_h5p_option_copyright_button', @@ -47,7 +46,6 @@ var CSS = { CONTENTWARNING: '.' + CSS.CONTENTWARNING, H5PBROWSER: '.' + CSS.H5PBROWSER, INPUTH5PFILE: '.' + CSS.INPUTH5PFILE, - INPUTH5PURL: '.' + CSS.INPUTH5PURL, INPUTSUBMIT: '.' + CSS.INPUTSUBMIT, OPTION_DOWNLOAD_BUTTON: '.' + CSS.OPTION_DOWNLOAD_BUTTON, OPTION_COPYRIGHT_BUTTON: '.' + CSS.OPTION_COPYRIGHT_BUTTON, @@ -62,65 +60,71 @@ var CSS = { '' + - '{{#if canUploadAndEmbed}}' + - '
{{{get_string "instructions" component}}}
' + - '
{{get_string "either" component}}
' + - '{{/if}}' + - '{{#if canEmbed}}' + - '
' + - '' + - '' + - '' + + '' + - '{{/if}}' + '{{#if canUploadAndEmbed}}' + - '
{{get_string "or" component}}
' + + '
{{{get_string "instructions" component}}}
' + '{{/if}}' + - '{{#if canUpload}}' + '
' + - '' + + '' + '
' + '' + - '' + - '' + - '' + + 'id="{{elementid}}_{{CSS.INPUTH5PFILE}}" data-region="h5pfile" size="32"/>' + + '{{#if canUpload}}' + + '' + + '' + + '' + + '{{/if}}' + '
' + - '
' + - '{{get_string "h5poptions" component}}' + - '
' + + '' + + '{{/if}}' + '
' + - '{{/if}}' + '
' + '' + @@ -268,9 +272,9 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito */ _getPermissions: function() { var permissions = { + 'canEmbed': false, 'canUpload': false, - 'canUploadAndEbmed': false, - 'canEmbed': false + 'canUploadAndEmbed': false }; if (this.get('host').canShowFilepicker('h5p')) { @@ -302,7 +306,6 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito var permissions = this._getPermissions(); var fileURL, - embedURL, optionDownloadButton, optionEmbedButton, optionCopyrightButton, @@ -332,7 +335,7 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito } } } else { - embedURL = H5PURL; + fileURL = H5PURL; } } @@ -343,10 +346,9 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito component: COMPONENTNAME, canUpload: permissions.canUpload, canEmbed: permissions.canEmbed, - fileURL: fileURL, - embedURL: embedURL, canUploadAndEmbed: permissions.canUploadAndEmbed, collapseOptions: collapseOptions, + fileURL: fileURL, optionDownloadButton: optionDownloadButton, optionEmbedButton: optionEmbedButton, optionCopyrightButton: optionCopyrightButton @@ -372,7 +374,6 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito if (params.url !== '') { var input = this._form.one(SELECTORS.INPUTH5PFILE); input.set('value', params.url); - this._form.one(SELECTORS.INPUTH5PURL).set('value', ''); this._removeWarnings(); } }, @@ -397,11 +398,6 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito if (permissions.canUploadAndEmbed) { form.one(SELECTORS.INPUTH5PFILE).on('change', function() { - form.one(SELECTORS.INPUTH5PURL).set('value', ''); - this._removeWarnings(); - }, this); - form.one(SELECTORS.INPUTH5PURL).on('change', function() { - form.one(SELECTORS.INPUTH5PFILE).set('value', ''); this._removeWarnings(); }, this); } @@ -421,7 +417,6 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito /** * Update the h5p in the contenteditable. - * * @method _setH5P * @param {EventFacade} e @@ -429,20 +424,11 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito */ _setH5P: function(e) { var form = this._form, - url = form.one(SELECTORS.INPUTH5PURL).get('value'), h5phtml, host = this.get('host'), - h5pfile, + h5pfile = form.one(SELECTORS.INPUTH5PFILE).get('value'), permissions = this._getPermissions(); - if (permissions.canEmbed) { - url = form.one(SELECTORS.INPUTH5PURL).get('value'); - } - - if (permissions.canUpload) { - h5pfile = form.one(SELECTORS.INPUTH5PFILE).get('value'); - } - e.preventDefault(); // Check if there are any issues. @@ -462,68 +448,49 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito addParagraphs = false; } - if (url !== '') { - + if (h5pfile !== '') { host.setSelection(this._currentSelection); - if (this._validEmbed(url)) { - var embedtemplate = Y.Handlebars.compile(H5PTEMPLATE); - var regex = //; - var src = url.match(regex)[1]; + if (h5pfile.startsWith(M.cfg.wwwroot)) { + // It's a local file. + var params = ''; + if (permissions.canUpload) { + var options = {}; + if (form.one(SELECTORS.OPTION_DOWNLOAD_BUTTON).get('checked')) { + options['export'] = '1'; + } + if (form.one(SELECTORS.OPTION_EMBED_BUTTON).get('checked')) { + options.embed = '1'; + } + if (form.one(SELECTORS.OPTION_COPYRIGHT_BUTTON).get('checked')) { + options.copyright = '1'; + } - // In case a local H5P embed code is used we need get the url - // param form the src and decode it. - if (src.startsWith(M.cfg.wwwroot + '/h5p/embed.php')) { - src = decodeURIComponent(src.split("url=")[1]); + for (var opt in options) { + if (params === "" && (h5pfile.indexOf("?") === -1)) { + params += "?"; + } else { + params += "&"; + } + params += opt + "=" + options[opt]; + } } - h5phtml = embedtemplate({ - url: src + var h5ptemplate = Y.Handlebars.compile(H5PTEMPLATE); + + h5phtml = h5ptemplate({ + url: h5pfile + params, + addParagraphs: addParagraphs }); } else { + // It's a URL. var urltemplate = Y.Handlebars.compile(H5PTEMPLATE); h5phtml = urltemplate({ - url: url + url: h5pfile }); } - this.get('host').insertContentAtFocusPoint(h5phtml); - - this.markUpdated(); - } else if (h5pfile !== '') { - - host.setSelection(this._currentSelection); - - var options = {}; - - if (form.one(SELECTORS.OPTION_DOWNLOAD_BUTTON).get('checked')) { - options['export'] = '1'; - } - if (form.one(SELECTORS.OPTION_EMBED_BUTTON).get('checked')) { - options.embed = '1'; - } - if (form.one(SELECTORS.OPTION_COPYRIGHT_BUTTON).get('checked')) { - options.copyright = '1'; - } - - var params = ""; - for (var opt in options) { - if (params === "" && (h5pfile.indexOf("?") === -1)) { - params += "?"; - } else { - params += "&"; - } - params += opt + "=" + options[opt]; - } - - var h5ptemplate = Y.Handlebars.compile(H5PTEMPLATE); - - h5phtml = h5ptemplate({ - url: h5pfile + params, - addParagraphs: addParagraphs - }); - - this.get('host').insertContentAtFocusPoint(h5phtml); + host.insertContentAtFocusPoint(h5phtml); this.markUpdated(); } @@ -572,30 +539,21 @@ Y.namespace('M.atto_h5p').Button = Y.Base.create('button', Y.M.editor_atto.Edito _updateWarning: function() { var form = this._form, state = true, - url, h5pfile, permissions = this._getPermissions(); - - if (permissions.canEmbed) { - url = form.one(SELECTORS.INPUTH5PURL).get('value'); - if (url !== '') { - if (this._validURL(url) || this._validEmbed(url)) { + if (permissions.canUpload || permissions.canEmbed) { + h5pfile = form.one(SELECTORS.INPUTH5PFILE).get('value'); + if (h5pfile !== '') { + form.one(SELECTORS.CONTENTWARNING).setStyle('display', 'none'); + if (h5pfile.startsWith(M.cfg.wwwroot) || this._validURL(h5pfile)) { + // Only external URLs have to be validated. form.one(SELECTORS.URLWARNING).setStyle('display', 'none'); state = false; } else { form.one(SELECTORS.URLWARNING).setStyle('display', 'block'); state = true; } - return state; - } - } - - if (permissions.canUpload) { - h5pfile = form.one(SELECTORS.INPUTH5PFILE).get('value'); - if (h5pfile !== '') { - form.one(SELECTORS.CONTENTWARNING).setStyle('display', 'none'); - state = false; } else { form.one(SELECTORS.CONTENTWARNING).setStyle('display', 'block'); state = true;