[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/js/ui/ -> common.js (source)

   1  /**

   2   * opens a window with some help information

   3   *

   4   * @param helpurl The destination url

   5   * @return nothing

   6   */ 
   7  function help_window(helpurl)
   8  {
   9      HelpWin = window.open( helpurl,'HelpWindow','scrollbars=yes,resizable=yes,toolbar=no,height=400,width=400');
  10  }
  11  
  12  /**

  13   * opens a window pointing to the list of resources so that we can easily add one to our current

  14   * article

  15   *

  16   * @param type

  17   * @return nothing

  18   */
  19  function resource_list_window( type ) {
  20      width  = 500;
  21      height = 450;
  22      
  23      x = parseInt(screen.width / 2.0) - (width / 2.0);
  24      y = parseInt(screen.height / 2.0) - (height / 2.0);
  25  
  26      // type == 1 => intro text

  27      // type == 2 => extended text

  28      HelpWin = window.open( '?op=resourceList&mode='+type,'ResourceListWindow','top='+y+',left='+x+',scrollbars=yes,resizable=yes,toolbar=no,height='+height+',width='+width);
  29  
  30  }
  31  
  32  function userPictureSelectWindow()
  33  {
  34      width  = 500;
  35      height = 450;
  36      
  37      x = parseInt(screen.width / 2.0) - (width / 2.0);
  38      y = parseInt(screen.height / 2.0) - (height / 2.0);
  39      
  40      UserPicture = window.open( '?op=userPictureSelect', 'UserPictureSelect','top='+y+',left='+x+',scrollbars=yes,resizable=yes,toolbar=no,height='+height+',width='+width);
  41  }
  42  
  43  /**

  44   * resets the user picture/avatar in the profile page

  45   */
  46  function resetUserPicture()
  47  {
  48      window.document.userSettings.userPictureId.value = 0;
  49      // and reload the image path

  50      window.document.userSettings.userPicture.src = 'imgs/no-user-picture.jpg';
  51  }
  52  
  53  /**

  54   * resets blogid in the general setting page

  55   */
  56  function resetBlogId()
  57  {
  58      window.document.updateGlobalSettings.blogId.value = '';
  59  }
  60  
  61  /**

  62   * empties a drop-down list

  63   *

  64   * @param box The form object representing the drop-down list

  65   * @return nothing

  66   */
  67  function emptyList( box )
  68  {
  69      while ( box.options.length ) box.options[0] = null;
  70  }
  71  
  72  /**

  73   * fill a list with data

  74   *

  75   * @param box

  76   * @param numElems

  77   * @return nothing

  78   */
  79  function fillList( box, numElems )
  80  {
  81      for ( i = 1; i <= numElems; i++ ) {
  82          option = new Option( i, i );
  83          box.options[box.length] = option;
  84      }
  85      
  86      box.selectedIndex=0;
  87  }
  88  
  89  /**

  90   * @private 

  91   * @param box

  92   * @return nothing

  93   */
  94  function changeList( box )
  95  {
  96      daysMonth = days[box.options[box.selectedIndex].value-1];
  97      emptyList( box.form.postDay );
  98      fillList( box.form.postDay, daysMonth );
  99  }
 100  
 101  /**

 102   * Adds some text where the cursor is.

 103   *

 104   * Works in IE and Mozilla 1.3b+

 105   * In other browsers, it simply adds the text at the end of the current text

 106   */
 107  function addText( input, insText ) 
 108  {
 109      input.focus();
 110      if( input.createTextRange ) {
 111          parent.opener.document.selection.createRange().text += insText;
 112      } 
 113      else if( input.setSelectionRange ) {
 114          var len = input.selectionEnd;
 115          input.value = input.value.substr( 0, len ) + insText + input.value.substr( len );
 116          input.setSelectionRange(len+insText.length,len+insText.length);
 117      } 
 118      else { 
 119          input.value += insText; 
 120      }
 121  }
 122  
 123  /**

 124   * Used in the' user profile' screen where users can pick an image from their collection

 125   * and set it as their 'avatar'

 126   *

 127   * @param resId

 128   * @param url

 129   * @return nothing

 130   */
 131  function returnResourceInformation(resId, url)
 132  {
 133      // set the picture id

 134      parent.opener.document.userSettings.userPictureId.value = resId;
 135      // and reload the image path

 136      parent.opener.document.userSettings.userPicture.src = url;
 137  }
 138  
 139  /**

 140   * opens a window to see an screenshot from a template

 141   *

 142   * @param destination url

 143   */
 144  function openScreenshotWindow( destUrl )
 145  {
 146      ScreenshotWindow = window.open( destUrl, 'Screenshot','scrollbars=yes,resizable=yes,toolbar=no,height=600,width=800');
 147  }
 148  
 149  /**

 150   * opens the window where users can choose their own template. The destination url is hardcoded

 151   */
 152  function openTemplateChooserWindow()
 153  {
 154      width  = 500;
 155      height = 450;
 156      
 157      x = parseInt(screen.width / 2.0) - (width / 2.0);
 158      y = parseInt(screen.height / 2.0) - (height / 2.0);
 159      
 160      TemplateSelectorWindow = window.open( '?op=blogTemplateChooser', 'TemplateChooser','top='+y+',left='+x+',scrollbars=yes,resizable=yes,toolbar=no,height='+height+',width='+width);
 161  }
 162  
 163  /**

 164   * tells the parent window which template we chose

 165   */
 166  function blogTemplateSelector( templateId )
 167  {
 168      templateSelectList = parent.opener.document.blogSettings.blogTemplate;
 169      
 170      // loop throough the array with the different template sets and if we find the

 171      // one that the use just selected, then automatically select it and quit the loop

 172      for( i = 0; i < templateSelectList.options.length; i++ ) {
 173          if( templateSelectList.options[i].value == templateId ) {
 174              templateSelectList.selectedIndex = i;
 175              break;
 176          }
 177      }
 178      
 179      window.close();
 180  }
 181  
 182  /**

 183   * in the "newBlogUser" screen, shows and hides the 'notification area', a textbox

 184   * where users can type some text that will be included in an email sent to the user that is

 185   * going to be invited to the blog

 186   */
 187  function toggleNotificationArea()
 188  {
 189      var elem = document.getElementById('emailTextNotification');
 190      if( elem.style.display == 'none' )
 191        elem.style.display = '';
 192      else
 193        elem.style.display = 'none';
 194        
 195      return true;  
 196  }
 197  
 198  /**

 199   * the functions below are used in the "global settings" page, so that 

 200   * whole blocks of the html page can appear and disappear when needed

 201   */
 202  // there is no current section selected

 203  var currentSection='';
 204  sections = ["general","summary","templates","urls","email","uploads","helpers","interfaces","security","bayesian","resources","search"];
 205  
 206  function _toggle( sectionId )
 207  {
 208   // get the dom object with such section

 209   element = document.getElementById( sectionId );
 210   
 211   currentStatus = element.style.display;
 212  
 213   // and toggle its visibility

 214   if( element.style.display == 'none' )
 215     element.style.display = 'block';
 216   else
 217     element.style.display = 'none';
 218    
 219   return true;
 220  }
 221  
 222  function toggleSection(sectionId)
 223  {
 224   // if no section selected, do nothing

 225   if( sectionId == 'none' )
 226     return false;
 227  
 228   toggleAll( false );
 229   
 230   // and toggle the new one

 231   _toggle(sectionId);
 232  
 233   // now we have a new current section

 234   currentSection = sectionId;
 235     
 236   return true;  
 237  }
 238  
 239  function toggleAll( enabled )
 240  {
 241    if( enabled ) statusString = 'block';
 242    else statusString = 'none';
 243    
 244    for( i = 0; i < sections.length; i++ ) {
 245      element = document.getElementById( sections[i] );
 246      element.style.display = statusString;
 247    }
 248  }
 249  
 250  /**

 251   * generic function for moving elements from one list to another!

 252   */
 253  function moveElement(srcList, dstList)
 254  {
 255      
 256      // now find out which user we've selected from the first list

 257      indexId = srcList.selectedIndex;
 258      
 259      // if no element was selected, quit

 260      if( indexId == -1 )
 261          return false;
 262      
 263      optText = srcList.options[indexId].text;
 264      optId  = srcList.options[indexId].value;
 265      
 266      if( optId == -1 ) {
 267          // do nothing, this is our special marker!

 268          return false;
 269      }
 270      
 271      // add the option to the opposite box

 272      newOpt = new Option( optText, optId );
 273      dstList.options[dstList.options.length] = newOpt;
 274      
 275      // and remove it from the current box

 276      srcList.options[indexId] = null;
 277      
 278      return true;
 279  }
 280  
 281  /**

 282   * automatically selects all the elements of a list

 283   */
 284  function listSelectAll(listId)
 285  {
 286      list = document.getElementById( listId );
 287      for( i = 0; i < list.options.length; i++ ) {
 288          list.options[i].selected = true;
 289      }
 290  
 291      return true;
 292  }
 293  
 294  function editBlogRemoveSelected()
 295  {
 296      userList = document.getElementById( 'userList' );
 297      length = userList.options.length;
 298      for( i = 0; i < length; i++ ) {
 299          if( userList.options[i] ) {
 300              if( userList.options[i].selected ){
 301                  userList.options[i] = null;
 302                  i--; 
 303                  //length--;

 304              }
 305          }
 306      }
 307      return( true );
 308  }
 309  
 310  function MM_jumpMenu(targ,selObj,restore){ //v3.0 
 311      eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); 
 312      if (restore) selObj.selectedIndex=0; 
 313  }
 314  
 315  function getPostEditFormElements( formId )
 316  {
 317      var formData = '';
 318      
 319      form = document.getElementById( formId );
 320      
 321      for(i = 0; i < form.elements.length; i++ ) {
 322          itemName = form.elements[i].name;
 323          itemValue = form.elements[i].value;
 324          
 325          if( itemName != "op" ) {
 326              // we don't want to send more than one "op" parameter... do we?

 327              if( itemName == "postCategories[]" ) {
 328                  // we need to have a special case for this one because it's a list that

 329                  // allows multiple selection... only using the "value" attribute will

 330                  // return one of the items and we would like to have them all

 331                  for (var j = 0; j < form.elements[i].options.length; j++) {
 332                      if (form.elements[i].options[j].selected) 
 333                          formData = formData + itemName + "=" + form.elements[i].options[j].value + "&";
 334                  }
 335              }
 336              else if( itemName == "postText" && htmlAreaEnabled ) {
 337                  if ( blogLocale == "UTF-8" ) {
 338                      formData = formData + itemName + "=" + encodeURIComponent(tinyMCE.getContent('postText')) + "&";
 339                  } else {
 340                      formData = formData + itemName + "=" + escape(tinyMCE.getContent('postText')) + "&";
 341                  }
 342              }
 343              else if( itemName == "postExtendedText" && htmlAreaEnabled ) {
 344                  if ( blogLocale == "UTF-8" ) {
 345                      formData = formData + itemName + "=" + encodeURIComponent(tinyMCE.getContent('postExtendedText')) + "&";
 346                  } else {
 347                      formData = formData + itemName + "=" + escape(tinyMCE.getContent('postExtendedText')) + "&";
 348                  }
 349              }
 350              else {
 351                  // for all other elements, normal handling

 352                  if ( blogLocale == "UTF-8" ) {
 353                      formData = formData + itemName + "=" + encodeURIComponent(itemValue) + "&";
 354                  } else {
 355                      formData = formData + itemName + "=" + escape(itemValue) + "&";
 356                  }
 357              }
 358          }
 359      }    
 360      
 361      return formData;
 362  }
 363  
 364  /**

 365   * Returns the HTML code required to embed the Flash MP3 and video player, given

 366   * a URL to a playable media file.

 367   *

 368   * @param url

 369   * @return

 370   */
 371  function getFlashPlayerHTML( url, height, width ) 
 372  {
 373      var playerUrl = plogBaseUrl + "/flash/mp3player/mp3player.swf";
 374      
 375      var htmlCode = "<object data=\"" + playerUrl + "\" type=\"application/x-shockwave-flash\" width=\"" + width +"\" height=\"" + height + "\" class=\"ltPlayer\">"+
 376          "<param name=\"quality\" value=\"best\" />"+
 377          "<param name=\"bgcolor\" value=\"#FFFFFF\" />" +
 378          "<param name=\"movie\" value=\"" + playerUrl + "\" />" +
 379          "<param name=\"FlashVars\" value=\"&file="+ url + "&height=" + height + "&width=" + width + "\" />" +
 380          "</object>";    
 381  
 382      return htmlCode;
 383  }


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics