Subversion Repositories DevTools

Rev

Rev 6610 | Rev 6625 | 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",
6577 dpurdie 27
        cancel : true,
28
        timeout : null,
29
        dlg : null
5190 dpurdie 30
     };
31
     $.extend( defaults, parms);
32
 
33
     defaults.open = function() {
34
        $(this).siblings('.ui-dialog-buttonpane').find('button:eq(1)').focus(); 
6577 dpurdie 35
        var markup = "";
36
        if (defaults.icon != null ) {
37
            markup += '<img src="'+ defaults.icon+ '" style="float:left; margin:0 7px 20px 0;">';
38
            }
39
        markup += text;
5190 dpurdie 40
        $(this).html(markup);
6577 dpurdie 41
         if ( defaults.timeout != null ) {
42
             setTimeout(function(){
43
                 defaults.dlg.dialog("close");
44
                }, defaults.timeout);
45
         }
5190 dpurdie 46
     };
47
 
48
    defaults.close = function() {
49
        $(this).remove();
50
    };
51
 
6577 dpurdie 52
    defaults.buttons = [];
53
    if ( defaults.button != null ) {
54
        defaults.buttons.push({
55
            text : defaults.button,
56
            click : function (){
57
                    if (defaults.ok != null ){
58
                        defaults.ok(defaults);
59
                    }
60
                    if ( defaults.progress != null) {
61
                        $(defaults.progress).show().css("visibility", "visible");    
62
                    }
63
                    if (defaults.url != null ) {
64
                        window.location.href = defaults.url;
65
                    }
66
                    if (defaults.post != null ) {
67
                        $('form[name="'+defaults.post+'"]').submit();    
68
                    }
69
                    $(this).dialog("close");
5190 dpurdie 70
                }
6577 dpurdie 71
        });
72
    }
73
 
74
    if(typeof(defaults.cancel) == 'boolean' && defaults.cancel) {
75
        defaults.buttons.push({
76
            text : 'Cancel',
77
            click : function (){
78
                $(this).dialog("close");
5190 dpurdie 79
                }
6577 dpurdie 80
        });
81
    }
5190 dpurdie 82
 
83
     var dd = $( "<div>Confirm</div>" ).dialog(defaults);
6577 dpurdie 84
     defaults.dlg = dd;
5190 dpurdie 85
     // Once the dialog has been instantiated the autosize dimensions are known
5266 dpurdie 86
     // and the dialog can be correctly positioned
87
     if (defaults.position == 'center')
88
     {
89
         dd.dialog("widget").center();
5560 dpurdie 90
         //console.log("Center in Window");
5266 dpurdie 91
     }
92
     else
93
     {
94
         dd.dialog("widget").position(defaults.position);
5560 dpurdie 95
         //console.log("Original position");
5266 dpurdie 96
     }
97
 
5190 dpurdie 98
     // Return false incase this is used as an onClick
99
     return false;
100
}
101
 
102
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
103
// Compatability function
104
//      Confirm Deletion of an item
105
//      Assumes that the item is within an 'anchor' and that an href can be located
106
//      Uses VixConfirm to do the heavy lifting
107
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
108
function vixConfirmDelete (txt)
109
{
110
    var href = window.event.currentTarget.href;
111
    vixConfirm('Are you sure you want to delete '+ txt +'?', {url : href})
112
    return false;
113
}
114
 
115
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
116
//  Similar to 'alert', but uses the jquery dialog mechnaism
117
//  Note: will return BEFORE the user makes a selection
118
//  Returns a Defereed object that will be rejected when the dialog is closed.
119
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
120
function vixAlert(text){
121
     var dbo = $.Deferred();
5207 dpurdie 122
     var dd = $( "<div>Alert</div>" ).dialog({
5190 dpurdie 123
        resizable: true,
124
        height: 'auto',
125
        width : 'auto',
126
        modal: true,
127
        title:'Alert',
5227 dpurdie 128
        position: { my: "top", at: "top+100", of: window },
5190 dpurdie 129
        open: function() {
130
            $(this).html('<img src="images/i_critical.gif" style="float:left; margin:0 7px 20px 0;">' + text);
131
        },
132
        close : function() {
133
            $(this).remove();
134
            dbo.reject();
135
        },
136
        buttons: {
137
            "Ok": function() {
138
                $(this).dialog("close");
139
            }
140
        }
141
     });
5207 dpurdie 142
     // Once the dialog has been instantiated the autosize dimensions are known
5266 dpurdie 143
     // and the dialog can be correctly positioned
5227 dpurdie 144
     // Note: Appears that we need to position it twice
145
     //       Once in the dialog creation, and once here
5207 dpurdie 146
     dd.dialog("widget").position({ my: "top", at: "top+100", of: window });
147
 
148
     return dbo;
5190 dpurdie 149
}
150
 
