-
Notifications
You must be signed in to change notification settings - Fork 4
/
popBox1.3.0.js
104 lines (81 loc) · 3.86 KB
/
popBox1.3.0.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
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
/*
* jQuery popBox
* Copyright (c) 2011 Simon Hibbard
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Version: V1.3.0
* Release: 26-01-2011
* Based on jQuery 1.5.0
* Additional features provided with thanks to Alex Lareau
*/
(function ($) {
$.fn.popBox = function (options) {
var defaults = {
height: 100,
width: 300,
newlineString: "<br/>"
};
var options = $.extend(defaults, options);
return this.each(function () {
obj = $(this);
var inputName = 'popBoxInput' + obj.attr("Id");
var labelValue = $("label[for=" + obj.attr('id') + "]").text();
obj.after('<div class="popBox-holder"></div><div class="popBox-container"><label style="display: none;" for="' + inputName + '">' + labelValue + '</label> <textarea id="' + inputName + '" name="' + inputName + '" class="popBox-input" /><div class="done-button"><input type="button" value="Done" class="button blue small"/></div></div>');
obj.focus(function () {
$(this).next(".popBox-holder").show();
var popBoxContainer = $(this).next().next(".popBox-container");
var change = true;
popBoxContainer.children('.popBox-input').css({ height: options.height, width: options.width });
popBoxContainer.show();
var winH = $(window).height();
var winW = $(window).width();
var objH = popBoxContainer.height();
var objW = popBoxContainer.width();
var left = (winW / 2) - (objW / 2);
var top = (winH / 2) - (objH / 2);
popBoxContainer.css({ position: 'fixed', margin: 0, top: (top > 0 ? top : 0) + 'px', left: (left > 0 ? left : 0) + 'px' });
popBoxContainer.children('.popBox-input').val($(this).val().replace(RegExp(options.newlineString, "g"), "\n"));
popBoxContainer.children('.popBox-input').focus();
popBoxContainer.children().keydown(function (e) {
if (e == null) { // ie
keycode = event.keyCode;
} else { // mozilla
keycode = e.which;
}
if (keycode == 27) { // close
$(this).parent().hide();
$(this).parent().prev().hide();
change = false;
}
});
popBoxContainer.children().blur(function () {
if (change) {
$(this).parent().hide();
$(this).parent().prev().hide();
$(this).parent().prev().prev().val($(this).val().replace(/\n/g, options.newlineString));
}
});
});
});
};
})(jQuery);