JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.2
[ckeditor.git] / _source / plugins / templates / dialogs / templates.js
index 98c8feb..eb86b65 100644 (file)
@@ -15,7 +15,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                // clear loading wait text.\r
                                container.setHtml( '' );\r
 \r
-                               for ( var i = 0 ; i < templatesDefinitions.length ; i++ )\r
+                               for ( var i = 0, totalDefs = templatesDefinitions.length ; i < totalDefs ; i++ )\r
                                {\r
                                        var definition = CKEDITOR.getTemplates( templatesDefinitions[ i ] ),\r
                                                imagesPath = definition.imagesPath,\r
@@ -41,10 +41,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                '</a>' );\r
 \r
                                // Build the inner HTML of our new item DIV.\r
-                               var html = '<table style="width:350px;" class="cke_tpl_preview"><tr>';\r
+                               var html = '<table style="width:350px;" class="cke_tpl_preview" role="presentation"><tr>';\r
 \r
                                if ( template.image && imagesPath )\r
-                                       html += '<td class="cke_tpl_preview_img"><img src="' + CKEDITOR.getUrl( imagesPath + template.image ) + '"></td>';\r
+                                       html += '<td class="cke_tpl_preview_img"><img src="' + CKEDITOR.getUrl( imagesPath + template.image ) + '"' + ( CKEDITOR.env.ie6Compat ? ' onload="this.width=this.width"' : '' ) + ' alt="" title=""></td>';\r
 \r
                                html += '<td style="white-space:normal;"><span class="cke_tpl_title">' + template.title + '</span><br/>';\r
 \r
@@ -80,12 +80,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                // Place the cursor at the first editable place.\r
                                                var range = new CKEDITOR.dom.range( editor.document );\r
                                                range.moveToElementEditStart( editor.document.getBody() );\r
-                                               range.select( true );\r
-                                               setTimeout( function ()\r
+                                               range.select( 1 );\r
+                                               setTimeout( function()\r
                                                {\r
                                                        editor.fire( 'saveSnapshot' );\r
                                                }, 0 );\r
-                                       } );\r
+                                       });\r
 \r
                                        editor.fire( 'saveSnapshot' );\r
                                        editor.setData( html );\r
