winbox icon indicating copy to clipboard operation
winbox copied to clipboard

Does window with same title already exist ?

Open MadTomT opened this issue 2 years ago • 1 comments

Hi I plan to open winboxes via buttons, each button will open a winbox with a specific title.

Is it possible to check if a winbox with that title already exists ? If it does bring to front and focus the winbox, if not open it.

Thanks

MadTomT avatar May 02 '22 23:05 MadTomT

I've sort of got this working. I've added jquery to check the open div's titles, but I'm struggling to bring into focus a window of the same name if it is found. Any ideas ?

$(document).ready(function() {

	$("body").on('click', '#add', function(){
		
		$('div[id^=winbox]').each(function(i, obj) {
			var openWindow = $(obj).find('.wb-title').text();
			if ( openWindow = 'name' ) {
				WinBox.focus( obj.id );
				return false
			}
		});
	        // add new window
		var Modal = new WinBox('name', {
			url: "https://127.0.0.1/newpage.php"
		})
	
	})

})

MadTomT avatar May 03 '22 08:05 MadTomT

It is simple like that:

const win = {};

function openWindow(title){
    if(win[title]) win[title].focus();
    else win[title] = new WinBox(title);
}
openWindow("foo");
openWindow("bar");
openWindow("foo");

ts-thomas avatar Aug 20 '22 12:08 ts-thomas