Advertisement
Guest User

Untitled

a guest
May 30th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function($) {
  2.     $( document ).ready( function() {
  3.        
  4.         var scrs = [
  5.             [0 , 620 , 'dm1.ru'] ,
  6.             [621 , 1024, 'dm2.ru'] ,
  7.             [1025, 2048, 'dm3.ru'] ,
  8.             [2049, -1, 'dm4.ru']
  9.         ];
  10.        
  11.         function redirect( nw , rp ) {
  12.             if ( rp ) window.location.replace( nw );
  13.             else window.location.href( nw );
  14.         }
  15.        
  16.         function replace_domen( new_domen , protocol ) {
  17.             if ( !protocol )
  18.                 protocol = window.location.protocol;
  19.             var hostname = window.location.hostname;
  20.             var link = window.location.href;
  21.             var dpos = link.indexOf( hostname );
  22.             if ( ( dpos == -1 ) || ( !hostname.length ) )
  23.                 return protocol + '//' + new_domen;
  24.             return protocol + '//' + new_domen + link.substr( dpos + hostname.length );
  25.         }
  26.        
  27.         function try_width( scrs , params ) {
  28.             if ( !params ) params = {};
  29.             if (params.hide_history===undefined) params.hide_history = true;
  30.            
  31.             var w = $( document ).width();
  32.        
  33.             for( var i in scrs ) {
  34.                 var item = scrs[i];
  35.            
  36.                 if ( ( (item[0]==-1) || (w >= item[0]) ) &&
  37.                     ( (item[1]==-1) || (w <= item[1]) ) ) {
  38.                     redirect(
  39.                         replace_domen( item[2] , params.protocol ) ,
  40.                         params.hide_history
  41.                     );
  42.                     return true;
  43.                 }
  44.             }
  45.             return false;
  46.         }
  47.  
  48.         try_width( scrs );
  49.        
  50.     } );
  51. })( jQuery );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement