Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-8 of 8 total  RSS 

instapaper bookmarklet

Assuming you are registered with the new bookmarking service 'instapaper', then you would use the following code which would normally be placed as a link within your web browser's toolbar.

javascript:var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,
s=(e?e():(k)?k():(x?x.createRange().text:0)),f='http://www.instapaper.com/b',
l=d.location,e=encodeURIComponent,p='?v=3&u='+e(l.href) +'&t='+e(d.title) +'&s='+e(s),
u=f+p;try{if(!/^(.*\.)?instapaper([^.]*)?$/.test(l.host))throw(0);
iptstbt();}catch(z){a =function(){if(!w.open(u,'t','toolbar=0,resizable=0,status=1,
width=250,height=150'))l.href=u;};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);
else a();}void(0)


I'm interested in using similar JavaScript if I ever write my own personal bookmarking service.

Open a popup window with specified parameters / arguments

opens a popup a window with the specified width and height. can be centered in the screen

function openAWindow( pageToLoad, winName, width, height, center)
{
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
	
	//0 => no
	//1 => yes
    var args = "";
    	args += "width=" + width + "," + "height=" + height + ","
		+ "location=0,"
		+ "menubar=0,"
		+ "resizable=0,"
		+ "scrollbars=0,"
		+ "statusbar=false,dependent,alwaysraised,"
		+ "status=false,"
		+ "titlebar=no,"
		+ "toolbar=0,"
		+ "hotkeys=0,"
		+ "screenx=" + xposition + ","  //NN Only
		+ "screeny=" + yposition + ","  //NN Only
		+ "left=" + xposition + ","     //IE Only
		+ "top=" + yposition;           //IE Only
		//fullscreen=yes, add for full screen
    	var dmcaWin = window.open(pageToLoad,winName,args );
    	dmcaWin.focus();
    //window.showModalDialog(pageToLoad,"","dialogWidth:650px;dialogHeight:500px");
}


call the function as openAWindow("yourfilenamehere","windownamehere",500,600,true);
500 => width
600 => height
true => if you want to place the popup window in the center of the screen

Customize JavaScript Popup Window Code in sigle one line

Oneline JavaScript Popup Window Code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title></title>
</head>

<body>
        <a href="#"
        onClick="MyWindow=window.open('http://www.yahoo.com','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=600,height=300,left=0,top=0'); return false;">
        Popup Window Code in single one line without any function</a>

</body>

</html>

C - Simple Example GTK

// gcc file.c -o file.o `pkg-config --libs --cflags gtk+-2.0`

#include <gtk/gtk.h>
#include <stdlib.h>

void displayUI()
{
	GtkWidget* mainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);

	gtk_window_set_default_size(GTK_WINDOW(mainWindow), 400, 300);
	gtk_window_set_title(GTK_WINDOW(mainWindow), "GTK Simple Example");
	gtk_window_set_position(GTK_WINDOW(mainWindow), GTK_WIN_POS_CENTER_ALWAYS);

	gtk_signal_connect(GTK_OBJECT(mainWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL);

	gtk_widget_show_all(mainWindow);
}

int main(int argc, char *argv[])
{
	gtk_init(&argc, &argv);

	displayUI();

	gtk_main();

	return EXIT_SUCCESS;
}

how to open links in current window, new window, background.

function open2(url, opt){
  if (opt == 0) // current window
    window.location = url;
  else if (opt == 1) // new window
    window.open(url);
  else if (opt == 2) // background window
    {window.open(url); self.focus();}
}

Xlib - mouseClick

// Simula il click del mouse

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <unistd.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>

void mouseClick(int button)
{
	Display *display = XOpenDisplay(NULL);

	XEvent event;
	
	if(display == NULL)
	{
		fprintf(stderr, "Errore nell'apertura del Display !!!\n");
		exit(EXIT_FAILURE);
	}
	
	memset(&event, 0x00, sizeof(event));
	
	event.type = ButtonPress;
	event.xbutton.button = button;
	event.xbutton.same_screen = True;
	
	XQueryPointer(display, RootWindow(display, DefaultScreen(display)), &event.xbutton.root, &event.xbutton.window, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state);
	
	event.xbutton.subwindow = event.xbutton.window;
	
	while(event.xbutton.subwindow)
	{
		event.xbutton.window = event.xbutton.subwindow;
		
		XQueryPointer(display, event.xbutton.window, &event.xbutton.root, &event.xbutton.subwindow, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state);
	}
	
	if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, "Errore nell'invio dell'evento !!!\n");
	
	XFlush(display);
	
	usleep(100000);
	
	event.type = ButtonRelease;
	event.xbutton.state = 0x100;
	
	if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, "Errore nell'invio dell'evento !!!\n");
	
	XFlush(display);
	
	XCloseDisplay(display);
}


// gcc source.c -L /usr/X11R6/lib -lX11

Java - UIManager all-windows

// Imposto il tema Metal non solo all'interno delle finestre di Java, ma anche al suo esterno...

    // Con queste definizioni dico che tutti i frame e i dialog prendono il tema Metal
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    //

    try
    {
        // Con questa imposto il tema
	UIManager.setLookAndFeel(new MetalLookAndFeel());
    }
    catch(UnsupportedLookAndFeelException e)
    {
	e.printStackTrace();
    }
    // In questo modo tutte le finestre avranno il tema Metal

dojo/window/slidshow

// description of your code here

<?php
/*
 * Created on 2006-4-7
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
?>

<html>
<head>
<meta http-equiv="Content-Language" content="en" />
<meta name="GENERATOR" content="PHPEclipse 1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>


<link href="dojo/src/widget/templates/HtmlSlideShow.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="dojo/dojo.js"></script>

	<script type="text/javascript" src="windows/javascripts/prototype.js"> </script> 
	<script type="text/javascript" src="windows/javascripts/effects.js"> </script>
	<script type="text/javascript" src="windows/javascripts/window.js"> </script>
	<script type="text/javascript" src="windows/javascripts/debug.js"> </script>
	<link href="windows/themes/default.css" rel="stylesheet" type="text/css" >	 </link>
	<link href="windows/themes/theme1.css" rel="stylesheet" type="text/css" >	 </link>
	<link href="winodws/themes/alert.css" rel="stylesheet" type="text/css" >	 </link>
	<title>Sample Windows</title>
<script type="text/javascript">
   //dojo.require("dojo.widget.Editor");
    //dojo.require("dojo.widget.SlideShow");
	//doji.require("dojo.event.*");
     </script>

<body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99">

	<a href="javascript:openModalDialog()">Click here to open a modal window</a>
	<br/>
	<script>
	var index= 0;
    var contentWin = null;
		function openContentWindow() {
		if (contentWin != null) {
			Dialog.alert("Close the window 'Test' before opening it again!"); 
		}
		else {
			contentWin = new Window('content_win', {title: "Test ",top:100, left:100, resizable: false})
			contentWin.setContent('test_content', true)
			contentWin.toFront();
			contentWin.setDestroyOnClose();
			contentWin.show();	
		}		
	}

		function openModalDialog() {
		var win = new Window('modal' + index, {title: "易登网",top:100, left:100,  width:300, height:200, zIndex:150, opacity:50, resizable: true,hideEffect: Effect.Grow})
		win.getContent().innerHTML = "&nbsp;&nbsp;<a href='http://www.edeng.cn'>edeng</a><br /><input type='submit' value='æ??交'>"
		win.show(true);	
		index++;
	}



	win = new Window('dialog1', {className: "dialog",  width:300, height:400, zIndex: 100, resizable: true, title: "Title", hideEffect: Effect.SwitchOff})
	win.getContent().innerHTML= "<div style='padding:10px'> Lorem ipsum dolor sit amet, consectetur adipiscing elit, set eiusmod tempor incidunt et labore et dolore magna aliquam. Ut enim ad minim veniam, quis nostrud exerc. Irure dolor in reprehend incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse molestaie cillum. Tia non ob ea soluad incom dereud facilis est er expedit distinct. Nam liber te conscient to factor tum poen legum odioque civiuda et tam. \
	At vver eos et accusam dignissum qui blandit est praesent. Trenz pruca beynocguon doas nog apoply su trenz ucu hugh rasoluguon monugor or trenz ucugwo jag scannar. Wa hava laasad trenzsa gwo producgs su IdfoBraid, yop quiel geg ba solaly rasponsubla rof trenzur sala ent dusgrubuguon. Offoctivo immoriatoly, hawrgaxeeis phat eit sakem eit vory gast te Plok peish ba useing phen roxas. Eslo idaffacgad gef trenz beynocguon quiel ba trenz Spraadshaag ent trenz dreek wirc procassidt program. Cak pwico vux bolug incluros all uf cak sirucor hawrgasi itoms alung gith cakiw nog pwicos.\
	Lor sum amet, commy nulputat. Duipit lum ipisl eros dolortionsed tin hent aliquis illam volor in ea feum in ut adipsustrud elent ulluptat. Duisl ullan ex et am vulputem augiam doloreet amet enibh eui te dipit acillutat acilis amet, suscil er iuscilla con utat, quisis eu feugait ad dolore commy nullam iuscilisl iureril ilisl del ut pratuer iliquis acipissit accum quis nulluptat. Dui bla faccumsan velis auguero con henis duismolor sumsandrem quat vulluptat alit er iniamcore exeriure vero core te dit ut nulla feummolore commod dipis augiamcommod tem ese dolestrud do odo odiamco eetummy nis aliquamcommy nonse eu feugue del eugiamconsed ming estrud magnis exero eumsandio enisim del dio od tat.sumsan et pratum velit ing etue te consequis alis nullan et, quis am iusci bla feummy.</div>"
	win.showCenter();
	</script>
<div dojoType="Editor" items="textGroup;|;listGroup;|;colorGroup;|;blockGroup;|;commandGroup;">
    some contentfsdfsdfsdfsdfsdfsdfsd  dddd
</div>
<img dojoType="SlideShow" 
    imgUrlBase="dojo/src/pic/"
    imgUrls="2.jpg;3.jpg" 
    transitionInterval="700"
    delay="1000"
    imgWidth="400"
    imgHeight="300"
    width="400"
    height="300"
    src="http://dojotoolkit.org/path/to/dojo/tests/widget/images/1.jpg" /><p>
    <?php echo "ddd" ?>





</body>
</html>
  

« Newer Snippets
Older Snippets »
Showing 1-8 of 8 total  RSS