14
14
WYMeditor . editor . prototype . image_upload = function ( ) {
15
15
var wym = this ;
16
16
var uploadUrl = wym . _options . dialogImageUploadUrl ;
17
+
18
+ wym . _options . attributionImgAttribute = 'data-attribution' ;
19
+ wym . _options . attributionSelector = '.wym_attribution' ;
20
+
17
21
// Check the options
18
22
if ( uploadUrl == undefined ) {
19
23
WYMeditor . console . warn (
@@ -29,7 +33,10 @@ WYMeditor.editor.prototype.image_upload = function() {
29
33
orig . call ( this , wDialog ) ;
30
34
var wym = this ,
31
35
doc = wDialog . document ,
32
- options = wym . _options ;
36
+ options = wym . _options ,
37
+ selectedImage = wym . getSelectedImage ( ) ;
38
+
39
+ jQuery ( options . attributionSelector , doc ) . val ( jQuery ( selectedImage ) . attr ( options . attributionImgAttribute ) ) ;
33
40
34
41
var oldSubmitLabel = jQuery ( "form#image_upload_form .submit" , doc ) . val ( ) ;
35
42
// WYMEditor automatically locks onto any form here, so remove the binding.
@@ -47,12 +54,37 @@ WYMeditor.editor.prototype.image_upload = function() {
47
54
} else {
48
55
jQuery ( options . srcSelector , doc ) . val ( response . thumbUrl ) ;
49
56
jQuery ( options . altSelector , doc ) . val ( response . original_filename ) ;
57
+ jQuery ( options . attributionSelector , doc ) . val ( response . attribution ) ;
50
58
}
51
59
jQuery ( "form#image_upload_form .submit" , doc ) . val ( oldSubmitLabel ) ;
52
60
}
53
61
} )
54
62
} ;
55
63
64
+ d . submitHandler = function ( wDialog ) {
65
+ var wym = this ,
66
+ options = wym . _options ,
67
+ imgAttrs ,
68
+ selectedImage = wym . getSelectedImage ( ) ;
69
+
70
+ imgAttrs = {
71
+ src : jQuery ( options . srcSelector , wDialog . document ) . val ( ) ,
72
+ title : jQuery ( options . titleSelector , wDialog . document ) . val ( ) ,
73
+ alt : jQuery ( options . altSelector , wDialog . document ) . val ( ) ,
74
+ } ;
75
+ imgAttrs [ options . attributionImgAttribute ] = jQuery ( options . attributionSelector , wDialog . document ) . val ( ) ;
76
+
77
+ wym . focusOnDocument ( ) ;
78
+
79
+ if ( selectedImage ) {
80
+ wym . _updateImageAttrs ( selectedImage , imgAttrs ) ;
81
+ wym . registerModification ( ) ;
82
+ } else {
83
+ wym . insertImage ( imgAttrs ) ;
84
+ }
85
+ wDialog . close ( ) ;
86
+ }
87
+
56
88
// Put together the whole dialog script
57
89
wym . _options . dialogImageHtml = String ( ) +
58
90
'<body class="wym_dialog wym_dialog_image">' +
@@ -95,6 +127,10 @@ WYMeditor.editor.prototype.image_upload = function() {
95
127
'<label>{Title}</label>' +
96
128
'<input type="text" class="wym_title" value="" size="40" />' +
97
129
'</div>' +
130
+ '<div class="row">' +
131
+ '<label>{Attribution}</label>' +
132
+ '<input type="text" class="wym_attribution" value="" size="40" placeholder="{Attribution_placeholder}" />' +
133
+ '</div>' +
98
134
'<div class="row row-indent">' +
99
135
'<input class="wym_submit" type="submit" ' + 'value="{Submit}" />' +
100
136
'<input class="wym_cancel" type="button" ' + 'value="{Cancel}" />' +
0 commit comments