Subversion Repositories DevTools

Rev

Rev 5603 | Rev 6577 | 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",
5598 dpurdie 26
        progress : "#ProgressBar",
5603 dpurdie 27
        cancel : true
5190 dpurdie 28
     };
29
     $.extend( defaults, parms);
30
 
31
     defaults.open = function() {
32
        $(this).siblings('.ui-dialog-buttonpane').find('button:eq(1)').focus(); 
33
        var markup = '<img src="'+defaults.icon+'" style="float:left; margin:0 7px 20px 0;">' + text;
34
        $(this).html(markup);
35
     };
36
 
37
    defaults.close = function() {
38
        $(this).remove();
39
    };
40
 
41
    defaults.buttons = [
42
        {
43
        text : defaults.button,
44
        click : function (){
45
                if (defaults.ok != null ){
46
                    defaults.ok(defaults);
47
                }
48
                if ( defaults.progress != null) {
49
                    $(defaults.progress).show().css("visibility", "visible");    
50
                }
51
                if (defaults.url != null ) {
52
                    window.location.href = defaults.url;
53
                }
54
                if (defaults.post != null ) {
55
                    $('form[name="'+defaults.post+'"]').submit();    
56
                }
57
                $(this).dialog("close");
58
            }
59
        }];
60
 
5598 dpurdie 61
		if(typeof(defaults.cancel) == 'boolean' && defaults.cancel)
62
		{
63
				defaults.buttons.push({
64
					text : 'Cancel',
65
					click : function (){
66
						$(this).dialog("close");
67
						}
68
				});
69
		}
70
 
5190 dpurdie 71
     var dd = $( "<div>Confirm</div>" ).dialog(defaults);
72
     // Once the dialog has been instantiated the autosize dimensions are known
5266 dpurdie 73
     // and the dialog can be correctly positioned
74
     if (defaults.position == 'center')
75
     {
76
         dd.dialog("widget").center();
5560 dpurdie 77
         //console.log("Center in Window");
5266 dpurdie 78
     }
79
     else
80
     {
81
         dd.dialog("widget").position(defaults.position);
5560 dpurdie 82
         //console.log("Original position");
5266 dpurdie 83
     }
84
 
5190 dpurdie 85
     // Return false incase this is used as an onClick
86
     return false;
87
}
88
 
89
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
90
// Compatability function
91
//      Confirm Deletion of an item
92
//      Assumes that the item is within an 'anchor' and that an href can be located
93
//      Uses VixConfirm to do the heavy lifting
94
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
95
function vixConfirmDelete (txt)
96
{
97
    var href = window.event.currentTarget.href;
98
    vixConfirm('Are you sure you want to delete '+ txt +'?', {url : href})
99
    return false;
100
}
101
 
102
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
103
//  Similar to 'alert', but uses the jquery dialog mechnaism
104
//  Note: will return BEFORE the user makes a selection
105
//  Returns a Defereed object that will be rejected when the dialog is closed.
106
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
107
function vixAlert(text){
108
     var dbo = $.Deferred();
5207 dpurdie 109
     var dd = $( "<div>Alert</div>" ).dialog({
5190 dpurdie 110
        resizable: true,
111
        height: 'auto',
112
        width : 'auto',
113
        modal: true,
114
        title:'Alert',
5227 dpurdie 115
        position: { my: "top", at: "top+100", of: window },
5190 dpurdie 116
        open: function() {
117
            $(this).html('<img src="images/i_critical.gif" style="float:left; margin:0 7px 20px 0;">' + text);
118
        },
119
        close : function() {
120
            $(this).remove();
121
            dbo.reject();
122
        },
123
        buttons: {
124
            "Ok": function() {
125
                $(this).dialog("close");
126
            }
127
        }
128
     });
5207 dpurdie 129
     // Once the dialog has been instantiated the autosize dimensions are known
5266 dpurdie 130
     // and the dialog can be correctly positioned
5227 dpurdie 131
     // Note: Appears that we need to position it twice
132
     //       Once in the dialog creation, and once here
5207 dpurdie 133
     dd.dialog("widget").position({ my: "top", at: "top+100", of: window });
134
 
135
     return dbo;
5190 dpurdie 136
}
137
 
