#fixed bugs not handling some special cases in code diff view including subversionmodel.
# partially changed the project catalog view to use ajax to load the project list
This commit is contained in:
		| @ -103,6 +103,8 @@ class Project extends Controller | ||||
| 		{ | ||||
| 			$this->pagination->initialize ($pagecfg); | ||||
| 			$data['page_links'] = $this->pagination->create_links (); | ||||
| 			$data['req_page_offset'] = $offset; | ||||
| 			$data['req_page_size'] = CODEPOT_MAX_PROJECTS_PER_PAGE; | ||||
| 			$data['total_num_projects'] = $num_entries; | ||||
| 			$data['projects'] = $projects; | ||||
| 			$this->load->view ($this->VIEW_CATALOG, $data); | ||||
| @ -164,7 +166,7 @@ class Project extends Controller | ||||
|  | ||||
| 		$data['login'] = $login; | ||||
|  | ||||
|                 // SET VALIDATION RULES | ||||
| 		// SET VALIDATION RULES | ||||
| 		$this->form_validation->set_rules ( | ||||
| 			'project_id', 'ID', 'required|alpha_dash|max_length[32]'); | ||||
| 		$this->form_validation->set_rules ( | ||||
| @ -208,10 +210,13 @@ class Project extends Controller | ||||
| 				// if ok, take action | ||||
| 				$result = ($mode == 'update')? | ||||
| 					$this->projects->update ($login['id'], $project): | ||||
| 					$this->projects->create ($login['id'], $project, $api_base_url); | ||||
| 					$this->projects->create ($login['id'], $project, $api_base_url, $repo_error); | ||||
| 				if ($result === FALSE) | ||||
| 				{ | ||||
| 					$data['message'] = 'DATABASE ERROR'; | ||||
| 					if ($repo_error) | ||||
| 						$data['message'] = 'REPOSITORY ERROR'; | ||||
| 					else | ||||
| 						$data['message'] = 'DATABASE ERROR'; | ||||
| 					$data['project'] = $project; | ||||
| 					$this->load->view ($this->VIEW_EDIT, $data); | ||||
| 				} | ||||
| @ -463,10 +468,100 @@ class Project extends Controller | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	function search_json ($needle = '') | ||||
| 	function catalog_json ($filter = '', $offset = '') | ||||
| 	{ | ||||
| 		$this->load->model ('ProjectModel', 'projects'); | ||||
| 	 | ||||
| 		$login = $this->login->getUser (); | ||||
| 		if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') | ||||
| 		{ | ||||
| 			$status = 'signin'; | ||||
| 			$projects = array(); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
|  | ||||
| 			if ($filter == '') | ||||
| 			{ | ||||
| 				$search->id = ''; | ||||
| 				$search->name = ''; | ||||
| 				$search->summary = ''; | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				parse_str ($this->converter->HexToAscii($filter), $search); | ||||
| 				if (!array_key_exists ('id', $search)) $search['id'] = ''; | ||||
| 				if (!array_key_exists ('name', $search)) $search['name'] = ''; | ||||
| 				if (!array_key_exists ('summary', $search)) $search['summary'] = ''; | ||||
|  | ||||
| 				$search = (object) $search; | ||||
| 			} | ||||
|  | ||||
| 			if ($filter == '' && $offset == '') | ||||
| 			{ | ||||
| 				$offset = 0; | ||||
| 			} | ||||
| 			else if ($filter != '' && $offset == '') | ||||
| 			{ | ||||
| 				if (is_numeric($filter)) | ||||
| 				{ | ||||
| 					$offset = (integer)$filter; | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| 					$offset = 0; | ||||
| 				} | ||||
| 			} | ||||
| 			else  | ||||
| 			{ | ||||
| 				$offset = (integer) $offset; | ||||
| 			} | ||||
|  | ||||
| 			// get the total number of entries available | ||||
| 			$num_entries = $this->projects->getNumEntries ($login['id'], $search); | ||||
| 			if ($num_entries === FALSE) | ||||
| 			{ | ||||
| 				$status = 'dberr'; | ||||
| 				$projects = array (); | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				// get project entries staring from the offset. | ||||
| 				$projects = $this->projects->getEntries ($login['id'], $offset, CODEPOT_MAX_PROJECTS_PER_PAGE, $search); | ||||
| 				if ($projects === FALSE) | ||||
| 				{ | ||||
| 					$status = 'dberr'; | ||||
| 					$projects = array (); | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| 					$status = 'ok'; | ||||
| 					// exclude the description column | ||||
| 					foreach ($projects as $p) unset ($p->description); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		$result = array ( | ||||
| 			'status' => $status, | ||||
| 			'total_num_projects' => $num_entries, | ||||
| 			'req_page_offset' => $offset, | ||||
| 			'req_page_size' => CODEPOT_MAX_PROJECTS_PER_PAGE, | ||||
| 			'projects' => $projects | ||||
| 		); | ||||
|  | ||||
| 		print codepot_json_encode ($result); | ||||
| 	} | ||||
|  | ||||
| 	function quickfind_json ($needle = '') | ||||
| 	{ | ||||
| 		// this function is to serve the intermediate search | ||||
| 		// by the quick project finder in the task bar. | ||||
| 		// it returns the array of {id: XXX, value: YYY} in the | ||||
| 		// json format. | ||||
|  | ||||
| 		$this->load->model ('ProjectModel', 'projects'); | ||||
|  | ||||
| 		$login = $this->login->getUser (); | ||||
| 		if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') | ||||
| 		{ | ||||
| @ -479,17 +574,16 @@ class Project extends Controller | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			$projects = $this->projects->findIDsAndNames ($login['id'], $needle); | ||||
| 			if ($projects === FALSE) | ||||
| 			{ | ||||
| 				$projects = array (); | ||||
| 			} | ||||
| 			$needle = $this->converter->HexToAscii($needle); | ||||
| 			$projects = $this->projects->quickfindEntries ($login['id'], $needle); | ||||
| 			if ($projects === FALSE) $projects = array (); | ||||
| 		} | ||||
|  | ||||
| 		foreach ($projects as &$p) | ||||
| 		{ | ||||
| 			$p->value = $p->id . ' - ' . $p->value; | ||||
| 			if ($p->id != $p->value) $p->value = $p->id . ' - ' . $p->value; | ||||
| 		} | ||||
|  | ||||
| 		print codepot_json_encode ($projects); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -29,7 +29,6 @@ if ( ! function_exists('codepot_merge_path')) | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| if ( !function_exists ('codepot_json_encode')) | ||||
| { | ||||
| 	function codepot_json_encode( $data )  | ||||
|  | ||||
| @ -58,9 +58,9 @@ class ProjectModel extends Model | ||||
|  | ||||
| 		$this->db->select ('count(id) as count'); | ||||
| 		$this->db->order_by ('name', 'asc'); | ||||
| 		if ($search->id != '') $this->db->like ('id', $search->id); | ||||
| 		if ($search->name != '') $this->db->like ('name', $search->name); | ||||
| 		if ($search->summary != '') $this->db->like ('summary', $search->summary); | ||||
| 		if (!empty($search->id)) $this->db->like ('id', $search->id); | ||||
| 		if (!empty($search->name)) $this->db->like ('name', $search->name); | ||||
| 		if (!empty($search->summary)) $this->db->like ('summary', $search->summary); | ||||
|  | ||||
| 		$query = $this->db->get ('project'); | ||||
| 		if ($this->db->trans_status() === FALSE) | ||||
| @ -83,16 +83,16 @@ class ProjectModel extends Model | ||||
| 	{ | ||||
| 		$this->db->trans_start (); | ||||
| 		$this->db->order_by ('name', 'asc'); | ||||
| 		if ($search->id != '') $this->db->like ('id', $search->id); | ||||
| 		if ($search->name != '') $this->db->like ('name', $search->name); | ||||
| 		if ($search->summary != '') $this->db->like ('summary', $search->summary); | ||||
| 		if (!empty($search->id)) $this->db->like ('id', $search->id); | ||||
| 		if (!empty($search->name)) $this->db->like ('name', $search->name); | ||||
| 		if (!empty($search->summary)) $this->db->like ('summary', $search->summary); | ||||
| 		$query = $this->db->get ('project', $limit, $offset); | ||||
| 		$this->db->trans_complete (); | ||||
| 		if ($this->db->trans_status() === FALSE) return FALSE; | ||||
| 		return $query->result (); | ||||
| 	} | ||||
|  | ||||
| 	function findIDsAndNames ($userid, $needle) | ||||
| 	function quickfindEntries ($userid, $needle) | ||||
| 	{ | ||||
| 		$this->db->trans_start (); | ||||
| 		$this->db->select(array('id', 'name as value')); // jquery ui autocomplete seems to require 'value'. | ||||
| @ -105,9 +105,10 @@ class ProjectModel extends Model | ||||
| 		return $query->result (); | ||||
| 	} | ||||
|  | ||||
| 	function create ($userid, $project, $api_base_url) | ||||
| 	function create ($userid, $project, $api_base_url, &$repo_error) | ||||
| 	{ | ||||
| 		// TODO: check if userid can do this.. | ||||
| 		$repo_error = FALSE; | ||||
|  | ||||
| 		$this->db->trans_begin (); // manual transaction. not using trans_start(). | ||||
|  | ||||
| @ -169,6 +170,7 @@ class ProjectModel extends Model | ||||
| 			if (@svn_repos_create ("{$repodir}/{$project->id}") === FALSE) | ||||
| 			{ | ||||
| 				$this->db->trans_rollback (); | ||||
| 				$repo_error = TRUE; | ||||
| 				return FALSE; | ||||
| 			} | ||||
|  | ||||
| @ -190,6 +192,7 @@ class ProjectModel extends Model | ||||
| 				{ | ||||
| 					$this->deleteDirectory ("{$repodir}/{$project->id}"); | ||||
| 					$this->db->trans_rollback (); | ||||
| 					$repo_error = TRUE; | ||||
| 					return FALSE; | ||||
| 				} | ||||
|  | ||||
| @ -199,6 +202,7 @@ class ProjectModel extends Model | ||||
| 				{ | ||||
| 					$this->deleteDirectory ("{$repodir}/{$project->id}"); | ||||
| 					$this->db->trans_rollback (); | ||||
| 					$repo_error = TRUE; | ||||
| 					return FALSE; | ||||
| 				} | ||||
|  | ||||
| @ -208,6 +212,7 @@ class ProjectModel extends Model | ||||
| 				{ | ||||
| 					$this->deleteDirectory ("{$repodir}/{$project->id}"); | ||||
| 					$this->db->trans_rollback (); | ||||
| 					$repo_error = TRUE; | ||||
| 					return FALSE; | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| @ -299,22 +299,44 @@ class SubversionModel extends Model | ||||
| 			rewind($nfile); | ||||
| 		} | ||||
|  | ||||
| 		// Ignore the 4 header lines | ||||
| 		$line = fgets($diff); | ||||
| 		$line = fgets($diff); | ||||
| 		$line = fgets($diff); | ||||
| 		$line = fgets($diff); | ||||
|  | ||||
| 		// Get the first real line | ||||
| 		$line = fgets($diff); | ||||
|  | ||||
| 		$abort = FALSE; | ||||
| 		$index = 0; | ||||
| 		$listing = array(); | ||||
|  | ||||
| 		$curoline = 1; | ||||
| 		$curnline = 1; | ||||
|  | ||||
| 		$abort = FALSE; | ||||
| 		// Ignore the 4 header lines. AFter that, it get the first real line | ||||
| 		// which is the 5th line. The header lines look like this: | ||||
| 		// | ||||
| 		// Index: test1.txt | ||||
| 		// =================================================================== | ||||
| 		// --- test1.txt	(revision 20) | ||||
| 		// +++ test1.txt	(revision 22) | ||||
| 		// | ||||
| 		// The fifth line should look like this: | ||||
| 		// @@ -2,5 +2,7 @@ | ||||
| 		// | ||||
| 		for ($i = 0; $i < 5 && !feof($diff); $i++) | ||||
| 		{ | ||||
| 			$line = fgets($diff); | ||||
| 			if ($line === FALSE || $line == "\n")  | ||||
| 			{ | ||||
| 				// the first line can be empty if there is no contents changes. | ||||
| 				// property changes may be following but this function is | ||||
| 				// not interested in it. | ||||
| 				$abort = TRUE; | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if (!feof($diff) && !$abort) | ||||
| 		{ | ||||
| 			// santy check on the fifth line. something bad must have | ||||
| 			// happened if it doesn't begin with @@. | ||||
| 			if (strncmp($line, "@@", 2) != 0) $abort = TRUE; | ||||
| 		} | ||||
|  | ||||
| 		while (!feof($diff) && !$abort)  | ||||
| 		{ | ||||
| 			// Get the first line of this range | ||||
| @ -437,9 +459,10 @@ class SubversionModel extends Model | ||||
| 					{ | ||||
| 						case "\\": | ||||
| 							// ignore it . | ||||
| 							// subversion seems to procude a like like this: | ||||
| 							// subversion seems to procude a line like this: | ||||
| 							//  \ No newline at the end of file | ||||
| 							// | ||||
| 							unset ($listing[$index]); // unset the data filled partially above. | ||||
| 							$index--; | ||||
| 							break; | ||||
|  | ||||
| @ -447,7 +470,8 @@ class SubversionModel extends Model | ||||
| 							$listing[$index]["rev1diffclass"] = "diffdeleted"; | ||||
| 							$listing[$index]["rev2diffclass"] = "diff"; | ||||
|  | ||||
| 							if ($all) { | ||||
| 							if ($all)  | ||||
| 							{ | ||||
| 								fgets($ofile); | ||||
| 								$curoline++; | ||||
| 							} | ||||
| @ -493,7 +517,6 @@ class SubversionModel extends Model | ||||
| 								$listing[$index]["rev1diffclass"] = "diff"; | ||||
| 								$listing[$index]["rev2diffclass"] = "diffadded"; | ||||
|  | ||||
|  | ||||
| 								//$listing[$index]["rev1line"] = " "; | ||||
| 								$listing[$index]["rev1line"] = ''; | ||||
| 								$listing[$index]["rev2line"] = $text; | ||||
| @ -525,9 +548,7 @@ class SubversionModel extends Model | ||||
| 					} | ||||
| 				} | ||||
|  | ||||
| 				if (!$fin) { | ||||
| 					$index++; | ||||
| 				} | ||||
| 				if (!$fin) $index++; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| @ -537,7 +558,6 @@ class SubversionModel extends Model | ||||
| 			while (1) | ||||
| 			{ | ||||
| 				if (feof($ofile) && feof($nfile)) break; | ||||
|  | ||||
| 				$listing[$index]["rev1diffclass"] = "diff"; | ||||
| 				$listing[$index]["rev2diffclass"] = "diff"; | ||||
|  | ||||
| @ -545,13 +565,12 @@ class SubversionModel extends Model | ||||
| 				{ | ||||
| 					$line = rtrim(fgets($ofile), "\r\n"); | ||||
| 					if ($ent) $line = replaceEntities($line, $rep); | ||||
| 				} | ||||
|  | ||||
| 				if (!feof($ofile)) { | ||||
| 					//$listing[$index]["rev1line"] = hardspace($line); | ||||
| 					$listing[$index]["rev1line"] = $line; | ||||
| 				} | ||||
| 				else { | ||||
| 				else  | ||||
| 				{ | ||||
| 					//$listing[$index]["rev1line"] = " "; | ||||
| 					$listing[$index]["rev1line"] = '';  | ||||
| 				} | ||||
| @ -560,13 +579,12 @@ class SubversionModel extends Model | ||||
| 				{ | ||||
| 					$line = rtrim(fgets($nfile), "\r\n"); | ||||
| 					if ($ent) $line = replaceEntities(rtrim(fgets($nfile), "\r\n"), $rep); | ||||
| 				} | ||||
|  | ||||
| 				if (!feof($nfile)) { | ||||
| 					//$listing[$index]["rev2line"] = hardspace($line); | ||||
| 					$listing[$index]["rev2line"] = $line; | ||||
| 				} | ||||
| 				else { | ||||
| 				else  | ||||
| 				{ | ||||
| 					//$listing[$index]["rev2line"] = " "; | ||||
| 					$listing[$index]["rev2line"] = ''; | ||||
| 				} | ||||
|  | ||||
| @ -3,8 +3,10 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/code.css')?>" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/prettify/prettify.js')?>"></script> | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/prettify/lang-ada.js')?>"></script> | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/prettify/lang-basic.js')?>"></script> | ||||
|  | ||||
| @ -3,8 +3,10 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/code.css')?>" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/prettify/prettify.js')?>"></script> | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/prettify/lang-css.js')?>"></script> | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/prettify/lang-lisp.js')?>"></script> | ||||
| @ -152,7 +154,7 @@ function format_diff2 ($a, $b, $css_class) | ||||
| 	$ms = codepot_find_matching_sequences ($a, $b); | ||||
| 	$ms_count = count($ms); | ||||
|  | ||||
|         $k = 0; | ||||
| 	$k = 0; | ||||
| 	$cc = '';  | ||||
|  | ||||
| 	if ($css_class == 'diffchangedold') | ||||
| @ -188,7 +190,7 @@ function format_diff2 ($a, $b, $css_class) | ||||
| 				$cc .= '</span>'; | ||||
| 			} | ||||
| 			$cc .= htmlspecialchars(substr($b, $mp2, $ml)); | ||||
| 			$k = $mp2 + $ml;	 | ||||
| 			$k = $mp2 + $ml; | ||||
| 		} | ||||
| 		if ($k < strlen($b))  | ||||
| 		{ | ||||
| @ -383,126 +385,125 @@ else | ||||
| 	$http_user_agent = $_SERVER['HTTP_USER_AGENT'];  | ||||
| 	$is_msie = (stristr($http_user_agent, 'MSIE') !== FALSE &&  | ||||
| 	            stristr($http_user_agent, 'Opera') === FALSE); | ||||
| 	if (!$is_msie) | ||||
| 	{ | ||||
| 		$is_msie = (preg_match ("/^Mozilla.+\(Windows.+\) like Gecko$/", $http_user_agent) !== FALSE); | ||||
| 	} | ||||
| 	if (!$is_msie) $is_msie = (preg_match ("/^Mozilla.+\(Windows.+\) like Gecko$/", $http_user_agent) !== FALSE); | ||||
|  | ||||
| 	$diff_view = $fullview? 'fulldiff': 'diff'; | ||||
|  | ||||
| 	print '<div style="width: 100%; overflow: hidden;" id="code_diff_mainarea_result_fullview">'; | ||||
|  | ||||
| 	if (empty($file['content'])) | ||||
| 	// | ||||
| 	// SHOW THE OLD FILE | ||||
| 	// | ||||
| 	print ("<div style='float:left; width: 49%;'>"); | ||||
|  | ||||
| 	print "<div class='navigator'>"; | ||||
| 	$currev = $file['created_rev']; | ||||
| 	$prevrev = $file['against']['prev_rev']; | ||||
| 	$prevanc = "code/{$diff_view}/{$project->id}/{$xpar}/{$currev}/{$prevrev}"; | ||||
|  | ||||
| 	print anchor ($prevanc, '<<'); | ||||
| 	print '   '; | ||||
|  | ||||
| 	// show the history details of the previous revision at the root directory | ||||
| 	$revanc = "code/revision/{$project->id}/!/{$prevrev}"; | ||||
| 	print anchor ($revanc, ($this->lang->line('Revision') . ' ' . $file['against']['created_rev'])); | ||||
|  | ||||
| 	$currev = $file['created_rev']; | ||||
| 	$nextrev = $file['against']['next_rev']; | ||||
| 	$nextanc = "code/{$diff_view}/{$project->id}/{$xpar}/{$currev}/{$nextrev}"; | ||||
| 	print '   '; | ||||
| 	print anchor ($nextanc, '>>'); | ||||
| 	print "</div>"; | ||||
|  | ||||
| 	print "<pre class='prettyprint lang-{$fileext}' style='width: 100%' id='code_diff_mainarea_result_fulldiffold'>"; | ||||
|  | ||||
| 	foreach ($file['content'] as $x) | ||||
| 	{ | ||||
| 		print htmlspecialchars ($this->lang->line('MSG_NO_DIFF')); | ||||
| 		if (array_key_exists('rev2line', $x))  | ||||
| 		{ | ||||
| 			$diffclass = array_key_exists('rev1diffclass', $x)? $x['rev1diffclass']: 'diff'; | ||||
| 			print "<span class='{$diffclass}'>"; | ||||
|  | ||||
| 			if ($diffclass == 'diffchanged') | ||||
| 			{ | ||||
| 				//$xline = format_diff ($x['rev1line'], $x['rev2line'], 'diffchangedold'); | ||||
| 				$xline = format_diff2 ($x['rev1line'], $x['rev2line'], 'diffchangedold'); | ||||
| 			} | ||||
| 			else  | ||||
| 			{ | ||||
| 				$xline = htmlspecialchars($x['rev1line']); | ||||
| 			} | ||||
|  | ||||
| 			if ($is_msie && $xline == '') $xline = ' '; | ||||
| 			print $xline; | ||||
| 			print "</span>\n"; | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			print "<span class='diffrow'> "; | ||||
| 			print $x['rev1lineno']; | ||||
| 			print " </span>\n"; | ||||
| 		} | ||||
| 	} | ||||
| 	else | ||||
| 	printf ("</div>"); | ||||
| 	print '</pre>'; | ||||
|  | ||||
| 	// | ||||
| 	// SHOW THE NEW FILE | ||||
| 	// | ||||
| 	print ("<div style='float:left; width: 49%;'>"); | ||||
|  | ||||
| 	print "<div class='navigator'>"; | ||||
| 	$currev = $file['against']['created_rev']; | ||||
| 	$prevrev = $file['prev_rev']; | ||||
| 	$prevanc = "code/{$diff_view}/{$project->id}/{$xpar}/{$prevrev}/{$currev}"; | ||||
| 	print anchor ($prevanc, '<<'); | ||||
| 	print '   '; | ||||
|  | ||||
| 	// show the history details of the current revision at the root directory | ||||
| 	$revanc = "code/revision/{$project->id}/!/{$currev}"; | ||||
| 	print anchor ($revanc, ($this->lang->line('Revision') . ' ' . $file['created_rev'])); | ||||
|  | ||||
| 	$currev = $file['against']['created_rev']; | ||||
| 	$nextrev = $file['next_rev']; | ||||
| 	$nextanc = "code/{$diff_view}/{$project->id}/{$xpar}/{$nextrev}/{$currev}"; | ||||
| 	print '   '; | ||||
| 	print anchor ($nextanc, '>>'); | ||||
| 	print "</div>"; | ||||
|  | ||||
| 	print "<pre class='prettyprint lang-{$fileext}' style='width: 100%' id='code_diff_mainarea_result_fulldiffnew'>"; | ||||
| 	foreach ($file['content'] as $x) | ||||
| 	{ | ||||
| 		print ("<div style='float:left; width: 49%;'>"); | ||||
|  | ||||
| 		print "<div class='navigator'>"; | ||||
| 		$currev = $file['created_rev']; | ||||
| 		$prevrev = $file['against']['prev_rev']; | ||||
| 		$prevanc = "code/fulldiff/{$project->id}/{$xpar}/{$currev}/{$prevrev}"; | ||||
| 		print anchor ($prevanc, '<<'); | ||||
| 		print '   '; | ||||
|  | ||||
| 		print $this->lang->line('Revision'); | ||||
| 		print ' '; | ||||
| 		print $file['against']['created_rev']; | ||||
|  | ||||
| 		$currev = $file['created_rev']; | ||||
| 		$nextrev = $file['against']['next_rev']; | ||||
| 		$nextanc = "code/fulldiff/{$project->id}/{$xpar}/{$currev}/{$nextrev}"; | ||||
| 		print '   '; | ||||
| 		print anchor ($nextanc, '>>'); | ||||
| 		print "</div>"; | ||||
|  | ||||
| 		print "<pre class='prettyprint lang-{$fileext}' style='width: 100%' id='code_diff_mainarea_result_fulldiffold'>"; | ||||
|  | ||||
| 		foreach ($file['content'] as $x) | ||||
| 		if (array_key_exists('rev2line', $x))  | ||||
| 		{ | ||||
| 			if (array_key_exists('rev2line', $x))  | ||||
| 			{ | ||||
| 				$diffclass = array_key_exists('rev1diffclass', $x)? $x['rev1diffclass']: 'diff'; | ||||
| 				print "<span class='{$diffclass}'>"; | ||||
| 			$diffclass = array_key_exists('rev2diffclass', $x)? $x['rev2diffclass']: 'diff'; | ||||
|  | ||||
| 				if ($diffclass == 'diffchanged') | ||||
| 				{ | ||||
| 					//$xline = format_diff ($x['rev1line'], $x['rev2line'], 'diffchangedold'); | ||||
| 					$xline = format_diff2 ($x['rev1line'], $x['rev2line'], 'diffchangedold'); | ||||
| 				} | ||||
| 				else  | ||||
| 				{ | ||||
| 					$xline = htmlspecialchars($x['rev1line']); | ||||
| 				} | ||||
| 			print "<span class='{$diffclass}'>"; | ||||
|  | ||||
| 				if ($is_msie && $xline == '') $xline = ' '; | ||||
| 				print $xline; | ||||
| 				print "</span>\n"; | ||||
| 			} | ||||
| 			else | ||||
| 			if ($diffclass == 'diffchanged') | ||||
| 			{ | ||||
| 				print "<span class='diffrow'> "; | ||||
| 				print $x['rev1lineno']; | ||||
| 				print " </span>\n"; | ||||
| 				//$xline = format_diff ($x['rev2line'], $x['rev1line'], 'diffchangednew'); | ||||
| 				$xline = format_diff2 ($x['rev1line'], $x['rev2line'], 'diffchangednew'); | ||||
| 			} | ||||
| 			else  | ||||
| 			{ | ||||
| 				$xline = htmlspecialchars($x['rev2line']); | ||||
| 			} | ||||
|  | ||||
| 			if ($is_msie && $xline == '') $xline = ' '; | ||||
| 			print $xline; | ||||
| 			print "</span>\n"; | ||||
| 		} | ||||
| 		printf ("</div>"); | ||||
| 		print '</pre>'; | ||||
|  | ||||
| 		print ("<div style='float:left; width: 49%;'>"); | ||||
|  | ||||
| 		print "<div class='navigator'>"; | ||||
| 		$currev = $file['against']['created_rev']; | ||||
| 		$prevrev = $file['prev_rev']; | ||||
| 		$prevanc = "code/fulldiff/{$project->id}/{$xpar}/{$prevrev}/{$currev}"; | ||||
| 		print anchor ($prevanc, '<<'); | ||||
| 		print '   '; | ||||
|  | ||||
| 		print $this->lang->line('Revision'); | ||||
| 		print ' '; | ||||
| 		print $file['created_rev']; | ||||
|  | ||||
| 		$currev = $file['against']['created_rev']; | ||||
| 		$nextrev = $file['next_rev']; | ||||
| 		$nextanc = "code/fulldiff/{$project->id}/{$xpar}/{$nextrev}/{$currev}"; | ||||
| 		print '   '; | ||||
| 		print anchor ($nextanc, '>>'); | ||||
| 		print "</div>"; | ||||
|  | ||||
| 		print "<pre class='prettyprint lang-{$fileext}' style='width: 100%' id='code_diff_mainarea_result_fulldiffnew'>"; | ||||
| 		foreach ($file['content'] as $x) | ||||
| 		else | ||||
| 		{ | ||||
| 			if (array_key_exists('rev2line', $x))  | ||||
| 			{ | ||||
| 				$diffclass = array_key_exists('rev2diffclass', $x)? $x['rev2diffclass']: 'diff'; | ||||
|  | ||||
| 				print "<span class='{$diffclass}'>"; | ||||
|  | ||||
| 				if ($diffclass == 'diffchanged') | ||||
| 				{ | ||||
| 					//$xline = format_diff ($x['rev2line'], $x['rev1line'], 'diffchangednew'); | ||||
| 					$xline = format_diff2 ($x['rev1line'], $x['rev2line'], 'diffchangednew'); | ||||
| 				} | ||||
| 				else  | ||||
| 				{ | ||||
| 					$xline = htmlspecialchars($x['rev2line']); | ||||
| 				} | ||||
|  | ||||
| 				if ($is_msie && $xline == '') $xline = ' '; | ||||
| 				print $xline; | ||||
| 				print "</span>\n"; | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				print "<span class='diffrow'> "; | ||||
| 				print $x['rev2lineno']; | ||||
| 				print " </span>\n"; | ||||
| 			} | ||||
| 			print "<span class='diffrow'> "; | ||||
| 			print $x['rev2lineno']; | ||||
| 			print " </span>\n"; | ||||
| 		} | ||||
|  | ||||
| 		print '</pre>'; | ||||
| 		printf ("</div>"); | ||||
| 	} | ||||
|  | ||||
| 	print '</pre>'; | ||||
| 	printf ("</div>"); | ||||
| 	print '</div>'; | ||||
| } | ||||
| ?> | ||||
|  | ||||
| @ -3,8 +3,10 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/code.css')?>" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/prettify/prettify.js')?>"></script> | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/prettify/lang-ada.js')?>"></script> | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/prettify/lang-basic.js')?>"></script> | ||||
|  | ||||
| @ -5,6 +5,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/code.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/code.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/code.css')?>" /> | ||||
|  | ||||
| @ -205,7 +206,7 @@ function hide_unneeded_divs() | ||||
| } | ||||
|  | ||||
| $(function() { | ||||
| 	hide_unnddeded_divs (); | ||||
| 	hide_unneeded_divs (); | ||||
| 	render_wiki (); | ||||
| }); | ||||
|  | ||||
|  | ||||
| @ -5,6 +5,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/code.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -4,6 +4,8 @@ | ||||
|  | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/project.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/file.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/file.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -5,6 +5,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/file.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/file.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -7,6 +7,7 @@ | ||||
| <meta name="keywords" content="<?php print $project->id?>" /> | ||||
| <meta name="description" content="<?php print htmlspecialchars($project->summary)?>" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/project.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/issue.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/issue.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -5,6 +5,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/issue.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -2,6 +2,8 @@ | ||||
|  | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/issue.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/log.css')?>" /> | ||||
|       | ||||
| @ -144,7 +145,7 @@ $this->load->view ( | ||||
|  | ||||
| <?php endif; ?> | ||||
|  | ||||
| <div id="log_mainarea_result"> | ||||
| <div id="log_mainarea_result" class="result"> | ||||
|  | ||||
| <table id="log_mainarea_result_table"> | ||||
| <?php  | ||||
|  | ||||
| @ -2,6 +2,7 @@ | ||||
|  | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/jquery.min.js')?>"></script> | ||||
|  | ||||
| @ -3,6 +3,8 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/project.css')?>" /> | ||||
|  | ||||
| @ -11,18 +13,120 @@ | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/jquery-ui.css')?>" /> | ||||
|  | ||||
| <script type="text/javascript"> | ||||
| function AsciiToHex (x) { | ||||
| 	var r=""; | ||||
| 	for(i=0; i<x.length; i++) | ||||
|  | ||||
| var site_url = "<?php print site_url(); ?>"; | ||||
| var total_num_avail = <?php print $total_num_projects; ?>;  | ||||
| var total_num_shown = <?php print count($projects); ?>;  | ||||
| var req_page_offset = <?php print $req_page_offset; ?>; | ||||
| var req_page_size = <?php print $req_page_size; ?>; | ||||
|  | ||||
| function prepare_page_button (i, req_size) | ||||
| { | ||||
| 	var id = "#project_catalog_mainarea_result_list_page_" + i; | ||||
| 	var b = $(id).button(); | ||||
|  | ||||
| 	b.click ( | ||||
| 		function ()  | ||||
| 		{ | ||||
| 			var filter = codepot_ascii_to_hex($('#project_search_form').serialize()); | ||||
| 			var offset = parseInt($(this).text()); | ||||
| 			$.ajax({ | ||||
| 				url: "<?php print site_url(); ?>/project/catalog_json/" + filter + "/" + ((offset  - 1) * req_size), | ||||
| 				dataType: "json", | ||||
| 				success: function(data) { render_project_list (data); } | ||||
| 			}); | ||||
| 		} | ||||
| 	); | ||||
|  | ||||
| 	return b; | ||||
| 	 | ||||
| } | ||||
| function render_project_pages (total, shown, req_offset, req_size) | ||||
| { | ||||
| 	var pages = ""; | ||||
|  | ||||
| 	if (req_size <= 0) req_size = 1; | ||||
| 	var num_pages = parseInt((total + req_size - 1) / req_size); | ||||
| 	var page_no = parseInt(req_offset / req_size) + 1; | ||||
|  | ||||
| 	var max_page_buttons = 10; | ||||
| 	var page_no_start = page_no, page_no_stop = page_no; | ||||
| 	var button_count = 1; | ||||
| 	while (button_count < max_page_buttons) | ||||
| 	{ | ||||
| 		var tmp = x.charCodeAt(i).toString(16); | ||||
| 		if (tmp.length == 1) r += "0"; | ||||
| 		r += tmp; | ||||
| 		var j = button_count; | ||||
| 		if (page_no_start > 1 && button_count < max_page_buttons)  | ||||
| 		{ | ||||
| 			page_no_start--; | ||||
| 			button_count++; | ||||
| 		} | ||||
| 		if (page_no_stop < num_pages && button_count < max_page_buttons)  | ||||
| 		{ | ||||
| 			page_no_stop++; | ||||
| 			button_count++; | ||||
| 		} | ||||
|  | ||||
| 		if (j == button_count) break; // no change | ||||
| 	} | ||||
| 	return r; | ||||
|  | ||||
| 	if (page_no_start > 1)  | ||||
| 	{ | ||||
| 		pages = pages + "<a href='#' id='project_catalog_mainarea_result_list_page_1'>1</a>"; | ||||
| 		if (page_no_start > 2) pages = pages + " ... "; | ||||
| 	} | ||||
|  | ||||
| 	for (i = page_no_start; i <= page_no_stop; i++) | ||||
| 	{ | ||||
| 		pages = pages + " <a href='#' id='project_catalog_mainarea_result_list_page_" + i + "'>" + i + "</a>"; | ||||
| 	} | ||||
|  | ||||
| 	if (page_no_stop < num_pages)  | ||||
| 	{ | ||||
| 		if (page_no_stop + 1 < num_pages) pages = pages +  " ... "; | ||||
| 		pages = pages + " <a href='#' id='project_catalog_mainarea_result_list_page_" + num_pages + "'>" + num_pages + "</a>"; | ||||
| 	} | ||||
|  | ||||
| 	$("#project_catalog_mainarea_result_pages").empty(); | ||||
| 	$("#project_catalog_mainarea_result_pages").append(pages); | ||||
|  | ||||
| 	if (page_no_start > 1) prepare_page_button (1, req_size); | ||||
| 	for (i = page_no_start; i <= page_no_stop; i++) | ||||
| 	{ | ||||
| 		var b = prepare_page_button (i, req_size); | ||||
| 		if (i == page_no) b.addClass ("ui-state-active"); | ||||
| 	} | ||||
| 	if (page_no_stop < num_pages) prepare_page_button (num_pages); | ||||
| } | ||||
|  | ||||
| function render_project_list (json) | ||||
| { | ||||
| 	if (json.status == 'ok') | ||||
| 	{ | ||||
| 		var status = json.status; | ||||
| 		var list = $("#project_catalog_mainarea_result_list"); | ||||
| 		list.empty (); // empty the list first. | ||||
| 		for (i = 0; i < json.projects.length; i++) | ||||
| 		{ | ||||
| 			var p = json.projects[i]; | ||||
|  | ||||
| 			var cap = p.name + " (" + p.id + ")"; | ||||
| 			var li = codepot_sprintf ("<li><a href='%s/project/home/%s'>%s</a> - %s</li>", site_url, p.id, cap, p.summary); | ||||
| 			list.append (li); // TODO: html escaping of p.id and p.name | ||||
| 		} | ||||
|  | ||||
| 		render_project_pages (parseInt(json.total_num_projects), parseInt(json.projects.length), parseInt(json.req_page_offset), parseInt(json.req_page_size)); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		/* TODO:  show error */ | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| $(function () {  | ||||
| /* | ||||
| 	$("#project_catalog_mainarea_search_form").dialog ({ | ||||
| 		title: '<?php print $this->lang->line('Search')?>', | ||||
| 		autoOpen: false, | ||||
| @ -31,8 +135,8 @@ $(function () { | ||||
| 		buttons: {  | ||||
| 			'<?php print $this->lang->line('OK')?>': function () {  | ||||
| 				$(this).dialog('close');  | ||||
| 				var filter = AsciiToHex($('#project_search_form').serialize()); | ||||
| 				var url='<?php print site_url()?>/project/catalog/' + filter;	 | ||||
| 				var filter = codepot_ascii_to_hex($('#project_search_form').serialize()); | ||||
| 				var url='<?php print site_url()?>/project/catalog/' + filter; | ||||
|  | ||||
| 				$('body').append('<form id="magic_form" method="get" action="'+url+'"></form>'); | ||||
| 				$('#magic_form').submit(); | ||||
| @ -44,13 +148,31 @@ $(function () { | ||||
| 		close: function() {} | ||||
| 	});  | ||||
|  | ||||
|  | ||||
| 	$("#project_catalog_mainarea_search_button").button().click ( | ||||
| 		function () {  | ||||
| 			$('#project_catalog_mainarea_search_form').dialog('open');  | ||||
| 			return false; | ||||
| 		} | ||||
| 	); | ||||
| */ | ||||
|  | ||||
| 	// Empty the page indicators generated by the server side. | ||||
| 	// as i want the next page or the previous page to be loaded dynamically | ||||
| 	// without killing the original pagination available. | ||||
| 	$("#project_catalog_mainarea_result_pages").empty();  | ||||
|  | ||||
| 	$("#project_catalog_mainarea_search_button").button().click ( | ||||
| 		function () {  | ||||
| 			var filter = codepot_ascii_to_hex($('#project_search_form').serialize()); | ||||
| 			$.ajax({ | ||||
| 				url: "<?php print site_url(); ?>/project/catalog_json/" + filter, | ||||
| 				dataType: "json", | ||||
| 				success: function(data) { render_project_list (data); } | ||||
| 			}); | ||||
| 		} | ||||
| 	); | ||||
|  | ||||
| 	render_project_pages (total_num_avail, total_num_shown, req_page_offset, req_page_size); | ||||
| }); | ||||
| </script> | ||||
|  | ||||
| @ -92,36 +214,36 @@ $this->load->view ( | ||||
| <div class="mainarea" id="project_catalog_mainarea"> | ||||
|  | ||||
| <div class="infostrip"> | ||||
| <?php printf ($this->lang->line('PROJECT_MSG_TOTAL_NUM_PROJECTS'), $total_num_projects); ?> |  | ||||
| <a id="project_catalog_mainarea_search_button" href='#'><?php print $this->lang->line('Search')?></a> | ||||
| <?php  | ||||
| 	printf ($this->lang->line('PROJECT_MSG_TOTAL_NUM_PROJECTS'), $total_num_projects);  | ||||
| 	print ' | '; | ||||
| 	printf ('<a id="project_catalog_mainarea_search_button" href="#">%s</a>', $this->lang->line('Search')); | ||||
| ?> | ||||
| </div> | ||||
|  | ||||
| <div id="project_catalog_mainarea_search_form"> | ||||
| 	<form id="project_search_form"> | ||||
| 		<div> | ||||
| 			<?php print form_label ($this->lang->line('ID'), 'id') | ||||
| 			?> | ||||
| 			<?php print form_input('id', | ||||
| 				set_value('owner', $search->id), | ||||
| 				'id="project_search_id"') | ||||
| 		<div id="project_search_form_id"> | ||||
| 			<?php | ||||
| 			print form_label($this->lang->line('ID'), 'id'); | ||||
| 			print ' '; | ||||
| 			print form_input('id', set_value('owner', $search->id), 'id="project_search_id"'); | ||||
| 			?> | ||||
| 		</div> | ||||
|  | ||||
| 		<div> | ||||
| 			<?php print form_label ($this->lang->line('Name'), 'name') | ||||
| 			?> | ||||
| 			<?php print form_input('name', | ||||
| 				set_value('owner', $search->name), | ||||
| 				'id="project_search_name"') | ||||
| 		<div id="project_search_form_name"> | ||||
| 			<?php | ||||
| 			print form_label($this->lang->line('Name'), 'name'); | ||||
| 			print ' '; | ||||
| 			print form_input('name', set_value('owner', $search->name), 'id="project_search_name"'); | ||||
| 			?> | ||||
| 		</div> | ||||
|  | ||||
| 		<div> | ||||
| 			<?php print form_label ($this->lang->line('Summary'), 'summary') | ||||
| 			?> | ||||
| 			<?php print form_input('summary', | ||||
| 				set_value('summary', $search->summary), | ||||
| 				'id="project_search_summary" size="50"') | ||||
| 		<div id="project_search_form_summary"> | ||||
| 			<?php  | ||||
| 			print form_label($this->lang->line('Summary'), 'summary'); | ||||
| 			print ' '; | ||||
| 			print form_input('summary', set_value('summary', $search->summary), 'id="project_search_summary" size="50"'); | ||||
| 			?> | ||||
| 		</div> | ||||
|  | ||||
| @ -137,44 +259,7 @@ if (empty($projects)) | ||||
| } | ||||
| else | ||||
| { | ||||
| /* | ||||
| 	print '<table id="project_catalog_mainarea_result_table">'; | ||||
| 	print '<tr class="heading">'; | ||||
| 	print '<th class="id">' . $this->lang->line('ID') . '</th>'; | ||||
| 	print '<th class="name">' . $this->lang->line('Name') . '</th>'; | ||||
| 	print '<th class="summary">' . $this->lang->line('Summary') . '</th>'; | ||||
| 	print '</tr>'; | ||||
|  | ||||
| 	$rowclasses = array ("even", "odd"); | ||||
| 	$rownum = 0; | ||||
| 	foreach ($projects as $project) | ||||
| 	{ | ||||
| 		$rowclass = $rowclasses[++$rownum % 2]; | ||||
| 		print "<tr class='{$rowclass}'>"; | ||||
|  | ||||
| 		print '<td class="id">'; | ||||
| 		print anchor ("project/home/{$project->id}",  | ||||
| 			htmlspecialchars($project->id)); | ||||
| 		print '</td>'; | ||||
|  | ||||
| 		print '<td class="name">'; | ||||
| 		print htmlspecialchars($project->name); | ||||
| 		print '</td>'; | ||||
|  | ||||
| 		print '<td class="summary">'; | ||||
| 		print htmlspecialchars($project->summary); | ||||
| 		print '</td>'; | ||||
|  | ||||
| 		print '</tr>'; | ||||
| 	} | ||||
|  | ||||
| 	print '<tr class="foot">'; | ||||
| 	print "<td colspan='3' class='pages'>{$page_links}</td>"; | ||||
| 	print '</tr>'; | ||||
|  | ||||
| 	print '</table>'; | ||||
| */ | ||||
| 	print '<ul>'; | ||||
| 	print '<ul id="project_catalog_mainarea_result_list">'; | ||||
| 	foreach ($projects as $project) | ||||
| 	{ | ||||
| 		$cap = "{$project->name} ({$project->id})"; | ||||
| @ -183,7 +268,8 @@ else | ||||
| 		print "<li>{$anc} - {$sum}</li>"; | ||||
| 	} | ||||
| 	print '</ul>'; | ||||
| 	print "<span class='pages'>{$page_links}</span>"; | ||||
|  | ||||
| 	print "<div class='pages' id='project_catalog_mainarea_result_pages'>{$page_links}</div>"; | ||||
| } | ||||
| ?> | ||||
| </div> <!-- project_catalog_mainarea_result --> | ||||
|  | ||||
| @ -4,6 +4,7 @@ | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
| <meta name="keywords" content="<?php print $project->id?>" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/project.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/project.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -7,6 +7,7 @@ | ||||
| <meta name="keywords" content="<?php print $project->id?>" /> | ||||
| <meta name="description" content="<?php print htmlspecialchars($project->summary)?>" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/project.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/site.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/site.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/site.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -5,6 +5,7 @@ | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
| <meta name="keywords" content="codepot" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/site.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/site.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -158,15 +158,18 @@ $(function () { | ||||
| 	$("#taskbar_project_to_find").button().autocomplete({ | ||||
| 		minLength: 1, // is this too small? | ||||
| 		source: function (request, response) { | ||||
|  | ||||
| 			var term = codepot_string_to_hex(request.term); | ||||
|  | ||||
| 			$.ajax({ | ||||
| 				url: "<?php print site_url(); ?>/project/search_json/" + request.term, | ||||
| 				url: "<?php print site_url(); ?>/project/quickfind_json/" + term, | ||||
| 				dataType: "json", | ||||
| 				success: function(data) { response(data); }, | ||||
| 			}); | ||||
| 		}, | ||||
| 		select: function( event, ui ) { | ||||
| 			$(location).attr ('href', "<?php print site_url(); ?>/project/home/" + ui.item.id); | ||||
| 			//ui.item.value , ui.item.id ,  this.value ); | ||||
| 			//ui.item.value , ui.item.id ,  this.value | ||||
| 		} | ||||
| 	}); | ||||
| }); | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/user.css')?>" /> | ||||
|       | ||||
| @ -60,7 +61,7 @@ $num_issues = count($issues); | ||||
| $num_activities = 0; | ||||
| ?> | ||||
|  | ||||
| <div id="user_home_mainarea_result"> | ||||
| <div id="user_home_mainarea_result" class="result"> | ||||
|  | ||||
|  | ||||
| <div id="tabs"> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/user.css')?>" /> | ||||
|       | ||||
| @ -59,7 +60,7 @@ $this->load->view ( | ||||
| 		print "<div id='user_settings_mainarea_message' class='form_message'>$message</div>"; | ||||
| ?> | ||||
|  | ||||
| <div id="user_settings_mainarea_result"> | ||||
| <div id="user_settings_mainarea_result" class="result"> | ||||
|  | ||||
| <div class="form_container"> | ||||
| <?php print form_open_multipart('user/settings/')?> | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/wiki.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/wiki.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -5,6 +5,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/wiki.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| <head> | ||||
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||||
|  | ||||
| <script type="text/javascript" src="<?php print base_url_make('/js/codepot.js')?>"></script> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/common.css')?>" /> | ||||
| <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/wiki.css')?>" /> | ||||
|  | ||||
|  | ||||
| @ -57,25 +57,15 @@ | ||||
| 	overflow: auto; | ||||
| } | ||||
|  | ||||
| #project_catalog_mainarea_result_table { | ||||
| 	width: 100%; | ||||
| } | ||||
|  | ||||
| #project_catalog_mainarea_result_table td { | ||||
| #project_catalog_mainarea_result_list { | ||||
| 	margin: 1em; | ||||
| 	padding: 1em; | ||||
| 	white-space: nowrap; | ||||
| 	vertical-align: top; | ||||
| 	line-height: 1.5em; | ||||
| } | ||||
|  | ||||
| #project_catalog_mainarea_result_table td.id { | ||||
| 	width: 1px; | ||||
| } | ||||
|  | ||||
| #project_catalog_mainarea_result_table td.name { | ||||
| 	width: 1px; | ||||
| } | ||||
|  | ||||
| #project_catalog_mainarea_result_table td.summary { | ||||
| 	white-space: pre-wrap; | ||||
| #project_catalog_mainarea_result_pages { | ||||
| 	margin: 1em; | ||||
| } | ||||
|  | ||||
| /*-----------------------------------------------  | ||||
|  | ||||
| @ -2,6 +2,7 @@ SUBDIRS =  prettify | ||||
|  | ||||
| wwwdir=$(WWWDIR)/js | ||||
| www_DATA = \ | ||||
| 	codepot.js \ | ||||
| 	creole.js  \ | ||||
| 	jquery.min.js \ | ||||
| 	jquery-ui.min.js \ | ||||
|  | ||||
							
								
								
									
										374
									
								
								codepot/src/js/codepot.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										374
									
								
								codepot/src/js/codepot.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,374 @@ | ||||
| function codepot_utf8_encode(argString) { | ||||
|   //  discuss at: http://phpjs.org/functions/utf8_encode/ | ||||
|   // original by: Webtoolkit.info (http://www.webtoolkit.info/) | ||||
|   // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | ||||
|   // improved by: sowberry | ||||
|   // improved by: Jack | ||||
|   // improved by: Yves Sucaet | ||||
|   // improved by: kirilloid | ||||
|   // bugfixed by: Onno Marsman | ||||
|   // bugfixed by: Onno Marsman | ||||
|   // bugfixed by: Ulrich | ||||
|   // bugfixed by: Rafal Kukawski | ||||
|   // bugfixed by: kirilloid | ||||
|   //   example 1: utf8_encode('Kevin van Zonneveld'); | ||||
|   //   returns 1: 'Kevin van Zonneveld' | ||||
|  | ||||
|   if (argString === null || typeof argString === 'undefined') { | ||||
|     return ''; | ||||
|   } | ||||
|  | ||||
|   var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n"); | ||||
|   var utftext = '', | ||||
|     start, end, stringl = 0; | ||||
|  | ||||
|   start = end = 0; | ||||
|   stringl = string.length; | ||||
|   for (var n = 0; n < stringl; n++) { | ||||
|     var c1 = string.charCodeAt(n); | ||||
|     var enc = null; | ||||
|  | ||||
|     if (c1 < 128) { | ||||
|       end++; | ||||
|     } else if (c1 > 127 && c1 < 2048) { | ||||
|       enc = String.fromCharCode( | ||||
|         (c1 >> 6) | 192, (c1 & 63) | 128 | ||||
|       ); | ||||
|     } else if ((c1 & 0xF800) != 0xD800) { | ||||
|       enc = String.fromCharCode( | ||||
|         (c1 >> 12) | 224, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128 | ||||
|       ); | ||||
|     } else { // surrogate pairs | ||||
|       if ((c1 & 0xFC00) != 0xD800) { | ||||
|         throw new RangeError('Unmatched trail surrogate at ' + n); | ||||
|       } | ||||
|       var c2 = string.charCodeAt(++n); | ||||
|       if ((c2 & 0xFC00) != 0xDC00) { | ||||
|         throw new RangeError('Unmatched lead surrogate at ' + (n - 1)); | ||||
|       } | ||||
|       c1 = ((c1 & 0x3FF) << 10) + (c2 & 0x3FF) + 0x10000; | ||||
|       enc = String.fromCharCode( | ||||
|         (c1 >> 18) | 240, ((c1 >> 12) & 63) | 128, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128 | ||||
|       ); | ||||
|     } | ||||
|     if (enc !== null) { | ||||
|       if (end > start) { | ||||
|         utftext += string.slice(start, end); | ||||
|       } | ||||
|       utftext += enc; | ||||
|       start = end = n + 1; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   if (end > start) { | ||||
|     utftext += string.slice(start, stringl); | ||||
|   } | ||||
|  | ||||
|   return utftext; | ||||
| } | ||||
|  | ||||
|  | ||||
| function codepot_utf8_decode(str_data) { | ||||
|   //  discuss at: http://phpjs.org/functions/utf8_decode/ | ||||
|   // original by: Webtoolkit.info (http://www.webtoolkit.info/) | ||||
|   //    input by: Aman Gupta | ||||
|   //    input by: Brett Zamir (http://brett-zamir.me) | ||||
|   // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | ||||
|   // improved by: Norman "zEh" Fuchs | ||||
|   // bugfixed by: hitwork | ||||
|   // bugfixed by: Onno Marsman | ||||
|   // bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | ||||
|   // bugfixed by: kirilloid | ||||
|   //   example 1: utf8_decode('Kevin van Zonneveld'); | ||||
|   //   returns 1: 'Kevin van Zonneveld' | ||||
|  | ||||
|   var tmp_arr = [], | ||||
|     i = 0, | ||||
|     ac = 0, | ||||
|     c1 = 0, | ||||
|     c2 = 0, | ||||
|     c3 = 0, | ||||
|     c4 = 0; | ||||
|  | ||||
|   str_data += ''; | ||||
|  | ||||
|   while (i < str_data.length) { | ||||
|     c1 = str_data.charCodeAt(i); | ||||
|     if (c1 <= 191) { | ||||
|       tmp_arr[ac++] = String.fromCharCode(c1); | ||||
|       i++; | ||||
|     } else if (c1 <= 223) { | ||||
|       c2 = str_data.charCodeAt(i + 1); | ||||
|       tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63)); | ||||
|       i += 2; | ||||
|     } else if (c1 <= 239) { | ||||
|       // http://en.wikipedia.org/wiki/UTF-8#Codepage_layout | ||||
|       c2 = str_data.charCodeAt(i + 1); | ||||
|       c3 = str_data.charCodeAt(i + 2); | ||||
|       tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); | ||||
|       i += 3; | ||||
|     } else { | ||||
|       c2 = str_data.charCodeAt(i + 1); | ||||
|       c3 = str_data.charCodeAt(i + 2); | ||||
|       c4 = str_data.charCodeAt(i + 3); | ||||
|       c1 = ((c1 & 7) << 18) | ((c2 & 63) << 12) | ((c3 & 63) << 6) | (c4 & 63); | ||||
|       c1 -= 0x10000; | ||||
|       tmp_arr[ac++] = String.fromCharCode(0xD800 | ((c1 >> 10) & 0x3FF)); | ||||
|       tmp_arr[ac++] = String.fromCharCode(0xDC00 | (c1 & 0x3FF)); | ||||
|       i += 4; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   return tmp_arr.join(''); | ||||
| } | ||||
|  | ||||
| function codepot_sprintf() { | ||||
|   //  discuss at: http://phpjs.org/functions/sprintf/ | ||||
|   // original by: Ash Searle (http://hexmen.com/blog/) | ||||
|   // improved by: Michael White (http://getsprink.com) | ||||
|   // improved by: Jack | ||||
|   // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | ||||
|   // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | ||||
|   // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | ||||
|   // improved by: Dj | ||||
|   // improved by: Allidylls | ||||
|   //    input by: Paulo Freitas | ||||
|   //    input by: Brett Zamir (http://brett-zamir.me) | ||||
|   //   example 1: sprintf("%01.2f", 123.1); | ||||
|   //   returns 1: 123.10 | ||||
|   //   example 2: sprintf("[%10s]", 'monkey'); | ||||
|   //   returns 2: '[    monkey]' | ||||
|   //   example 3: sprintf("[%'#10s]", 'monkey'); | ||||
|   //   returns 3: '[####monkey]' | ||||
|   //   example 4: sprintf("%d", 123456789012345); | ||||
|   //   returns 4: '123456789012345' | ||||
|   //   example 5: sprintf('%-03s', 'E'); | ||||
|   //   returns 5: 'E00' | ||||
|  | ||||
|   var regex = /%%|%(\d+\$)?([-+\'#0 ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([scboxXuideEfFgG])/g; | ||||
|   var a = arguments; | ||||
|   var i = 0; | ||||
|   var format = a[i++]; | ||||
|  | ||||
|   // pad() | ||||
|   var pad = function (str, len, chr, leftJustify) { | ||||
|     if (!chr) { | ||||
|       chr = ' '; | ||||
|     } | ||||
|     var padding = (str.length >= len) ? '' : new Array(1 + len - str.length >>> 0) | ||||
|       .join(chr); | ||||
|     return leftJustify ? str + padding : padding + str; | ||||
|   }; | ||||
|  | ||||
|   // justify() | ||||
|   var justify = function (value, prefix, leftJustify, minWidth, zeroPad, customPadChar) { | ||||
|     var diff = minWidth - value.length; | ||||
|     if (diff > 0) { | ||||
|       if (leftJustify || !zeroPad) { | ||||
|         value = pad(value, minWidth, customPadChar, leftJustify); | ||||
|       } else { | ||||
|         value = value.slice(0, prefix.length) + pad('', diff, '0', true) + value.slice(prefix.length); | ||||
|       } | ||||
|     } | ||||
|     return value; | ||||
|   }; | ||||
|  | ||||
|   // formatBaseX() | ||||
|   var formatBaseX = function (value, base, prefix, leftJustify, minWidth, precision, zeroPad) { | ||||
|     // Note: casts negative numbers to positive ones | ||||
|     var number = value >>> 0; | ||||
|     prefix = prefix && number && { | ||||
|       '2': '0b', | ||||
|       '8': '0', | ||||
|       '16': '0x' | ||||
|     }[base] || ''; | ||||
|     value = prefix + pad(number.toString(base), precision || 0, '0', false); | ||||
|     return justify(value, prefix, leftJustify, minWidth, zeroPad); | ||||
|   }; | ||||
|  | ||||
|   // formatString() | ||||
|   var formatString = function (value, leftJustify, minWidth, precision, zeroPad, customPadChar) { | ||||
|     if (precision != null) { | ||||
|       value = value.slice(0, precision); | ||||
|     } | ||||
|     return justify(value, '', leftJustify, minWidth, zeroPad, customPadChar); | ||||
|   }; | ||||
|  | ||||
|   // doFormat() | ||||
|   var doFormat = function (substring, valueIndex, flags, minWidth, _, precision, type) { | ||||
|     var number, prefix, method, textTransform, value; | ||||
|  | ||||
|     if (substring === '%%') { | ||||
|       return '%'; | ||||
|     } | ||||
|  | ||||
|     // parse flags | ||||
|     var leftJustify = false; | ||||
|     var positivePrefix = ''; | ||||
|     var zeroPad = false; | ||||
|     var prefixBaseX = false; | ||||
|     var customPadChar = ' '; | ||||
|     var flagsl = flags.length; | ||||
|     for (var j = 0; flags && j < flagsl; j++) { | ||||
|       switch (flags.charAt(j)) { | ||||
|       case ' ': | ||||
|         positivePrefix = ' '; | ||||
|         break; | ||||
|       case '+': | ||||
|         positivePrefix = '+'; | ||||
|         break; | ||||
|       case '-': | ||||
|         leftJustify = true; | ||||
|         break; | ||||
|       case "'": | ||||
|         customPadChar = flags.charAt(j + 1); | ||||
|         break; | ||||
|       case '0': | ||||
|         zeroPad = true; | ||||
|         customPadChar = '0'; | ||||
|         break; | ||||
|       case '#': | ||||
|         prefixBaseX = true; | ||||
|         break; | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     // parameters may be null, undefined, empty-string or real valued | ||||
|     // we want to ignore null, undefined and empty-string values | ||||
|     if (!minWidth) { | ||||
|       minWidth = 0; | ||||
|     } else if (minWidth === '*') { | ||||
|       minWidth = +a[i++]; | ||||
|     } else if (minWidth.charAt(0) == '*') { | ||||
|       minWidth = +a[minWidth.slice(1, -1)]; | ||||
|     } else { | ||||
|       minWidth = +minWidth; | ||||
|     } | ||||
|  | ||||
|     // Note: undocumented perl feature: | ||||
|     if (minWidth < 0) { | ||||
|       minWidth = -minWidth; | ||||
|       leftJustify = true; | ||||
|     } | ||||
|  | ||||
|     if (!isFinite(minWidth)) { | ||||
|       throw new Error('sprintf: (minimum-)width must be finite'); | ||||
|     } | ||||
|  | ||||
|     if (!precision) { | ||||
|       precision = 'fFeE'.indexOf(type) > -1 ? 6 : (type === 'd') ? 0 : undefined; | ||||
|     } else if (precision === '*') { | ||||
|       precision = +a[i++]; | ||||
|     } else if (precision.charAt(0) == '*') { | ||||
|       precision = +a[precision.slice(1, -1)]; | ||||
|     } else { | ||||
|       precision = +precision; | ||||
|     } | ||||
|  | ||||
|     // grab value using valueIndex if required? | ||||
|     value = valueIndex ? a[valueIndex.slice(0, -1)] : a[i++]; | ||||
|  | ||||
|     switch (type) { | ||||
|     case 's': | ||||
|       return formatString(String(value), leftJustify, minWidth, precision, zeroPad, customPadChar); | ||||
|     case 'c': | ||||
|       return formatString(String.fromCharCode(+value), leftJustify, minWidth, precision, zeroPad); | ||||
|     case 'b': | ||||
|       return formatBaseX(value, 2, prefixBaseX, leftJustify, minWidth, precision, zeroPad); | ||||
|     case 'o': | ||||
|       return formatBaseX(value, 8, prefixBaseX, leftJustify, minWidth, precision, zeroPad); | ||||
|     case 'x': | ||||
|       return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad); | ||||
|     case 'X': | ||||
|       return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad) | ||||
|         .toUpperCase(); | ||||
|     case 'u': | ||||
|       return formatBaseX(value, 10, prefixBaseX, leftJustify, minWidth, precision, zeroPad); | ||||
|     case 'i': | ||||
|     case 'd': | ||||
|       number = +value || 0; | ||||
|       // Plain Math.round doesn't just truncate | ||||
|       number = Math.round(number - number % 1); | ||||
|       prefix = number < 0 ? '-' : positivePrefix; | ||||
|       value = prefix + pad(String(Math.abs(number)), precision, '0', false); | ||||
|       return justify(value, prefix, leftJustify, minWidth, zeroPad); | ||||
|     case 'e': | ||||
|     case 'E': | ||||
|     case 'f': // Should handle locales (as per setlocale) | ||||
|     case 'F': | ||||
|     case 'g': | ||||
|     case 'G': | ||||
|       number = +value; | ||||
|       prefix = number < 0 ? '-' : positivePrefix; | ||||
|       method = ['toExponential', 'toFixed', 'toPrecision']['efg'.indexOf(type.toLowerCase())]; | ||||
|       textTransform = ['toString', 'toUpperCase']['eEfFgG'.indexOf(type) % 2]; | ||||
|       value = prefix + Math.abs(number)[method](precision); | ||||
|       return justify(value, prefix, leftJustify, minWidth, zeroPad)[textTransform](); | ||||
|     default: | ||||
|       return substring; | ||||
|     } | ||||
|   }; | ||||
|  | ||||
|   return format.replace(regex, doFormat); | ||||
| } | ||||
|  | ||||
| function codepot_ascii_to_hex (x) | ||||
| { | ||||
| 	var r=""; | ||||
|  | ||||
| 	var i; | ||||
| 	/* | ||||
| 	for(i=0; i<x.length; i++) | ||||
| 	{ | ||||
| 		var tmp = x.charCodeAt(i).toString(16); | ||||
| 		if (tmp.length == 1) r += "0"; | ||||
| 		r += tmp; | ||||
| 	} | ||||
| 	*/ | ||||
|  | ||||
| 	r = "!"; // the new style conversion begins with an exclamation mark | ||||
| 	for(i = 0; i < x.length; i++) | ||||
| 	{ | ||||
| 		var seg; | ||||
| 		var c = x.charAt(i); | ||||
| 		if (c == "!") | ||||
| 		{ | ||||
| 			seg = "!!"; | ||||
| 		} | ||||
| 		else if (c == "|") | ||||
| 		{ | ||||
| 			seg = "!|"; | ||||
| 		} | ||||
| 		else if (c == "/") | ||||
| 		{ | ||||
| 			seg = "|"; | ||||
| 		} | ||||
| 		else if (c == "." || c == "_" || c == "-" ||  | ||||
| 			    c == ":" || c == "@" || c == " ") | ||||
| 		{ | ||||
| 			seg = c; | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			if (/^[A-Za-z0-9]$/.test (c)) | ||||
| 			{ | ||||
| 				seg = c; | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				var seg = x.charCodeAt(i).toString(16); | ||||
| 				if (seg.length == 1) seg = "0" + seg; | ||||
| 				seg = "!" + seg; | ||||
| 			} | ||||
| 		} | ||||
| 		r += seg; | ||||
| 	} | ||||
|  | ||||
| 	return r; | ||||
| } | ||||
|  | ||||
| function codepot_string_to_hex (x) | ||||
| { | ||||
| 	var utf8 = codepot_utf8_encode(x); | ||||
| 	return codepot_ascii_to_hex(utf8); | ||||
| } | ||||
| @ -195,6 +195,8 @@ var asciiToHex = function (x,dir) { | ||||
|  | ||||
| 	if (dir == "A2H")  | ||||
| 	{ | ||||
| 		/* codepot_ascii_to_hex provides the same functionality. | ||||
| 		 * but let me duplicate the code here for no dependency */ | ||||
| 		var i; | ||||
| 		/* | ||||
| 		for(i=0; i<x.length; i++) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user