Subversion Repositories DevTools

Rev

Rev 5590 | Rev 5598 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5190 dpurdie 1
//  Vix specific Javascript for jquery use
2
//
3
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4
//  Generate a confirmation dialog
5
//  Args:   text - Body of the message
6
//          parms - A simple object of options - see defaults
5266 dpurdie 7
//                  Special: position of 'center' will place in center of visible screen.
5190 dpurdie 8
//  Note: will return BEFORE the user makes a selection
9
//        Can call a function and/or a URL if confirmed
10
//        Can 'show' a progress element
11
//        See 'defaults' below for bits that can be modified
12
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
13
function vixConfirm(text, parms){
14
     var defaults = {
15
        resizable: true,
16
        height: 'auto',
17
        width : 'auto',
18
        modal: true,
19
        position: { my: "top", at: "top+100", of: window },
20
        title: "Confirm",
21
        icon: "images/i_warning.gif",
22
        url : null,
23
        ok : null,
24
        post : null,
25
        button : "Confirm",
5245 dpurdie 26
        progress : "#ProgressBar"
5190 dpurdie 27
     };
28
     $.extend( defaults, parms);
29
 
30
     defaults.open = function() {
31
        $(this).siblings('.ui-dialog-buttonpane').find('button:eq(1)').focus(); 
32
        var markup = '<img src="'+defaults.icon+'" style="float:left; margin:0 7px 20px 0;">' + text;
33
        $(this).html(markup);
34
     };
35
 
36
    defaults.close = function() {
37
        $(this).remove();
38
    };
39
 
40
    defaults.buttons = [
41
        {
42
        text : defaults.button,
43
        click : function (){
44
                if (defaults.ok != null ){
45
                    defaults.ok(defaults);
46
                }
47
                if ( defaults.progress != null) {
48
                    $(defaults.progress).show().css("visibility", "visible");    
49
                }
50
                if (defaults.url != null ) {
51
                    window.location.href = defaults.url;
52
                }
53
                if (defaults.post != null ) {
54
                    $('form[name="'+defaults.post+'"]').submit();    
55
                }
56
                $(this).dialog("close");
57
            }
58
        },
59
        {
60
        text : 'Cancel',
61
        click : function (){
62
            $(this).dialog("close");
63
            }
64
        }];
65
 
66
     var dd = $( "<div>Confirm</div>" ).dialog(defaults);
67
     // Once the dialog has been instantiated the autosize dimensions are known
5266 dpurdie 68
     // and the dialog can be correctly positioned
69
     if (defaults.position == 'center')
70
     {
71
         dd.dialog("widget").center();
5560 dpurdie 72
         //console.log("Center in Window");
5266 dpurdie 73
     }
74
     else
75
     {
76
         dd.dialog("widget").position(defaults.position);
5560 dpurdie 77
         //console.log("Original position");
5266 dpurdie 78
     }
79
 
5190 dpurdie 80
     // Return false incase this is used as an onClick
81
     return false;
82
}
83
 
84
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85
// Compatability function
86
//      Confirm Deletion of an item
87
//      Assumes that the item is within an 'anchor' and that an href can be located
88
//      Uses VixConfirm to do the heavy lifting
89
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
90
function vixConfirmDelete (txt)
91
{
92
    var href = window.event.currentTarget.href;
93
    vixConfirm('Are you sure you want to delete '+ txt +'?', {url : href})
94
    return false;
95
}
96
 
97
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
98
//  Similar to 'alert', but uses the jquery dialog mechnaism
99
//  Note: will return BEFORE the user makes a selection
100
//  Returns a Defereed object that will be rejected when the dialog is closed.
101
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
102
function vixAlert(text){
103
     var dbo = $.Deferred();
5207 dpurdie 104
     var dd = $( "<div>Alert</div>" ).dialog({
5190 dpurdie 105
        resizable: true,
106
        height: 'auto',
107
        width : 'auto',
108
        modal: true,
109
        title:'Alert',
5227 dpurdie 110
        position: { my: "top", at: "top+100", of: window },
5190 dpurdie 111
        open: function() {
112
            $(this).html('<img src="images/i_critical.gif" style="float:left; margin:0 7px 20px 0;">' + text);
113
        },
114
        close : function() {
115
            $(this).remove();
116
            dbo.reject();
117
        },
118
        buttons: {
119
            "Ok": function() {
120
                $(this).dialog("close");
121
            }
122
        }
123
     });
5207 dpurdie 124
     // Once the dialog has been instantiated the autosize dimensions are known
5266 dpurdie 125
     // and the dialog can be correctly positioned
5227 dpurdie 126
     // Note: Appears that we need to position it twice
127
     //       Once in the dialog creation, and once here
5207 dpurdie 128
     dd.dialog("widget").position({ my: "top", at: "top+100", of: window });
129
 
130
     return dbo;
5190 dpurdie 131
}
132
 
5266 dpurdie 133
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
134
//  jQuery extension function
135
//  Position an element inthe center of the visible window. Not the document and not the window(viewport).
136
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
137
jQuery.fn.center = function () {
5190 dpurdie 138
 
5266 dpurdie 139
    //  Support many browsers
140
    var w = window.innerWidth  || document.documentElement.clientWidth  || document.body.clientWidth;
141
    var h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
142
 
143
    this.css("position","fixed");
144
    this.css("top", Math.max(0,  ((h - $(this).outerHeight()) / 2) ) + "px");
145
    this.css("left", Math.max(0, ((w - $(this).outerWidth()) / 2) ) + "px");
146
    return this;
147
}
148
 
