javascript

проверка даты на корректность, аля 30.02.2013

15.01.2013 javascript No comments , ,

function checkDay(R_BIRTHDAY_DAY, R_BIRTHDAY_MONTH, R_BIRTHDAY_YEAR){

	if(R_BIRTHDAY_DAY == '' || R_BIRTHDAY_MONTH == '' || R_BIRTHDAY_YEAR == ''){

		return false;
	}
	R_BIRTHDAY_MONTH = R_BIRTHDAY_MONTH - 1; 						
	var thisDate     = new Date(R_BIRTHDAY_YEAR, R_BIRTHDAY_MONTH , R_BIRTHDAY_DAY);
	var dayThis      = thisDate.getDate()
	var monthThis    = thisDate.getMonth()
	var yearThis     = thisDate.getFullYear()
	var errorAr      = new Array();
	
	if( R_BIRTHDAY_YEAR +'.'+ R_BIRTHDAY_MONTH +'.'+ R_BIRTHDAY_DAY != yearThis +'.'+ monthThis +'.'+ dayThis){
	
		errorAr.push( 1 ) 

	}
	
	if( errorAr.length == 0 ){
		return true;
	}else{
		return false;
	}
	
}

проверка mail javascript

14.01.2013 javascript 1 comment , , , , ,

if(EMAIL != ''){

			var checkMail = (
									EMAIL &&
									EMAIL.indexOf('@') > 0 &&
									EMAIL.toLowerCase().match(/^(?:[-a-z\d\+\*\/\?!{}`~_%&'=^$#]+(?:\.[-a-z\d\+\*\/\?!{}`~_%&'=^$#]+)*)@(?:[-a-z\d_]+\.){1,60}[a-z]{2,6}$/)
								) ? true : false;
			
			if(checkMail){
				hideError('EMAIL');
			}else{		
				showError('EMAIL');
				errorArr.push(1);
			}
		}else{
		
			showError('EMAIL');
			errorArr.push(1);
		
		}

Расчет центра Яндекс.Карты

14.12.2012 Bitrix, javascript ,

<?
 foreach($arResult["YANDEX_COORD"]["PLACEMARKS"] as $arItemKey=>$arItem)
 {
  $min_x = ($arItem["LAT"]<$min_x || !$min_x)? $arItem["LAT"] : $min_x;
  $max_x = ($arItem["LAT"]>$max_x || !$max_x)? $arItem["LAT"] : $max_x;
  $min_y = ($arItem["LON"]<$min_y || !$min_y)? $arItem["LON"] : $min_y;
  $max_y = ($arItem["LON"]>$max_y || !$max_y)? $arItem["LON"] : $max_y;
 }

 $x = round((($max_x - $min_x)/2 + $min_x), 6);
 $y = round((($max_y - $min_y)/2 + $min_y), 6);

 $arResult["YANDEX_COORD"]['yandex_lat'] = $x;
 $arResult["YANDEX_COORD"]['yandex_lon'] = $y;
 ?>

Проверка на совершеннолетие

30.11.2012 javascript No comments , , ,


function checkBirthDay(R_BIRTHDAY_DAY, R_BIRTHDAY_MONTH, R_BIRTHDAY_YEAR){

	if(R_BIRTHDAY_DAY == '' || R_BIRTHDAY_MONTH == '' || R_BIRTHDAY_YEAR == ''){

		return false;
	}
	R_BIRTHDAY_MONTH = R_BIRTHDAY_MONTH - 1; 						
	var thisDate     = new Date(R_BIRTHDAY_YEAR, R_BIRTHDAY_MONTH , R_BIRTHDAY_DAY);
	var dayThis      = thisDate.getDate()
	var monthThis    = thisDate.getMonth()
	var yearThis     = thisDate.getFullYear()
	var errorAr      = new Array();
	
	if( R_BIRTHDAY_YEAR +'.'+ R_BIRTHDAY_MONTH +'.'+ R_BIRTHDAY_DAY != yearThis +'.'+ monthThis +'.'+ dayThis){
	
		errorAr.push( 1 ) 

	}else{
		
		var date = new Date();                   // создается дата "сегодня"
		var year = date.getFullYear();	         // Выбор от "сегодня" года
		
		if(R_BIRTHDAY_YEAR > 1900){				
		
			if((year - R_BIRTHDAY_YEAR) >= 18){}else{			
				errorAr.push( 1 ) 			
			}
			
		}else{			
			errorAr.push( 1 ) 		
		}		
	}
	
	if( errorAr.length == 0 ){
		return true;
	}else{
		return false;
	}
	
}

javascript изменение параметров в GET

26.10.2012 javascript No comments , , ,

-------------------------------------------------------
var queryParameters = {}, queryString = location.search.substring(1),re = /([^&=]+)=([^&]*)/g, m;
   while (m = re.exec(queryString)) {
    queryParameters[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
   }
   queryParameters['region'] = this.$Button.data('region');
   queryParameters['city'] = this.$Button.data('city');
   
 
   location.search = $.param(queryParameters);
-----------------------------------------------------------------

Сегодня

14.10.2012 javascript No comments , ,

var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth()
var year = currentDate.getFullYear()
var today = new Date(year, month, day);

bitrix jquery

27.09.2012 Bitrix, javascript No comments , , ,

bitrix jquery

CJSCore::Init(Array("jquery"));

Склонение слов с помощью javaScript

27.09.2012 javascript 15 комментариев , ,


function declination(a5, b1, c2, s) { 
 	var words = [a5, b1, c2]; 
	var index = s % 100; 
	if (index >=11 && index <= 14) { index = 0; } 
	else { index = (index %= 10) < 5 ? (index > 2 ? 2 : index): 0; } 
	return(words[index]); 
} 

declination('лет', 'год', 'года', 23)

php

function declination($status= array('','а','ов'), $value){
	$array =array(2,0,1,1,1,2);
	return $status[($value%100>4 && $value%100<20)? 2 : $array[($value%10<5)?$value%10:5]];
	}

Bitrix

use Bitrix\Main\Grid\Declension;
$yearDeclension = new Declension('год', 'года', 'лет');
$yearDeclension->get($year);

Преобразования числа «09» в «9»

25.09.2012 javascript No comments ,

Приведение числа с 0 в начале в число без 0 в начале javascript

parseInt("09", 10)

или

'09'.replace(/^0*/, '')

вызов ajax с ожиданием ответа

var GoAjax = false;
	var AjaxTimer;
	
	function keyupHandler(){
		 // console.log('keyupHandler');
		clearTimeout(AjaxTimer);
		AjaxTimer = setTimeout('ajaxJet()', 5000);
	}
	function ajaxJet(){
	 // console.log('ajaxJet');
		if(GoAjax === true){
			return;
		}
		GoAjax = true;
		
		
		jQuery.ajax({
			type: 'POST',
			data: 'FAVORITE_AJAX_CALL=Y&FAVORITE_AJAX_CALL_TYPE=DEL',
			dataType:'json',
			url: pathTocomponent,
			success: function(data){
				GoAjax=false;		
			},
			error: function(){
				GoAjax=false;
			}
		});		
	}
	
	function keydownHandler(){
	 // console.log('keydownHandler');
		clearTimeout(AjaxTimer);	
	}

	jQuery(document).keyup(keyupHandler).keydown(keydownHandler);