5266 dpurdie 151
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
152
//  jQuery extension function
153
//  Position an element inthe center of the visible window. Not the document and not the window(viewport).
154
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
155
jQuery.fn.center = function () {
5190 dpurdie 156
 
5266 dpurdie 157
    //  Support many browsers
158
    var w = window.innerWidth  || document.documentElement.clientWidth  || document.body.clientWidth;
159
    var h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
160
 
161
    this.css("position","fixed");
162
    this.css("top", Math.max(0,  ((h - $(this).outerHeight()) / 2) ) + "px");
163
    this.css("left", Math.max(0, ((w - $(this).outerWidth()) / 2) ) + "px");
164
    return this;
165
}
166
 
167
//--------- Support to open modal dialog in an iFrame
5590 dpurdie 168
//  Example: <a class="vixIframeDialog" href="aaa.asp" title="Some Title">Link Text</a>
5266 dpurdie 169
//
170
var vixIframe = {};
171
$(document).ready(function () {
5560 dpurdie 172
    $('.vixIframeDialog').on('click', function(e){
5590 dpurdie 173
		if (!vixIframe.parent) {
174
			e.preventDefault();
175
			vixIframe.parent = this;
176
			vixIframe.pagetitle = $(this).attr("title");
177
			if (! vixIframe.pagetitle) {
178
				vixIframe.pagetitle = $(this).text();
179
			}
180
			vixIframe.url = $(this).attr("href");
181
			vixIframeDialogCommon();
182
		}
5560 dpurdie 183
	});
5266 dpurdie 184
 
185
    //
186
    // Prevent (at least control) the user from navigating within the iframe
187
    // If this invocation is within an iFrame, then close the iFrame if
188
    // the user attempt to navigate away from the iFrame.
189
    //      This means that the iFrame cannot replace itself
190
    // 
191
    if (typeof parent.vixIframe.pagetitle !== 'undefined')
192
    {
5560 dpurdie 193
        //console.log("DocumentReady within iframe");
5266 dpurdie 194
        window.onunload = function(){
5560 dpurdie 195
            //console.log("Unloading within iframe");
5266 dpurdie 196
        }
197
    }
198
 
199
});
200
 
5560 dpurdie 201
//
202
//	Callable function to instantiate an Iframe Dialog
5590 dpurdie 203
//  Used in a replacement for MM_openBrWindow called MM_openVixIFrame
5560 dpurdie 204
// 	Parameters:
205
// 		pthis	- The parent's context
5590 dpurdie 206
//		url		- URL of the windoe content
207
//  	winName	- Title of the new Window
208
 
209
function vixIframeDialog2(pthis, url, winName)
210
{
5560 dpurdie 211
	vixIframe.parent = pthis;
5590 dpurdie 212
	vixIframe.pagetitle = winName;
213
	vixIframe.url = url;
214
	vixIframeDialogCommon();
215
}
216
 