149
//--------- Support to open modal dialog in an iFrame
5590 dpurdie 150
//  Example: <a class="vixIframeDialog" href="aaa.asp" title="Some Title">Link Text</a>
5266 dpurdie 151
//
152
var vixIframe = {};
153
$(document).ready(function () {
5560 dpurdie 154
    $('.vixIframeDialog').on('click', function(e){
5590 dpurdie 155
		if (!vixIframe.parent) {
156
			e.preventDefault();
157
			vixIframe.parent = this;
158
			vixIframe.pagetitle = $(this).attr("title");
159
			if (! vixIframe.pagetitle) {
160
				vixIframe.pagetitle = $(this).text();
161
			}
162
			vixIframe.url = $(this).attr("href");
163
			vixIframeDialogCommon();
164
		}
5560 dpurdie 165
	});
5266 dpurdie 166
 
167
    //
168
    // Prevent (at least control) the user from navigating within the iframe
169
    // If this invocation is within an iFrame, then close the iFrame if
170
    // the user attempt to navigate away from the iFrame.
171
    //      This means that the iFrame cannot replace itself
172
    // 
173
    if (typeof parent.vixIframe.pagetitle !== 'undefined')
174
    {
5560 dpurdie 175
        //console.log("DocumentReady within iframe");
5266 dpurdie 176
        window.onunload = function(){
5560 dpurdie 177
            //console.log("Unloading within iframe");
5266 dpurdie 178
        }
179
    }
180
 
181
});
182
 
5560 dpurdie 183
//
184
//	Callable function to instantiate an Iframe Dialog
5590 dpurdie 185
//  Used in a replacement for MM_openBrWindow called MM_openVixIFrame
5560 dpurdie 186
// 	Parameters:
187
// 		pthis	- The parent's context
5590 dpurdie 188
//		url		- URL of the windoe content
189
//  	winName	- Title of the new Window
190
 
191
function vixIframeDialog2(pthis, url, winName)
192
{
5560 dpurdie 193
	vixIframe.parent = pthis;
5590 dpurdie 194
	vixIframe.pagetitle = winName;
195
	vixIframe.url = url;
196
	vixIframeDialogCommon();
197
}
198
 
199
function vixIframeDialogCommon()
200
{
201
	var iframe = $('<iframe onload="IframeLoaded(this);" id="iframe" style="border:0px; overflow: scroll;" src="' + vixIframe.url + '" width="100%" height="100%" ></iframe>');
5560 dpurdie 202
	var $dialog = $('<div></div>').html(iframe);
203
	var $dialog2 = $dialog.dialog({
204
		autoOpen: true,
205
		modal: true,
5590 dpurdie 206
		height : 'auto,', 
207
		width : 'auto',
208
		resizable: false,
5560 dpurdie 209
		position : { my:'top', at: 'top+100', of : window },
210
		dialogClass: "rounded_box",
211
		title: 'Loading - ' + vixIframe.pagetitle,
212
		close: function(event, ui){
213
			//console.log('closing dialog');
214
			$(this).dialog("destroy");
215
			vixIframe = {};
216
			window.onbeforeunload = null;
217
			window.onunload = null;
218
			},
5590 dpurdie 219
		// Prevent Chrome from adding scrollbars when dragged
220
		dragStop: function( event, ui ){
221
			vixIframe.IFrame.parentElement.style.overflow = "";
222
			},
223
		dragStart: function( event, ui ){
224
			vixIframe.IFrame.parentElement.style.overflow = "hidden";
225
			}
5560 dpurdie 226
	});
227
	vixIframe.Dialog = $dialog;
5590 dpurdie 228
	vixIframe.DialogProps = $dialog2;
5560 dpurdie 229
	vixIframe.DialogWidget = $($dialog2).dialog('widget');
5597 dpurdie 230
 
5560 dpurdie 231
	return false;
232
}
5590 dpurdie 233
//
234
//	Called when the iframe is loaded or reloaded
235
//
236
function IframeLoaded(iframe) {
237
	// Save to resize iframe
238
	vixIframe.IFrame = iframe;
5560 dpurdie 239
 
5590 dpurdie 240
	// Reset the title
241
	vixIframe.Dialog.dialog('option','title', vixIframe.pagetitle);
5266 dpurdie 242
 
5590 dpurdie 243
	// Resize the frame
244
	resizeIframe();
5266 dpurdie 245
};
5590 dpurdie 246
//
247
//	This function can be called from within the iframe to have it resized
248
//	Used if the iframe is too dynamic and extends itself from time to time
249
//
250
function resizeIframe()
251
{
252
    if (vixIframe.IFrame != null) {
253
		iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
254
		$(vixIframe.Dialog).height(iframe.height);
255
		//console.log ("Resize Iframe:",iframe.height );
5266 dpurdie 256
 
5590 dpurdie 257
		iframe.width = iframe.contentWindow.document.body.scrollWidth + "px";
258
		$(vixIframe.Dialog).width(iframe.width);
259
		//console.log ("Resize Iframe:",iframe.width );
260
 
261
		// Reposition the dialog
262
		$(vixIframe.DialogWidget).position($(vixIframe.DialogProps).dialog("option").position);
263
	}
264
}
265
//
266
//	This function can be called from with the iframe to close the Iframe
267
//	Often wired up to the cancel button
268
function closeIFrame()
5266 dpurdie 269
{
270
    if (vixIframe.Dialog != null) {
5590 dpurdie 271
        //console.log('closing iframe');
5266 dpurdie 272
        vixIframe.Dialog.dialog('close');
273
        vixIframe = {};
274
    }
275
}
276
 
277
 
278