Advertisement
Guest User

image.js

a guest
Jun 14th, 2011
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(){
  2.    
  3.     var VbImage = function(editor)
  4.     {
  5.         this.editor = editor;
  6.     };
  7.     VbImage.prototype =
  8.     {
  9.  
  10.         tryMoveFlashObj: function(iteration)
  11.         {
  12.             var me = this;
  13.             if (!iteration)
  14.             {
  15.                 iteration = 5;
  16.             };
  17.  
  18.             if (this.moveFlashObj() || iteration == 0)
  19.             {
  20.                 return;
  21.             }
  22.  
  23.             setTimeout(
  24.                 function()
  25.                 {
  26.                     me.tryMoveFlashObj(iteration - 1);
  27.                 },
  28.                 500
  29.             );
  30.         },
  31.  
  32.         moveFlashObj: function()
  33.         {
  34.             // move flash holder to where it needs to be!
  35.  
  36.             var region = YAHOO.util.Dom.getRegion("yui_selectfilestext");
  37.             if (!region || region.height == 0)
  38.             {
  39.                 return false;
  40.             }
  41.  
  42.             YAHOO.util.Dom.setStyle("yui_selectfiles", "width", region.width - 2 + "px");
  43.             YAHOO.util.Dom.setStyle("yui_selectfiles", "height", region.height - 2 + "px");
  44.             var xy = YAHOO.util.Dom.getXY("yui_selectfilestext");
  45.             YAHOO.util.Dom.setXY("yui_selectfiles", xy);
  46.  
  47.             if (is_moz)
  48.             {   // Don't even ask!
  49.                 YAHOO.util.Dom.setStyle("yui_selectfiles", "overflow-x", "");
  50.                 YAHOO.util.Dom.setStyle("yui_selectfiles", "overflow-y", "");
  51.                 YAHOO.util.Dom.setStyle("yui_selectfiles", "overflow", "");
  52.                 YAHOO.util.Dom.setStyle("yui_selectfiles", "overflow", "none");
  53.             }
  54.  
  55.             return true;
  56.         },
  57.  
  58.         getImageUploadHtml: function()
  59.         {
  60.             var postData = {
  61.                 ajax: 1,
  62.                 'do': 'fetchhtml',
  63.                 template: 'editor_upload_overlay',
  64.                 securitytoken:  this.editor.config.vbulletin.securitytoken
  65.             };
  66.            
  67.             var responseXML = CKEDITOR.vbajax.open({
  68.                 url: 'ajax.php',
  69.                 type: 'POST',
  70.                 data: postData,
  71.                 async: false,
  72.                 dataType: 'xml'
  73.             }).responseXML;
  74.            
  75.             var html = responseXML.getElementsByTagName('html')[0].firstChild.nodeValue;
  76.            
  77.             return '<form id="' + this.editor.editorid + '_dialog" style="position: absoulte; z-index:999999; ">' + html + '</form>';
  78.         },
  79.        
  80.         insertImageReady: function()
  81.         {
  82.             var imageuploadobj = new vB_ImageUpload(this.editor.editorid, this.editor);
  83.             imageuploadobj.events.complete.subscribe(this.insertImageComplete, this);
  84.             imageuploadobj.events.uploaddone.subscribe(this.insertImageUploadOne, this);
  85.         },
  86.        
  87.         insertImageComplete: function (event, args, me)
  88.         {
  89.             // close dialog
  90.             CKEDITOR.dialog.getCurrent().hide();
  91.         },
  92.        
  93.         insertImageUploadOne: function (event, args, me)
  94.         {
  95.             var attachmentid = args[0], contenttypeid = args[1], thumbnail = args[2];
  96.             if (thumbnail != 0)
  97.             {
  98.                 me.editor.insert_attachment(attachmentid);
  99.             }
  100.             else
  101.             {
  102.                 me.editor.insert_attachment(attachmentid, false);
  103.             }
  104.         },
  105.        
  106.         doAttachmentFromUrl: function(dialog)
  107.         {
  108.             var url = dialog.getContentElement('from_url', 'url').getValue();
  109.             if (dialog.getContentElement('from_url', 'remote_file').getValue())
  110.             {
  111.                 var postData = {
  112.                     ajax: 1,
  113.                     'do': 'manageattach',
  114.                     flash: 1,
  115.                     upload: 1,
  116.                     posthash: this.editor.config.vbulletin.attachinfo.posthash,
  117.                     poststarttime: this.editor.config.vbulletin.attachinfo.poststarttime,
  118.                     contenttypeid: this.editor.config.vbulletin.contenttypeid,
  119.                     'attachmenturl[]': url,
  120.                     securitytoken: this.editor.config.vbulletin.securitytoken
  121.                 };
  122.                
  123.                 var responseText = CKEDITOR.vbajax.open({
  124.                     url: 'newattachment.php',
  125.                     type: 'POST',
  126.                     data: CKEDITOR.vbajax.parseRequestData(postData) + this.editor.config.vbulletin.attachinfo.valuestring,
  127.                     async: false
  128.                 }).responseText;
  129.                
  130.                 var response = responseText.split(' - ');
  131.                 if (response[0] == 'ok')
  132.                 {
  133.                     this.editor.insert_attachment(response[1]);
  134.                 }
  135.                 else
  136.                 {
  137.                     alert(this.editor.lang.vbulletin.invalidurl);
  138.                     return false;
  139.                 }
  140.             }
  141.             else
  142.             {
  143.                 this.editor.insertHtml('[IMG]'+url+'[/IMG]');
  144.             }
  145.             return true;
  146.         },
  147.        
  148.         getImageDialog: function()
  149.         {
  150.             var phrase = this.editor.config.vbulletin.phrase;
  151.             var me = this;
  152.                        
  153.             return {
  154.                 title: 'Insert Image',
  155.                 onOk: function(event){
  156.                     return me.doAttachmentFromUrl(CKEDITOR.dialog.getCurrent());
  157.                 },
  158.                 onLoad: function(){
  159.                     var dialog = CKEDITOR.dialog.getCurrent();
  160.                     dialog.on('selectPage', function(event)
  161.                     {
  162.                         if (event.data.page == 'from_computer')
  163.                         {
  164.                             dialog.parts.footer.setStyle('display', 'none');
  165.                             // the 'selectPage' event is fired before the page is actually displayed so moveFlashObj() will
  166.                             // fail until yui_selectfilestest is visible
  167.                             me.tryMoveFlashObj();
  168.                         }
  169.                         else
  170.                         {
  171.                             dialog.parts.footer.setStyle('display', 'block');
  172.                             YAHOO.util.Dom.setStyle("yui_selectfiles", "width", "1px");
  173.                             YAHOO.util.Dom.setStyle("yui_selectfiles", "height", "1px");
  174.                         }
  175.                     });
  176.  
  177.                     if (false && me.editor.config.vbulletin.attachinfo && me.editor.config.vbulletin.attachinfo.advimagepopup != 0)
  178.                     {
  179.    
  180.                     }
  181.                     else
  182.                     {
  183.                         dialog.selectPage('from_url');
  184.                         dialog.hidePage('from_computer')
  185.                         var remote = dialog.getContentElement('from_url', 'remote_file');
  186.                         remote.getElement().hide();
  187.                     }
  188.                 },
  189.                 onShow: function(){
  190.                     var node1 = YAHOO.util.Dom.get("uploadtabs0");
  191.                     var node2 = YAHOO.util.Dom.get("_uploadtabs0");
  192.                     if (node2)
  193.                     {
  194.                         if (node1)
  195.                         {
  196.                             node1.parentNode.replaceChild(node2, node1);
  197.                         }
  198.                         node2.id = "uploadtabs0";
  199.                     }
  200.                     this.setupContent();
  201.                 },
  202.                 onHide: function(){
  203.                     YAHOO.util.Dom.setStyle("yui_selectfiles", "width", "1px");
  204.                     YAHOO.util.Dom.setStyle("yui_selectfiles", "height", "1px");
  205.                     YAHOO.util.Dom.get("uploadtabs0").id = '_uploadtabs0';
  206.                 },
  207.                 minWidth: '410',
  208.                 minHeight: '220',
  209.                 //buttons: [],
  210.                 contents: [{
  211.                     id: 'from_computer',
  212.                     label: 'From Computer',
  213.             elements:[{
  214.                 type: 'html',
  215.               html: me.getImageUploadHtml()
  216.             }]
  217.                 },{
  218.                     id: 'from_url',
  219.                     label: 'From URL',
  220.             elements:[{
  221.                 type: 'html',
  222.                 html: '<h2>Add an Image from Url</h2>' +
  223.                             '<div>Allowed Filetypes: jpg, jpeg, png, gif</div>'
  224.             },{
  225.                 type: 'text',
  226.               id: 'url',
  227.               label: 'URL',
  228.               labelLayout: 'vertical'
  229.             },{
  230.                 type: 'checkbox',
  231.               id: 'remote_file',
  232.               label: 'Retrieve remote file and reference locally',
  233.               labelLayout: 'horizontal',
  234.               setup: function() {
  235.                     if (me.editor.config.vbulletin.attachinfo)
  236.                     {
  237.                         this.setValue(false);
  238.                     }
  239.                 }
  240.             }]
  241.                 }]
  242.             }
  243.         }
  244.     };
  245.    
  246.     CKEDITOR.dialog.add('vbimage', function(editor) {
  247.         var vbimage = new VbImage(editor);
  248.         return vbimage.getImageDialog();
  249.     });
  250.        
  251. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement