|
1 | 1 | YUI.add('moodle-atto_kalturamedia-button', function (Y, NAME) {
|
2 | 2 |
|
3 |
| -// This file is part of Moodle - http://moodle.org/ |
4 |
| -// |
5 |
| -// Moodle is free software: you can redistribute it and/or modify |
6 |
| -// it under the terms of the GNU General Public License as published by |
7 |
| -// the Free Software Foundation, either version 3 of the License, or |
8 |
| -// (at your option) any later version. |
9 |
| -// |
10 |
| -// Moodle is distributed in the hope that it will be useful, |
11 |
| -// but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
| -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
| -// GNU General Public License for more details. |
14 |
| -// |
15 |
| -// You should have received a copy of the GNU General Public License |
16 |
| -// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
17 |
| - |
18 |
| -/* |
19 |
| - * @package atto_kalturamedia |
20 |
| - * @copyright 2Kaltura |
21 |
| - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
22 |
| - */ |
23 |
| - |
24 |
| -/** |
25 |
| - * @module moodle-atto_kalturamedia-button |
26 |
| - */ |
27 |
| - |
28 |
| -/** |
29 |
| - * Atto text editor kalturamedia plugin. |
30 |
| - * |
31 |
| - * @namespace M.atto_kalturamedia |
32 |
| - * @class button |
33 |
| - * @extends M.editor_atto.EditorPlugin |
34 |
| - */ |
35 |
| - |
36 |
| -var COMPONENTNAME = 'atto_kalturamedia', |
37 |
| - CSS = { |
38 |
| - URLINPUT: 'atto_kalturamedia_urlentry', |
39 |
| - NAMEINPUT: 'atto_kalturamedia_nameentry' |
40 |
| - }, |
41 |
| - SELECTORS = { |
42 |
| - URLINPUT: '.' + CSS.URLINPUT, |
43 |
| - NAMEINPUT: '.' + CSS.NAMEINPUT |
44 |
| - }; |
45 |
| - |
46 |
| -Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], { |
47 |
| - _currentSelection: null, |
48 |
| - embedWindow: null, |
49 |
| - |
50 |
| - initializer: function() { |
51 |
| - this.addButton({ |
52 |
| - icon: 'icon', |
53 |
| - iconComponent: COMPONENTNAME, |
54 |
| - callback: this._kalturamedia |
55 |
| - }); |
56 |
| - }, |
57 |
| - _kalturamedia: function() { |
58 |
| - this._currentSelection = this.get('host').getSelection(); |
59 |
| - if (this._currentSelection === false) { |
60 |
| - return; |
61 |
| - } |
62 |
| - |
63 |
| - var w = 1200; |
64 |
| - var h = 700; |
65 |
| - var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left; |
66 |
| - var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top; |
67 |
| - |
68 |
| - var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; |
69 |
| - var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; |
70 |
| - |
71 |
| - var left = ((width / 2) - (w / 2)) + dualScreenLeft; |
72 |
| - var top = ((height / 2) - (h / 2)) + dualScreenTop; |
73 |
| - var newWindow = window.open(this._getIframeURL(), M.util.get_string("browse_and_embed", COMPONENTNAME), 'scrollbars=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left); |
74 |
| - |
75 |
| - window.buttonJs = this; |
76 |
| - |
77 |
| - if (window.focus) { |
78 |
| - newWindow.focus(); |
79 |
| - } |
80 |
| - |
81 |
| - this.embedWindow = newWindow; |
82 |
| - }, |
83 |
| - |
84 |
| - _getIframeURL: function() { |
85 |
| - |
86 |
| - var args = Y.mix({ |
87 |
| - elementid: this.get('host').get('elementid'), |
88 |
| - contextid: this.get('contextid'), |
89 |
| - height: '600px', |
90 |
| - width: '1112px' |
91 |
| - }, |
92 |
| - this.get('area')); |
93 |
| - return M.cfg.wwwroot + '/lib/editor/atto/plugins/kalturamedia/ltibrowse_container.php?' + |
94 |
| - Y.QueryString.stringify(args); |
95 |
| - }, |
96 |
| - |
97 |
| - _getCourseId: function() { |
98 |
| - var courseId; |
99 |
| - var bodyClasses = document.getElementsByTagName('body')[0].className; |
100 |
| - var classes = bodyClasses.split(' '); |
101 |
| - for(i in classes) |
102 |
| - { |
103 |
| - if(classes[i].indexOf('course-') > -1) |
104 |
| - { |
105 |
| - var parts = classes[i].split('-'); |
106 |
| - courseId = parts[1]; |
107 |
| - } |
108 |
| - } |
109 |
| - |
110 |
| - return courseId; |
111 |
| - }, |
112 |
| - |
113 |
| - _removeProtocolFromUrl: function(fullUrl) { |
114 |
| - return fullUrl.replace(/^https?:\/\//,''); |
115 |
| - }, |
116 |
| - |
117 |
| - embedItem: function(what, data) { |
118 |
| - var sourceUrl = data.url; |
119 |
| - var url = this._removeProtocolFromUrl(sourceUrl); |
120 |
| - var parser = document.createElement('a'); |
121 |
| - parser.href = sourceUrl; |
122 |
| - url += parser.search; |
123 |
| - |
124 |
| - var content = '<a href="http://'+url+'">tinymce-kalturamedia-embed||'+data.title+'||'+data.width+'||'+data.height+'</a>'; |
125 |
| - |
126 |
| - host = this.get('host'); |
127 |
| - host.setSelection(this._currentSelection); |
128 |
| - host.insertContentAtFocusPoint(content); |
129 |
| - this.markUpdated(); |
130 |
| - this.embedWindow.close(); |
131 |
| - } |
132 |
| - |
133 |
| - } , { |
134 |
| - ATTRS: { |
135 |
| - /** |
136 |
| - * The contextid to use when generating this preview. |
137 |
| - * |
138 |
| - * @attribute contextid |
139 |
| - * @type String |
140 |
| - */ |
141 |
| - contextid: { |
142 |
| - value: null |
143 |
| - }, |
144 |
| - |
145 |
| - /** |
146 |
| - * The KAF URI, as configured in Kaltura's plugin settings. |
147 |
| - */ |
148 |
| - kafuri: { |
149 |
| - value: null |
150 |
| - } |
151 |
| - }} |
152 |
| -); |
| 3 | +// This file is part of Moodle - http://moodle.org/ |
| 4 | +// |
| 5 | +// Moodle is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// Moodle is distributed in the hope that it will be useful, |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU General Public License |
| 16 | +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +/* |
| 19 | + * @package atto_kalturamedia |
| 20 | + * @copyright 2Kaltura |
| 21 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 22 | + */ |
| 23 | + |
| 24 | +/* eslint-disable max-len */ |
| 25 | + |
| 26 | +/** |
| 27 | + * @module moodle-atto_kalturamedia-button |
| 28 | + */ |
| 29 | + |
| 30 | +/** |
| 31 | + * Atto text editor kalturamedia plugin. |
| 32 | + * |
| 33 | + * @namespace M.atto_kalturamedia |
| 34 | + * @class button |
| 35 | + * @extends M.editor_atto.EditorPlugin |
| 36 | + */ |
| 37 | + |
| 38 | +var COMPONENTNAME = 'atto_kalturamedia', |
| 39 | + CSS = { |
| 40 | + URLINPUT: 'atto_kalturamedia_urlentry', |
| 41 | + NAMEINPUT: 'atto_kalturamedia_nameentry' |
| 42 | + }, |
| 43 | + SELECTORS = { |
| 44 | + URLINPUT: '.' + CSS.URLINPUT, |
| 45 | + NAMEINPUT: '.' + CSS.NAMEINPUT |
| 46 | + }; |
| 47 | + |
| 48 | +Y.namespace('M.atto_kalturamedia').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], { |
| 49 | + _currentSelection: null, |
| 50 | + embedWindow: null, |
| 51 | + |
| 52 | + initializer: function() { |
| 53 | + this.addButton({ |
| 54 | + icon: 'icon', |
| 55 | + iconComponent: COMPONENTNAME, |
| 56 | + callback: this._kalturamedia |
| 57 | + }); |
| 58 | + }, |
| 59 | + _kalturamedia: function() { |
| 60 | + this._currentSelection = this.get('host').getSelection(); |
| 61 | + if (this._currentSelection === false) { |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | + var w = 1200; |
| 66 | + var h = 700; |
| 67 | + var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left; |
| 68 | + var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top; |
| 69 | + |
| 70 | + var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; |
| 71 | + var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; |
| 72 | + |
| 73 | + var left = ((width / 2) - (w / 2)) + dualScreenLeft; |
| 74 | + var top = ((height / 2) - (h / 2)) + dualScreenTop; |
| 75 | + var newWindow = window.open(this._getIframeURL(), M.util.get_string("browse_and_embed", COMPONENTNAME), 'scrollbars=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left); |
| 76 | + |
| 77 | + window.buttonJs = this; |
| 78 | + |
| 79 | + if (window.focus) { |
| 80 | + newWindow.focus(); |
| 81 | + } |
| 82 | + |
| 83 | + this.embedWindow = newWindow; |
| 84 | + }, |
| 85 | + |
| 86 | + _getIframeURL: function() { |
| 87 | + |
| 88 | + var args = Y.mix({ |
| 89 | + elementid: this.get('host').get('elementid'), |
| 90 | + contextid: this.get('contextid'), |
| 91 | + height: '600px', |
| 92 | + width: '1112px' |
| 93 | + }, |
| 94 | + this.get('area')); |
| 95 | + return M.cfg.wwwroot + '/lib/editor/atto/plugins/kalturamedia/ltibrowse_container.php?' + |
| 96 | + Y.QueryString.stringify(args); |
| 97 | + }, |
| 98 | + |
| 99 | + _getCourseId: function() { |
| 100 | + var courseId; |
| 101 | + var bodyClasses = document.getElementsByTagName('body')[0].className; |
| 102 | + var classes = bodyClasses.split(' '); |
| 103 | + for(i in classes) |
| 104 | + { |
| 105 | + if(classes[i].indexOf('course-') > -1) |
| 106 | + { |
| 107 | + var parts = classes[i].split('-'); |
| 108 | + courseId = parts[1]; |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + return courseId; |
| 113 | + }, |
| 114 | + |
| 115 | + _removeProtocolFromUrl: function(fullUrl) { |
| 116 | + return fullUrl.replace(/^https?:\/\//,''); |
| 117 | + }, |
| 118 | + |
| 119 | + embedItem: function(what, data) { |
| 120 | + var sourceUrl = data.url; |
| 121 | + var url = this._removeProtocolFromUrl(sourceUrl); |
| 122 | + var parser = document.createElement('a'); |
| 123 | + parser.href = sourceUrl; |
| 124 | + url += parser.search; |
| 125 | + |
| 126 | + var content = '<a href="http://'+url+'">tinymce-kalturamedia-embed||'+data.title+'||'+data.width+'||'+data.height+'</a>'; |
| 127 | + |
| 128 | + host = this.get('host'); |
| 129 | + host.setSelection(this._currentSelection); |
| 130 | + host.insertContentAtFocusPoint(content); |
| 131 | + this.markUpdated(); |
| 132 | + this.embedWindow.close(); |
| 133 | + } |
| 134 | + |
| 135 | + } , { |
| 136 | + ATTRS: { |
| 137 | + /** |
| 138 | + * The contextid to use when generating this preview. |
| 139 | + * |
| 140 | + * @attribute contextid |
| 141 | + * @type String |
| 142 | + */ |
| 143 | + contextid: { |
| 144 | + value: null |
| 145 | + }, |
| 146 | + |
| 147 | + /** |
| 148 | + * The KAF URI, as configured in Kaltura's plugin settings. |
| 149 | + */ |
| 150 | + kafuri: { |
| 151 | + value: null |
| 152 | + } |
| 153 | + }} |
| 154 | +); |
153 | 155 |
|
154 | 156 |
|
155 | 157 | }, '@VERSION@', {"requires": ["moodle-editor_atto-plugin"]});
|
0 commit comments