src/cm/media/js/site/layout/base.js
changeset 0 40c8f766c9b8
child 341 053551f213fb
equal deleted inserted replaced
-1:000000000000 0:40c8f766c9b8
       
     1 // this == dom element
       
     2 onFadeEnd = function () {
       
     3 	$(this).remove() ;
       
     4 } ;
       
     5 
       
     6 _enqueueMsg = function(msg, cls, remainVisibleTime) {
       
     7 	var m = $('<span>' + msg + '</span>').addClass("f-msg-cls").addClass(cls).appendTo("#t-msg-wrapper") ;
       
     8 	if (remainVisibleTime)
       
     9 		m.parent().animate({'opacity':.95}, remainVisibleTime).fadeOut(2000, onFadeEnd) ;
       
    10 	return m ;
       
    11 	
       
    12 }
       
    13 
       
    14 enqueueMsg = function(msg) {
       
    15 	var cls = "f-msg" ;
       
    16 	var remainVisibleTime = 2000 ;
       
    17 	_enqueueMsg(msg, cls, remainVisibleTime) ;	
       
    18 }
       
    19 
       
    20 enqueueErrorMsg = function(msg) {
       
    21 	var cls = "f-msg-e" ;
       
    22 	var remainVisibleTime = 4000 ;
       
    23 	_enqueueMsg(msg, cls, remainVisibleTime) ;	
       
    24 }
       
    25 
       
    26 setCookie = function(name, value) {
       
    27 	var cookieExpire = new Date();
       
    28 	cookieExpire.setFullYear(2100, 0, 1);
       
    29 	$.cookie(name, value, {
       
    30 		'expires' :cookieExpire,
       
    31 		'path': '/'
       
    32 	});
       
    33 }
       
    34 
       
    35 /* utility function to remember form field value into cookie */
       
    36 rememberFormField = function(form_id, field_id, cookie_name) {
       
    37 	/* value gets fetched from cookie if possible */	
       
    38 	$(document).ready(function(){
       
    39 		var cookie_val = $.cookie(cookie_name); 
       
    40 		if (cookie_val) {
       
    41 			$('#' + form_id + ' #' + field_id)[0].value = cookie_val; 
       
    42 		}
       
    43 	})
       
    44 
       
    45 	/* value gets saved on submit */
       
    46 	$(document).ready(function(){
       
    47 		$('#' + form_id + ' input[type=submit]').click(function() {
       
    48 			var val = $('#' + form_id + ' #' + field_id)[0].value;
       
    49 			if (val) {
       
    50 				setCookie(cookie_name, val);
       
    51 			}
       
    52 	    });
       
    53 	})	
       
    54 }
       
    55