-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsAutoCaption.js
More file actions
50 lines (37 loc) · 1.63 KB
/
Copy pathjsAutoCaption.js
File metadata and controls
50 lines (37 loc) · 1.63 KB
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
(function($) {
$.fn.showAltTitle = function(options) {
var img = $(this);
if (options == undefined) {
options = {
"courtesyText" : "Caption not available",
"borderWidth" : "1",
"borderColor" : "#c0c0c0",
"textAlign" : "center",
};
}
var text = img.attr('title') || img.attr('alt');
if ((text == undefined || text == '') && options.courtesyText) {
text = options.courtesyText;
}
var imgCssWidth = img.css('width');
var width = imgCssWidth || img.width();
var borderCol = options.borderColor || '#c0c0c0';
var tAlign = options.textAlign || 'center';
var cssFloat = img.css('float');
var floatTag = '';
if (cssFloat != undefined && cssFloat != '') {
floatTag = 'float: ' + cssFloat + ';';
}
var imgSrc = img.attr('src');
var slashPos = imgSrc.lastIndexOf('/');
var wrapDivId = imgSrc.substr(slashPos + 1).replace('.','');
var textDivId = 'vis-' + wrapDivId;
$("<div id='" + wrapDivId + "'></div>").insertBefore(img);
img.appendTo($('#' + wrapDivId));
$('#' + wrapDivId).append("<div id='" + textDivId + "' style='clear:both;'></div>");
var stl = "clear:both; " + floatTag + " width: " + width + "; border:1px solid " + borderCol + "; text-align:" + tAlign + ";";
var textDiv = $('#' + textDivId);
textDiv.attr('style', stl);
textDiv.html(text);
}
}(jQuery));