thd/web/js/uc.common.js
changeset 104 8e4fe6f3337d
parent 103 d2af8a210f5d
child 105 c8f710cd1fb1
equal deleted inserted replaced
103:d2af8a210f5d 104:8e4fe6f3337d
     1 var uc = uc || {};
       
     2 uc.common = uc.common || {};
       
     3 
       
     4 //Ajaxify content
       
     5 uc.common.ajaxify = function (timeout) {
       
     6 	if (timeout == null) timeout = 0;
       
     7 	
       
     8 	// Fix section header width
       
     9 	// Wait a time to make sure css is loaded
       
    10 	window.setTimeout(uc.common.fixSectionStyle, timeout);
       
    11 	
       
    12 	uc.utils.ajaxifyLink(jQuery('a.ajax-post'), 'POST', function() {uc.common.ajaxify();});
       
    13 	uc.utils.ajaxifyLink(jQuery('a.ajax'), 'GET', function() {uc.common.ajaxify();});
       
    14 	uc.utils.ajaxifyLink(jQuery('.ajax a'), 'GET', function() {uc.common.ajaxify();});
       
    15 	uc.utils.ajaxifyForm(jQuery('form.ajax'), function() {uc.common.ajaxify();});
       
    16 }
       
    17 
       
    18 uc.common.fixSectionStyle = function() {
       
    19 	jQuery('.border-section').each(function(index) {
       
    20 		var jq_section = jQuery(this);
       
    21 		var section_width = jq_section.outerWidth();
       
    22 		var jq_head = jQuery('.head', jq_section);
       
    23 		var head_width = jq_head.outerWidth();
       
    24 		var jq_header = jQuery('.section-header', jq_section);
       
    25 		var header_padding = parseInt(jq_header.css('padding-left')) + parseInt(jq_header.css('padding-right')) + 2;
       
    26 		jq_header.width(section_width-head_width-header_padding);
       
    27 	});
       
    28 }
       
    29 
       
    30 // Process document after its loading
       
    31 jQuery(document).ready(function() {
       
    32 	// Cycle
       
    33 	uc.cycle.build("ul.cycle-list");
       
    34 	
       
    35 	// Ajaxify
       
    36 	uc.common.ajaxify(200);
       
    37 	
       
    38 	// Add help feature to input text
       
    39 	jQuery('input.help[type=text]').each(function(index) {
       
    40 		var jq_this = jQuery(this);
       
    41 		var help = jq_this.val();
       
    42 		jq_this.focus(function() {if (jq_this.val() == help) jq_this.val('');});
       
    43 		jq_this.blur(function() {if (jq_this.val() == '') jq_this.val(help);});
       
    44 	});
       
    45 
       
    46 	// Wrap select list. If user click on a list item, add a 'selected' class
       
    47 	uc.utils.buildSelectList(jQuery('ul.select-list'));
       
    48 	
       
    49 	// Add livesearch on search input
       
    50 	uc.search.build('#search input', 2, '#page', 316, -11);
       
    51 
       
    52 	// Form rating
       
    53 	uc.rating.build('form select.input-rating', 10);
       
    54 
       
    55 	jQuery('.form-rating').bind('rated', function () {
       
    56 		jQuery(this).submit();
       
    57 	});
       
    58 
       
    59 	// Add scrolling wrapper around image playlist
       
    60 	jQuery('.image-playlist').each(function() {
       
    61 		jq_this = jQuery(this);
       
    62 
       
    63 		if (jQuery('ul.media-list li', this).length > 4) {
       
    64 			jQuery('.scrolling', jq_this).scrollable({items: 'ul', size: 4, clickable: false, prevPage: '.rewind-page', nextPage: '.forward-page'});
       
    65 		} else {
       
    66 			jQuery('.rewind-page, .forward-page', jq_this).addClass('disabled');
       
    67 		}
       
    68 
       
    69 	});
       
    70 
       
    71 	// Instantiate all flow player
       
    72 	uc.player.build(".media-playlist");
       
    73 	
       
    74 	jQuery('a.cycle-random-list').each(function () {
       
    75 		var jq_this = jQuery(this);
       
    76 		var json_url = jq_this.attr('href');
       
    77 		jQuery.ajax({
       
    78 			url: json_url,
       
    79 			beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "application/json");},
       
    80 			complete: function (XMLHttpRequest, textStatus) {},
       
    81 			success: function (data, textStatus) {alert(data);},
       
    82 			dataType: "script"
       
    83 		})
       
    84 	});	
       
    85 });
       
    86