Advertisement
Guest User

Sedo Js Redactor function

a guest
Apr 12th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         execToSpan: function(tag, tagPropType, tagProp, cssProp, propFunc, addClass)
  2.         {
  3.             var ed = this, prop;
  4.            
  5.             $tag = ed.$editor.find(tag).filter(function() {
  6.                 if(tagPropType == 'css'){
  7.                     return $(this).css(tagProp).indexOf();
  8.                 }else if (tagPropType == 'attr'){
  9.                     return $(this).attr(tagProp);              
  10.                 }
  11.             });
  12.  
  13.             $tagChildren = $tag.children('span');
  14.             $tag.first().before('<span id="memTemp1" />');
  15.             $tag.last().after('<span id="memTemp2" />');
  16.  
  17.             /***
  18.             *   Get final property value
  19.             ***/
  20.             if(tagPropType == 'css'){
  21.                 prop = $tag.css(tagProp);
  22.             }else if (tagPropType == 'attr'){
  23.                 prop = $tag.attr(tagProp);         
  24.             }
  25.    
  26.             if(typeof(prop) === 'undefined'){
  27.                 return false;
  28.             }
  29.    
  30.             /***
  31.             *   Modify if needed the tagProp value for css
  32.             *   I just needs an object with the value of the tagProp as key
  33.             ***/
  34.             if(propFunc !== false){
  35.                 prop = propFunc[prop];
  36.             }
  37.  
  38.             /***
  39.             *   Replace font=>span OR update existed span
  40.             ***/           
  41.             if($tagChildren.length > 0) {
  42.                
  43.                 $tagChildren.each(function()
  44.                 {
  45.                     $(this).css(cssProp, prop);
  46.                 })
  47.                 .unwrap();
  48.                
  49.                 if(typeof(addClass) !== 'undefined')
  50.                 {
  51.                     $tagChildren.addClass(addClass);
  52.                 }
  53.                
  54.             }else{
  55.                
  56.                 var cssClass = (typeof(addClass) !== 'undefined') ? 'class="'+addClass+'"' : '';
  57.  
  58.                 $tag.replaceWith(function() {
  59.                     return $('<span '+cssClass+' style="'+cssProp+': ' + prop + ';">' + $(this).html() + '</span>');
  60.                 });
  61.             }
  62.  
  63.             /***
  64.             *   Retrieve selection
  65.             ***/   
  66.             first = $("#memTemp1").get(0);
  67.             last = $("#memTemp2").get(0);
  68.  
  69.             try{
  70.                 ed.setSelection(first, 0, last, 0);
  71.             }catch(e){
  72.                 console.error(e.message);
  73.             }
  74.                
  75.                 ed.saveSelection();
  76.             $('#memTemp1, #memTemp2').remove();
  77.  
  78.             /***
  79.             *   Sync rte editor content with textarea
  80.             ***/           
  81.             ed.syncCode();     
  82.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement