aboutsummaryrefslogtreecommitdiffstats
path: root/webclient/lib/jquery.dialog.js
diff options
context:
space:
mode:
authorZaran <zaran.krleza@gmail.com>2011-05-13 14:19:26 +0200
committerZaran <zaran.krleza@gmail.com>2011-05-13 14:19:26 +0200
commit368ada44db571c46deea674eadd410ac9bc47ebc (patch)
tree5b33bc0977b1cba67ff1e973f8e339e5b3718e3f /webclient/lib/jquery.dialog.js
parent02a4212494e1d42f50d8fb1c8daede32ae9cb744 (diff)
downloadalias-368ada44db571c46deea674eadd410ac9bc47ebc.tar.gz
Simple dialog plugin.
Test dialog when clicking register link.
Diffstat (limited to 'webclient/lib/jquery.dialog.js')
-rw-r--r--webclient/lib/jquery.dialog.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/webclient/lib/jquery.dialog.js b/webclient/lib/jquery.dialog.js
new file mode 100644
index 0000000..1a5679e
--- /dev/null
+++ b/webclient/lib/jquery.dialog.js
@@ -0,0 +1,63 @@
+/**
+ * jQuery dialog plugin
+ *
+ * <div id="dialogs">
+ * <div id="#dialog-overlay"></div>
+ * <div class="dialog" id="dialog1"></div>
+ * <div class="dialog" id="dialog2"></div>
+ * </div>
+ */
+(function( $ ){
+
+ var methods = {
+
+ init: function(){
+ this.data('dialog', {opened: []});
+ this.find('#dialog-overlay').bind('click.dialog', function(){
+ $(this).parent().dialog('hide');
+ });
+ },
+
+ show: function(name){
+ var maskHeight = $(document).height();
+ var maskWidth = $(window).width();
+ var overlay = this.find('#dialog-overlay');
+ overlay.css({'width':maskWidth,'height':maskHeight});
+ var winH = $(window).height();
+ var winW = $(window).width();
+ var dialog = this.find('#'+name);
+ dialog.css('top', winH/2-dialog.height()/2);
+ dialog.css('left', winW/2-dialog.width()/2);
+ this.data('dialog').opened.push(name);
+ overlay.show();
+ dialog.show();
+ },
+
+ hide: function(){
+ var name = this.data('dialog').opened.pop();
+ var dialog = this.find('#'+name);
+ var overlay = this.find('#dialog-overlay');
+ dialog.hide();
+ if (this.data('dialog').opened.length === 0){
+ overlay.hide();
+ }
+ }
+ };
+
+ /*
+ * Register the 'dialog' method to the jQuery objects
+ * the first argument of this method is the submethod
+ * you want to call
+ */
+ $.fn.dialog = function(method) {
+ if ( methods[method] ) {
+ return methods[method].apply(this, Array.prototype.slice
+ .call(arguments, 1));
+ } else if ( typeof method === 'object' || !method ) {
+ return methods.init.apply(this, arguments);
+ } else {
+ $.error('Method ' + method + ' does not exist on jQuery.dialog');
+ }
+ };
+
+})(jQuery); \ No newline at end of file