-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.lock.js
41 lines (37 loc) · 1.29 KB
/
jquery.lock.js
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
//
// jQuery Lock Plugin
//
(function($) {
$.fn.lock = function(options) {
// Keep the reference for later usage
var elements = this;
// Save the html of the elements
var savedHtmlList = elements.map(function(i, el) {
return $(el).html();
});
// Options
var settings = $.extend({
// Default options
customHandler: null, // Function
alertMessage: null // String
}, options);
// Check for DOM changes
$(elements).on('DOMSubtreeModified', function() {
var savedHtml = savedHtmlList[elements.index(this)];
var updatedHtml = $(this).html();
//Check if there is a change in the element HTML
if (updatedHtml != savedHtml) {
// If a customHandler is defined, call it and don`t continue
if (settings.customHandler)
settings.customHandler(this, updatedHtml, savedHtml);
else
$(this).html(savedHtml);
// If the alertMessage was set, send the alert
if (settings.alertMessage)
alert(settings.alertMessage);
}
});
// Support chaining
return elements;
};
}(jQuery));