5266 dpurdie 138
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
139
//  jQuery extension function
140
//  Position an element inthe center of the visible window. Not the document and not the window(viewport).
141
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
142
jQuery.fn.center = function () {
5190 dpurdie 143
 
5266 dpurdie 144
    //  Support many browsers
145
    var w = window.innerWidth  || document.documentElement.clientWidth  || document.body.clientWidth;
146
    var h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
147
 
148
    this.css("position","fixed");
149
    this.css("top", Math.max(0,  ((h - $(this).outerHeight()) / 2) ) + "px");
150
    this.css("left", Math.max(0, ((w - $(this).outerWidth()) / 2) ) + "px");
151
    return this;
152
}
153
 
154
//--------- Support to open modal dialog in an iFrame
5590 dpurdie 155
//  Example: <a class="vixIframeDialog" href="aaa.asp" title="Some Title">Link Text</a>
5266 dpurdie 156
//
157
var vixIframe = {};
158
$(document).ready(function () {
5560 dpurdie 159
    $('.vixIframeDialog').on('click', function(e){
5590 dpurdie 160
		if (!vixIframe.parent) {
161
			e.preventDefault();
162
			vixIframe.parent = this;
163
			vixIframe.pagetitle = $(this).attr("title");
164
			if (! vixIframe.pagetitle) {
165
				vixIframe.pagetitle = $(this).text();
166
			}
167
			vixIframe.url = $(this).attr("href");
168
			vixIframeDialogCommon();
169
		}
5560 dpurdie 170
	});
5266 dpurdie 171
 
172
    //
173
    // Prevent (at least control) the user from navigating within the iframe
174
    // If this invocation is within an iFrame, then close the iFrame if
175
    // the user attempt to navigate away from the iFrame.
176
    //      This means that the iFrame cannot replace itself
177
    // 
178
    if (typeof parent.vixIframe.pagetitle !== 'undefined')
179
    {
5560 dpurdie 180
        //console.log("DocumentReady within iframe");
5266 dpurdie 181
        window.onunload = function(){
5560 dpurdie 182
            //console.log("Unloading within iframe");
5266 dpurdie 183
        }
184
    }
185
 
186
});
187
 
5560 dpurdie 188
//
189
//	Callable function to instantiate an Iframe Dialog
5590 dpurdie 190
//  Used in a replacement for MM_openBrWindow called MM_openVixIFrame
5560 dpurdie 191
// 	Parameters:
192
// 		pthis	- The parent's context
5590 dpurdie 193
//		url		- URL of the windoe content
194
//  	winName	- Title of the new Window
195
 
196
function vixIframeDialog2(pthis, url, winName)
197
{
5560 dpurdie 198
	vixIframe.parent = pthis;
5590 dpurdie 199
	vixIframe.pagetitle = winName;
200
	vixIframe.url = url;
201
	vixIframeDialogCommon();
202
}
203
 
