Feeds:
Posts
Comments

Posts Tagged ‘example’

Twitter Typeahead is a fast and effective auto-complete jQuery plugin for form filling.

Twitter Typeahead 插件是一個jQuery 插件,用作快速而有效率的自動填表工具。

In desktop computer, this plugin (Twitter Typeahead) works properly. However, when this plugin is run on a mobile computer, it cannot detect the “blur” event properly. The suggested text cannot be closed when you click outside the suggestion box.

在正常的桌面電腦上,這個Twitter Typeahead插件能正常地運作。可是,一旦放在手機的瀏覽器上運行,卻因無法捕捉到“blur”的事件。如果輕觸瀏覽器的其他地方,無法可以正常關閉“提示列”。

One of the possible method is add a close button “x” to close the suggestion list. I’ve done an ugly example illustrate this: typeahead with close button “x”

其中一個可行的方法,就是在提示清單上加入一個關閉的按鈕”x”,小弟做了個核突的版本:typeahead with close button “x”

只要您修改第849行,
What you need to do is to change line 849:

 dropdown: '<span class="tt-dropdown-menu"></span>'

換成以下,
To

 dropdown: '<span class="tt-dropdown-menu"><a class="tt-dropdown-close" onclick="$(this).closest(\'span\').hide()">x</a></span>'

還有,只要修改CSS就能改善畫面。
If you feel this screen is ugly, what you need is to add CSS file.

Read Full Post »

Java HelloFriend Guide

Java is a quite common programming language nowadays. If you want to know more about Java, you better trying to play and write Java program yourself. The following program may give you some ideas about Java:

1. Create a folder to store your source file (Java uses subfolder as packages: org.examplet.HelloFriend should be store in folders: org/examplet), for example:

mkdir -p ~/source/java/src/org/examplet

2. Go to your folder, for example:

cd ~/source/java

3. Edit your Java source code:

nano src/org/examplet/HelloFriend.java

4. In the nano screen, type the following source code:

package org.examplet;
import java.util.Scanner;
import static java.lang.System.out;
import static java.lang.System.in;
class HelloFriend{
	public static void main(String args[]){
		String name="";
		Scanner sc=new Scanner(in);
		while(true){
			out.print("What is your name (type 'quit' to quit) ? ");
			if(sc.hasNext()){
				name=sc.nextLine().trim();
				if(name.toLowerCase().equals("quit"))
					break;
			}
			out.printf("Hello, %s!\n",name);
		}
	}
}

5. save the file by press ctrl-x

6. create a folder to store the compiled file, for example:

mkdir build

7. compile the file and output the file to the “build” folder

javac -d build -sourcepath src src/org/examplet/HelloWorld.java

8. run the code by the following command:

java -cp build org.examplet.HelloFriend

9. As you run the program, you’ve been asked for your name repeatedly:

What is your name (type 'quit' to quit) ? Peter Pan
Hello, Peter Pan!
What is your name (type 'quit' to quit) ? quit

Read Full Post »

C++ HelloFriend Guide

Elementary Tutorial for Writing and Running c++. Follows the following steps to run a basic C++ program:

1. create a folder to store your source code, for example:

mkdir -p ~/source/cpp/HelloFriend/src

2. change the current directory to the working folder, for example:

cd ~/source/cpp/HelloFriend

3. create the source code by the following command:

nano src/HelloFriend.cpp

4. In the nano environment, type the source code:

#include<iostream>
#include<string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main(int argc, char* argv[]){
	string name;
	while(true){
		cout<<"What is your name (type 'quit' to quit) ? ";
		getline(cin,name);
		if(name.compare("quit")==0) break;
		cout<<"Hello, "<<name<<"!"<<endl;
	}
	return 0;
}

5. press ctrl-x to leave and save the source code

6. Create the Makefile.am to instruct makefile program to look for sub-folders

nano Makefile.am

7. The source code for the Makefile.am should be:

SUBDIRS=src

8. press ctrl-x to save and exit the nano editor

9. Create the sub-folder Makefile.am, e.g.

nano src/Makefile.am
[/source}

10. Update the sub-folder Makefile.am as followings:

bin_PROGRAMS=HelloFriend
HelloFriend_SOURCES=HelloFriend.cpp

11. Press Ctrl-X to Save and Exit the nano editor.

12. Generate a template config file by invoking the autoscan command:

autoscan

13. A file called configure.scan has been generate for you, change the name to configure.ac and edit it by the following command:

mv configure.scan configure.ac
nano configure.ac

14. Change line 5 of the code into (replace your email accordingly):

AC_INIT([HelloFriend],[1.0],[cloudgen@examplet.org])

15. Add a line below line 5 and type the following:

AM_INIT_AUTOMAKE([foreign])

16. Then your configure.ac should look like:

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([HelloFriend],[1.0],[cloudgen@examplet.org])
AM_INIT_AUTOMAKE([foreign])
AC_CONFIG_SRCDIR([src/HelloFriend.cpp])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CXX

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL

# Checks for library functions.

AC_CONFIG_FILES([Makefile
                 src/Makefile])
AC_OUTPUT

17. Prepare the makefile.in and config.h.in by the following command:

autoheader
aclocal
autoconf
automake --add-missing

18. Configure your compiler by the following command:

./configure

19. Compile runnable code by the following command:

make

20. Install the program to your system by the following command,

make install

21. Run the installed program by,

HelloFriend

22. As you run the program, you’ve been asked for your name repeatedly:

What is your name (type 'quit' to quit) ? Peter Pan
Hello, Peter Pan!
What is your name (type 'quit' to quit) ? quit

Read Full Post »