| 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,
|
| 6697 |
dpurdie |
29 |
dlg : null,
|
|
|
30 |
deferred : null,
|
| 5190 |
dpurdie |
31 |
};
|
|
|
32 |
$.extend( defaults, parms);
|
|
|
33 |
|
|
|
34 |
defaults.open = function() {
|
|
|
35 |
$(this).siblings('.ui-dialog-buttonpane').find('button:eq(1)').focus();
|
| 6577 |
dpurdie |
36 |
var markup = "";
|
|
|
37 |
if (defaults.icon != null ) {
|
|
|
38 |
markup += '<img src="'+ defaults.icon+ '" style="float:left; margin:0 7px 20px 0;">';
|
|
|
39 |
}
|
|
|
40 |
markup += text;
|
| 5190 |
dpurdie |
41 |
$(this).html(markup);
|
| 6577 |
dpurdie |
42 |
if ( defaults.timeout != null ) {
|
|
|
43 |
setTimeout(function(){
|
|
|
44 |
defaults.dlg.dialog("close");
|
|
|
45 |
}, defaults.timeout);
|
|
|
46 |
}
|
| 5190 |
dpurdie |
47 |
};
|
|
|
48 |
|
|
|
49 |
defaults.close = function() {
|
|
|
50 |
$(this).remove();
|
|
|
51 |
};
|
|
|
52 |
|
| 6697 |
dpurdie |
53 |
if(typeof(defaults.deferred) == typeof(true)){
|
|
|
54 |
if ( defaults.deferred ) {
|
|
|
55 |
defaults.deferred = new $.Deferred();
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
| 6577 |
dpurdie |
59 |
defaults.buttons = [];
|
|
|
60 |
if ( defaults.button != null ) {
|
|
|
61 |
defaults.buttons.push({
|
|
|
62 |
text : defaults.button,
|
|
|
63 |
click : function (){
|
|
|
64 |
if (defaults.ok != null ){
|
|
|
65 |
defaults.ok(defaults);
|
|
|
66 |
}
|
|
|
67 |
if ( defaults.progress != null) {
|
|
|
68 |
$(defaults.progress).show().css("visibility", "visible");
|
|
|
69 |
}
|
|
|
70 |
if (defaults.url != null ) {
|
|
|
71 |
window.location.href = defaults.url;
|
|
|
72 |
}
|
|
|
73 |
if (defaults.post != null ) {
|
|
|
74 |
$('form[name="'+defaults.post+'"]').submit();
|
|
|
75 |
}
|
| 6697 |
dpurdie |
76 |
if ( defaults.deferred != null ) {
|
|
|
77 |
defaults.deferred.resolve();
|
|
|
78 |
}
|
| 6577 |
dpurdie |
79 |
$(this).dialog("close");
|
| 5190 |
dpurdie |
80 |
}
|
| 6577 |
dpurdie |
81 |
});
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
if(typeof(defaults.cancel) == 'boolean' && defaults.cancel) {
|
|
|
85 |
defaults.buttons.push({
|
|
|
86 |
text : 'Cancel',
|
|
|
87 |
click : function (){
|
|
|
88 |
$(this).dialog("close");
|
| 6697 |
dpurdie |
89 |
if ( defaults.deferred != null) {
|
|
|
90 |
defaults.deferred.reject();
|
|
|
91 |
}
|
| 5190 |
dpurdie |
92 |
}
|
| 6577 |
dpurdie |
93 |
});
|
|
|
94 |
}
|
| 5190 |
dpurdie |
95 |
|
|
|
96 |
var dd = $( "<div>Confirm</div>" ).dialog(defaults);
|
| 6577 |
dpurdie |
97 |
defaults.dlg = dd;
|
| 5190 |
dpurdie |
98 |
// Once the dialog has been instantiated the autosize dimensions are known
|
| 5266 |
dpurdie |
99 |
// and the dialog can be correctly positioned
|
|
|
100 |
if (defaults.position == 'center')
|
|
|
101 |
{
|
|
|
102 |
dd.dialog("widget").center();
|
| 5560 |
dpurdie |
103 |
//console.log("Center in Window");
|
| 5266 |
dpurdie |
104 |
}
|
|
|
105 |
else
|
|
|
106 |
{
|
|
|
107 |
dd.dialog("widget").position(defaults.position);
|
| 5560 |
dpurdie |
108 |
//console.log("Original position");
|
| 5266 |
dpurdie |
109 |
}
|
| 6697 |
dpurdie |
110 |
|
|
|
111 |
// If using deferred objects
|
|
|
112 |
if ( defaults.deferred ) {
|
|
|
113 |
return defaults.deferred.promise();
|
|
|
114 |
}
|
| 5266 |
dpurdie |
115 |
|
| 5190 |
dpurdie |
116 |
// Return false incase this is used as an onClick
|
|
|
117 |
return false;
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
121 |
// Compatability function
|
|
|
122 |
// Confirm Deletion of an item
|
| 6873 |
dpurdie |
123 |
// Assumes that the item is within an
|
|
|
124 |
// - 'anchor' and that an href can be located
|
|
|
125 |
// - other and that a 'data-href' will specify the 'url'
|
|
|
126 |
//
|
| 5190 |
dpurdie |
127 |
// Uses VixConfirm to do the heavy lifting
|
|
|
128 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
129 |
function vixConfirmDelete (txt)
|
|
|
130 |
{
|
|
|
131 |
var href = window.event.currentTarget.href;
|
| 6873 |
dpurdie |
132 |
if ( !href ) {
|
|
|
133 |
href = $(event.currentTarget).data('href');
|
|
|
134 |
}
|
|
|
135 |
vixConfirm('Are you sure you want to delete ' + txt + '?', { url: href })
|
| 5190 |
dpurdie |
136 |
return false;
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
140 |
// Similar to 'alert', but uses the jquery dialog mechnaism
|
|
|
141 |
// Note: will return BEFORE the user makes a selection
|
|
|
142 |
// Returns a Defereed object that will be rejected when the dialog is closed.
|
|
|
143 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
144 |
function vixAlert(text){
|
|
|
145 |
var dbo = $.Deferred();
|
| 5207 |
dpurdie |
146 |
var dd = $( "<div>Alert</div>" ).dialog({
|
| 5190 |
dpurdie |
147 |
resizable: true,
|
|
|
148 |
height: 'auto',
|
|
|
149 |
width : 'auto',
|
|
|
150 |
modal: true,
|
|
|
151 |
title:'Alert',
|
| 5227 |
dpurdie |
152 |
position: { my: "top", at: "top+100", of: window },
|
| 5190 |
dpurdie |
153 |
open: function() {
|
|
|
154 |
$(this).html('<img src="images/i_critical.gif" style="float:left; margin:0 7px 20px 0;">' + text);
|
|
|
155 |
},
|
|
|
156 |
close : function() {
|
|
|
157 |
$(this).remove();
|
|
|
158 |
dbo.reject();
|
|
|
159 |
},
|
|
|
160 |
buttons: {
|
|
|
161 |
"Ok": function() {
|
|
|
162 |
$(this).dialog("close");
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
});
|
| 5207 |
dpurdie |
166 |
// Once the dialog has been instantiated the autosize dimensions are known
|
| 5266 |
dpurdie |
167 |
// and the dialog can be correctly positioned
|
| 5227 |
dpurdie |
168 |
// Note: Appears that we need to position it twice
|
|
|
169 |
// Once in the dialog creation, and once here
|
| 5207 |
dpurdie |
170 |
dd.dialog("widget").position({ my: "top", at: "top+100", of: window });
|
|
|
171 |
|
|
|
172 |
return dbo;
|
| 5190 |
dpurdie |
173 |
}
|
|
|
174 |
|
| 5266 |
dpurdie |
175 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
176 |
// jQuery extension function
|
|
|
177 |
// Position an element inthe center of the visible window. Not the document and not the window(viewport).
|
|
|
178 |
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
179 |
jQuery.fn.center = function () {
|
| 5190 |
dpurdie |
180 |
|
| 5266 |
dpurdie |
181 |
// Support many browsers
|
|
|
182 |
var w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
|
|
183 |
var h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
|
|
|
184 |
|
|
|
185 |
this.css("position","fixed");
|
|
|
186 |
this.css("top", Math.max(0, ((h - $(this).outerHeight()) / 2) ) + "px");
|
|
|
187 |
this.css("left", Math.max(0, ((w - $(this).outerWidth()) / 2) ) + "px");
|
|
|
188 |
return this;
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
//--------- Support to open modal dialog in an iFrame
|
| 5590 |
dpurdie |
192 |
// Example: <a class="vixIframeDialog" href="aaa.asp" title="Some Title">Link Text</a>
|
| 5266 |
dpurdie |
193 |
//
|
| 7003 |
dpurdie |
194 |
var vixIframe;
|
|
|
195 |
if (typeof vixIframe === 'undefined') {
|
|
|
196 |
vixIframe = {};
|
|
|
197 |
}
|
| 7261 |
dpurdie |
198 |
|
|
|
199 |
//--------- vixIframeDialog class
|
|
|
200 |
// Allow for dynamic creation of elements with this class
|
|
|
201 |
$( document ).on('click', '.vixIframeDialog', function(e){
|
|
|
202 |
if (!vixIframe.parent) {
|
|
|
203 |
e.preventDefault();
|
|
|
204 |
vixIframe.parent = this;
|
|
|
205 |
vixIframe.pagetitle = $(this).attr("title");
|
|
|
206 |
if (! vixIframe.pagetitle) {
|
|
|
207 |
vixIframe.pagetitle = $(this).text();
|
|
|
208 |
}
|
|
|
209 |
vixIframe.url = $(this).attr("href");
|
|
|
210 |
vixIframeDialogCommon();
|
|
|
211 |
}
|
|
|
212 |
})
|
|
|
213 |
|
| 5266 |
dpurdie |
214 |
$(document).ready(function () {
|
| 7003 |
dpurdie |
215 |
|
| 5266 |
dpurdie |
216 |
// Prevent (at least control) the user from navigating within the iframe
|
|
|
217 |
// If this invocation is within an iFrame, then close the iFrame if
|
|
|
218 |
// the user attempt to navigate away from the iFrame.
|
|
|
219 |
// This means that the iFrame cannot replace itself
|
|
|
220 |
//
|
|
|
221 |
if (typeof parent.vixIframe.pagetitle !== 'undefined')
|
|
|
222 |
{
|
| 5560 |
dpurdie |
223 |
//console.log("DocumentReady within iframe");
|
| 5266 |
dpurdie |
224 |
window.onunload = function(){
|
| 5560 |
dpurdie |
225 |
//console.log("Unloading within iframe");
|
| 5266 |
dpurdie |
226 |
}
|
|
|
227 |
}
|
|
|
228 |
});
|
|
|
229 |
|
| 5560 |
dpurdie |
230 |
//
|
|
|
231 |
// Callable function to instantiate an Iframe Dialog
|
| 5590 |
dpurdie |
232 |
// Used in a replacement for MM_openBrWindow called MM_openVixIFrame
|
| 5560 |
dpurdie |
233 |
// Parameters:
|
|
|
234 |
// pthis - The parent's context
|
| 6625 |
dpurdie |
235 |
// url - URL of the window content
|
| 5590 |
dpurdie |
236 |
// winName - Title of the new Window
|
|
|
237 |
|
|
|
238 |
function vixIframeDialog2(pthis, url, winName)
|
|
|
239 |
{
|
| 5560 |
dpurdie |
240 |
vixIframe.parent = pthis;
|
| 5590 |
dpurdie |
241 |
vixIframe.pagetitle = winName;
|
|
|
242 |
vixIframe.url = url;
|
|
|
243 |
vixIframeDialogCommon();
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
function vixIframeDialogCommon()
|
|
|
247 |
{
|
| 7003 |
dpurdie |
248 |
var iframe = $('<iframe onload="IframeLoaded(this);" id="iframe" style="border:0px; overflow: scroll;" src="' + vixIframe.url + '" height="50px" width="100%"" ></iframe>');
|
| 5560 |
dpurdie |
249 |
var $dialog = $('<div></div>').html(iframe);
|
|
|
250 |
var $dialog2 = $dialog.dialog({
|
|
|
251 |
autoOpen: true,
|
|
|
252 |
modal: true,
|
| 7003 |
dpurdie |
253 |
height : 'auto',
|
| 5590 |
dpurdie |
254 |
width : 'auto',
|
|
|
255 |
resizable: false,
|
| 5560 |
dpurdie |
256 |
position : { my:'top', at: 'top+100', of : window },
|
|
|
257 |
dialogClass: "rounded_box",
|
|
|
258 |
title: 'Loading - ' + vixIframe.pagetitle,
|
|
|
259 |
close: function(event, ui){
|
|
|
260 |
//console.log('closing dialog');
|
|
|
261 |
$(this).dialog("destroy");
|
|
|
262 |
vixIframe = {};
|
|
|
263 |
window.onbeforeunload = null;
|
|
|
264 |
window.onunload = null;
|
|
|
265 |
},
|
| 5590 |
dpurdie |
266 |
// Prevent Chrome from adding scrollbars when dragged
|
|
|
267 |
dragStop: function( event, ui ){
|
|
|
268 |
vixIframe.IFrame.parentElement.style.overflow = "";
|
|
|
269 |
},
|
|
|
270 |
dragStart: function( event, ui ){
|
|
|
271 |
vixIframe.IFrame.parentElement.style.overflow = "hidden";
|
|
|
272 |
}
|
| 5560 |
dpurdie |
273 |
});
|
|
|
274 |
vixIframe.Dialog = $dialog;
|
| 5590 |
dpurdie |
275 |
vixIframe.DialogProps = $dialog2;
|
| 5560 |
dpurdie |
276 |
vixIframe.DialogWidget = $($dialog2).dialog('widget');
|
| 5597 |
dpurdie |
277 |
|
| 5560 |
dpurdie |
278 |
return false;
|
|
|
279 |
}
|
| 5590 |
dpurdie |
280 |
//
|
|
|
281 |
// Called when the iframe is loaded or reloaded
|
|
|
282 |
//
|
|
|
283 |
function IframeLoaded(iframe) {
|
|
|
284 |
// Save to resize iframe
|
|
|
285 |
vixIframe.IFrame = iframe;
|
| 5560 |
dpurdie |
286 |
|
| 5590 |
dpurdie |
287 |
// Reset the title
|
|
|
288 |
vixIframe.Dialog.dialog('option','title', vixIframe.pagetitle);
|
| 5266 |
dpurdie |
289 |
|
| 5590 |
dpurdie |
290 |
// Resize the frame
|
|
|
291 |
resizeIframe();
|
| 5266 |
dpurdie |
292 |
};
|
| 5590 |
dpurdie |
293 |
//
|
|
|
294 |
// This function can be called from within the iframe to have it resized
|
|
|
295 |
// Used if the iframe is too dynamic and extends itself from time to time
|
|
|
296 |
//
|
|
|
297 |
function resizeIframe()
|
|
|
298 |
{
|
|
|
299 |
if (vixIframe.IFrame != null) {
|
| 7003 |
dpurdie |
300 |
var iframe = vixIframe.IFrame;
|
| 5590 |
dpurdie |
301 |
iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
|
|
|
302 |
$(vixIframe.Dialog).height(iframe.height);
|
|
|
303 |
//console.log ("Resize Iframe:",iframe.height );
|
| 5266 |
dpurdie |
304 |
|
| 5590 |
dpurdie |
305 |
iframe.width = iframe.contentWindow.document.body.scrollWidth + "px";
|
|
|
306 |
$(vixIframe.Dialog).width(iframe.width);
|
|
|
307 |
//console.log ("Resize Iframe:",iframe.width );
|
|
|
308 |
|
|
|
309 |
// Reposition the dialog
|
|
|
310 |
$(vixIframe.DialogWidget).position($(vixIframe.DialogProps).dialog("option").position);
|
|
|
311 |
}
|
|
|
312 |
}
|
|
|
313 |
//
|
|
|
314 |
// This function can be called from with the iframe to close the Iframe
|
|
|
315 |
// Often wired up to the cancel button
|
|
|
316 |
function closeIFrame()
|
| 5266 |
dpurdie |
317 |
{
|
|
|
318 |
if (vixIframe.Dialog != null) {
|
| 5590 |
dpurdie |
319 |
//console.log('closing iframe');
|
| 5266 |
dpurdie |
320 |
vixIframe.Dialog.dialog('close');
|
|
|
321 |
vixIframe = {};
|
|
|
322 |
}
|
|
|
323 |
}
|
|
|
324 |
|
| 7003 |
dpurdie |
325 |
// Load a dialog into a dialog element
|
|
|
326 |
// Like iFrame, but without the iFrame
|
| 7022 |
dpurdie |
327 |
// Useful options:
|
|
|
328 |
// title - Window Title
|
|
|
329 |
// onLoad - Function name to call after load
|
|
|
330 |
// class - Optional class to add to the dialog
|
| 6427 |
dpurdie |
331 |
//
|
| 7022 |
dpurdie |
332 |
function vixDialog( theURL, usrOptions ) {
|
|
|
333 |
|
| 7240 |
dpurdie |
334 |
$("body").addClass("cursor-wait");
|
| 7022 |
dpurdie |
335 |
|
| 7240 |
dpurdie |
336 |
var options = $.extend({title : 'Dialog ', width : 300}, usrOptions,);
|
|
|
337 |
|
| 7003 |
dpurdie |
338 |
vixIframe.parent = this;
|
| 7022 |
dpurdie |
339 |
vixIframe.pagetitle = options.title;
|
| 7003 |
dpurdie |
340 |
vixIframe.url = theURL;
|
|
|
341 |
|
|
|
342 |
var $dialog = $('<div></div>');
|
|
|
343 |
$(document.body).append($dialog);
|
|
|
344 |
$dialog.load( theURL, function(){
|
|
|
345 |
var $dialog2 = $dialog.dialog({
|
|
|
346 |
autoOpen: true,
|
|
|
347 |
modal: true,
|
|
|
348 |
height : 'auto',
|
| 7240 |
dpurdie |
349 |
width : options.width,
|
| 7003 |
dpurdie |
350 |
resizable: true,
|
|
|
351 |
position : { my:'top', at: 'top+100', of : window },
|
| 7022 |
dpurdie |
352 |
dialogClass: options.class,
|
|
|
353 |
minHeight: 10,
|
| 7003 |
dpurdie |
354 |
title: 'Loading - ' + vixIframe.pagetitle,
|
|
|
355 |
close: function(event, ui){
|
|
|
356 |
//console.log('closing dialog');
|
|
|
357 |
$(this).dialog("destroy");
|
|
|
358 |
vixIframe = {};
|
|
|
359 |
$(this).remove();
|
|
|
360 |
window.onbeforeunload = null;
|
|
|
361 |
window.onunload = null;
|
|
|
362 |
},
|
|
|
363 |
dragStop: function( event, ui ){
|
| 7022 |
dpurdie |
364 |
// Dragging adds a height which kill autosizing
|
|
|
365 |
vixIframe.Dialog.closest('.ui-dialog').height('auto');
|
| 7003 |
dpurdie |
366 |
},
|
|
|
367 |
});
|
|
|
368 |
vixIframe.Dialog = $dialog;
|
|
|
369 |
vixIframe.DialogProps = $dialog2;
|
|
|
370 |
|
|
|
371 |
// Save to resize iframe
|
|
|
372 |
vixIframe.IFrame = $dialog;
|
|
|
373 |
|
|
|
374 |
// Reset the title
|
|
|
375 |
vixIframe.Dialog.dialog('option','title', vixIframe.pagetitle);
|
|
|
376 |
|
|
|
377 |
// Run init code for the frame
|
| 7022 |
dpurdie |
378 |
// Have a possible function name
|
|
|
379 |
if ( options.onLoad ) {
|
|
|
380 |
try {
|
|
|
381 |
eval (options.onLoad + '();');
|
|
|
382 |
}
|
|
|
383 |
catch (e) {
|
|
|
384 |
console.log ("vixDialog failed to run the onLoad script:" + options.onLoad );
|
|
|
385 |
}
|
|
|
386 |
}
|
| 7243 |
dpurdie |
387 |
$("body").removeClass("cursor-wait");
|
| 7003 |
dpurdie |
388 |
});
|
|
|
389 |
}
|
|
|
390 |
|
|
|
391 |
//
|
| 6626 |
dpurdie |
392 |
// Copy the HTML from an element into the clipboard
|
|
|
393 |
// Highlight the element clipped
|
|
|
394 |
//
|
|
|
395 |
function vixEl2Clip( el ) {
|
|
|
396 |
// Get the text and clean it up
|
|
|
397 |
var html = $.trim(el.html());
|
|
|
398 |
|
|
|
399 |
var breakToken = '_______break_______';
|
|
|
400 |
var lineBreakedHtml = html.replace(/<br\s?\/?>/gi, breakToken).replace(/<p\.*?>(.*?)<\/p>/gi, breakToken + '$1' + breakToken);
|
|
|
401 |
var text = $('<div>').html(lineBreakedHtml).text().replace(new RegExp(breakToken, 'g'), '\r\n');
|
|
|
402 |
text = $.trim(text);
|
|
|
403 |
|
|
|
404 |
// Copy to clipboard
|
|
|
405 |
var $temp = $("<textarea>");
|
|
|
406 |
$(el).append($temp);
|
|
|
407 |
$temp.val(text).select();
|
|
|
408 |
document.execCommand("copy");
|
|
|
409 |
$temp.remove();
|
|
|
410 |
|
|
|
411 |
|
|
|
412 |
// Highlight the text that has been selected
|
|
|
413 |
el.effect("highlight", {}, 1000);
|
|
|
414 |
// el.css('background-color', 'rgba(0, 102, 255, .5)');
|
|
|
415 |
// el.animate({backgroundColor: 'transparent'}, '1000');
|
|
|
416 |
|
|
|
417 |
return el;
|
|
|
418 |
}
|
|
|
419 |
|
|
|
420 |
//
|
| 6427 |
dpurdie |
421 |
// Add copy to clipboard icon to every element with a class of 'clip'
|
|
|
422 |
//
|
|
|
423 |
$( document ).ready(function() {
|
| 6626 |
dpurdie |
424 |
var myClipHandler = function (event) {
|
| 6427 |
dpurdie |
425 |
// Get element to clip
|
| 6626 |
dpurdie |
426 |
vixEl2Clip($(this).find('.clipSel').eq(0));
|
|
|
427 |
}
|
| 5266 |
dpurdie |
428 |
|
| 6626 |
dpurdie |
429 |
$('.clip').on("click", myClipHandler).on("dblclick", myClipHandler);
|
| 5266 |
dpurdie |
430 |
|
| 6626 |
dpurdie |
431 |
// Add a clip image to every class of either .clip
|
|
|
432 |
$('.clip').wrapInner('<span class=clipSel></span>').append(
|
| 6427 |
dpurdie |
433 |
$('<img />')
|
|
|
434 |
.attr({
|
|
|
435 |
title : "Copy to clipboard",
|
|
|
436 |
src : "images/CopyToClipboard.ico",
|
|
|
437 |
height : "12px",
|
|
|
438 |
width : "12px",
|
|
|
439 |
hspace : "0px",
|
|
|
440 |
align : "absmiddle",
|
|
|
441 |
border : "0"
|
|
|
442 |
})
|
| 6626 |
dpurdie |
443 |
);
|
|
|
444 |
});
|
| 6427 |
dpurdie |
445 |
|
| 6626 |
dpurdie |
446 |
// Copy data from a named element to clipboard
|
|
|
447 |
// Supports multi-line data with <p> and <br> in it
|
|
|
448 |
// Elements have a class of clipElement and have an attribute of data-target=elementId
|
|
|
449 |
$( document ).on('click', '.clipElement', function(event){
|
|
|
450 |
|
|
|
451 |
var ename = $(this).data('target');
|
|
|
452 |
var el = $('#' + ename);
|
|
|
453 |
vixEl2Clip(el);
|
| 6427 |
dpurdie |
454 |
});
|
|
|
455 |
|
| 6592 |
dpurdie |
456 |
// Add a clipThis handler to each element with a clipThis class
|
| 6610 |
dpurdie |
457 |
// Will copy the text of the element to the clipboard
|
|
|
458 |
// Add dynamically so that it will be invoked on dynamically created elements
|
| 6592 |
dpurdie |
459 |
$( document ).on('click', '.clipThis', function(event){
|
|
|
460 |
var txt = $(this).eq(0).text();
|
|
|
461 |
vixTextToClipBoard(txt, {note : "Copied to Clipboard", duration : 1000});
|
|
|
462 |
});
|
|
|
463 |
|
| 6610 |
dpurdie |
464 |
// Copy data from element to clipboard
|
|
|
465 |
// Elements have a class of clipData and an attribute of data-clip=xxx
|
|
|
466 |
// Add dynamically so that it will be invoked on dynamically created elements
|
|
|
467 |
$( document ).on('click', '.clipData', function(event){
|
|
|
468 |
var txt = $(this).data('clip');
|
|
|
469 |
vixTextToClipBoard(txt, {note : "Copied to Clipboard", duration : 1000});
|
|
|
470 |
});
|
|
|
471 |
|
|
|
472 |
|
|
|
473 |
// Invoke mailto on elements with a suitable class
|
|
|
474 |
// Elements with class mailto. and a data item of email
|
|
|
475 |
// Add dynamically so that it will be invoked on newly created elements
|
|
|
476 |
$( document ).on('click', '.mailto', function(event){
|
|
|
477 |
var email = $(this).data('email');
|
|
|
478 |
var name = $(this).data('name');
|
| 6623 |
dpurdie |
479 |
var uname = $(this).data('uname');
|
| 6610 |
dpurdie |
480 |
if ( !name ) {
|
|
|
481 |
name = $(this).eq(0).text();
|
|
|
482 |
}
|
|
|
483 |
|
|
|
484 |
var menu = '<div class="rex_clm" > Select Operation</div>';
|
|
|
485 |
if ( name ) {
|
|
|
486 |
menu += '<div class="mmItem clipData" data-clip="' + name + '">Copy Name to Clipboard</div>';
|
|
|
487 |
}
|
| 6623 |
dpurdie |
488 |
if ( uname ) {
|
|
|
489 |
menu += '<div class="mmItem clipData" data-clip="' + uname + '">Copy Login Name to Clipboard</div>';
|
|
|
490 |
}
|
| 6610 |
dpurdie |
491 |
menu += '<div class="mmItem clipData" data-clip="' + email + '">Copy Email Address to Clipboard</div>';
|
|
|
492 |
menu += '<div onClick="window.open(\'mailto:' + email + '\', \'_blank\');" class="mmItem">Send Email</div>';
|
|
|
493 |
showmenu(event,menu);
|
|
|
494 |
event.stopImmediatePropagation();
|
|
|
495 |
event.stopPropagation();
|
|
|
496 |
return false;
|
|
|
497 |
});
|
|
|
498 |
|
| 6589 |
dpurdie |
499 |
// Copy text to clipboard
|
| 6971 |
dpurdie |
500 |
// Need to append a dummy eleemnt to a point inthe document that can be selected
|
|
|
501 |
// In a modal dialog, the 'body' cannot be used. Use 'clipRoot' if its available
|
| 6589 |
dpurdie |
502 |
function vixTextToClipBoard(txt, options){
|
|
|
503 |
if ( txt == null ) {
|
|
|
504 |
return;
|
|
|
505 |
}
|
|
|
506 |
var opts = {
|
|
|
507 |
note : "Data copied to Clipboard",
|
|
|
508 |
title: "Notification",
|
|
|
509 |
notify : true,
|
|
|
510 |
timeout : 100,
|
|
|
511 |
duration: 2000,
|
|
|
512 |
}
|
|
|
513 |
$.extend(opts, options);
|
| 6427 |
dpurdie |
514 |
|
| 6971 |
dpurdie |
515 |
var useEl = $('#clipRoot');
|
|
|
516 |
if ( useEl.length === 0 ){
|
|
|
517 |
useEl =$('body') ;
|
|
|
518 |
}
|
|
|
519 |
|
| 6589 |
dpurdie |
520 |
var $temp = $("<textarea>");
|
| 6971 |
dpurdie |
521 |
useEl.prepend($temp);
|
| 6589 |
dpurdie |
522 |
$temp.val(txt).select();
|
|
|
523 |
document.execCommand("copy");
|
|
|
524 |
$temp.remove();
|
| 6427 |
dpurdie |
525 |
|
| 6589 |
dpurdie |
526 |
if ( opts.notify ) {
|
|
|
527 |
vixConfirm(opts.note, {
|
|
|
528 |
title: opts.title,
|
| 6641 |
dpurdie |
529 |
icon : "images/i_info.png",
|
|
|
530 |
cancel: false,
|
| 6589 |
dpurdie |
531 |
button: null,
|
|
|
532 |
timeout : opts.timeout,
|
|
|
533 |
modal : false,
|
| 6641 |
dpurdie |
534 |
minHeight: 10,
|
| 6589 |
dpurdie |
535 |
hide: { effect: 'fade', duration: opts.duration }
|
|
|
536 |
});
|
|
|
537 |
}
|
|
|
538 |
}
|
|
|
539 |
|
| 6651 |
dpurdie |
540 |
// Export Table as CSV support functions
|
|
|
541 |
// Allow a table that has been tagged with a class of etable to be exported
|
|
|
542 |
//
|
|
|
543 |
// Global variable for use of the table to CSV widget
|
|
|
544 |
// Used to convey info though the selection callback
|
|
|
545 |
//
|
|
|
546 |
var vixEtableData;
|
|
|
547 |
|
|
|
548 |
$( document ).ready(function() {
|
|
|
549 |
vixEtableInit();
|
|
|
550 |
});
|
|
|
551 |
|
|
|
552 |
// vixPostPageLoad is called when dynamic DOM elements are loaded
|
|
|
553 |
function vixPostPageLoad(){
|
|
|
554 |
vixEtableInit();
|
|
|
555 |
}
|
|
|
556 |
|
|
|
557 |
// Init all elements marked with a class of 'etable'
|
|
|
558 |
// Insert an icon
|
|
|
559 |
// Remove original class so that the DOM can be scanned again
|
|
|
560 |
function vixEtableInit(){
|
|
|
561 |
$('.etable').css('position', 'relative');
|
|
|
562 |
$('.etable th:last-child').append(
|
|
|
563 |
$('<img />')
|
|
|
564 |
.attr({
|
|
|
565 |
title : "Export table as CSV",
|
|
|
566 |
src : "images/CopyToClipboard.ico",
|
|
|
567 |
height : "12px",
|
|
|
568 |
width : "12px",
|
|
|
569 |
hspace : "0px",
|
|
|
570 |
align : "absmiddle",
|
|
|
571 |
border : "0"
|
|
|
572 |
})
|
|
|
573 |
.css({position : 'absolute', top : '0px', right : '0px'})
|
|
|
574 |
.click(function(event){
|
|
|
575 |
vixEtableData = $(this).closest('table');
|
|
|
576 |
var menu = '<div class="rex_clm" > Select Operation</div>';
|
| 6695 |
dpurdie |
577 |
menu += '<div class="mmItem" onClick="vixEtableProc(\'popup\');">Show in New Window</div>';
|
|
|
578 |
menu += '<div class="mmItem" onClick="vixEtableProc(\'modal\');">Show in Dialog</div>';
|
| 6651 |
dpurdie |
579 |
menu += '<div class="mmItem" onClick="vixEtableProc(\'download\');">Download File</div>';
|
|
|
580 |
menu += '<div class="mmItem" onClick="vixEtableProc(\'clip\');">Copy to Clipboard</div>';
|
|
|
581 |
showmenu(event,menu);
|
|
|
582 |
event.stopImmediatePropagation();
|
|
|
583 |
event.stopPropagation();
|
|
|
584 |
return false;
|
|
|
585 |
})
|
|
|
586 |
);
|
|
|
587 |
$('.etable').addClass('etable-done').removeClass('etable');
|
|
|
588 |
}
|
|
|
589 |
|
|
|
590 |
// Global function to support post-selection processing of CSV data
|
|
|
591 |
function vixEtableProc(mode) {
|
|
|
592 |
var tdata = vixEtableData.data('etable')
|
|
|
593 |
var defData = {
|
|
|
594 |
delivery: mode,
|
|
|
595 |
filename: 'data.csv',
|
|
|
596 |
rowFilter: '.csvData'
|
|
|
597 |
};
|
|
|
598 |
$.extend(defData, tdata) ;
|
|
|
599 |
var data = vixEtableData.TableCSVExport(defData);
|
|
|
600 |
if ( mode == 'clip' ) {
|
|
|
601 |
vixTextToClipBoard(data, {note : "CSV copied to Clipboard", duration : 1000});
|
|
|
602 |
}
|
|
|
603 |
}
|
|
|
604 |
|
| 6695 |
dpurdie |
605 |
// Create a new window in the center of the current screen
|
|
|
606 |
// A wrapper for window.open(), with a few smarts
|
|
|
607 |
// Does not position correctly on Widows-Edge
|
|
|
608 |
function PopupCenter(url, title, w, h) {
|
|
|
609 |
// Fixes dual-screen position Most browsers Firefox
|
|
|
610 |
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : window.screenX;
|
|
|
611 |
var dualScreenTop = window.screenTop != undefined ? window.screenTop : window.screenY;
|
| 6651 |
dpurdie |
612 |
|
| 6695 |
dpurdie |
613 |
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
|
|
|
614 |
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
|
| 6651 |
dpurdie |
615 |
|
| 6695 |
dpurdie |
616 |
var left = ((width / 2) - (w / 2)) + dualScreenLeft;
|
|
|
617 |
var top = ((height / 2) - (h / 2)) + dualScreenTop;
|
|
|
618 |
var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
|
| 6651 |
dpurdie |
619 |
|
| 6695 |
dpurdie |
620 |
// Puts focus on the newWindow
|
|
|
621 |
if (window.focus) {
|
|
|
622 |
newWindow.focus();
|
|
|
623 |
}
|
| 6651 |
dpurdie |
624 |
|
| 6695 |
dpurdie |
625 |
return newWindow;
|
|
|
626 |
}
|
| 6651 |
dpurdie |
627 |
|
|
|
628 |
|
|
|
629 |
|
| 6695 |
dpurdie |
630 |
|
|
|
631 |
|
|
|
632 |
|
|
|
633 |
|
|
|
634 |
|
|
|
635 |
|