[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/libraries/jquery/ckeditor/plugins/docprops/dialogs/ -> docprops.js (source)

   1  /**
   2   * @license Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
   3   * For licensing, see LICENSE.md or http://ckeditor.com/license
   4   */
   5  
   6  CKEDITOR.dialog.add( 'docProps', function( editor ) {
   7      var lang = editor.lang.docprops,
   8          langCommon = editor.lang.common,
   9          metaHash = {};
  10  
  11  	function getDialogValue( dialogName, callback ) {
  12          var onOk = function() {
  13                  releaseHandlers( this );
  14                  callback( this, this._.parentDialog );
  15              };
  16          var releaseHandlers = function( dialog ) {
  17                  dialog.removeListener( 'ok', onOk );
  18                  dialog.removeListener( 'cancel', releaseHandlers );
  19              };
  20          var bindToDialog = function( dialog ) {
  21                  dialog.on( 'ok', onOk );
  22                  dialog.on( 'cancel', releaseHandlers );
  23              };
  24          editor.execCommand( dialogName );
  25          if ( editor._.storedDialogs.colordialog )
  26              bindToDialog( editor._.storedDialogs.colordialog );
  27          else {
  28              CKEDITOR.on( 'dialogDefinition', function( e ) {
  29                  if ( e.data.name != dialogName )
  30                      return;
  31  
  32                  var definition = e.data.definition;
  33  
  34                  e.removeListener();
  35                  definition.onLoad = CKEDITOR.tools.override( definition.onLoad, function( orginal ) {
  36                      return function() {
  37                          bindToDialog( this );
  38                          definition.onLoad = orginal;
  39                          if ( typeof orginal == 'function' )
  40                              orginal.call( this );
  41                      };
  42                  });
  43              });
  44          }
  45      }
  46  
  47  	function handleOther() {
  48          var dialog = this.getDialog(),
  49              other = dialog.getContentElement( 'general', this.id + 'Other' );
  50          if ( !other )
  51              return;
  52          if ( this.getValue() == 'other' ) {
  53              other.getInputElement().removeAttribute( 'readOnly' );
  54              other.focus();
  55              other.getElement().removeClass( 'cke_disabled' );
  56          } else {
  57              other.getInputElement().setAttribute( 'readOnly', true );
  58              other.getElement().addClass( 'cke_disabled' );
  59          }
  60      }
  61  
  62  	function commitMeta( name, isHttp, value ) {
  63          return function( doc, html, head ) {
  64              var hash = metaHash,
  65                  val = typeof value != 'undefined' ? value : this.getValue();
  66              if ( !val && ( name in hash ) )
  67                  hash[ name ].remove();
  68              else if ( val && ( name in hash ) )
  69                  hash[ name ].setAttribute( 'content', val );
  70              else if ( val ) {
  71                  var meta = new CKEDITOR.dom.element( 'meta', editor.document );
  72                  meta.setAttribute( isHttp ? 'http-equiv' : 'name', name );
  73                  meta.setAttribute( 'content', val );
  74                  head.append( meta );
  75              }
  76          };
  77      }
  78  
  79  	function setupMeta( name, ret ) {
  80          return function() {
  81              var hash = metaHash,
  82                  result = ( name in hash ) ? hash[ name ].getAttribute( 'content' ) || '' : '';
  83              if ( ret )
  84                  return result;
  85              this.setValue( result );
  86              return null;
  87          };
  88      }
  89  
  90  	function commitMargin( name ) {
  91          return function( doc, html, head, body ) {
  92              body.removeAttribute( 'margin' + name );
  93              var val = this.getValue();
  94              if ( val !== '' )
  95                  body.setStyle( 'margin-' + name, CKEDITOR.tools.cssLength( val ) );
  96              else
  97                  body.removeStyle( 'margin-' + name );
  98          };
  99      }
 100  
 101  	function createMetaHash( doc ) {
 102          var hash = {},
 103              metas = doc.getElementsByTag( 'meta' ),
 104              count = metas.count();
 105  
 106          for ( var i = 0; i < count; i++ ) {
 107              var meta = metas.getItem( i );
 108              hash[ meta.getAttribute( meta.hasAttribute( 'http-equiv' ) ? 'http-equiv' : 'name' ).toLowerCase() ] = meta;
 109          }
 110          return hash;
 111      }
 112      // We cannot just remove the style from the element, as it might be affected from non-inline stylesheets.
 113      // To get the proper result, we should manually set the inline style to its default value.
 114  	function resetStyle( element, prop, resetVal ) {
 115          element.removeStyle( prop );
 116          if ( element.getComputedStyle( prop ) != resetVal )
 117              element.setStyle( prop, resetVal );
 118      }
 119  
 120      // Utilty to shorten the creation of color fields in the dialog.
 121      var colorField = function( id, label, fieldProps ) {
 122              return {
 123                  type: 'hbox',
 124                  padding: 0,
 125                  widths: [ '60%', '40%' ],
 126                  children: [
 127                      CKEDITOR.tools.extend({
 128                      type: 'text',
 129                      id: id,
 130                      label: lang[ label ]
 131                  }, fieldProps || {}, 1 ),
 132                  {
 133                      type: 'button',
 134                      id: id + 'Choose',
 135                      label: lang.chooseColor,
 136                      className: 'colorChooser',
 137                      onClick: function() {
 138                          var self = this;
 139                          getDialogValue( 'colordialog', function( colorDialog ) {
 140                              var dialog = self.getDialog();
 141                              dialog.getContentElement( dialog._.currentTabId, id ).setValue( colorDialog.getContentElement( 'picker', 'selectedColor' ).getValue() );
 142                          });
 143                      }
 144                  }
 145                  ]
 146              };
 147          };
 148      var previewSrc = 'javascript:' +
 149          'void((function(){' + encodeURIComponent(
 150              'document.open();' +
 151              ( CKEDITOR.env.ie ? '(' + CKEDITOR.tools.fixDomain + ')();' : '' ) +
 152              'document.write( \'<html style="background-color: #ffffff; height: 100%"><head></head><body style="width: 100%; height: 100%; margin: 0px">' + lang.previewHtml + '</body></html>\' );' +
 153              'document.close();'
 154          ) + '})())';
 155  
 156      return {
 157          title: lang.title,
 158          minHeight: 330,
 159          minWidth: 500,
 160          onShow: function() {
 161              var doc = editor.document,
 162                  html = doc.getElementsByTag( 'html' ).getItem( 0 ),
 163                  head = doc.getHead(),
 164                  body = doc.getBody();
 165              metaHash = createMetaHash( doc );
 166              this.setupContent( doc, html, head, body );
 167          },
 168          onHide: function() {
 169              metaHash = {};
 170          },
 171          onOk: function() {
 172              var doc = editor.document,
 173                  html = doc.getElementsByTag( 'html' ).getItem( 0 ),
 174                  head = doc.getHead(),
 175                  body = doc.getBody();
 176              this.commitContent( doc, html, head, body );
 177          },
 178          contents: [
 179              {
 180              id: 'general',
 181              label: langCommon.generalTab,
 182              elements: [
 183                  {
 184                  type: 'text',
 185                  id: 'title',
 186                  label: lang.docTitle,
 187                  setup: function( doc ) {
 188                      this.setValue( doc.getElementsByTag( 'title' ).getItem( 0 ).data( 'cke-title' ) );
 189                  },
 190                  commit: function( doc, html, head, body, isPreview ) {
 191                      if ( isPreview )
 192                          return;
 193                      doc.getElementsByTag( 'title' ).getItem( 0 ).data( 'cke-title', this.getValue() );
 194                  }
 195              },
 196                  {
 197                  type: 'hbox',
 198                  children: [
 199                      {
 200                      type: 'select',
 201                      id: 'dir',
 202                      label: langCommon.langDir,
 203                      style: 'width: 100%',
 204                      items: [
 205                          [ langCommon.notSet, '' ],
 206                          [ langCommon.langDirLtr, 'ltr' ],
 207                          [ langCommon.langDirRtl, 'rtl' ]
 208                          ],
 209                      setup: function( doc, html, head, body ) {
 210                          this.setValue( body.getDirection() || '' );
 211                      },
 212                      commit: function( doc, html, head, body ) {
 213                          var val = this.getValue();
 214                          if ( val )
 215                              body.setAttribute( 'dir', val );
 216                          else
 217                              body.removeAttribute( 'dir' );
 218                          body.removeStyle( 'direction' );
 219                      }
 220                  },
 221                      {
 222                      type: 'text',
 223                      id: 'langCode',
 224                      label: langCommon.langCode,
 225                      setup: function( doc, html ) {
 226                          this.setValue( html.getAttribute( 'xml:lang' ) || html.getAttribute( 'lang' ) || '' );
 227                      },
 228                      commit: function( doc, html, head, body, isPreview ) {
 229                          if ( isPreview )
 230                              return;
 231                          var val = this.getValue();
 232                          if ( val )
 233                              html.setAttributes({ 'xml:lang': val, lang: val } );
 234                          else
 235                              html.removeAttributes( { 'xml:lang':1,lang:1 } );
 236                      }
 237                  }
 238                  ]
 239              },
 240                  {
 241                  type: 'hbox',
 242                  children: [
 243                      {
 244                      type: 'select',
 245                      id: 'charset',
 246                      label: lang.charset,
 247                      style: 'width: 100%',
 248                      items: [
 249                          [ langCommon.notSet, '' ],
 250                          [ lang.charsetASCII, 'us-ascii' ],
 251                          [ lang.charsetCE, 'iso-8859-2' ],
 252                          [ lang.charsetCT, 'big5' ],
 253                          [ lang.charsetCR, 'iso-8859-5' ],
 254                          [ lang.charsetGR, 'iso-8859-7' ],
 255                          [ lang.charsetJP, 'iso-2022-jp' ],
 256                          [ lang.charsetKR, 'iso-2022-kr' ],
 257                          [ lang.charsetTR, 'iso-8859-9' ],
 258                          [ lang.charsetUN, 'utf-8' ],
 259                          [ lang.charsetWE, 'iso-8859-1' ],
 260                          [ lang.other, 'other' ]
 261                          ],
 262                      'default': '',
 263                      onChange: function() {
 264                          this.getDialog().selectedCharset = this.getValue() != 'other' ? this.getValue() : '';
 265                          handleOther.call( this );
 266                      },
 267                      setup: function() {
 268                          this.metaCharset = ( 'charset' in metaHash );
 269  
 270                          var func = setupMeta( this.metaCharset ? 'charset' : 'content-type', 1, 1 ),
 271                              val = func.call( this );
 272  
 273                          !this.metaCharset && val.match( /charset=[^=]+$/ ) && ( val = val.substring( val.indexOf( '=' ) + 1 ) );
 274  
 275                          if ( val ) {
 276                              this.setValue( val.toLowerCase() );
 277                              if ( !this.getValue() ) {
 278                                  this.setValue( 'other' );
 279                                  var other = this.getDialog().getContentElement( 'general', 'charsetOther' );
 280                                  other && other.setValue( val );
 281                              }
 282                              this.getDialog().selectedCharset = val;
 283                          }
 284  
 285                          handleOther.call( this );
 286                      },
 287                      commit: function( doc, html, head, body, isPreview ) {
 288                          if ( isPreview )
 289                              return;
 290                          var value = this.getValue(),
 291                              other = this.getDialog().getContentElement( 'general', 'charsetOther' );
 292  
 293                          value == 'other' && ( value = other ? other.getValue() : '' );
 294  
 295                          value && !this.metaCharset && ( value = ( metaHash[ 'content-type' ] ? metaHash[ 'content-type' ].getAttribute( 'content' ).split( ';' )[ 0 ] : 'text/html' ) + '; charset=' + value );
 296  
 297                          var func = commitMeta( this.metaCharset ? 'charset' : 'content-type', 1, value );
 298                          func.call( this, doc, html, head );
 299                      }
 300                  },
 301                      {
 302                      type: 'text',
 303                      id: 'charsetOther',
 304                      label: lang.charsetOther,
 305                      onChange: function() {
 306                          this.getDialog().selectedCharset = this.getValue();
 307                      }
 308                  }
 309                  ]
 310              },
 311                  {
 312                  type: 'hbox',
 313                  children: [
 314                      {
 315                      type: 'select',
 316                      id: 'docType',
 317                      label: lang.docType,
 318                      style: 'width: 100%',
 319                      items: [
 320                          [ langCommon.notSet, '' ],
 321                          [ 'XHTML 1.1', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">' ],
 322                          [ 'XHTML 1.0 Transitional', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' ],
 323                          [ 'XHTML 1.0 Strict', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' ],
 324                          [ 'XHTML 1.0 Frameset', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">' ],
 325                          [ 'HTML 5', '<!DOCTYPE html>' ],
 326                          [ 'HTML 4.01 Transitional', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' ],
 327                          [ 'HTML 4.01 Strict', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' ],
 328                          [ 'HTML 4.01 Frameset', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">' ],
 329                          [ 'HTML 3.2', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">' ],
 330                          [ 'HTML 2.0', '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">' ],
 331                          [ lang.other, 'other' ]
 332                          ],
 333                      onChange: handleOther,
 334                      setup: function() {
 335                          if ( editor.docType ) {
 336                              this.setValue( editor.docType );
 337                              if ( !this.getValue() ) {
 338                                  this.setValue( 'other' );
 339                                  var other = this.getDialog().getContentElement( 'general', 'docTypeOther' );
 340                                  other && other.setValue( editor.docType );
 341                              }
 342                          }
 343                          handleOther.call( this );
 344                      },
 345                      commit: function( doc, html, head, body, isPreview ) {
 346                          if ( isPreview )
 347                              return;
 348                          var value = this.getValue(),
 349                              other = this.getDialog().getContentElement( 'general', 'docTypeOther' );
 350                          editor.docType = value == 'other' ? ( other ? other.getValue() : '' ) : value;
 351                      }
 352                  },
 353                      {
 354                      type: 'text',
 355                      id: 'docTypeOther',
 356                      label: lang.docTypeOther
 357                  }
 358                  ]
 359              },
 360                  {
 361                  type: 'checkbox',
 362                  id: 'xhtmlDec',
 363                  label: lang.xhtmlDec,
 364                  setup: function() {
 365                      this.setValue( !!editor.xmlDeclaration );
 366                  },
 367                  commit: function( doc, html, head, body, isPreview ) {
 368                      if ( isPreview )
 369                          return;
 370                      if ( this.getValue() ) {
 371                          editor.xmlDeclaration = '<?xml version="1.0" encoding="' + ( this.getDialog().selectedCharset || 'utf-8' ) + '"?>';
 372                          html.setAttribute( 'xmlns', 'http://www.w3.org/1999/xhtml' );
 373                      } else {
 374                          editor.xmlDeclaration = '';
 375                          html.removeAttribute( 'xmlns' );
 376                      }
 377                  }
 378              }
 379              ]
 380          },
 381              {
 382              id: 'design',
 383              label: lang.design,
 384              elements: [
 385                  {
 386                  type: 'hbox',
 387                  widths: [ '60%', '40%' ],
 388                  children: [
 389                      {
 390                      type: 'vbox',
 391                      children: [
 392                          colorField( 'txtColor', 'txtColor', {
 393                          setup: function( doc, html, head, body ) {
 394                              this.setValue( body.getComputedStyle( 'color' ) );
 395                          },
 396                          commit: function( doc, html, head, body, isPreview ) {
 397                              if ( this.isChanged() || isPreview ) {
 398                                  body.removeAttribute( 'text' );
 399                                  var val = this.getValue();
 400                                  if ( val )
 401                                      body.setStyle( 'color', val );
 402                                  else
 403                                      body.removeStyle( 'color' );
 404                              }
 405                          }
 406                      }),
 407                          colorField( 'bgColor', 'bgColor', {
 408                          setup: function( doc, html, head, body ) {
 409                              var val = body.getComputedStyle( 'background-color' ) || '';
 410                              this.setValue( val == 'transparent' ? '' : val );
 411                          },
 412                          commit: function( doc, html, head, body, isPreview ) {
 413                              if ( this.isChanged() || isPreview ) {
 414                                  body.removeAttribute( 'bgcolor' );
 415                                  var val = this.getValue();
 416                                  if ( val )
 417                                      body.setStyle( 'background-color', val );
 418                                  else
 419                                      resetStyle( body, 'background-color', 'transparent' );
 420                              }
 421                          }
 422                      }),
 423                      {
 424                          type: 'hbox',
 425                          widths: [ '60%', '40%' ],
 426                          padding: 1,
 427                          children: [
 428                              {
 429                              type: 'text',
 430                              id: 'bgImage',
 431                              label: lang.bgImage,
 432                              setup: function( doc, html, head, body ) {
 433                                  var val = body.getComputedStyle( 'background-image' ) || '';
 434                                  if ( val == 'none' )
 435                                      val = '';
 436                                  else {
 437                                      val = val.replace( /url\(\s*(["']?)\s*([^\)]*)\s*\1\s*\)/i, function( match, quote, url ) {
 438                                          return url;
 439                                      });
 440                                  }
 441                                  this.setValue( val );
 442                              },
 443                              commit: function( doc, html, head, body ) {
 444                                  body.removeAttribute( 'background' );
 445                                  var val = this.getValue();
 446                                  if ( val )
 447                                      body.setStyle( 'background-image', 'url(' + val + ')' );
 448                                  else
 449                                      resetStyle( body, 'background-image', 'none' );
 450                              }
 451                          },
 452                              {
 453                              type: 'button',
 454                              id: 'bgImageChoose',
 455                              label: langCommon.browseServer,
 456                              style: 'display:inline-block;margin-top:10px;',
 457                              hidden: true,
 458                              filebrowser: 'design:bgImage'
 459                          }
 460                          ]
 461                      },
 462                          {
 463                          type: 'checkbox',
 464                          id: 'bgFixed',
 465                          label: lang.bgFixed,
 466                          setup: function( doc, html, head, body ) {
 467                              this.setValue( body.getComputedStyle( 'background-attachment' ) == 'fixed' );
 468                          },
 469                          commit: function( doc, html, head, body ) {
 470                              if ( this.getValue() )
 471                                  body.setStyle( 'background-attachment', 'fixed' );
 472                              else
 473                                  resetStyle( body, 'background-attachment', 'scroll' );
 474                          }
 475                      }
 476                      ]
 477                  },
 478                      {
 479                      type: 'vbox',
 480                      children: [
 481                          {
 482                          type: 'html',
 483                          id: 'marginTitle',
 484                          html: '<div style="text-align: center; margin: 0px auto; font-weight: bold">' + lang.margin + '</div>'
 485                      },
 486                          {
 487                          type: 'text',
 488                          id: 'marginTop',
 489                          label: lang.marginTop,
 490                          style: 'width: 80px; text-align: center',
 491                          align: 'center',
 492                          inputStyle: 'text-align: center',
 493                          setup: function( doc, html, head, body ) {
 494                              this.setValue( body.getStyle( 'margin-top' ) || body.getAttribute( 'margintop' ) || '' );
 495                          },
 496                          commit: commitMargin( 'top' )
 497                      },
 498                          {
 499                          type: 'hbox',
 500                          children: [
 501                              {
 502                              type: 'text',
 503                              id: 'marginLeft',
 504                              label: lang.marginLeft,
 505                              style: 'width: 80px; text-align: center',
 506                              align: 'center',
 507                              inputStyle: 'text-align: center',
 508                              setup: function( doc, html, head, body ) {
 509                                  this.setValue( body.getStyle( 'margin-left' ) || body.getAttribute( 'marginleft' ) || '' );
 510                              },
 511                              commit: commitMargin( 'left' )
 512                          },
 513                              {
 514                              type: 'text',
 515                              id: 'marginRight',
 516                              label: lang.marginRight,
 517                              style: 'width: 80px; text-align: center',
 518                              align: 'center',
 519                              inputStyle: 'text-align: center',
 520                              setup: function( doc, html, head, body ) {
 521                                  this.setValue( body.getStyle( 'margin-right' ) || body.getAttribute( 'marginright' ) || '' );
 522                              },
 523                              commit: commitMargin( 'right' )
 524                          }
 525                          ]
 526                      },
 527                          {
 528                          type: 'text',
 529                          id: 'marginBottom',
 530                          label: lang.marginBottom,
 531                          style: 'width: 80px; text-align: center',
 532                          align: 'center',
 533                          inputStyle: 'text-align: center',
 534                          setup: function( doc, html, head, body ) {
 535                              this.setValue( body.getStyle( 'margin-bottom' ) || body.getAttribute( 'marginbottom' ) || '' );
 536                          },
 537                          commit: commitMargin( 'bottom' )
 538                      }
 539                      ]
 540                  }
 541                  ]
 542              }
 543              ]
 544          },
 545              {
 546              id: 'meta',
 547              label: lang.meta,
 548              elements: [
 549                  {
 550                  type: 'textarea',
 551                  id: 'metaKeywords',
 552                  label: lang.metaKeywords,
 553                  setup: setupMeta( 'keywords' ),
 554                  commit: commitMeta( 'keywords' )
 555              },
 556                  {
 557                  type: 'textarea',
 558                  id: 'metaDescription',
 559                  label: lang.metaDescription,
 560                  setup: setupMeta( 'description' ),
 561                  commit: commitMeta( 'description' )
 562              },
 563                  {
 564                  type: 'text',
 565                  id: 'metaAuthor',
 566                  label: lang.metaAuthor,
 567                  setup: setupMeta( 'author' ),
 568                  commit: commitMeta( 'author' )
 569              },
 570                  {
 571                  type: 'text',
 572                  id: 'metaCopyright',
 573                  label: lang.metaCopyright,
 574                  setup: setupMeta( 'copyright' ),
 575                  commit: commitMeta( 'copyright' )
 576              }
 577              ]
 578          },
 579              {
 580              id: 'preview',
 581              label: langCommon.preview,
 582              elements: [
 583                  {
 584                  type: 'html',
 585                  id: 'previewHtml',
 586                  html: '<iframe src="' + previewSrc + '" style="width: 100%; height: 310px" hidefocus="true" frameborder="0" ' +
 587                      'id="cke_docProps_preview_iframe"></iframe>',
 588                  onLoad: function() {
 589                      this.getDialog().on( 'selectPage', function( ev ) {
 590                          if ( ev.data.page == 'preview' ) {
 591                              var self = this;
 592                              setTimeout( function() {
 593                                  var doc = CKEDITOR.document.getById( 'cke_docProps_preview_iframe' ).getFrameDocument(),
 594                                      html = doc.getElementsByTag( 'html' ).getItem( 0 ),
 595                                      head = doc.getHead(),
 596                                      body = doc.getBody();
 597                                  self.commitContent( doc, html, head, body, 1 );
 598                              }, 50 );
 599                          }
 600                      });
 601                      CKEDITOR.document.getById( 'cke_docProps_preview_iframe' ).getAscendant( 'table' ).setStyle( 'height', '100%' );
 602                  }
 603              }
 604              ]
 605          }
 606          ]
 607      };
 608  });


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1