204
function vixIframeDialogCommon()
205
{
206
	var iframe = $('<iframe onload="IframeLoaded(this);" id="iframe" style="border:0px; overflow: scroll;" src="' + vixIframe.url + '" width="100%" height="100%" ></iframe>');
5560 dpurdie 207
	var $dialog = $('<div></div>').html(iframe);
208
	var $dialog2 = $dialog.dialog({
209
		autoOpen: true,
210
		modal: true,
5590 dpurdie 211
		height : 'auto,', 
212
		width : 'auto',
213
		resizable: false,
5560 dpurdie 214
		position : { my:'top', at: 'top+100', of : window },
215
		dialogClass: "rounded_box",
216
		title: 'Loading - ' + vixIframe.pagetitle,
217
		close: function(event, ui){
218
			//console.log('closing dialog');
219
			$(this).dialog("destroy");
220
			vixIframe = {};
221
			window.onbeforeunload = null;
222
			window.onunload = null;
223
			},
5590 dpurdie 224
		// Prevent Chrome from adding scrollbars when dragged
225
		dragStop: function( event, ui ){
226
			vixIframe.IFrame.parentElement.style.overflow = "";
227
			},
228
		dragStart: function( event, ui ){
229
			vixIframe.IFrame.parentElement.style.overflow = "hidden";
230
			}
5560 dpurdie 231
	});
232
	vixIframe.Dialog = $dialog;
5590 dpurdie 233
	vixIframe.DialogProps = $dialog2;
5560 dpurdie 234
	vixIframe.DialogWidget = $($dialog2).dialog('widget');
5597 dpurdie 235
 
5560 dpurdie 236
	return false;
237
}
5590 dpurdie 238
//
239
//	Called when the iframe is loaded or reloaded
240
//
241
function IframeLoaded(iframe) {
242
	// Save to resize iframe
243
	vixIframe.IFrame = iframe;
5560 dpurdie 244
 
5590 dpurdie 245
	// Reset the title
246
	vixIframe.Dialog.dialog('option','title', vixIframe.pagetitle);
5266 dpurdie 247
 
5590 dpurdie 248
	// Resize the frame
249
	resizeIframe();
5266 dpurdie 250
};
5590 dpurdie 251
//
252
//	This function can be called from within the iframe to have it resized
253
//	Used if the iframe is too dynamic and extends itself from time to time
254
//
255
function resizeIframe()
256
{
257
    if (vixIframe.IFrame != null) {
258
		iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
259
		$(vixIframe.Dialog).height(iframe.height);
260
		//console.log ("Resize Iframe:",iframe.height );
5266 dpurdie 261
 
5590 dpurdie 262
		iframe.width = iframe.contentWindow.document.body.scrollWidth + "px";
263
		$(vixIframe.Dialog).width(iframe.width);
264
		//console.log ("Resize Iframe:",iframe.width );
265
 
266
		// Reposition the dialog
267
		$(vixIframe.DialogWidget).position($(vixIframe.DialogProps).dialog("option").position);
268
	}
269
}
270
//
271
//	This function can be called from with the iframe to close the Iframe
272
//	Often wired up to the cancel button
273
function closeIFrame()
5266 dpurdie 274
{
275
    if (vixIframe.Dialog != null) {
5590 dpurdie 276
        //console.log('closing iframe');
5266 dpurdie 277
        vixIframe.Dialog.dialog('close');
278
        vixIframe = {};
279
    }
280
}
281
 
6427 dpurdie 282
//
283
//  Add copy to clipboard icon to every element with a class of 'clip'
284
//
285
$( document ).ready(function() {
286
    var myClipHandler = function (event)
287
    {
288
        // Get element to clip
289
        var el = $(this).closest('.clip').eq(0);
5266 dpurdie 290
 
6427 dpurdie 291
        // Get the text and clean it up
292
        var text = $.trim(el.text());
293
            text = text.replace(/\s+/g, ' '); 
5266 dpurdie 294
 
6427 dpurdie 295
        // Copy to clipboard
296
        var $temp = $("<input>");
297
        $("body").append($temp);
298
        $temp.val(text).select();
299
        document.execCommand("copy");
300
        $temp.remove();
301
 
302
        // Highlight (the text that has been selected
303
        //  Appears to be no nice way to do this :(
304
        var doc = document, range, selection;    
305
        if (window.getSelection) {
306
            selection = window.getSelection();        
307
            range = document.createRange();
308
            range.selectNodeContents(el[0]);
309
            selection.removeAllRanges();
310
            selection.addRange(range);
311
            setTimeout(function(){selection.removeAllRanges();},500);
312
        } else { 
313
            range = document.body.createTextRange();
314
            range.moveToElementText(el[0]);
315
            range.select();
316
            setTimeout(function(){document.selection.empty();},500);
317
        }
318
    }
319
 
320
    $('.clip').append(
321
        $('<img />')
322
            .attr({
323
                title : "Copy to clipboard",
324
                src : "images/CopyToClipboard.ico",
325
                height : "12px",
326
                width : "12px",
327
                hspace : "0px",
328
                align : "absmiddle",
329
                border : "0"
330
                })
331
            .on("click", myClipHandler)
332
        )
333
        .on("dblclick", myClipHandler);
334
 
335
});
336
 
337
 
338
 
339