Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- execToSpan: function(tag, tagPropType, tagProp, cssProp, propFunc, addClass)
- {
- var ed = this, prop;
- $tag = ed.$editor.find(tag).filter(function() {
- if(tagPropType == 'css'){
- return $(this).css(tagProp).indexOf();
- }else if (tagPropType == 'attr'){
- return $(this).attr(tagProp);
- }
- });
- $tagChildren = $tag.children('span');
- $tag.first().before('<span id="memTemp1" />');
- $tag.last().after('<span id="memTemp2" />');
- /***
- * Get final property value
- ***/
- if(tagPropType == 'css'){
- prop = $tag.css(tagProp);
- }else if (tagPropType == 'attr'){
- prop = $tag.attr(tagProp);
- }
- if(typeof(prop) === 'undefined'){
- return false;
- }
- /***
- * Modify if needed the tagProp value for css
- * I just needs an object with the value of the tagProp as key
- ***/
- if(propFunc !== false){
- prop = propFunc[prop];
- }
- /***
- * Replace font=>span OR update existed span
- ***/
- if($tagChildren.length > 0) {
- $tagChildren.each(function()
- {
- $(this).css(cssProp, prop);
- })
- .unwrap();
- if(typeof(addClass) !== 'undefined')
- {
- $tagChildren.addClass(addClass);
- }
- }else{
- var cssClass = (typeof(addClass) !== 'undefined') ? 'class="'+addClass+'"' : '';
- $tag.replaceWith(function() {
- return $('<span '+cssClass+' style="'+cssProp+': ' + prop + ';">' + $(this).html() + '</span>');
- });
- }
- /***
- * Retrieve selection
- ***/
- first = $("#memTemp1").get(0);
- last = $("#memTemp2").get(0);
- try{
- ed.setSelection(first, 0, last, 0);
- }catch(e){
- console.error(e.message);
- }
- ed.saveSelection();
- $('#memTemp1, #memTemp2').remove();
- /***
- * Sync rte editor content with textarea
- ***/
- ed.syncCode();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement