~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/web/static/htdocs/applets/moinFCKplugins/placeholder/fckplugin.js

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
Import upstream version 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Register the related command.
2
 
FCKCommands.RegisterCommand( 'Placeholder', new FCKDialogCommand( 'Placeholder', FCKLang.PlaceholderDlgTitle, FCKPlugins.Items['placeholder'].Path + 'fck_placeholder.html', 340, 170 ) ) ;
3
 
 
4
 
// Create the "Plaholder" toolbar button.
5
 
var oPlaceholderItem = new FCKToolbarButton( 'Placeholder', FCKLang.PlaceholderBtn ) ;
6
 
oPlaceholderItem.IconPath = FCKPlugins.Items['placeholder'].Path + 'placeholder.gif' ;
7
 
FCKToolbarItems.RegisterItem( 'Placeholder', oPlaceholderItem ) ;
8
 
 
9
 
 
10
 
// The object used for all Placeholder operations.
11
 
var FCKPlaceholders = new Object() ;
12
 
 
13
 
// Add a new placeholder at the actual selection.
14
 
FCKPlaceholders.Add = function( name )
15
 
{
16
 
  var oSpan = FCK.CreateElement( 'SPAN' ) ;
17
 
  this.SetupSpan( oSpan, name ) ;
18
 
}
19
 
 
20
 
FCKPlaceholders.SetupSpan = function( span, name )
21
 
{
22
 
  span.innerHTML = '[[ ' + name + ' ]]' ;
23
 
 
24
 
        span.style.backgroundColor = '#ffff00' ;
25
 
        span.style.color = '#000000' ;
26
 
 
27
 
        if ( FCKBrowserInfo.IsGecko )
28
 
    span.style.cursor = 'default' ;
29
 
 
30
 
        span._fckplaceholder = name ;
31
 
        span.contentEditable = false ;
32
 
 
33
 
  // To avoid it to be resized.
34
 
  span.onresizestart = function()
35
 
  {
36
 
    FCK.EditorWindow.event.returnValue = false ;
37
 
    return false ;
38
 
  }
39
 
}
40
 
 
41
 
// On Gecko we must do this trick so the user select all the SPAN when clicking on it.
42
 
FCKPlaceholders._SetupClickListener = function()
43
 
{
44
 
  FCKPlaceholders._ClickListener = function( e )
45
 
  {
46
 
    if ( e.target.tagName == 'SPAN' && e.target._fckplaceholder )
47
 
      FCKSelection.SelectNode( e.target ) ;
48
 
  }
49
 
 
50
 
  FCK.EditorDocument.addEventListener( 'click', FCKPlaceholders._ClickListener, true ) ;
51
 
}
52
 
 
53
 
// Open the Placeholder dialog on double click.
54
 
FCKPlaceholders.OnDoubleClick = function( span )
55
 
{
56
 
  if ( span.tagName == 'SPAN' && span._fckplaceholder )
57
 
    FCKCommands.GetCommand( 'Placeholder' ).Execute() ;
58
 
}
59
 
 
60
 
FCK.RegisterDoubleClickHandler( FCKPlaceholders.OnDoubleClick, 'SPAN' ) ;
61
 
 
62
 
// Check if a Placholder name is already in use.
63
 
FCKPlaceholders.Exist = function( name )
64
 
{
65
 
  var aSpans = FCK.EditorDocument.getElementsByTagName( 'SPAN' )
66
 
 
67
 
  for ( var i = 0 ; i < aSpans.length ; i++ )
68
 
  {
69
 
    if ( aSpans[i]._fckplaceholder == name )
70
 
      return true ;
71
 
  }
72
 
}
73
 
 
74
 
if ( FCKBrowserInfo.IsIE )
75
 