@@ -100,10 +100,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        function keyNavigation( evt )\r
                        {\r
                                var target = evt.data.getTarget(),\r
-                                       position = listContainer.getPosition( target );\r
+                                               onList = listContainer.equals( target );\r
 \r
                                // Keyboard navigation for template list.\r
-                               if ( position > CKEDITOR.POSITION_CONTAINS )\r
+                               if (  onList || listContainer.contains( target ) )\r
                                {\r
                                        var keystroke = evt.data.getKeystroke(),\r
                                                items = listContainer.getElementsByTag( 'a' ),\r
@@ -111,19 +111,25 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                                        if ( items )\r
                                        {\r
-                                               switch ( keystroke )\r
+                                               // Focus not yet onto list items?\r
+                                               if ( onList )\r
+                                                       focusItem = items.getItem( 0 );\r
+                                               else\r
                                                {\r
-                                                       case 40 :                                       // ARROW-DOWN\r
-                                                               focusItem = target.getNext();\r
-                                                               break;\r
+                                                       switch ( keystroke )\r
+                                                       {\r
+                                                               case 40 :                                       // ARROW-DOWN\r
+                                                                       focusItem = target.getNext();\r
+                                                                       break;\r
 \r
-                                                       case 38 :                                       // ARROW-UP\r
-                                                               focusItem = target.getPrevious();\r
-                                                               break;\r
+                                                               case 38 :                                       // ARROW-UP\r
+                                                                       focusItem = target.getPrevious();\r
+                                                                       break;\r
 \r
-                                                       case 13 :                                       // ENTER\r
-                                                       case 32 :                                       // SPACE\r
-                                                               target.fire( 'click' );\r
+                                                               case 13 :                                       // ENTER\r
+                                                               case 32 :                                       // SPACE\r
+                                                                       target.fire( 'click' );\r
+                                                       }\r
                                                }\r
 \r
                                                if ( focusItem )\r
@@ -140,6 +146,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
 \r
                        var listContainer;\r
 \r
+                       var templateListLabelId = 'cke_tpl_list_label_' + CKEDITOR.tools.getNextNumber(),\r
+                               lang = editor.lang.templates,\r
+                               config = editor.config;\r
                        return {\r
                                title :editor.lang.templates.title,\r
 \r
@@ -150,7 +159,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                [\r
                                        {\r
                                                id :'selectTpl',\r
-                                               label : editor.lang.templates.title,\r
+                                               label : lang.title,\r
                                                elements :\r
                                                [\r
                                                        {\r
@@ -162,29 +171,24 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                                                type : 'html',\r
                                                                                html :\r
                                                                                        '<span>'  +\r
-                                                                                               editor.lang.templates.selectPromptMsg +\r
+                                                                                               lang.selectPromptMsg +\r
                                                                                        '</span>'\r
                                                                        },\r
                                                                        {\r
-                                                                               id : "templatesList",\r
+                                                                               id : 'templatesList',\r
                                                                                type : 'html',\r
-                                                                               focus: function()\r
-                                                                               {\r
-                                                                                       // Move focus to the first list item if available.\r
-                                                                                       try { this.getElement().getElementsByTag( 'a' ).getItem( 0 ).focus(); }\r
-                                                                                       catch( er ){}\r
-                                                                               },\r
+                                                                               focus: true,\r
                                                                                html :\r
-                                                                                       '<div class="cke_tpl_list" tabIndex="-1" role="listbox" aria-labelledby="cke_tpl_list_label">' +\r
+                                                                                       '<div class="cke_tpl_list" tabIndex="-1" role="listbox" aria-labelledby="' + templateListLabelId+ '">' +\r
                                                                                                '<div class="cke_tpl_loading"><span></span></div>' +\r
                                                                                        '</div>' +\r
-                                                                                       '<span class="cke_voice_label" id="cke_tpl_list_label">' + editor.lang.common.options+ '</span>'\r
+                                                                                       '<span class="cke_voice_label" id="' + templateListLabelId + '">' + lang.options+ '</span>'\r
                                                                        },\r
                                                                        {\r
                                                                                id : 'chkInsertOpt',\r
                                                                                type : 'checkbox',\r
-                                                                               label : editor.lang.templates.insertOption,\r
-                                                                               'default' : editor.config.templates_replaceContent\r
+                                                                               label : lang.insertOption,\r
+                                                                               'default' : config.templates_replaceContent\r
                                                                        }\r
                                                                ]\r
                                                        }\r
@@ -199,9 +203,9 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        var templatesListField = this.getContentElement( 'selectTpl' , 'templatesList' );\r
                                        listContainer = templatesListField.getElement();\r
 \r
-                                       CKEDITOR.loadTemplates( editor.config.templates_files, function()\r
+                                       CKEDITOR.loadTemplates( config.templates_files, function()\r
                                                {\r
-                                                       var templates = editor.config.templates.split( ',' );\r
+                                                       var templates = ( config.templates || 'default' ).split( ',' );\r
 \r
                                                        if ( templates.length )\r
                                                        {\r
@@ -212,7 +216,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                                        {\r
                                                                listContainer.setHtml(\r
                                                                        '<div class="cke_tpl_empty">' +\r
-                                                                               '<span>' + editor.lang.templates.emptyListMsg + '</span>' +\r
+                                                                               '<span>' + lang.emptyListMsg + '</span>' +\r
                                                                        '</div>' );\r
                                                        }\r
                                                });\r
@@ -220,7 +224,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                        this._.element.on( 'keydown', keyNavigation );\r
                                },\r
 \r
-                               onHide : function ()\r
+                               onHide : function()\r
                                {\r
                                        this._.element.removeListener( 'keydown', keyNavigation );\r
                                }\r