217
function vixIframeDialogCommon()
218
{
219
	var iframe = $('<iframe onload="IframeLoaded(this);" id="iframe" style="border:0px; overflow: scroll;" src="' + vixIframe.url + '" width="100%" height="100%" ></iframe>');
5560 dpurdie 220
	var $dialog = $('<div></div>').html(iframe);
221
	var $dialog2 = $dialog.dialog({
222
		autoOpen: true,
223
		modal: true,
5590 dpurdie 224
		height : 'auto,', 
225
		width : 'auto',
226
		resizable: false,
5560 dpurdie 227
		position : { my:'top', at: 'top+100', of : window },
228
		dialogClass: "rounded_box",
229
		title: 'Loading - ' + vixIframe.pagetitle,
230
		close: function(event, ui){
231
			//console.log('closing dialog');
232
			$(this).dialog("destroy");
233
			vixIframe = {};
234
			window.onbeforeunload = null;
235
			window.onunload = null;
236
			},
5590 dpurdie 237
		// Prevent Chrome from adding scrollbars when dragged
238
		dragStop: function( event, ui ){
239
			vixIframe.IFrame.parentElement.style.overflow = "";
240
			},
241
		dragStart: function( event, ui ){
242
			vixIframe.IFrame.parentElement.style.overflow = "hidden";
243
			}
5560 dpurdie 244
	});
245
	vixIframe.Dialog = $dialog;
5590 dpurdie 246
	vixIframe.DialogProps = $dialog2;
5560 dpurdie 247
	vixIframe.DialogWidget = $($dialog2).dialog('widget');
5597 dpurdie 248
 
5560 dpurdie 249
	return false;
250
}
5590 dpurdie 251
//
252
//	Called when the iframe is loaded or reloaded
253
//
254
function IframeLoaded(iframe) {
255
	// Save to resize iframe
256
	vixIframe.IFrame = iframe;
5560 dpurdie 257
 
5590 dpurdie 258
	// Reset the title
259
	vixIframe.Dialog.dialog('option','title', vixIframe.pagetitle);
5266 dpurdie 260
 
5590 dpurdie 261
	// Resize the frame
262
	resizeIframe();
5266 dpurdie 263
};
5590 dpurdie 264
//
265
//	This function can be called from within the iframe to have it resized
266
//	Used if the iframe is too dynamic and extends itself from time to time
267
//
268
function resizeIframe()
269
{
270
    if (vixIframe.IFrame != null) {
271
		iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
272
		$(vixIframe.Dialog).height(iframe.height);
273
		//console.log ("Resize Iframe:",iframe.height );
5266 dpurdie 274
 
5590 dpurdie 275
		iframe.width = iframe.contentWindow.document.body.scrollWidth + "px";
276
		$(vixIframe.Dialog).width(iframe.width);
277
		//console.log ("Resize Iframe:",iframe.width );
278
 
279
		// Reposition the dialog
280
		$(vixIframe.DialogWidget).position($(vixIframe.DialogProps).dialog("option").position);
281
	}
282
}
283
//
284
//	This function can be called from with the iframe to close the Iframe
285
//	Often wired up to the cancel button
286
function closeIFrame()
5266 dpurdie 287
{
288
    if (vixIframe.Dialog != null) {
5590 dpurdie 289
        //console.log('closing iframe');
5266 dpurdie 290
        vixIframe.Dialog.dialog('close');
291
        vixIframe = {};
292
    }
293
}
294
 
6427 dpurdie 295
//
296
//  Add copy to clipboard icon to every element with a class of 'clip'
297
//
298
$( document ).ready(function() {
299
    var myClipHandler = function (event)
300
    {
301
        // Get element to clip
302
        var el = $(this).closest('.clip').eq(0);
5266 dpurdie 303
 
6427 dpurdie 304
        // Get the text and clean it up
305
        var text = $.trim(el.text());
306
            text = text.replace(/\s+/g, ' '); 
5266 dpurdie 307
 
6427 dpurdie 308
        // Copy to clipboard
309
        var $temp = $("<input>");
310
        $("body").append($temp);
311
        $temp.val(text).select();
312
        document.execCommand("copy");
313
        $temp.remove();
314
 
315
        // Highlight (the text that has been selected
316
        //  Appears to be no nice way to do this :(
317
        var doc = document, range, selection;    
318
        if (window.getSelection) {
319
            selection = window.getSelection();        
320
            range = document.createRange();
321
            range.selectNodeContents(el[0]);
322
            selection.removeAllRanges();
323
            selection.addRange(range);
324
            setTimeout(function(){selection.removeAllRanges();},500);
325
        } else { 
326
            range = document.body.createTextRange();
327
            range.moveToElementText(el[0]);
328
            range.select();
329
            setTimeout(function(){document.selection.empty();},500);
330
        }
331
    }
332
 
333
    $('.clip').append(
334
        $('<img />')
335
            .attr({
336
                title : "Copy to clipboard",
337
                src : "images/CopyToClipboard.ico",
338
                height : "12px",
339
                width : "12px",
340
                hspace : "0px",
341
                align : "absmiddle",
342
                border : "0"
343
                })
344
            .on("click", myClipHandler)
345
        )
346
        .on("dblclick", myClipHandler);
347
 
348
});
349
 
6592 dpurdie 350
// Add a clipThis handler to each element with a clipThis class
6610 dpurdie 351
//      Will copy the text of the element to the clipboard
352
//      Add dynamically so that it will be invoked on dynamically created elements
6592 dpurdie 353
$( document ).on('click', '.clipThis', function(event){
354
    var txt = $(this).eq(0).text();
355
    vixTextToClipBoard(txt, {note : "Copied to Clipboard", duration : 1000});
356
});
357
 
6610 dpurdie 358
// Copy data from element to clipboard
359
//      Elements have a class of clipData and an attribute of data-clip=xxx
360
//  Add dynamically so that it will be invoked on dynamically created elements
361
$( document ).on('click', '.clipData', function(event){
362
    var txt = $(this).data('clip');
363
    vixTextToClipBoard(txt, {note : "Copied to Clipboard", duration : 1000});
364
});
365
 
366
// Copy data from a named element to clipboard
367
// Supports multi-line data with <p> and <br> in it
368
//      Elements have a class of clipElement and an attribute of data-target=elementId
369
$( document ).on('click', '.clipElement', function(event){
370
    var ename = $(this).data('target');
371
    var html = $('#' + ename).eq(0).html();
372
    var breakToken = '_______break_______';
373
    var lineBreakedHtml = html.replace(/<br\s?\/?>/gi, breakToken).replace(/<p\.*?>(.*?)<\/p>/gi, breakToken + '$1' + breakToken);
374
    var txt = $('<div>').html(lineBreakedHtml).text().replace(new RegExp(breakToken, 'g'), '\r\n');
375
 
376
    vixTextToClipBoard(txt.trim(), {note : "Copied to Clipboard", duration : 1000});
377
});
378
 
379
 
380
// Invoke mailto on elements with a suitable class
381
//  Elements with class mailto. and a data item of email
382
// Add dynamically so that it will be invoked on newly created elements
383
$( document ).on('click', '.mailto', function(event){
384
    var email = $(this).data('email');
385
    var name =  $(this).data('name');
6623 dpurdie 386
    var uname =  $(this).data('uname');
6610 dpurdie 387
    if ( !name ) {
388
        name =  $(this).eq(0).text();
389
    }
390
 
391
    var menu = '<div class="rex_clm" >&nbsp;Select Operation</div>';
392
    if ( name ) {
393
        menu += '<div class="mmItem clipData" data-clip="' + name + '">Copy Name to Clipboard</div>';
394
    }
6623 dpurdie 395
    if ( uname ) {
396
        menu += '<div class="mmItem clipData" data-clip="' + uname + '">Copy Login Name to Clipboard</div>';
397
    }
6610 dpurdie 398
    menu += '<div class="mmItem clipData" data-clip="' + email + '">Copy Email Address to Clipboard</div>';
399
    menu += '<div onClick="window.open(\'mailto:' + email + '\', \'_blank\');" class="mmItem">Send Email</div>';
400
    showmenu(event,menu);
401
    event.stopImmediatePropagation();
402
    event.stopPropagation();
403
    return false;
404
});
405
 
6589 dpurdie 406
// Copy text to clipboard
407
function vixTextToClipBoard(txt, options){
408
    if ( txt == null ) {
409
        return;
410
    }
411
    var opts  = {
412
        note : "Data copied to Clipboard",
413
        title: "Notification",
414
        notify : true,
415
        timeout : 100,
416
        duration: 2000,
417
    }
418
    $.extend(opts, options);
6427 dpurdie 419
 
6589 dpurdie 420
    var $temp = $("<textarea>");
421
    $("body").append($temp);
422
    $temp.val(txt).select();
423
    document.execCommand("copy");
424
    $temp.remove();
6427 dpurdie 425
 
6589 dpurdie 426
    if ( opts.notify ) {
427
        vixConfirm(opts.note, {
428
            title: opts.title,
429
            icon : "images/i_info.png", 
430
            cancel: false, 
431
            button: null,
432
            timeout : opts.timeout,
6610 dpurdie 433
            not_on_firefox_position : {my: 'center', at: 'top', of: event},
6589 dpurdie 434
            modal : false,
435
            minHeight: 10, 
436
            hide: { effect: 'fade', duration: opts.duration }
437
            });
6427 dpurdie 438
 
6589 dpurdie 439
    }
440
}
441
 
442
 
443
 
444
 
445