| 156 | | if (idApplicable) // IDs |
| 157 | | { |
| 158 | | // requires specific html tag |
| 159 | | tag = className.substring(0, className.indexOf('#')).toLowerCase(); |
| 160 | | var idName = className.substring(className.indexOf('#'), className.length); |
| 161 | | |
| 162 | | // To apply we must have an ancestor tag that is the right type |
| 163 | | if(active_elem != null && active_elem.tagName.toLowerCase() == tag) |
| 164 | | { |
| 165 | | idApplicable = true; |
| 166 | | apply_to = active_elem; |
| 167 | | } |
| 168 | | else |
| 169 | | { |
| 170 | | if(this._getFirstAncestor(this._getSelection(), [tag]) != null) |
| 171 | | { |
| 172 | | idApplicable = true; |
| 173 | | apply_to = this._getFirstAncestor(this._getSelection(), [tag]); |
| 174 | | } |
| 175 | | else |
| 176 | | { |
| 177 | | // alert (this._getFirstAncestor(this._getSelection(), tag)); |
| 178 | | // If we don't have an ancestor, but it's a div/span/p/hx stle, we can make one |
| 179 | | if(( tag == 'div' || tag == 'span' || tag == 'p' |
| 180 | | || (tag.substr(0,1) == 'h' && tag.length == 2 && tag != 'hr'))) |
| 181 | | { |
| 182 | | if(!this._selectionEmpty(this._getSelection())) |
| 183 | | { |
| 184 | | idApplicable = true; |
| 185 | | apply_to = 'new'; |
| 186 | | } |
| 187 | | else |
| 188 | | { |
| 189 | | // See if we can get a paragraph or header that can be converted |
| 190 | | apply_to = this._getFirstAncestor(sel, ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7']); |
| 191 | | if(apply_to != null) |
| 192 | | { |
| 193 | | idApplicable = true; |
| 194 | | } |
| 195 | | } |
| 196 | | } |
| 197 | | else |
| 198 | | { |
| 199 | | idApplicable = false; |
| 200 | | } |
| 201 | | } |
| 202 | | } |
| 203 | | } |
| 204 | | |
| 205 | | |
| 206 | | if(applicable || idApplicable) |
| 207 | | { |
| 208 | | |
| 209 | | if (idApplicable) |
| 210 | | { |
| 211 | | // Remove the first . |
| 212 | | idName = idName.substring(idName.indexOf('#'), idName.length); |
| 213 | | |
| 214 | | // Replace any futher ones with spaces (for multiple id definitions (yes it happens)) |
| 215 | | idName = idName.replace('#', ' '); |
| 216 | | } |
| 217 | | else |
| 218 | | { |
| 219 | | // Remove the first . |
| 220 | | className = className.substring(className.indexOf('.'), className.length); |
| 221 | | |
| 222 | | // Replace any futher ones with spaces (for multiple class definitions) |
| 223 | | className = className.replace('.', ' '); |
| 224 | | } |
| | 150 | if(applicable) |
| | 151 | { |
| | 152 | // Remove the first . |
| | 153 | className = className.substring(className.indexOf('.'), className.length); |
| | 154 | |
| | 155 | // Replace any futher ones with spaces (for multiple class definitions) |
| | 156 | className = className.replace('.', ' '); |
| 241 | | if (idApplicable) |
| 242 | | { |
| 243 | | var applied = (this._ancestorsWithIDs(sel, tag, idName).length > 0 ? true : false); |
| 244 | | var applied_to = this._ancestorsWithIDs(sel, tag, idName); |
| 245 | | } |
| 246 | | else |
| 247 | | { |
| 248 | | var applied = (this._ancestorsWithClasses(sel, tag, className).length > 0 ? true : false); |
| 249 | | var applied_to = this._ancestorsWithClasses(sel, tag, className); |
| 250 | | } |
| 251 | | |
| 252 | | if(applicable || idApplicable) |
| | 173 | var applied = (this._ancestorsWithClasses(sel, tag, className).length > 0 ? true : false); |
| | 174 | var applied_to = this._ancestorsWithClasses(sel, tag, className); |
| | 175 | |
| | 176 | if(applicable) |
| 267 | | if (idApplicable) |
| 268 | | { |
| 269 | | anch.onclick = function() |
| 270 | | { |
| 271 | | if(this._stylist_applied == true) |
| 272 | | { |
| 273 | | editor._stylistRemoveIDs(this._stylist_idName, this._stylist_appliedTo); |
| 274 | | } |
| 275 | | else |
| 276 | | { |
| 277 | | editor._stylistAddIDs(this._stylist_applyTo, this._stylist_applyTag, this._stylist_idName); |
| 278 | | } |
| 279 | | return false; |
| 280 | | } |
| 281 | | } |
| 282 | | else |
| 283 | | { |
| 284 | | anch.onclick = function() |
| 285 | | { |
| 286 | | if(this._stylist_applied == true) |
| 287 | | { |
| 288 | | editor._stylistRemoveClasses(this._stylist_className, this._stylist_appliedTo); |
| 289 | | } |
| 290 | | else |
| 291 | | { |
| 292 | | editor._stylistAddClasses(this._stylist_applyTo, this._stylist_applyTag, this._stylist_className); |
| 293 | | } |
| 294 | | return false; |
| 295 | | } |
| | 188 | anch.onclick = function() |
| | 189 | { |
| | 190 | if(this._stylist_applied == true) |
| | 191 | { |
| | 192 | editor._stylistRemoveClasses(this._stylist_className, this._stylist_appliedTo); |
| | 193 | } |
| | 194 | else |
| | 195 | { |
| | 196 | editor._stylistAddClasses(this._stylist_applyTo, this._stylist_applyTag, this._stylist_className); |
| | 197 | } |
| | 198 | return false; |
| 353 | | |
| 354 | | Xinha.prototype._stylistAddIDs = function(el, tag, ids) |
| 355 | | { |
| 356 | | if(el == 'new') |
| 357 | | { |
| 358 | | this.insertHTML('<' + tag + ' id="' + ids + '">' + this.getSelectedHTML() + '</' + tag + '>'); |
| 359 | | } |
| 360 | | else |
| 361 | | { |
| 362 | | if(tag != null && el.tagName.toLowerCase() != tag) |
| 363 | | { |
| 364 | | // Have to change the tag! |
| 365 | | var new_el = this.switchElementTag(el, tag); |
| 366 | | |
| 367 | | if(typeof el._stylist_usedToBe != 'undefined') |
| 368 | | { |
| 369 | | new_el._stylist_usedToBe = el._stylist_usedToBe; |
| 370 | | new_el._stylist_usedToBe[new_el._stylist_usedToBe.length] = {'tagName' : el.tagName, 'id' : el.getAttribute('id')}; |
| 371 | | } |
| 372 | | else |
| 373 | | { |
| 374 | | new_el._stylist_usedToBe = [{'tagName' : el.tagName, 'id' : el.getAttribute('id')}]; |
| 375 | | } |
| 376 | | |
| 377 | | Xinha.addIDs(new_el, ids); |
| 378 | | } |
| 379 | | else |
| 380 | | { |
| 381 | | Xinha._addIDs(el, ids); |
| 382 | | } |
| 383 | | } |
| 384 | | this.focusEditor(); |
| 385 | | this.updateToolbar(); |
| 386 | | }; |
| 465 | | } |
| 466 | | else |
| 467 | | { |
| 468 | | // Must be a span with no classes and no id, so we can splice it out |
| 469 | | var prnt = el.parentNode; |
| 470 | | var childs = el.childNodes; |
| 471 | | for(var x = 0; x < childs.length; x++) |
| 472 | | { |
| 473 | | prnt.insertBefore(childs[x], el); |
| 474 | | } |
| 475 | | prnt.removeChild(el); |
| 476 | | } |
| 477 | | } |
| 478 | | }; |
| 479 | | |
| 480 | | Xinha.prototype._stylistRemoveIDsFull = function(el, ids) |
| 481 | | { |
| 482 | | if(el != null) |
| 483 | | { |
| 484 | | var thiers = el.id.trim().split(' '); |
| 485 | | var new_thiers = [ ]; |
| 486 | | var ours = ids.split(' '); |
| 487 | | for(var x = 0; x < thiers.length; x++) |
| 488 | | { |
| 489 | | var exists = false; |
| 490 | | for(var i = 0; exists == false && i < ours.length; i++) |
| 491 | | { |
| 492 | | if(ours[i] == thiers[x]) |
| 493 | | { |
| 494 | | exists = true; |
| 495 | | } |
| 496 | | } |
| 497 | | if(exists == false) |
| 498 | | { |
| 499 | | new_thiers[new_thiers.length] = thiers[x]; |
| 500 | | } |
| 501 | | } |
| 502 | | |
| 503 | | if(new_thiers.length == 0 && el._stylist_usedToBe && el._stylist_usedToBe.length > 0 && el._stylist_usedToBe[el._stylist_usedToBe.length - 1].id != null) |
| 504 | | { |
| 505 | | // Revert back to what we were IF the classes are identical |
| 506 | | var last_el = el._stylist_usedToBe[el._stylist_usedToBe.length - 1]; |
| 507 | | var last_ids = Xinha.arrayFilter(last_el.id.trim().split(' '), function(c) { if (c == null || c.trim() == '') { return false;} return true; }); |
| 508 | | |
| 509 | | if( |
| 510 | | (new_thiers.length == 0) |
| 511 | | || |
| 512 | | ( |
| 513 | | Xinha.arrayContainsArray(new_thiers, last_ids) |
| 514 | | && Xinha.arrayContainsArray(last_ids, new_thiers) |
| 515 | | ) |
| 516 | | ) |
| 517 | | { |
| 518 | | el = this.switchElementTag(el, last_el.tagName); |
| 519 | | new_thiers = last_ids; |
| 520 | | } |
| 521 | | else |
| 522 | | { |
| 523 | | // We can't rely on the remembered tags any more |
| 524 | | el._stylist_usedToBe = [ ]; |
| 525 | | } |
| 526 | | } |
| 527 | | |
| 528 | | if( new_thiers.length > 0 |
| 529 | | || el.tagName.toLowerCase() != 'span' |
| 530 | | || (el.id && el.id != '') |
| 531 | | ) |
| 532 | | { |
| 533 | | el.id = new_thiers.join(' ').trim(); |
| 640 | | { |
| 641 | | found_all = false; |
| 642 | | break; |
| 643 | | } |
| 644 | | } |
| 645 | | |
| 646 | | if(found_all) ancestors[ancestors.length] = prnt; |
| 647 | | } |
| 648 | | if(prnt.tagName.toLowerCase() == 'body') break; |
| 649 | | if(prnt.tagName.toLowerCase() == 'table' ) break; |
| 650 | | } |
| 651 | | prnt = prnt.parentNode; |
| 652 | | } |
| 653 | | |
| 654 | | return ancestors; |
| 655 | | }; |
| 656 | | |
| 657 | | Xinha.prototype._ancestorsWithIDs = function(sel, tag, ids) |
| 658 | | { |
| 659 | | var ancestors = [ ]; |
| 660 | | var prnt = this._activeElement(sel); |
| 661 | | if(prnt == null) |
| 662 | | { |
| 663 | | try |
| 664 | | { |
| 665 | | prnt = (Xinha.is_ie ? this._createRange(sel).parentElement() : this._createRange(sel).commonAncestorContainer); |
| 666 | | } |
| 667 | | catch(e) |
| 668 | | { |
| 669 | | return ancestors; |
| 670 | | } |
| 671 | | } |
| 672 | | var search_ids = ids.trim().split(' '); |
| 673 | | |
| 674 | | while(prnt) |
| 675 | | { |
| 676 | | if(prnt.nodeType == 1 && prnt.id) |
| 677 | | { |
| 678 | | if(tag == null || prnt.tagName.toLowerCase() == tag) |
| 679 | | { |
| 680 | | var ids = prnt.id.trim().split(' '); |
| 681 | | var found_all = true; |
| 682 | | for(var i = 0; i < search_ids.length; i++) |
| 683 | | { |
| 684 | | var found_id = false; |
| 685 | | for(var x = 0; x < ids.length; x++) |
| 686 | | { |
| 687 | | if(search_ids[i] == ids[x]) |
| 688 | | { |
| 689 | | found_id = true; |
| 690 | | break; |
| 691 | | } |
| 692 | | } |
| 693 | | |
| 694 | | if(!found_id) |