{
76
 
  FCKPlaceholders.Redraw = function()
77
 
  {
78
 
    var aPlaholders = FCK.EditorDocument.body.innerText.match( /\[\[[^\[\]]+\]\]/g ) ;
79
 
    if ( !aPlaholders )
80
 
      return ;
81
 
 
82
 
    var oRange = FCK.EditorDocument.body.createTextRange() ;
83
 
 
84
 
    for ( var i = 0 ; i < aPlaholders.length ; i++ )
85
 
    {
86
 
      if ( oRange.findText( aPlaholders[i] ) )
87
 
      {
88
 
        var sName = aPlaholders[i].match( /\[\[\s*([^\]]*?)\s*\]\]/ )[1] ;
89
 
        oRange.pasteHTML( '<span style="color: #000000; background-color: #ffff00" contenteditable="false" _fckplaceholder="' + sName + '">' + aPlaholders[i] + '</span>' ) ;
90
 
      }
91
 
    }
92
 
  }
93
 
}
94
 
else
95
 
{
96
 
  FCKPlaceholders.Redraw = function()
97
 
  {
98
 
    var oInteractor = FCK.EditorDocument.createTreeWalker( FCK.EditorDocument.body, NodeFilter.SHOW_TEXT, FCKPlaceholders._AcceptNode, true ) ;
99
 
 
100
 
    var aNodes = new Array() ;
101
 
 
102
 
    while ( oNode = oInteractor.nextNode() )
103
 
    {
104
 
      aNodes[ aNodes.length ] = oNode ;
105
 
    }
106
 
 
107
 
    for ( var n = 0 ; n < aNodes.length ; n++ )
108
 
    {
109
 
      var aPieces = aNodes[n].nodeValue.split( /(\[\[[^\[\]]+\]\])/g ) ;
110
 
 
111
 
      for ( var i = 0 ; i < aPieces.length ; i++ )
112
 
      {
113
 
        if ( aPieces[i].length > 0 )
114
 
        {
115
 
          if ( aPieces[i].indexOf( '[[' ) == 0 )
116
 
          {
117
 
            var sName = aPieces[i].match( /\[\[\s*([^\]]*?)\s*\]\]/ )[1] ;
118
 
 
119
 
            var oSpan = FCK.EditorDocument.createElement( 'span' ) ;
120
 
            FCKPlaceholders.SetupSpan( oSpan, sName ) ;
121
 
 
122
 
            aNodes[n].parentNode.insertBefore( oSpan, aNodes[n] ) ;
123
 
          }
124
 
          else
125
 
            aNodes[n].parentNode.insertBefore( FCK.EditorDocument.createTextNode( aPieces[i] ) , aNodes[n] ) ;
126
 
        }
127
 
      }
128
 
 
129
 
      aNodes[n].parentNode.removeChild( aNodes[n] ) ;
130
 
    }
131
 
    
132
 
    FCKPlaceholders._SetupClickListener() ;
133
 
  }
134
 
 
135
 
  FCKPlaceholders._AcceptNode = function( node )
136
 
  {
137
 
    if ( /\[\[[^\[\]]+\]\]/.test( node.nodeValue ) )
138
 
      return NodeFilter.FILTER_ACCEPT ;
139
 
    else
140
 
      return NodeFilter.FILTER_SKIP ;
141
 
  }
142
 
}
143
 
 
144
 
FCK.Events.AttachEvent( 'OnAfterSetHTML', FCKPlaceholders.Redraw ) ;
145
 
 
146
 
// The "Redraw" method must be called on startup.
147
 
FCKPlaceholders.Redraw() ;
148
 
 
149
 
// We must process the SPAN tags to replace then with the real resulting value of the placeholder.
150
 
FCKXHtml.TagProcessors['span'] = function( node, htmlNode )
151
 
{
152
 
  if ( htmlNode._fckplaceholder )
153
 
    node = FCKXHtml.XML.createTextNode( '[[' + htmlNode._fckplaceholder + ']]' ) ;
154
 
  else
155
 
    FCKXHtml._AppendChildNodes( node, htmlNode, false ) ;
156
 
 
157
 
  return node ;
158
 
}