webapp.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. ///import core
  2. ///import plugins/inserthtml.js
  3. ///commands 百度应用
  4. ///commandsName webapp
  5. ///commandsTitle 百度应用
  6. ///commandsDialog dialogs\webapp
  7. UE.plugins['webapp'] = function () {
  8. var me = this;
  9. function createInsertStr( obj, toIframe, addParagraph ) {
  10. return !toIframe ?
  11. (addParagraph ? '<p>' : '') + '<img title="'+obj.title+'" width="' + obj.width + '" height="' + obj.height + '"' +
  12. ' src="' + me.options.UEDITOR_HOME_URL + 'themes/default/images/spacer.gif" style="background:url(' + obj.logo+') no-repeat center center; border:1px solid gray;" class="edui-faked-webapp" _url="' + obj.url + '" />' +
  13. (addParagraph ? '</p>' : '')
  14. :
  15. '<iframe class="edui-faked-webapp" title="'+obj.title+'" width="' + obj.width + '" height="' + obj.height + '" scrolling="no" frameborder="0" src="' + obj.url + '" logo_url = '+obj.logo+'></iframe>';
  16. }
  17. function switchImgAndIframe( img2frame ) {
  18. var tmpdiv,
  19. nodes = domUtils.getElementsByTagName( me.document, !img2frame ? "iframe" : "img" );
  20. for ( var i = 0, node; node = nodes[i++]; ) {
  21. if ( node.className != "edui-faked-webapp" ){
  22. continue;
  23. }
  24. tmpdiv = me.document.createElement( "div" );
  25. tmpdiv.innerHTML = createInsertStr( img2frame ? {url:node.getAttribute( "_url" ), width:node.width, height:node.height,title:node.title,logo:node.style.backgroundImage.replace("url(","").replace(")","")} : {url:node.getAttribute( "src", 2 ),title:node.title, width:node.width, height:node.height,logo:node.getAttribute("logo_url")}, img2frame ? true : false,false );
  26. node.parentNode.replaceChild( tmpdiv.firstChild, node );
  27. }
  28. }
  29. me.addListener( "beforegetcontent", function () {
  30. switchImgAndIframe( true );
  31. } );
  32. me.addListener( 'aftersetcontent', function () {
  33. switchImgAndIframe( false );
  34. } );
  35. me.addListener( 'aftergetcontent', function ( cmdName ) {
  36. if ( cmdName == 'aftergetcontent' && me.queryCommandState( 'source' ) ){
  37. return;
  38. }
  39. switchImgAndIframe( false );
  40. } );
  41. me.commands['webapp'] = {
  42. execCommand:function ( cmd, obj ) {
  43. me.execCommand( "inserthtml", createInsertStr( obj, false,true ) );
  44. }
  45. };
  46. };