[pLog-svn] r7092 - plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource

Mark Wu markplace at gmail.com
Tue Dec 21 04:51:23 EST 2010


Damn, it is sizzlejs, not sizzler.. it is typo .

2010/12/21 <mark at devel.lifetype.net>

> Author: mark
> Date: 2010-12-20 12:29:08 -0500 (Mon, 20 Dec 2010)
> New Revision: 7092
>
> Modified:
>
> plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/editor_plugin.js
>
> plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/editor_plugin_src.js
> Log:
> Refactoring the insert resource plugin based on DOMUtils from Tinymce(from
> sizzler), and also fixed some bugs. (PS. the media plugin will hijack the
> embed code from insert resource plugin, therefore the _edit2html does not do
> anything if media plugin enabled.)
>
> Modified:
> plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/editor_plugin.js
> ===================================================================
> ---
> plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/editor_plugin.js
>       2010-12-19 17:43:03 UTC (rev 7091)
> +++
> plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/editor_plugin.js
>       2010-12-20 17:29:08 UTC (rev 7092)
> @@ -1,22 +1,4 @@
>
> -(function(){tinymce.PluginManager.requireLangPack('insertresource');tinymce.create('tinymce.plugins.InsertResourcePlugin',{init:function(ed,url){var
> t=this;ed.onBeforeSetContent.add(function(ed,o){o.content=t.edit2html(t,o.content);});ed.onPostProcess.add(function(ed,o){if(o.set){o.content=t.edit2html(t,o.content);}
>
> -if(o.get){o.content=t.html2edit(t,o.content);}});ed.addCommand('mceInsertResource',function(){ed.windowManager.open({file:url+'../../../../../admin.php?op=resourceList&mode=1',width:500+parseInt(ed.getLang('InsertResource.delta_width',0)),height:450+parseInt(ed.getLang('InsertResource.delta_height',0)),inline:1},{plugin_url:url,});});ed.addButton('insertresource',{title:'insertresource.desc',cmd:'mceInsertResource',image:url+'/img/insertresource.gif'});ed.onInit.add(function(){if(ed.settings.content_css!==false)
> -ed.dom.loadCSS(url+"/css/content.css");});ed.onNodeChange.add(function(ed,cm,n){cm.setActive('insertresource',n.nodeName=='IMG');});},getInfo:function(){return{longname:'InsertResource
> plugin',author:'LifeType',authorurl:'http://lifetype.net',infourl:'',version:"2.0"};},edit2html:function(t,content){var
> startPos=0;var embedList=new Array();content=content.replace(new RegExp('<[
> ]*object','gi'),'<object');content=content.replace(new RegExp('<[ ]*/object[
> ]*>','gi'),'</object>');var
> index=0;while((startPos=content.indexOf('<object',startPos))!=-1){endPos=content.indexOf('</object>',startPos);endPos+=9;objectTag=content.substring(startPos,endPos);attribs=t._parseAttributes(objectTag);var
> cssClass="";if(!attribs||attribs["value"]==undefined||attribs["class"]!="ltPlayer"){startPos++;continue;}
> -var
> regexp=/.*file=([a-zA-Z0-9\-\/:._%]*)/i;result=regexp.exec(attribs["value"]);var
> fileUrl="";if(result){fileUrl=result[1];}
> -if(attribs["height"]==undefined)
> -attribs["height"]=20;if(attribs["width"]==undefined)
> -attribs["width"]=320;var
> contentAfter=content.substring(endPos);content=content.substring(0,startPos);content+='<img
> width="'+attribs["width"]+'" height="'+attribs["height"]+'"';content+='
> src="'+(tinyMCE.getParam("theme_href")+'/images/spacer.gif')+'"
> title="'+fileUrl+'"';content+=' alt="'+fileUrl+'" class="ltFlashPlayer"
> />'+content.substring(endPos);content+=contentAfter;index++;startPos++;}
> -return content;},html2edit:function(t,content){var
> startPos=-1;while((startPos=content.indexOf('<img',startPos+1))!=-1){var
> endPos=content.indexOf('/>',startPos);var
> attribs=t._parseAttributes(content.substring(startPos+4,endPos));if(!attribs||attribs['class']!="ltFlashPlayer")
> -continue;endPos+=2;var embedHTML='';if(attribs["height"]==undefined)
> -attribs["height"]=20;if(attribs["width"]==undefined)
>
> -attribs["width"]=320;embedHTML=getFlashPlayerHTML(attribs["alt"],attribs["height"],attribs["width"]);chunkBefore=content.substring(0,startPos);chunkAfter=content.substring(endPos);content=chunkBefore+embedHTML+chunkAfter;}
> -return content;},_parseAttributes:function(attribute_string){var
> attributeName="";var attributeValue="";var withInName;var withInValue;var
> attributes=new Array();var whiteSpaceRegExp=new RegExp('^[
> \n\r\t]+','g');if(attribute_string==null||attribute_string.length<2)
> -return null;withInName=withInValue=false;for(var
> i=0;i<attribute_string.length;i++){var
> chr=attribute_string.charAt(i);if((chr=='"')&&!withInValue)
> -withInValue=true;else if((chr=='"')&&withInValue){withInValue=false;var
> pos=attributeName.lastIndexOf(' ');if(pos!=-1)
>
> -attributeName=attributeName.substring(pos+1);attributes[attributeName.toLowerCase()]=attributeValue.substring(1);attributeName="";attributeValue="";}
> -else if(!whiteSpaceRegExp.test(chr)&&!withInName&&!withInValue)
> -withInName=true;if(chr=='='&&withInName)
> -withInName=false;if(withInName)
> -attributeName+=chr;if(withInValue)
> -attributeValue+=chr;}
> -return
> attributes;}});tinymce.PluginManager.add('insertresource',tinymce.plugins.InsertResourcePlugin);})();
> \ No newline at end of file
> +(function(){tinymce.PluginManager.requireLangPack('insertresource');tinymce.create('tinymce.plugins.InsertResourcePlugin',{init:function(ed,url){var
> t=this;t.ed=ed;t.url=url;ed.onBeforeSetContent.add(function(ed,o){o.content=t._edit2html(t,o.content);});ed.onPostProcess.add(function(ed,o){if(o.set){o.content=t._edit2html(t,o.content);}
>
> +if(o.get){o.content=t._html2edit(t,o.content);}});ed.addCommand('mceInsertResource',function(){ed.windowManager.open({file:url+'../../../../../admin.php?op=resourceList&mode=1',width:500+parseInt(ed.getLang('InsertResource.delta_width',0)),height:450+parseInt(ed.getLang('InsertResource.delta_height',0)),inline:1},{plugin_url:url,});});ed.addButton('insertresource',{title:'insertresource.desc',cmd:'mceInsertResource',image:url+'/img/insertresource.gif'});ed.onInit.add(function(){if(ed.settings.content_css!==false)
> +ed.dom.loadCSS(url+"/css/content.css");});},getInfo:function(){return{longname:'Insert
> Resource',author:'LifeType Team',authorurl:'http://www.lifetype.net
> ',infourl:'http://www.lifetype.net',version:tinymce.majorVersion+"."+tinymce.minorVersion};},_edit2html:function(t,content){cdom=t.ed.dom.create('div');t.ed.dom.setHTML(cdom,content);elems=t.ed.dom.select('object[class=ltPlayer]',cdom);tinymce.each(elems,function(e){html=e.innerHTML;result=html.match(/.*file=([a-zA-Z0-9\-\/:._%]*)/i);src=(result?result[1]:0);if(src){height=(e.height?e.height:20);width=(e.width?e.width:320);imgHTML=t._createImg(src,height,width);t.ed.dom.setOuterHTML(e,imgHTML);}});content=cdom.innerHTML;t.ed.dom.remove(cdom);return
> content;},_html2edit:function(t,content){cdom=t.ed.dom.create('div');t.ed.dom.setHTML(cdom,content);elems=t.ed.dom.select('img[class=ltFlashPlayer]',cdom);tinymce.each(elems,function(e){if(e.alt){height=(e.height?e.height:20);width=(e.width?e.width:320);src=e.alt;embedHTML=getFla
>  shPlayerHTML(src,height,width);t.ed.dom.setOuterHTML(e,embedHTML);}});content=cdom.innerHTML;t.ed.dom.remove(cdom);return
> content;},_createImg:function(src,height,width){imgHTML='<img
> width="'+width+'" height="'+height+'"';imgHTML+='
> src="'+this.url+'/img/spacer.gif'+'" title="'+src+'"';imgHTML+='
> alt="'+src+'" class="ltFlashPlayer" />';return
> imgHTML;}});tinymce.PluginManager.add('insertresource',tinymce.plugins.InsertResourcePlugin);})();
> \ No newline at end of file
>
> Modified:
> plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/editor_plugin_src.js
> ===================================================================
> ---
> plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/editor_plugin_src.js
>   2010-12-19 17:43:03 UTC (rev 7091)
> +++
> plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/editor_plugin_src.js
>   2010-12-20 17:29:08 UTC (rev 7092)
> @@ -1,219 +1,125 @@
> +/**
> + * editor_plugin_src.js
> + *
> + * Copyright 2010, Lifetype Team, http://www.lifetype.net
> + * Released under GPLv2 License.
> + */
> +
>  (function() {
> -       // Load plugin specific language pack
> -       tinymce.PluginManager.requireLangPack('insertresource');
> +    tinymce.PluginManager.requireLangPack('insertresource');
> +    tinymce.create('tinymce.plugins.InsertResourcePlugin', {
> +        init : function(ed, url) {
> +            var t = this;
> +                t.ed = ed;
> +                t.url = url;
>
> -       tinymce.create('tinymce.plugins.InsertResourcePlugin', {
> -               /**
> -                * Initializes the plugin, this will be executed after the
> plugin has been created.
> -                * This call is done before the editor instance has
> finished it's initialization so use the onInit event
> -                * of the editor instance to intercept that event.
> -                *
> -                * @param {tinymce.Editor} ed Editor instance that the
> plugin is initialized in.
> -                * @param {string} url Absolute URL to where the plugin is
> located.
> -                */
> -               init : function(ed, url) {
> -            var t=this;
> -
>             ed.onBeforeSetContent.add(function(ed, o) {
> -               o.content = t.edit2html(t, o.content);
> +                o.content = t._edit2html(t, o.content);
>             });
>
>             ed.onPostProcess.add(function(ed, o) {
> -               if (o.set){
> -                   o.content = t.edit2html(t, o.content);
> -               }
> -               if (o.get){
> -                   o.content = t.html2edit(t, o.content);
> -               }
> +                if (o.set){
> +                    o.content = t._edit2html(t, o.content);
> +                }
> +                if (o.get){
> +                    o.content = t._html2edit(t, o.content);
> +                }
>             });
>
> -                       ed.addCommand('mceInsertResource', function() {
> -                               ed.windowManager.open({
> -                      file : url +
> '../../../../../admin.php?op=resourceList&mode=1', // Relative to theme
> -                      width : 500 +
> parseInt(ed.getLang('InsertResource.delta_width', 0)),
> -                                         height : 450 +
> parseInt(ed.getLang('InsertResource.delta_height', 0)),
> -                                         inline : 1
> -                               }, {
> -                                       plugin_url : url, // Plugin
> absolute URL
> -                               });
> -                       });
> +            ed.addCommand('mceInsertResource', function() {
> +                ed.windowManager.open({
> +                    file : url +
> '../../../../../admin.php?op=resourceList&mode=1', // Relative to theme
> +                    width : 500 +
> parseInt(ed.getLang('InsertResource.delta_width', 0)),
> +                    height : 450 +
> parseInt(ed.getLang('InsertResource.delta_height', 0)),
> +                    inline : 1
> +                }, {
> +                    plugin_url : url, // Plugin absolute URL
> +                });
> +            });
>
> -                       // Register insertresource button
> -                       ed.addButton('insertresource', {
> -                               title : 'insertresource.desc',
> -                               cmd : 'mceInsertResource',
> -                               image : url + '/img/insertresource.gif'
> -                       });
> +            // Register insertresource button
> +            ed.addButton('insertresource', {
> +                title : 'insertresource.desc',
> +                cmd : 'mceInsertResource',
> +                image : url + '/img/insertresource.gif'
> +            });
>
>             ed.onInit.add(function() {
> -                    if (ed.settings.content_css !== false)
> -                        ed.dom.loadCSS(url + "/css/content.css");
> +                if (ed.settings.content_css !== false)
> +                    ed.dom.loadCSS(url + "/css/content.css");
>             });
> +        },
>
> -                       // Add a node change handler, selects the button in
> the UI when a image is selected
> -                       ed.onNodeChange.add(function(ed, cm, n) {
> -                               cm.setActive('insertresource', n.nodeName
> == 'IMG');
> -                       });
> -            },
> -
> -               /**
> -                * Returns information about the plugin as a name/value
> array.
> -                * The current keys are longname, author, authorurl,
> infourl and version.
> -                *
> -                * @return {Object} Name/value array containing information
> about the plugin.
> -                */
> -               getInfo : function() {
> -                       return {
> -                               longname : 'InsertResource plugin',
> -                               author : 'LifeType',
> -                               authorurl : 'http://lifetype.net',
> -                               infourl : '',
> -                               version : "2.0"
> -                       };
> +        /**
> +         * Returns information about the plugin as a name/value array.
> +         * The current keys are longname, author, authorurl, infourl and
> version.
> +         *
> +         * @return {Object} Name/value array containing information about
> the plugin.
> +         */
> +        getInfo : function() {
> +            return {
> +                longname : 'Insert Resource',
> +                author : 'LifeType Team',
> +                authorurl : 'http://www.lifetype.net',
> +                infourl : 'http://www.lifetype.net',
> +                version : tinymce.majorVersion + "." +
> tinymce.minorVersion
> +            };
>         },
>
> -        edit2html : function(t,content){
> -           var startPos = 0;
> -           var embedList = new Array();
> -
> -               // Fix the embed and object elements
> -           content = content.replace(new RegExp('<[
> ]*object','gi'),'<object');
> -           content = content.replace(new RegExp('<[ ]*/object[
> ]*>','gi'),'</object>');
> -
> -               // Parse all object tags and replace them with images from
> the embed data
> -           var index = 0;
> -           while ((startPos = content.indexOf('<object', startPos)) != -1)
> {
> -
> -                   // Find end of object
> -               endPos = content.indexOf('</object>', startPos);
> -               endPos += 9;
> -
> -               objectTag = content.substring(startPos,endPos);
> -
> -                   /**
> -                    * NOTE: this method call relies in a bug of the
> _parseAttributes method.
> -                    * This method parses a tag and returns a list of its
> attributes. It works fine
> -                    * when presented with a single tag but now that we're
> passing a whole <object>...</object>
> -                    * block, it will also parse any other tags in the
> block. This means that it will return the
> -                    * value we're looking for as long as "FlashVars" is
> passed as the last parameter
> -                    * in the <object> block.
> -                    */
> -               attribs = t._parseAttributes( objectTag );
> -
> -               var cssClass = "";
> -               if( !attribs || attribs["value"] == undefined ||
> attribs["class"] != "ltPlayer" ) {
> -                   startPos++;
> -                   continue;
> -               }
> -
> -                   // find the value in "file=XXX"
> -               var regexp = /.*file=([a-zA-Z0-9\-\/:._%]*)/i;
> -               result = regexp.exec( attribs["value"] );
> -               var fileUrl = "";
> -               if( result ) {
> -                   fileUrl = result[1];
> -               }
> -
> -                   // default values for height and width in case they
> were not defined (for some reason)
> -               if( attribs["height"] == undefined )
> -                   attribs["height"] = 20;
> -               if( attribs["width"] == undefined )
> -                   attribs["width"] = 320;
> +        _edit2html : function(t,content){
> +            // Parse all object[class=ltPlayer] tags and replace them with
> img
> +            cdom = t.ed.dom.create('div');
> +            t.ed.dom.setHTML(cdom, content);
> +            elems = t.ed.dom.select('object[class=ltPlayer]', cdom);
>
> -                   // Insert image
> -               var contentAfter = content.substring(endPos);
> -               content = content.substring(0, startPos);
> -               content += '<img width="' + attribs["width"] + '" height="'
> + attribs["height"] + '"';
> -               content += ' src="' + (tinyMCE.getParam("theme_href") +
> '/images/spacer.gif') + '" title="' + fileUrl + '"';
> -               content += ' alt="' + fileUrl + '" class="ltFlashPlayer"
> />' + content.substring(endPos);
> -               content += contentAfter;
> -
> -               index++;
> -
> -               startPos++;
> -           }
> -           return content;
> -        },
> +            tinymce.each(elems, function(e) {
> +                html = e.innerHTML;
> +                result = html.match(/.*file=([a-zA-Z0-9\-\/:._%]*)/i);
> +                src = (result ? result[1] : 0);
> +                if (src) {
> +                    height = (e.height? e.height : 20);
> +                    width = (e.width ? e.width : 320);
> +                    imgHTML = t._createImg(src, height, width);
> +                    t.ed.dom.setOuterHTML(e, imgHTML);
> +                }
> +            });
>
> -        html2edit : function(t,content){
> -                // Parse all img[class=ltFlashPlayer] tags and replace
> them with object+embed
> -           var startPos = -1;
> -
> -           while ((startPos = content.indexOf('<img', startPos+1)) != -1)
> {
> -               var endPos = content.indexOf('/>', startPos);
> -               var attribs = t._parseAttributes(content.substring(startPos
> + 4, endPos));
> -
> -                   // If not flash, skip it
> -               if (!attribs || attribs['class'] != "ltFlashPlayer" )
> -                   continue;
> -
> -               endPos += 2;
> -
> -               var embedHTML = '';
> -
> -               if( attribs["height"] == undefined )
> -                   attribs["height"] = 20;
> -               if( attribs["width"] == undefined )
> -                   attribs["width"] = 320;
> -
> -               embedHTML = getFlashPlayerHTML( attribs["alt"],
> attribs["height"], attribs["width"] );
> -
> -                   // Insert embed/object chunk
> -               chunkBefore = content.substring(0, startPos);
> -               chunkAfter = content.substring(endPos);
> -               content = chunkBefore + embedHTML + chunkAfter;
> -           }
> -           return content;
> +            content = cdom.innerHTML;
> +            t.ed.dom.remove(cdom);
> +
> +            return content;
>         },
>
> -              // Private plugin internal functions
> +        _html2edit : function(t, content) {
> +            // Parse all img[class=ltFlashPlayer] tags and replace them
> with object+embed
> +            cdom = t.ed.dom.create('div');
> +            t.ed.dom.setHTML(cdom, content);
> +            elems = t.ed.dom.select('img[class=ltFlashPlayer]', cdom);
>
> -        _parseAttributes : function(attribute_string) {
> -            var attributeName = "";
> -            var attributeValue = "";
> -            var withInName;
> -            var withInValue;
> -            var attributes = new Array();
> -            var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g');
> -
> -            if (attribute_string == null || attribute_string.length < 2)
> -                return null;
> -
> -            withInName = withInValue = false;
> -
> -            for (var i=0; i<attribute_string.length; i++) {
> -                var chr = attribute_string.charAt(i);
> -
> -                if ((chr == '"' ) && !withInValue)
> -                    withInValue = true;
> -                else if ((chr == '"' ) && withInValue) {
> -                    withInValue = false;
> -
> -                    var pos = attributeName.lastIndexOf(' ');
> -                    if (pos != -1)
> -                        attributeName = attributeName.substring(pos+1);
> -
> -                    attributes[attributeName.toLowerCase()] =
> attributeValue.substring(1);
> -
> -                    attributeName = "";
> -                    attributeValue = "";
> +            tinymce.each(elems, function(e) {
> +                if (e.alt) {
> +                    height = (e.height? e.height : 20);
> +                    width = (e.width ? e.width : 320);
> +                    src = e.alt;
> +                    embedHTML = getFlashPlayerHTML(src, height, width);
> +                    t.ed.dom.setOuterHTML(e, embedHTML);
>                 }
> -                else if (!whiteSpaceRegExp.test(chr) && !withInName &&
> !withInValue)
> -                    withInName = true;
> -
> -                if (chr == '=' && withInName)
> -                    withInName = false;
> -
> -                if (withInName)
> -                    attributeName += chr;
> -
> -                if (withInValue)
> -                    attributeValue += chr;
> -            }
> -
> -            return attributes;
> +            });
> +
> +            content = cdom.innerHTML;
> +            t.ed.dom.remove(cdom);
> +
> +            return content;
> +        },
> +
> +        _createImg : function(src, height, width) {
> +            imgHTML  = '<img width="' + width + '" height="' + height +
> '"';
> +            imgHTML += ' src="' + this.url + '/img/spacer.gif' + '"
> title="' + src + '"';
> +            imgHTML += ' alt="' + src + '" class="ltFlashPlayer" />';
> +
> +            return imgHTML;
>         }
>     });
> -        // Register plugin
> -       tinymce.PluginManager.add('insertresource',
> tinymce.plugins.InsertResourcePlugin);
> +    // Register plugin
> +    tinymce.PluginManager.add('insertresource',
> tinymce.plugins.InsertResourcePlugin);
>  })();
>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://limedaley.com/mailman/listinfo/plog-svn
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://limedaley.com/pipermail/plog-svn/attachments/20101221/9f72f6d2/attachment-0001.htm>


More information about the pLog-svn mailing list