Halftone.php
changeset 1 87dfd1a261bd
parent 0 16db14829751
child 2 2f3b76a405ce
equal deleted inserted replaced
0:16db14829751 1:87dfd1a261bd
   252 	{
   252 	{
   253 		global $template;
   253 		global $template;
   254 		$template->preload_js(array('jquery', 'jquery-ui'));
   254 		$template->preload_js(array('jquery', 'jquery-ui'));
   255 		$template->add_header('
   255 		$template->add_header('
   256 			<style type="text/css">
   256 			<style type="text/css">
   257 				h1.halftone-title {
   257 				div.halftone {
   258 					page-break-before: always;
   258 					page-break-before: always;
   259 				}
   259 				}
   260 				span.halftone-line {
   260 				span.halftone-line {
   261 					display: block;
   261 					display: block;
   262 					padding-top: 10pt;
   262 					padding-top: 10pt;
   275 				}
   275 				}
   276 			</style>
   276 			</style>
   277 			<script type="text/javascript">
   277 			<script type="text/javascript">
   278 				addOnloadHook(function()
   278 				addOnloadHook(function()
   279 					{
   279 					{
       
   280 						$("div.halftone").get(0).style.pageBreakBefore = "auto";
   280 						$("select.halftone-key").change(function()
   281 						$("select.halftone-key").change(function()
   281 							{
   282 							{
   282 								var me = this;
   283 								var me = this;
   283 								var src = $(this.parentNode.parentNode).attr("halftone:src");
   284 								var src = $(this.parentNode.parentNode).attr("halftone:src");
   284 								ajaxPost(makeUrlNS("Special", "HalftoneRender", "transpose=" + $(this).val()) + "&tokey=" + $("option:selected", this).attr("halftone:abs"), "src=" + encodeURIComponent(src), function(ajax)
   285 								ajaxPost(makeUrlNS("Special", "HalftoneRender", "transpose=" + $(this).val()) + "&tokey=" + $("option:selected", this).attr("halftone:abs"), "src=" + encodeURIComponent(src), function(ajax)
   313 				$label = prettify_accidentals($label);
   314 				$label = prettify_accidentals($label);
   314 				$sel = $key == $i ? ' selected="selected"' : '';
   315 				$sel = $key == $i ? ' selected="selected"' : '';
   315 				$select .= sprintf("<option%s value=\"%d\" halftone:abs=\"%d\">%s</option>", $sel, $i - $key, $i, $label);
   316 				$select .= sprintf("<option%s value=\"%d\" halftone:abs=\"%d\">%s</option>", $sel, $i - $key, $i, $label);
   316 			}
   317 			}
   317 			$select .= '</select>';
   318 			$select .= '</select>';
   318 			$text = str_replace_once($whole_match, "<div class=\"halftone\" halftone:src=\"$src\"><div class=\"halftone-key-select\">$select</div><h1 class=\"halftone-title\">$song_title</h1>\n\n<div class=\"halftone-song\">\n" . $song . "</div></div>", $text);
   319 			$headid = 'song:' . sanitize_page_id($song_title);
       
   320 			$text = str_replace_once($whole_match, "<div id=\"$headid\" class=\"halftone\" halftone:src=\"$src\"><div class=\"halftone-key-select\">$select</div><h1 class=\"halftone-title\">$song_title</h1>\n\n<div class=\"halftone-song\">\n" . $song . "</div></div>", $text);
   319 		}
   321 		}
   320 	}
   322 	}
   321 }
   323 }
   322 
   324 
   323 function halftone_render_body($inner, &$chord_list, $inkey = false)
   325 function halftone_render_body($inner, &$chord_list, $inkey = false)
   324 {
   326 {
   325 	global $accidentals;
   327 	global $accidentals;
   326 	$song = '';
   328 	$song = '<div class="section">';
   327 	$chord_list = array();
   329 	$chord_list = array();
   328 	$transpose = isset($_GET['transpose']) ? intval($_GET['transpose']) : 0;
   330 	$transpose = isset($_GET['transpose']) ? intval($_GET['transpose']) : 0;
   329 	$transpose_accidental = $inkey ? $accidentals[$inkey] : false;
   331 	$transpose_accidental = $inkey ? $accidentals[$inkey] : false;
   330 	foreach ( explode("\n", $inner) as $line )
   332 	foreach ( explode("\n", $inner) as $line )
   331 	{
   333 	{
   368 			}
   370 			}
   369 			$song .= '<span class="halftone-line">' . implode("", $line_final) . "</span>\n";
   371 			$song .= '<span class="halftone-line">' . implode("", $line_final) . "</span>\n";
   370 		}
   372 		}
   371 		else if ( preg_match('/^=\s*(.+?)\s*=$/', $line, $match) )
   373 		else if ( preg_match('/^=\s*(.+?)\s*=$/', $line, $match) )
   372 		{
   374 		{
   373 			$song .= "== {$match[1]} ==\n";
   375 			$song .= "</div>\n<div class=\"section\">\n== {$match[1]} ==\n\n";
   374 		} 
   376 		} 
   375 		else if ( trim($line) == '' )
   377 		else if ( trim($line) == '' )
   376 		{
   378 		{
   377 			continue;
   379 			continue;
   378 		}
   380 		}
       
   381 		else if ( preg_match('/^\[(.+)\]$/', trim($line), $match) )
       
   382 		{
       
   383 			$song .= "<br /><strong>Jump to:</strong> {$match[1]}\n";
       
   384 		}
   379 		else
   385 		else
   380 		{
   386 		{
   381 			$song .= "$line<br />\n";
   387 			$song .= "$line<br />\n";
   382 		}
   388 		}
   383 	}
   389 	}
   384 	return $song;
   390 	return $song . '</div>';
   385 }
   391 }
   386 
   392 
   387 function page_Special_HalftoneRender()
   393 function page_Special_HalftoneRender()
   388 {
   394 {
   389 	global $accidentals;
   395 	global $accidentals;