forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iframes the Authoring MFE's Library Content Picker
- Loading branch information
1 parent
2cb69c0
commit df77ff7
Showing
11 changed files
with
128 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Provides utilities to open and close the library content picker. | ||
* | ||
* To use this picker you need to add the following code into your template: | ||
* | ||
* ``` | ||
* <div id="library-content-picker" class="picker"></div> | ||
* <div class="picker-cover"></div> | ||
* ``` | ||
*/ | ||
define(['jquery'], | ||
function($) { | ||
'use strict'; | ||
|
||
const closePicker = (picker, pickerCover) => { | ||
$(pickerCover).css('display', 'none'); | ||
$(picker).empty(); | ||
$(picker).css('display', 'none'); | ||
$('body').removeClass('picker-open'); | ||
}; | ||
|
||
const openPicker = (contentPickerUrl, picker, pickerCover) => { | ||
// Add event listen to close picker when the iframe tells us to | ||
window.addEventListener("message", function (event) { | ||
if (event.data === 'closeComponentPicker') { | ||
closePicker(picker, pickerCover); | ||
} | ||
}.bind(this)); | ||
|
||
$(pickerCover).css('display', 'block'); | ||
// xss-lint: disable=javascript-jquery-html | ||
$(picker).html( | ||
`<iframe src="${contentPickerUrl}" onload="this.contentWindow.focus()" frameborder="0" style="width: 100%; height: 100%;"></iframe>` | ||
); | ||
$(picker).css('display', 'block'); | ||
|
||
// Prevent background from being scrollable when picker is open | ||
$('body').addClass('picker-open'); | ||
}; | ||
|
||
const createComponent = (contentPickerUrl) => { | ||
const picker = document.querySelector("#library-content-picker"); | ||
const pickerCover = document.querySelector(".picker-cover"); | ||
|
||
return openPicker(contentPickerUrl, picker, pickerCover); | ||
}; | ||
|
||
return { | ||
createComponent: createComponent, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters