-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.extractor.js
More file actions
56 lines (53 loc) · 2.09 KB
/
jquery.extractor.js
File metadata and controls
56 lines (53 loc) · 2.09 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
51
52
53
54
55
56
/**
* @preserve Extractor 1.1
* Copyright 2011 Kevin Wetzels - Licensed under the MIT License.
*/
(function($) {
var extractorCount = 0;
$.fn.extractor = function(opts) {
var attrKeys = opts.attributesToSave || ['class', 'style'];
this.each(function() {
var e = $(this);
// Since loading the dialog will override the class and style
// attributes of the content, we want to keep track of their
// original values.
var attrs = {};
for (var i = 0, len = attrKeys.length; i < len; ++i) {
var k = attrKeys[i];
var v = e.attr(k);
attrs[k] = (v ? v : '');
}
// Get or generate the id of the content loaded into the modal.
var id = e.attr('id');
if (!$.trim(id)) {
id = 'extractor-' + (++extractorCount);
e.attr('id', id);
}
// Generate the placeholder so we know where to put the content
// when the dialog is closed.
var placeholderId = 'extractor-placeholder-' + id;
$('<div id="' + placeholderId + '"></div>').insertBefore(e).hide();
// Get a hold of the options we have to alter
var originalClose = (opts.close ? opts.close : $.noop);
var c = opts.dialogClass;
// Override those options
var options = $.extend(true, opts, {
close: function(evt, ui) {
// Perform the regular close
originalClose(evt, ui);
// And place the content back where it belongs
var o = $('#' + id);
o.dialog('destroy');
o.attr(attrs);
$('#' + placeholderId).replaceWith(o);
// IE needs this
$('#' + id).show();
},
dialogClass: (c ? c : '') + ' ui-extractor'
});
// Ready to rock.
e.dialog(options);
});
return this;
};
})(jQuery);