-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdepage-textbutton.js
90 lines (75 loc) · 2.97 KB
/
depage-textbutton.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
/**
* @require framework/shared/jquery-1.8.3.js
*
* @file depage-textbutton.js
*
* replaces buttons with links to apply css-styles more easily
*
*
* copyright (c) 2009-2012 Frank Hellenkamp [[email protected]]
*
* @author Frank Hellenkamp [[email protected]]
*/
;(function($){
if(!$.depage){
$.depage = {};
};
$.depage.textbutton = function(el, options){
// To avoid scope issues, use 'base' instead of 'this' to reference this class from internal events and functions.
var base = this;
// Access to jQuery and DOM versions of element
base.$el = $(el);
base.el = el;
// Add a reverse reference to the DOM object
base.$el.data("depage.textbutton", base);
base.init = function(){
base.options = $.extend({},$.depage.textbutton.defaultOptions, options);
var $inputs = base.$el.filter("input");
if ($inputs.length == 0) {
// base.$el is not a input so we search for the children
$inputs = base.$el.find(base.options.elements);
}
$inputs.each( function() {
var button = this;
var $button = $(this);
$button.css({
position: "absolute",
left: "-10000px",
width: "100px"
});
// add link and click event to it
$("<a href=\"#" + button.value + "\" class=\"textbutton\">" + button.value + "</a>").insertAfter(button).click( function() {
if ($button.filter(":submit").length == 0) {
$button.click();
} else {
var $form = $button.parents("form");
if ($button.parent().hasClass("cancel")) {
// dont validate when cancel-button was pressed
$("<input type=\"hidden\" class=\"formSubmit\" name=\"formSubmit\" value=\"" + button.value + "\">").appendTo($form);
if(typeof($form.data("validator")) !== 'undefined') {
// @todo validation should be handled in effects
$form.data("validator").destroy();
}
} else {
$form.find("input.formSubmit:hidden").remove();
}
$form.submit();
$button.click();
}
return false;
});
});
};
// Run initializer
base.init();
};
$.depage.textbutton.defaultOptions = {
elements: "input:submit, input:reset, input:button"
};
$.fn.depageTextbutton = function(options){
return this.each(function(){
(new $.depage.textbutton(this, options));
});
};
})(jQuery);
/* vim:set ft=javascript sw=4 sts=4 fdm=marker : */