-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedia-edit-popup-2.patch
136 lines (136 loc) · 4.9 KB
/
media-edit-popup-2.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
diff --git a/js/plugins/media.image.overlay.js b/js/plugins/media.image.overlay.js
new file mode 100644
index 0000000..1ba03f3
--- /dev/null
+++ b/js/plugins/media.image.overlay.js
@@ -0,0 +1,97 @@
+(function() {
+ tinymce.create('tinymce.plugins.distroMediaEdit', {
+ mceTout : 0,
+
+ init: function(ed, url) {
+ DOM = tinymce.DOM;
+
+ DOM.remove('media_editbtns');
+
+ DOM.add(document.body, 'div', {
+ id: 'media_editbtns',
+ style: 'position:absolute;z-index:1000;display:none;'
+ });
+
+ editButton = DOM.add('media_editbtns', 'img', {
+ src: Drupal.settings.media.path + '/images/wysiwyg-media.gif',
+ id: 'media_editimgbtn',
+ width: '24',
+ height: '24',
+ title: 'Edit media'
+ });
+
+ tinymce.dom.Event.add(editButton, 'mousedown', function(e) {
+ var ed = tinyMCE.activeEditor;
+ // Fetch all the classes applied to the current selection (file)
+ var classesString = ed.dom.getAttrib(ed.selection.getNode(), 'class');
+ // Get the file id (fid) of the image from the class name (format 'img__fid__123')
+ var matchesArray = classesString.match(/\bimg__fid__(\d+)\b/);
+ // Show the editor for the file id (multiple instances of the same fid on the page share the same values)
+ // So if the same file is on the page more than once, they will share the same Title, alt, description etc.
+ if (matchesArray) {
+ var fid = matchesArray[1];
+ Drupal.media.popups.mediaFieldEditor(fid);
+ }
+ // This is to prevent the default behaviour of the JS from refreshing the page
+ e.preventDefault();
+ });
+
+ // show editimage buttons
+ ed.onMouseDown.add(function(ed, e) {
+ if ( e.target && ( e.target.nodeName == 'IMG' || (e.target.firstChild && e.target.firstChild.nodeName == 'IMG') ) ) {
+ mouse = {
+ // @todo this is going to be deprecated
+ x: e.clientX,
+ y: e.clientY,
+ img_w: e.target.clientWidth,
+ img_h: e.target.clientHeight
+ };
+ if ( ed.dom.getAttrib(e.target, 'class').indexOf('media-image') !== -1 ) {
+ ed.plugins.distromediaedit._showButtons(e.target, 'media_editbtns');
+ }
+ }
+ });
+
+ ed.onInit.add(function(ed) {
+ tinymce.dom.Event.add(ed.getWin(), 'scroll', function(e) {
+ ed.plugins.distromediaedit._hideButtons();
+ });
+ tinymce.dom.Event.add(ed.getBody(), 'dragstart', function(e) {
+ ed.plugins.distromediaedit._hideButtons();
+ });
+ });
+ },
+
+ _showButtons : function(n, id) {
+ var ed = tinyMCE.activeEditor, p1, p2, vp, DOM = tinymce.DOM, X, Y;
+ vp = ed.dom.getViewPort(ed.getWin());
+ p1 = DOM.getPos(ed.getContentAreaContainer());
+ p2 = ed.dom.getPos(n);
+ X = Math.max(p2.x - vp.x, 0) + p1.x;
+ Y = Math.max(p2.y - vp.y, 0) + p1.y;
+ DOM.setStyles(id, {
+ 'top' : Y+5+'px',
+ 'left' : X+5+'px',
+ 'display' : 'block'
+ });
+ if ( this.mceTout ) {
+ clearTimeout(this.mceTout);
+ }
+ this.mceTout = setTimeout( function(){ed.plugins.distromediaedit._hideButtons();}, 5000 );
+ },
+
+ _hideButtons : function() {
+ if ( !this.mceTout ) {
+ return;
+ }
+
+ if ( document.getElementById('media_editbtns') ) {
+ tinymce.DOM.hide('media_editbtns');
+ }
+
+ clearTimeout(this.mceTout);
+ this.mceTout = 0;
+ }
+ });
+ tinymce.PluginManager.add('distromediaedit', tinymce.plugins.distroMediaEdit)
+})();
diff --git a/wysiwyg_plugins/media.inc b/wysiwyg_plugins/media.inc
index 8e0c862..fcffb06 100644
--- a/wysiwyg_plugins/media.inc
+++ b/wysiwyg_plugins/media.inc
@@ -62,6 +62,14 @@ function media_include_browser_js() {
}
}
// Add wysiwyg-specific settings.
- $settings = array('blacklist' => array('src', 'fid', 'view_mode', 'format'));
+ $settings = array(
+ 'blacklist' => array('src', 'fid', 'view_mode', 'format'),
+ 'path' => url(drupal_get_path('module', 'media'), array('absolute' => TRUE)),
+ );
drupal_add_js(array('media' => $settings), 'setting');
+ drupal_add_js(drupal_get_path('module', 'media') . '/js/plugins/media.image.overlay.js');
+}
+
+function media_wysiwyg_editor_settings_alter(&$settings, $context) {
+ $settings['plugins'] .= ',distromediaedit';
}
diff --git a/js/media.popups.js b/js/media.popups.js
index 9a615c5..b494697 100644
--- a/js/media.popups.js
+++ b/js/media.popups.js
@@ -282,7 +282,7 @@ Drupal.media.popups.mediaFieldEditor.mediaBrowserOnLoad = function (e) {
Drupal.media.popups.mediaFieldEditor.getDefaults = function () {
return {
// @todo: do this for real
- src: '/media/-media_id-/edit?render=media-popup',
+ src: '/file/-media_id-/edit?render=media-popup',
onLoad: Drupal.media.popups.mediaFieldEditor.mediaBrowserOnLoad
};
};