12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816 |
- goog.provide('goog.editor.Field');
- goog.provide('goog.editor.Field.EventType');
- goog.require('goog.a11y.aria');
- goog.require('goog.a11y.aria.Role');
- goog.require('goog.array');
- goog.require('goog.asserts');
- goog.require('goog.async.Delay');
- goog.require('goog.dom');
- goog.require('goog.dom.Range');
- goog.require('goog.dom.TagName');
- goog.require('goog.dom.classlist');
- goog.require('goog.dom.safe');
- goog.require('goog.editor.BrowserFeature');
- goog.require('goog.editor.Command');
- goog.require('goog.editor.Plugin');
- goog.require('goog.editor.icontent');
- goog.require('goog.editor.icontent.FieldFormatInfo');
- goog.require('goog.editor.icontent.FieldStyleInfo');
- goog.require('goog.editor.node');
- goog.require('goog.editor.range');
- goog.require('goog.events');
- goog.require('goog.events.EventHandler');
- goog.require('goog.events.EventTarget');
- goog.require('goog.events.EventType');
- goog.require('goog.events.KeyCodes');
- goog.require('goog.functions');
- goog.require('goog.html.SafeHtml');
- goog.require('goog.html.legacyconversions');
- goog.require('goog.log');
- goog.require('goog.log.Level');
- goog.require('goog.string');
- goog.require('goog.string.Unicode');
- goog.require('goog.style');
- goog.require('goog.userAgent');
- goog.require('goog.userAgent.product');
- goog.editor.Field = function(id, opt_doc) {
- goog.events.EventTarget.call(this);
-
- this.id = id;
-
- this.hashCode_ = id;
-
- this.editableDomHelper = null;
-
- this.plugins_ = {};
-
- this.indexedPlugins_ = {};
- for (var op in goog.editor.Plugin.OPCODE) {
- this.indexedPlugins_[op] = [];
- }
-
- this.cssStyles = '';
-
-
- this.stoppedEvents_ = {};
- this.stopEvent(goog.editor.Field.EventType.CHANGE);
- this.stopEvent(goog.editor.Field.EventType.DELAYEDCHANGE);
-
- this.isModified_ = false;
-
- this.isEverModified_ = false;
-
- this.delayedChangeTimer_ = new goog.async.Delay(
- this.dispatchDelayedChange_, goog.editor.Field.DELAYED_CHANGE_FREQUENCY,
- this);
-
- this.debouncedEvents_ = {};
- for (var key in goog.editor.Field.EventType) {
- this.debouncedEvents_[goog.editor.Field.EventType[key]] = 0;
- }
- if (goog.editor.BrowserFeature.USE_MUTATION_EVENTS) {
-
- this.changeTimerGecko_ = new goog.async.Delay(
- this.handleChange, goog.editor.Field.CHANGE_FREQUENCY, this);
- }
-
- this.eventRegister = new goog.events.EventHandler(this);
-
-
- this.wrappers_ = [];
-
- this.loadState_ = goog.editor.Field.LoadState_.UNEDITABLE;
- var doc = opt_doc || document;
-
- this.originalDomHelper = goog.dom.getDomHelper(doc);
-
- this.originalElement = this.originalDomHelper.getElement(this.id);
-
- this.followLinkInNewWindow_ =
- goog.editor.BrowserFeature.FOLLOWS_EDITABLE_LINKS;
-
-
- this.appWindow_ = this.originalDomHelper.getWindow();
- };
- goog.inherits(goog.editor.Field, goog.events.EventTarget);
- goog.editor.Field.prototype.field = null;
- goog.editor.Field.prototype.logger = goog.log.getLogger('goog.editor.Field');
- goog.editor.Field.EventType = {
-
- COMMAND_VALUE_CHANGE: 'cvc',
-
- LOAD: 'load',
-
- UNLOAD: 'unload',
-
- BEFORECHANGE: 'beforechange',
-
- CHANGE: 'change',
-
- DELAYEDCHANGE: 'delayedchange',
-
- BEFOREFOCUS: 'beforefocus',
-
- FOCUS: 'focus',
-
- BLUR: 'blur',
-
- BEFORETAB: 'beforetab',
-
- IFRAME_RESIZED: 'ifrsz',
-
- BEFORESELECTIONCHANGE: 'beforeselectionchange',
-
- SELECTIONCHANGE: 'selectionchange'
- };
- goog.editor.Field.LoadState_ = {
- UNEDITABLE: 0,
- LOADING: 1,
- EDITABLE: 2
- };
- goog.editor.Field.DEBOUNCE_TIME_MS_ = 500;
- goog.editor.Field.activeFieldId_ = null;
- goog.editor.Field.prototype.inModalMode_ = false;
- goog.editor.Field.prototype.appWindow_;
- goog.editor.Field.prototype.selectionChangeTarget_;
- goog.editor.Field.prototype.useWindowMouseUp_ = false;
- goog.editor.Field.prototype.waitingForMouseUp_ = false;
- goog.editor.Field.setActiveFieldId = function(fieldId) {
- goog.editor.Field.activeFieldId_ = fieldId;
- };
- goog.editor.Field.getActiveFieldId = function() {
- return goog.editor.Field.activeFieldId_;
- };
- goog.editor.Field.prototype.setUseWindowMouseUp = function(flag) {
- goog.asserts.assert(
- !flag || !this.usesIframe(),
- 'procssing window mouse up should only be enabled when not using iframe');
- this.useWindowMouseUp_ = flag;
- };
- goog.editor.Field.prototype.inModalMode = function() {
- return this.inModalMode_;
- };
- goog.editor.Field.prototype.setModalMode = function(inModalMode) {
- this.inModalMode_ = inModalMode;
- };
- goog.editor.Field.prototype.getHashCode = function() {
- return this.hashCode_;
- };
- goog.editor.Field.prototype.getElement = function() {
- return this.field;
- };
- goog.editor.Field.prototype.getOriginalElement = function() {
- return this.originalElement;
- };
- goog.editor.Field.prototype.addListener = function(
- type, listener, opt_capture, opt_handler) {
- var elem = this.getElement();
-
-
- if (goog.editor.BrowserFeature.USE_DOCUMENT_FOR_KEY_EVENTS && elem &&
- this.usesIframe()) {
- elem = elem.ownerDocument;
- }
- if (opt_handler) {
- this.eventRegister.listenWithScope(
- elem, type, listener, opt_capture, opt_handler);
- } else {
- this.eventRegister.listen(elem, type, listener, opt_capture);
- }
- };
- goog.editor.Field.prototype.getPluginByClassId = function(classId) {
- return this.plugins_[classId];
- };
- goog.editor.Field.prototype.registerPlugin = function(plugin) {
- var classId = plugin.getTrogClassId();
- if (this.plugins_[classId]) {
- goog.log.error(
- this.logger, 'Cannot register the same class of plugin twice.');
- }
- this.plugins_[classId] = plugin;
-
-
-
- for (var op in goog.editor.Plugin.OPCODE) {
- var opcode = goog.editor.Plugin.OPCODE[op];
- if (plugin[opcode]) {
- this.indexedPlugins_[op].push(plugin);
- }
- }
- plugin.registerFieldObject(this);
-
- if (this.isLoaded()) {
- plugin.enable(this);
- }
- };
- goog.editor.Field.prototype.unregisterPlugin = function(plugin) {
- var classId = plugin.getTrogClassId();
- if (!this.plugins_[classId]) {
- goog.log.error(
- this.logger, 'Cannot unregister a plugin that isn\'t registered.');
- }
- delete this.plugins_[classId];
- for (var op in goog.editor.Plugin.OPCODE) {
- var opcode = goog.editor.Plugin.OPCODE[op];
- if (plugin[opcode]) {
- goog.array.remove(this.indexedPlugins_[op], plugin);
- }
- }
- plugin.unregisterFieldObject(this);
- };
- goog.editor.Field.prototype.setInitialStyle = function(cssText) {
- this.cssText = cssText;
- };
- goog.editor.Field.prototype.resetOriginalElemProperties = function() {
- var field = this.getOriginalElement();
- field.removeAttribute('contentEditable');
- field.removeAttribute('g_editable');
- field.removeAttribute('role');
- if (!this.id) {
- field.removeAttribute('id');
- } else {
- field.id = this.id;
- }
- field.className = this.savedClassName_ || '';
- var cssText = this.cssText;
- if (!cssText) {
- field.removeAttribute('style');
- } else {
- goog.dom.setProperties(field, {'style': cssText});
- }
- if (goog.isString(this.originalFieldLineHeight_)) {
- goog.style.setStyle(field, 'lineHeight', this.originalFieldLineHeight_);
- this.originalFieldLineHeight_ = null;
- }
- };
- goog.editor.Field.prototype.isModified = function(opt_useIsEverModified) {
- return opt_useIsEverModified ? this.isEverModified_ : this.isModified_;
- };
- goog.editor.Field.CHANGE_FREQUENCY = 15;
- goog.editor.Field.DELAYED_CHANGE_FREQUENCY = 250;
- goog.editor.Field.prototype.usesIframe = goog.functions.TRUE;
- goog.editor.Field.prototype.isFixedHeight = goog.functions.TRUE;
- goog.editor.Field.prototype.shouldRefocusOnInputMobileSafari =
- goog.functions.FALSE;
- goog.editor.Field.KEYS_CAUSING_CHANGES_ = {
- 46: true,
- 8: true
- };
- if (!goog.userAgent.IE) {
-
-
- goog.editor.Field.KEYS_CAUSING_CHANGES_[9] = true;
- }
- goog.editor.Field.CTRL_KEYS_CAUSING_CHANGES_ = {
- 86: true,
- 88: true
- };
- if (goog.userAgent.WINDOWS && !goog.userAgent.GECKO) {
-
-
-
-
-
- goog.editor.Field.KEYS_CAUSING_CHANGES_[229] = true;
- }
- goog.editor.Field.isGeneratingKey_ = function(e, testAllKeys) {
- if (goog.editor.Field.isSpecialGeneratingKey_(e)) {
- return true;
- }
- return !!(
- testAllKeys && !(e.ctrlKey || e.metaKey) &&
- (!goog.userAgent.GECKO || e.charCode));
- };
- goog.editor.Field.isSpecialGeneratingKey_ = function(e) {
- var testCtrlKeys = (e.ctrlKey || e.metaKey) &&
- e.keyCode in goog.editor.Field.CTRL_KEYS_CAUSING_CHANGES_;
- var testRegularKeys = !(e.ctrlKey || e.metaKey) &&
- e.keyCode in goog.editor.Field.KEYS_CAUSING_CHANGES_;
- return testCtrlKeys || testRegularKeys;
- };
- goog.editor.Field.prototype.setAppWindow = function(appWindow) {
- this.appWindow_ = appWindow;
- };
- goog.editor.Field.prototype.getAppWindow = function() {
- return this.appWindow_;
- };
- goog.editor.Field.prototype.setBaseZindex = function(zindex) {
- this.baseZindex_ = zindex;
- };
- goog.editor.Field.prototype.getBaseZindex = function() {
- return this.baseZindex_ || 0;
- };
- goog.editor.Field.prototype.setupFieldObject = function(field) {
- this.loadState_ = goog.editor.Field.LoadState_.EDITABLE;
- this.field = field;
- this.editableDomHelper = goog.dom.getDomHelper(field);
- this.isModified_ = false;
- this.isEverModified_ = false;
- field.setAttribute('g_editable', 'true');
- goog.a11y.aria.setRole(field, goog.a11y.aria.Role.TEXTBOX);
- };
- goog.editor.Field.prototype.tearDownFieldObject_ = function() {
- this.loadState_ = goog.editor.Field.LoadState_.UNEDITABLE;
- for (var classId in this.plugins_) {
- var plugin = this.plugins_[classId];
- if (!plugin.activeOnUneditableFields()) {
- plugin.disable(this);
- }
- }
- this.field = null;
- this.editableDomHelper = null;
- };
- goog.editor.Field.prototype.setupChangeListeners_ = function() {
- if ((goog.userAgent.product.IPHONE || goog.userAgent.product.IPAD) &&
- this.usesIframe() && this.shouldRefocusOnInputMobileSafari()) {
-
-
- var editWindow = this.getEditableDomHelper().getWindow();
- this.boundRefocusListenerMobileSafari_ =
- goog.bind(editWindow.focus, editWindow);
- editWindow.addEventListener(
- goog.events.EventType.KEYDOWN, this.boundRefocusListenerMobileSafari_,
- false);
- editWindow.addEventListener(
- goog.events.EventType.TOUCHEND, this.boundRefocusListenerMobileSafari_,
- false);
- }
- if (goog.userAgent.OPERA && this.usesIframe()) {
-
-
-
- this.boundFocusListenerOpera_ =
- goog.bind(this.dispatchFocusAndBeforeFocus_, this);
- this.boundBlurListenerOpera_ = goog.bind(this.dispatchBlur, this);
- var editWindow = this.getEditableDomHelper().getWindow();
- editWindow.addEventListener(
- goog.events.EventType.FOCUS, this.boundFocusListenerOpera_, false);
- editWindow.addEventListener(
- goog.events.EventType.BLUR, this.boundBlurListenerOpera_, false);
- } else {
- if (goog.editor.BrowserFeature.SUPPORTS_FOCUSIN) {
- this.addListener(goog.events.EventType.FOCUS, this.dispatchFocus_);
- this.addListener(
- goog.events.EventType.FOCUSIN, this.dispatchBeforeFocus_);
- } else {
- this.addListener(
- goog.events.EventType.FOCUS, this.dispatchFocusAndBeforeFocus_);
- }
- this.addListener(
- goog.events.EventType.BLUR, this.dispatchBlur,
- goog.editor.BrowserFeature.USE_MUTATION_EVENTS);
- }
- if (goog.editor.BrowserFeature.USE_MUTATION_EVENTS) {
-
-
-
-
-
-
-
-
-
-
-
-
- this.setupMutationEventHandlersGecko();
- } else {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- this.addListener(
- ['beforecut', 'beforepaste', 'drop', 'dragend'],
- this.dispatchBeforeChange);
- this.addListener(
- ['cut', 'paste'], goog.functions.lock(this.dispatchChange));
- this.addListener('drop', this.handleDrop_);
- }
-
-
- var dropEventName = goog.userAgent.WEBKIT ? 'dragend' : 'dragdrop';
- this.addListener(dropEventName, this.handleDrop_);
- this.addListener(goog.events.EventType.KEYDOWN, this.handleKeyDown_);
- this.addListener(goog.events.EventType.KEYPRESS, this.handleKeyPress_);
- this.addListener(goog.events.EventType.KEYUP, this.handleKeyUp_);
- this.selectionChangeTimer_ = new goog.async.Delay(
- this.handleSelectionChangeTimer_,
- goog.editor.Field.SELECTION_CHANGE_FREQUENCY_, this);
- if (this.followLinkInNewWindow_) {
- this.addListener(
- goog.events.EventType.CLICK, goog.editor.Field.cancelLinkClick_);
- }
- this.addListener(goog.events.EventType.MOUSEDOWN, this.handleMouseDown_);
- if (this.useWindowMouseUp_) {
- this.eventRegister.listen(
- this.editableDomHelper.getDocument(), goog.events.EventType.MOUSEUP,
- this.handleMouseUp_);
- this.addListener(goog.events.EventType.DRAGSTART, this.handleDragStart_);
- } else {
- this.addListener(goog.events.EventType.MOUSEUP, this.handleMouseUp_);
- }
- };
- goog.editor.Field.SELECTION_CHANGE_FREQUENCY_ = 250;
- goog.editor.Field.prototype.clearListeners = function() {
- if (this.eventRegister) {
- this.eventRegister.removeAll();
- }
- if ((goog.userAgent.product.IPHONE || goog.userAgent.product.IPAD) &&
- this.usesIframe() && this.shouldRefocusOnInputMobileSafari()) {
- try {
- var editWindow = this.getEditableDomHelper().getWindow();
- editWindow.removeEventListener(
- goog.events.EventType.KEYDOWN, this.boundRefocusListenerMobileSafari_,
- false);
- editWindow.removeEventListener(
- goog.events.EventType.TOUCHEND,
- this.boundRefocusListenerMobileSafari_, false);
- } catch (e) {
-
-
-
- }
- delete this.boundRefocusListenerMobileSafari_;
- }
- if (goog.userAgent.OPERA && this.usesIframe()) {
- try {
- var editWindow = this.getEditableDomHelper().getWindow();
- editWindow.removeEventListener(
- goog.events.EventType.FOCUS, this.boundFocusListenerOpera_, false);
- editWindow.removeEventListener(
- goog.events.EventType.BLUR, this.boundBlurListenerOpera_, false);
- } catch (e) {
-
-
-
- }
- delete this.boundFocusListenerOpera_;
- delete this.boundBlurListenerOpera_;
- }
- if (this.changeTimerGecko_) {
- this.changeTimerGecko_.stop();
- }
- this.delayedChangeTimer_.stop();
- };
- goog.editor.Field.prototype.disposeInternal = function() {
- if (this.isLoading() || this.isLoaded()) {
- goog.log.warning(this.logger, 'Disposing a field that is in use.');
- }
- if (this.getOriginalElement()) {
- this.execCommand(goog.editor.Command.CLEAR_LOREM);
- }
- this.tearDownFieldObject_();
- this.clearListeners();
- this.clearFieldLoadListener_();
- this.originalDomHelper = null;
- if (this.eventRegister) {
- this.eventRegister.dispose();
- this.eventRegister = null;
- }
- this.removeAllWrappers();
- if (goog.editor.Field.getActiveFieldId() == this.id) {
- goog.editor.Field.setActiveFieldId(null);
- }
- for (var classId in this.plugins_) {
- var plugin = this.plugins_[classId];
- if (plugin.isAutoDispose()) {
- plugin.dispose();
- }
- }
- delete (this.plugins_);
- goog.editor.Field.superClass_.disposeInternal.call(this);
- };
- goog.editor.Field.prototype.attachWrapper = function(wrapper) {
- this.wrappers_.push(wrapper);
- };
- goog.editor.Field.prototype.removeAllWrappers = function() {
- var wrapper;
- while (wrapper = this.wrappers_.pop()) {
- wrapper.dispose();
- }
- };
- goog.editor.Field.prototype.setFollowLinkInNewWindow = function(
- followLinkInNewWindow) {
- this.followLinkInNewWindow_ = followLinkInNewWindow;
- };
- goog.editor.Field.MUTATION_EVENTS_GECKO = [
- 'DOMNodeInserted', 'DOMNodeRemoved', 'DOMNodeRemovedFromDocument',
- 'DOMNodeInsertedIntoDocument', 'DOMCharacterDataModified'
- ];
- goog.editor.Field.prototype.setupMutationEventHandlersGecko = function() {
-
-
- if (goog.editor.BrowserFeature.HAS_DOM_SUBTREE_MODIFIED_EVENT ||
- !this.usesIframe()) {
- this.eventRegister.listen(
- this.getElement(), 'DOMSubtreeModified',
- this.handleMutationEventGecko_);
- } else {
- var doc = this.getEditableDomHelper().getDocument();
- this.eventRegister.listen(
- doc, goog.editor.Field.MUTATION_EVENTS_GECKO,
- this.handleMutationEventGecko_, true);
-
-
- this.eventRegister.listen(
- doc, 'DOMAttrModified',
- goog.bind(
- this.handleDomAttrChange, this, this.handleMutationEventGecko_),
- true);
- }
- };
- goog.editor.Field.prototype.handleBeforeChangeKeyEvent_ = function(e) {
-
- var block =
-
-
-
- (e.keyCode == goog.events.KeyCodes.TAB && !this.dispatchBeforeTab_(e)) ||
-
-
-
-
- (goog.userAgent.GECKO && e.metaKey &&
- !goog.userAgent.isVersionOrHigher(29) &&
- (e.keyCode == goog.events.KeyCodes.LEFT ||
- e.keyCode == goog.events.KeyCodes.RIGHT));
- if (block) {
- e.preventDefault();
- return false;
- } else {
-
-
-
-
-
- this.gotGeneratingKey_ = e.charCode ||
- goog.editor.Field.isGeneratingKey_(e, goog.userAgent.GECKO);
- if (this.gotGeneratingKey_) {
- this.dispatchBeforeChange();
-
- }
- }
- return true;
- };
- goog.editor.Field.SELECTION_CHANGE_KEYCODES = {
- 8: 1,
- 9: 1,
- 13: 1,
- 33: 1,
- 34: 1,
- 35: 1,
- 36: 1,
- 37: 1,
- 38: 1,
- 39: 1,
- 40: 1,
- 46: 1
- };
- goog.editor.Field.CTRL_KEYS_CAUSING_SELECTION_CHANGES_ = {
- 65: true,
- 86: true,
- 88: true
- };
- goog.editor.Field.POTENTIAL_SHORTCUT_KEYCODES_ = {
- 8: 1,
- 9: 1,
- 13: 1,
- 27: 1,
- 33: 1,
- 34: 1,
- 37: 1,
- 38: 1,
- 39: 1,
- 40: 1
- };
- goog.editor.Field.prototype.invokeShortCircuitingOp_ = function(op, var_args) {
- var plugins = this.indexedPlugins_[op];
- var argList = goog.array.slice(arguments, 1);
- for (var i = 0; i < plugins.length; ++i) {
-
-
- var plugin = plugins[i];
- if ((plugin.isEnabled(this) || goog.editor.Plugin.IRREPRESSIBLE_OPS[op]) &&
- plugin[goog.editor.Plugin.OPCODE[op]].apply(plugin, argList)) {
-
-
-
- return true;
- }
- }
- return false;
- };
- goog.editor.Field.prototype.invokeOp_ = function(op, var_args) {
- var plugins = this.indexedPlugins_[op];
- var argList = goog.array.slice(arguments, 1);
- for (var i = 0; i < plugins.length; ++i) {
- var plugin = plugins[i];
- if (plugin.isEnabled(this) || goog.editor.Plugin.IRREPRESSIBLE_OPS[op]) {
- plugin[goog.editor.Plugin.OPCODE[op]].apply(plugin, argList);
- }
- }
- };
- goog.editor.Field.prototype.reduceOp_ = function(op, arg, var_args) {
- var plugins = this.indexedPlugins_[op];
- var argList = goog.array.slice(arguments, 1);
- for (var i = 0; i < plugins.length; ++i) {
- var plugin = plugins[i];
- if (plugin.isEnabled(this) || goog.editor.Plugin.IRREPRESSIBLE_OPS[op]) {
- argList[0] = plugin[goog.editor.Plugin.OPCODE[op]].apply(plugin, argList);
- }
- }
- return argList[0];
- };
- goog.editor.Field.prototype.injectContents = function(contents, field) {
- var styles = {};
- var newHtml = this.getInjectableContents(contents, styles);
- goog.style.setStyle(field, styles);
- goog.editor.node.replaceInnerHtml(field, newHtml);
- };
- goog.editor.Field.prototype.getInjectableContents = function(contents, styles) {
- return this.reduceOp_(
- goog.editor.Plugin.Op.PREPARE_CONTENTS_HTML, contents || '', styles);
- };
- goog.editor.Field.prototype.handleKeyDown_ = function(e) {
-
- if (goog.userAgent.MAC && e.keyCode == goog.events.KeyCodes.A) {
- this.maybeStartSelectionChangeTimer_(e);
- }
- if (!goog.editor.BrowserFeature.USE_MUTATION_EVENTS) {
- if (!this.handleBeforeChangeKeyEvent_(e)) {
- return;
- }
- }
- if (!this.invokeShortCircuitingOp_(goog.editor.Plugin.Op.KEYDOWN, e) &&
- goog.editor.BrowserFeature.USES_KEYDOWN) {
- this.handleKeyboardShortcut_(e);
- }
- };
- goog.editor.Field.prototype.handleKeyPress_ = function(e) {
- if (goog.editor.BrowserFeature.USE_MUTATION_EVENTS) {
- if (!this.handleBeforeChangeKeyEvent_(e)) {
- return;
- }
- } else {
-
-
- this.gotGeneratingKey_ = true;
- this.dispatchBeforeChange();
- }
- if (!this.invokeShortCircuitingOp_(goog.editor.Plugin.Op.KEYPRESS, e) &&
- !goog.editor.BrowserFeature.USES_KEYDOWN) {
- this.handleKeyboardShortcut_(e);
- }
- };
- goog.editor.Field.prototype.handleKeyUp_ = function(e) {
- if (!goog.editor.BrowserFeature.USE_MUTATION_EVENTS &&
- (this.gotGeneratingKey_ ||
- goog.editor.Field.isSpecialGeneratingKey_(e))) {
-
-
- this.handleChange();
- }
- this.invokeShortCircuitingOp_(goog.editor.Plugin.Op.KEYUP, e);
- this.maybeStartSelectionChangeTimer_(e);
- };
- goog.editor.Field.prototype.maybeStartSelectionChangeTimer_ = function(e) {
- if (this.isEventStopped(goog.editor.Field.EventType.SELECTIONCHANGE)) {
- return;
- }
- if (goog.editor.Field.SELECTION_CHANGE_KEYCODES[e.keyCode] ||
- ((e.ctrlKey || e.metaKey) &&
- goog.editor.Field.CTRL_KEYS_CAUSING_SELECTION_CHANGES_[e.keyCode])) {
- this.dispatchEvent(goog.editor.Field.EventType.BEFORESELECTIONCHANGE);
- this.selectionChangeTimer_.start();
- }
- };
- goog.editor.Field.prototype.handleKeyboardShortcut_ = function(e) {
-
-
-
- if (e.altKey) {
- return;
- }
- var isModifierPressed = goog.userAgent.MAC ? e.metaKey : e.ctrlKey;
- if (isModifierPressed ||
- goog.editor.Field.POTENTIAL_SHORTCUT_KEYCODES_[e.keyCode]) {
-
-
- var key = e.charCode || e.keyCode;
- if (key == 17) {
-
- return;
- }
- var stringKey = String.fromCharCode(key).toLowerCase();
-
-
- if (goog.userAgent.MAC && goog.userAgent.GECKO && stringKey == '`' &&
- e.getBrowserEvent().key == ' ') {
- stringKey = ' ';
- }
-
-
- if (e.keyCode == goog.events.KeyCodes.BACKSLASH) {
- stringKey = '\\';
- }
- if (this.invokeShortCircuitingOp_(
- goog.editor.Plugin.Op.SHORTCUT, e, stringKey, isModifierPressed)) {
- e.preventDefault();
-
-
- }
- }
- };
- goog.editor.Field.prototype.execCommand = function(command, var_args) {
- var args = arguments;
- var result;
- var plugins = this.indexedPlugins_[goog.editor.Plugin.Op.EXEC_COMMAND];
- for (var i = 0; i < plugins.length; ++i) {
-
-
- var plugin = plugins[i];
- if (plugin.isEnabled(this) && plugin.isSupportedCommand(command)) {
- result = plugin.execCommand.apply(plugin, args);
- break;
- }
- }
- return result;
- };
- goog.editor.Field.prototype.queryCommandValue = function(commands) {
- var isEditable = this.isLoaded() && this.isSelectionEditable();
- if (goog.isString(commands)) {
- return this.queryCommandValueInternal_(commands, isEditable);
- } else {
- var state = {};
- for (var i = 0; i < commands.length; i++) {
- state[commands[i]] =
- this.queryCommandValueInternal_(commands[i], isEditable);
- }
- return state;
- }
- };
- goog.editor.Field.prototype.queryCommandValueInternal_ = function(
- command, isEditable) {
- var plugins = this.indexedPlugins_[goog.editor.Plugin.Op.QUERY_COMMAND];
- for (var i = 0; i < plugins.length; ++i) {
- var plugin = plugins[i];
- if (plugin.isEnabled(this) && plugin.isSupportedCommand(command) &&
- (isEditable || plugin.activeOnUneditableFields())) {
- return plugin.queryCommandValue(command);
- }
- }
- return isEditable ? null : false;
- };
- goog.editor.Field.prototype.handleDomAttrChange = function(
- handler, browserEvent) {
- if (this.isEventStopped(goog.editor.Field.EventType.CHANGE)) {
- return;
- }
- var e = browserEvent.getBrowserEvent();
-
- try {
- if (e.originalTarget.prefix ||
- (e.originalTarget).nodeName == 'scrollbar') {
- return;
- }
- } catch (ex1) {
-
-
- return;
- }
-
-
- if (e.prevValue == e.newValue) {
- return;
- }
- handler.call(this, e);
- };
- goog.editor.Field.prototype.handleMutationEventGecko_ = function(e) {
- if (this.isEventStopped(goog.editor.Field.EventType.CHANGE)) {
- return;
- }
- e = e.getBrowserEvent ? e.getBrowserEvent() : e;
-
-
- if (e.target.firebugIgnore) {
- return;
- }
- this.isModified_ = true;
- this.isEverModified_ = true;
- this.changeTimerGecko_.start();
- };
- goog.editor.Field.prototype.handleDrop_ = function(e) {
- if (goog.userAgent.IE) {
-
- this.execCommand(goog.editor.Command.CLEAR_LOREM, true);
- }
-
-
- if (goog.editor.BrowserFeature.USE_MUTATION_EVENTS) {
- this.dispatchFocusAndBeforeFocus_();
- }
- this.dispatchChange();
- };
- goog.editor.Field.prototype.getEditableIframe = function() {
- var dh;
- if (this.usesIframe() && (dh = this.getEditableDomHelper())) {
-
-
- var win = dh.getWindow();
- return (win && win.frameElement);
- }
- return null;
- };
- goog.editor.Field.prototype.getEditableDomHelper = function() {
- return this.editableDomHelper;
- };
- goog.editor.Field.prototype.getRange = function() {
- var win = this.editableDomHelper && this.editableDomHelper.getWindow();
- return win && goog.dom.Range.createFromWindow(win);
- };
- goog.editor.Field.prototype.dispatchSelectionChangeEvent = function(
- opt_e, opt_target) {
- if (this.isEventStopped(goog.editor.Field.EventType.SELECTIONCHANGE)) {
- return;
- }
-
-
- var range = this.getRange();
- var rangeContainer = range && range.getContainerElement();
- this.isSelectionEditable_ =
- !!rangeContainer && goog.dom.contains(this.getElement(), rangeContainer);
- this.dispatchCommandValueChange();
- this.dispatchEvent({
- type: goog.editor.Field.EventType.SELECTIONCHANGE,
- originalType: opt_e && opt_e.type
- });
- this.invokeShortCircuitingOp_(
- goog.editor.Plugin.Op.SELECTION, opt_e, opt_target);
- };
- goog.editor.Field.prototype.handleSelectionChangeTimer_ = function() {
- var t = this.selectionChangeTarget_;
- this.selectionChangeTarget_ = null;
- this.dispatchSelectionChangeEvent(undefined, t);
- };
- goog.editor.Field.prototype.dispatchBeforeChange = function() {
- if (this.isEventStopped(goog.editor.Field.EventType.BEFORECHANGE)) {
- return;
- }
- this.dispatchEvent(goog.editor.Field.EventType.BEFORECHANGE);
- };
- goog.editor.Field.prototype.dispatchBeforeTab_ = function(e) {
- return this.dispatchEvent({
- type: goog.editor.Field.EventType.BEFORETAB,
- shiftKey: e.shiftKey,
- altKey: e.altKey,
- ctrlKey: e.ctrlKey
- });
- };
- goog.editor.Field.prototype.stopChangeEvents = function(
- opt_stopChange, opt_stopDelayedChange) {
- if (opt_stopChange) {
- if (this.changeTimerGecko_) {
- this.changeTimerGecko_.fireIfActive();
- }
- this.stopEvent(goog.editor.Field.EventType.CHANGE);
- }
- if (opt_stopDelayedChange) {
- this.clearDelayedChange();
- this.stopEvent(goog.editor.Field.EventType.DELAYEDCHANGE);
- }
- };
- goog.editor.Field.prototype.startChangeEvents = function(
- opt_fireChange, opt_fireDelayedChange) {
- if (!opt_fireChange && this.changeTimerGecko_) {
-
-
-
-
-
- this.changeTimerGecko_.fireIfActive();
- }
- this.startEvent(goog.editor.Field.EventType.CHANGE);
- this.startEvent(goog.editor.Field.EventType.DELAYEDCHANGE);
- if (opt_fireChange) {
- this.handleChange();
- }
- if (opt_fireDelayedChange) {
- this.dispatchDelayedChange_();
- }
- };
- goog.editor.Field.prototype.stopEvent = function(eventType) {
- this.stoppedEvents_[eventType] = 1;
- };
- goog.editor.Field.prototype.startEvent = function(eventType) {
-
-
- this.stoppedEvents_[eventType] = 0;
- };
- goog.editor.Field.prototype.debounceEvent = function(eventType) {
- this.debouncedEvents_[eventType] = goog.now();
- };
- goog.editor.Field.prototype.isEventStopped = function(eventType) {
- return !!this.stoppedEvents_[eventType] ||
- (this.debouncedEvents_[eventType] &&
- (goog.now() - this.debouncedEvents_[eventType] <=
- goog.editor.Field.DEBOUNCE_TIME_MS_));
- };
- goog.editor.Field.prototype.manipulateDom = function(
- func, opt_preventDelayedChange, opt_handler) {
- this.stopChangeEvents(true, true);
-
-
- try {
- func.call(opt_handler);
- } finally {
-
-
- if (this.isLoaded()) {
-
-
- if (opt_preventDelayedChange) {
- this.startEvent(goog.editor.Field.EventType.CHANGE);
- this.handleChange();
- this.startEvent(goog.editor.Field.EventType.DELAYEDCHANGE);
- } else {
- this.dispatchChange();
- }
- }
- }
- };
- goog.editor.Field.prototype.dispatchCommandValueChange = function(
- opt_commands) {
- if (opt_commands) {
- this.dispatchEvent({
- type: goog.editor.Field.EventType.COMMAND_VALUE_CHANGE,
- commands: opt_commands
- });
- } else {
- this.dispatchEvent(goog.editor.Field.EventType.COMMAND_VALUE_CHANGE);
- }
- };
- goog.editor.Field.prototype.dispatchChange = function(opt_noDelay) {
- this.startChangeEvents(true, opt_noDelay);
- };
- goog.editor.Field.prototype.handleChange = function() {
- if (this.isEventStopped(goog.editor.Field.EventType.CHANGE)) {
- return;
- }
-
-
- if (this.changeTimerGecko_) {
- this.changeTimerGecko_.stop();
- }
- this.isModified_ = true;
- this.isEverModified_ = true;
- if (this.isEventStopped(goog.editor.Field.EventType.DELAYEDCHANGE)) {
- return;
- }
- this.delayedChangeTimer_.start();
- };
- goog.editor.Field.prototype.dispatchDelayedChange_ = function() {
- if (this.isEventStopped(goog.editor.Field.EventType.DELAYEDCHANGE)) {
- return;
- }
-
-
- this.delayedChangeTimer_.stop();
- this.isModified_ = false;
- this.dispatchEvent(goog.editor.Field.EventType.DELAYEDCHANGE);
- };
- goog.editor.Field.prototype.clearDelayedChange = function() {
-
-
- if (this.changeTimerGecko_) {
- this.changeTimerGecko_.fireIfActive();
- }
- this.delayedChangeTimer_.fireIfActive();
- };
- goog.editor.Field.prototype.dispatchFocusAndBeforeFocus_ = function() {
- this.dispatchBeforeFocus_();
- this.dispatchFocus_();
- };
- goog.editor.Field.prototype.dispatchBeforeFocus_ = function() {
- if (this.isEventStopped(goog.editor.Field.EventType.BEFOREFOCUS)) {
- return;
- }
- this.execCommand(goog.editor.Command.CLEAR_LOREM, true);
- this.dispatchEvent(goog.editor.Field.EventType.BEFOREFOCUS);
- };
- goog.editor.Field.prototype.dispatchFocus_ = function() {
- if (this.isEventStopped(goog.editor.Field.EventType.FOCUS)) {
- return;
- }
- goog.editor.Field.setActiveFieldId(this.id);
- this.isSelectionEditable_ = true;
- this.dispatchEvent(goog.editor.Field.EventType.FOCUS);
- if (goog.editor.BrowserFeature
- .PUTS_CURSOR_BEFORE_FIRST_BLOCK_ELEMENT_ON_FOCUS) {
-
-
-
-
-
- var field = this.getElement();
- var range = this.getRange();
- if (range) {
- var focusNode = (range.getFocusNode());
- if (range.getFocusOffset() == 0 &&
- (!focusNode || focusNode == field ||
- focusNode.tagName == goog.dom.TagName.BODY)) {
- goog.editor.range.selectNodeStart(field);
- }
- }
- }
- if (!goog.editor.BrowserFeature.CLEARS_SELECTION_WHEN_FOCUS_LEAVES &&
- this.usesIframe()) {
- var parent = this.getEditableDomHelper().getWindow().parent;
- parent.getSelection().removeAllRanges();
- }
- };
- goog.editor.Field.prototype.dispatchBlur = function() {
- if (this.isEventStopped(goog.editor.Field.EventType.BLUR)) {
- return;
- }
-
-
- if (goog.editor.Field.getActiveFieldId() == this.id) {
- goog.editor.Field.setActiveFieldId(null);
- }
- this.isSelectionEditable_ = false;
- this.dispatchEvent(goog.editor.Field.EventType.BLUR);
- };
- goog.editor.Field.prototype.isSelectionEditable = function() {
- return this.isSelectionEditable_;
- };
- goog.editor.Field.cancelLinkClick_ = function(e) {
- if (goog.dom.getAncestorByTagNameAndClass(
- (e.target), goog.dom.TagName.A)) {
- e.preventDefault();
- }
- };
- goog.editor.Field.prototype.handleMouseDown_ = function(e) {
- goog.editor.Field.setActiveFieldId(this.id);
-
- if (goog.userAgent.IE) {
- var targetElement = e.target;
- if (targetElement &&
- (targetElement).tagName == goog.dom.TagName.A &&
- e.ctrlKey) {
- this.originalDomHelper.getWindow().open(targetElement.href);
- }
- }
- this.waitingForMouseUp_ = true;
- };
- goog.editor.Field.prototype.handleDragStart_ = function(e) {
- this.waitingForMouseUp_ = false;
- };
- goog.editor.Field.prototype.handleMouseUp_ = function(e) {
- if (this.useWindowMouseUp_ && !this.waitingForMouseUp_) {
- return;
- }
- this.waitingForMouseUp_ = false;
-
- this.dispatchEvent(goog.editor.Field.EventType.BEFORESELECTIONCHANGE);
- this.dispatchSelectionChangeEvent(e);
- if (goog.userAgent.IE) {
-
- this.selectionChangeTarget_ = (e.target);
- this.selectionChangeTimer_.start();
- }
- };
- goog.editor.Field.prototype.getCleanContents = function() {
- if (this.queryCommandValue(goog.editor.Command.USING_LOREM)) {
- return goog.string.Unicode.NBSP;
- }
- if (!this.isLoaded()) {
-
- var elem = this.getOriginalElement();
- if (!elem) {
- goog.log.log(
- this.logger, goog.log.Level.SHOUT,
- "Couldn't get the field element to read the contents");
- }
- return elem.innerHTML;
- }
- var fieldCopy = this.getFieldCopy();
-
- this.invokeOp_(goog.editor.Plugin.Op.CLEAN_CONTENTS_DOM, fieldCopy);
- return this.reduceOp_(
- goog.editor.Plugin.Op.CLEAN_CONTENTS_HTML, fieldCopy.innerHTML);
- };
- goog.editor.Field.prototype.getFieldCopy = function() {
- var field = this.getElement();
-
- var fieldCopy = (field.cloneNode(false));
-
-
-
- var html = field.innerHTML;
- if (goog.userAgent.IE && html.match(/^\s*<script/i)) {
- html = goog.string.Unicode.NBSP + html;
- }
- fieldCopy.innerHTML = html;
- return fieldCopy;
- };
- goog.editor.Field.prototype.setHtml = function(
- addParas, html, opt_dontFireDelayedChange, opt_applyLorem) {
- var safeHtml =
- html ? goog.html.legacyconversions.safeHtmlFromString(html) : null;
- this.setSafeHtml(
- addParas, safeHtml, opt_dontFireDelayedChange, opt_applyLorem);
- };
- goog.editor.Field.prototype.setSafeHtml = function(
- addParas, html, opt_dontFireDelayedChange, opt_applyLorem) {
- if (this.isLoading()) {
- goog.log.error(this.logger, "Can't set html while loading Trogedit");
- return;
- }
-
- if (opt_applyLorem) {
- this.execCommand(goog.editor.Command.CLEAR_LOREM);
- }
- if (html && addParas) {
- html = goog.html.SafeHtml.create('p', {}, html);
- }
-
-
- if (opt_dontFireDelayedChange) {
- this.stopChangeEvents(false, true);
- }
- this.setInnerHtml_(html);
-
- if (opt_applyLorem) {
- this.execCommand(goog.editor.Command.UPDATE_LOREM);
- }
-
-
- if (this.isLoaded()) {
- if (opt_dontFireDelayedChange) {
-
-
-
-
-
-
-
-
-
- if (goog.editor.BrowserFeature.USE_MUTATION_EVENTS) {
- this.changeTimerGecko_.fireIfActive();
- }
- this.startChangeEvents();
- } else {
- this.dispatchChange();
- }
- }
- };
- goog.editor.Field.prototype.setInnerHtml_ = function(html) {
- var field = this.getElement();
- if (field) {
-
-
-
-
-
- if (this.usesIframe() && goog.editor.BrowserFeature.MOVES_STYLE_TO_HEAD) {
- var heads = goog.dom.getElementsByTagName(
- goog.dom.TagName.HEAD, goog.asserts.assert(field.ownerDocument));
- for (var i = heads.length - 1; i >= 1; --i) {
- heads[i].parentNode.removeChild(heads[i]);
- }
- }
- } else {
- field = this.getOriginalElement();
- }
- if (field) {
- this.injectContents(html && goog.html.SafeHtml.unwrap(html), field);
- }
- };
- goog.editor.Field.prototype.turnOnDesignModeGecko = function() {
- var doc = this.getEditableDomHelper().getDocument();
-
-
-
- doc.designMode = 'on';
- if (goog.editor.BrowserFeature.HAS_STYLE_WITH_CSS) {
- doc.execCommand('styleWithCSS', false, false);
- }
- };
- goog.editor.Field.prototype.installStyles = function() {
- if (this.cssStyles && this.shouldLoadAsynchronously()) {
- goog.style.installSafeStyleSheet(
- goog.html.legacyconversions.safeStyleSheetFromString(this.cssStyles),
- this.getElement());
- }
- };
- goog.editor.Field.prototype.dispatchLoadEvent_ = function() {
- this.getElement();
- this.installStyles();
- this.startChangeEvents();
- goog.log.info(this.logger, 'Dispatching load ' + this.id);
- this.dispatchEvent(goog.editor.Field.EventType.LOAD);
- };
- goog.editor.Field.prototype.isUneditable = function() {
- return this.loadState_ == goog.editor.Field.LoadState_.UNEDITABLE;
- };
- goog.editor.Field.prototype.isLoaded = function() {
- return this.loadState_ == goog.editor.Field.LoadState_.EDITABLE;
- };
- goog.editor.Field.prototype.isLoading = function() {
- return this.loadState_ == goog.editor.Field.LoadState_.LOADING;
- };
- goog.editor.Field.prototype.focus = function() {
- if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE && this.usesIframe()) {
-
- this.getEditableDomHelper().getWindow().focus();
- } else {
- if (goog.userAgent.OPERA) {
-
-
-
-
-
- var scrollX = this.appWindow_.pageXOffset;
- var scrollY = this.appWindow_.pageYOffset;
- }
- this.getElement().focus();
- if (goog.userAgent.OPERA) {
- this.appWindow_.scrollTo(
- (scrollX), (scrollY));
- }
- }
- };
- goog.editor.Field.prototype.focusAndPlaceCursorAtStart = function() {
-
-
-
-
-
-
-
- if (goog.editor.BrowserFeature.HAS_IE_RANGES || !goog.userAgent.GECKO) {
- this.placeCursorAtStart();
- }
- this.focus();
- };
- goog.editor.Field.prototype.placeCursorAtStart = function() {
- this.placeCursorAtStartOrEnd_(true);
- };
- goog.editor.Field.prototype.placeCursorAtEnd = function() {
- this.placeCursorAtStartOrEnd_(false);
- };
- goog.editor.Field.prototype.placeCursorAtStartOrEnd_ = function(isStart) {
- var field = this.getElement();
- if (field) {
- var cursorPosition = isStart ? goog.editor.node.getLeftMostLeaf(field) :
- goog.editor.node.getRightMostLeaf(field);
- if (field == cursorPosition) {
-
-
-
- goog.dom.Range.createCaret(field, 0).select();
- } else {
- goog.editor.range.placeCursorNextTo(cursorPosition, isStart);
- }
- this.dispatchSelectionChangeEvent();
- }
- };
- goog.editor.Field.prototype.restoreSavedRange = function(opt_range) {
- if (opt_range) {
- opt_range.restore();
- }
- this.focus();
- };
- goog.editor.Field.prototype.makeEditable = function(opt_iframeSrc) {
- this.loadState_ = goog.editor.Field.LoadState_.LOADING;
- var field = this.getOriginalElement();
-
-
-
- this.nodeName = field.nodeName;
- this.savedClassName_ = field.className;
- this.setInitialStyle(field.style.cssText);
- goog.dom.classlist.add(field, 'editable');
- var iframeSrc;
- if (goog.isString(opt_iframeSrc)) {
- iframeSrc =
- goog.html.legacyconversions.trustedResourceUrlFromString(opt_iframeSrc);
- } else {
- iframeSrc = opt_iframeSrc;
- }
- this.makeEditableInternal(iframeSrc);
- };
- goog.editor.Field.prototype.makeEditableInternal = function(opt_iframeSrc) {
- this.makeIframeField_(opt_iframeSrc);
- };
- goog.editor.Field.prototype.handleFieldLoad = function() {
- if (goog.userAgent.IE) {
-
-
-
-
-
- goog.dom.Range.clearSelection(this.editableDomHelper.getWindow());
- }
- if (goog.editor.Field.getActiveFieldId() != this.id) {
- this.execCommand(goog.editor.Command.UPDATE_LOREM);
- }
- this.setupChangeListeners_();
- this.dispatchLoadEvent_();
-
-
-
- for (var classId in this.plugins_) {
- this.plugins_[classId].enable(this);
- }
- };
- goog.editor.Field.prototype.makeUneditable = function(opt_skipRestore) {
- if (this.isUneditable()) {
- throw Error('makeUneditable: Field is already uneditable');
- }
-
-
- this.clearDelayedChange();
- this.selectionChangeTimer_.fireIfActive();
- this.execCommand(goog.editor.Command.CLEAR_LOREM);
- var html = null;
- if (!opt_skipRestore && this.getElement()) {
-
- html = this.getCleanContents();
- }
-
-
- this.clearFieldLoadListener_();
- var field = this.getOriginalElement();
- if (goog.editor.Field.getActiveFieldId() == field.id) {
- goog.editor.Field.setActiveFieldId(null);
- }
-
-
-
- this.clearListeners();
-
-
-
-
-
- if (goog.isString(html)) {
- goog.editor.node.replaceInnerHtml(field, html);
- this.resetOriginalElemProperties();
- }
- this.restoreDom();
- this.tearDownFieldObject_();
-
-
- if (goog.userAgent.WEBKIT) {
- field.blur();
- }
- this.execCommand(goog.editor.Command.UPDATE_LOREM);
- this.dispatchEvent(goog.editor.Field.EventType.UNLOAD);
- };
- goog.editor.Field.prototype.restoreDom = function() {
-
-
- var field = this.getOriginalElement();
-
- if (field) {
-
-
- var iframe = this.getEditableIframe();
- if (iframe) {
- goog.dom.replaceNode(field, iframe);
- }
- }
- };
- goog.editor.Field.prototype.shouldLoadAsynchronously = function() {
- if (!goog.isDef(this.isHttps_)) {
- this.isHttps_ = false;
- if (goog.userAgent.IE && this.usesIframe()) {
-
-
-
-
-
-
-
- var win = this.originalDomHelper.getWindow();
- while (win != win.parent) {
- try {
- win = win.parent;
- } catch (e) {
- break;
- }
- }
- var loc = win.location;
- this.isHttps_ =
- loc.protocol == 'https:' && loc.search.indexOf('nocheckhttps') == -1;
- }
- }
- return this.isHttps_;
- };
- goog.editor.Field.prototype.makeIframeField_ = function(opt_iframeSrc) {
- var field = this.getOriginalElement();
-
- if (field) {
- var html = field.innerHTML;
-
-
-
-
- var styles = {};
- html = this.reduceOp_(
- goog.editor.Plugin.Op.PREPARE_CONTENTS_HTML, html, styles);
- var iframe = this.originalDomHelper.createDom(
- goog.dom.TagName.IFRAME, this.getIframeAttributes());
-
-
-
-
-
-
-
-
- if (this.shouldLoadAsynchronously()) {
-
-
- var onLoad =
- goog.bind(this.iframeFieldLoadHandler, this, iframe, html, styles);
- this.fieldLoadListenerKey_ =
- goog.events.listen(iframe, goog.events.EventType.LOAD, onLoad, true);
- if (opt_iframeSrc) {
- goog.dom.safe.setIframeSrc(iframe, opt_iframeSrc);
- }
- }
- this.attachIframe(iframe);
-
- if (!this.shouldLoadAsynchronously()) {
- this.iframeFieldLoadHandler(iframe, html, styles);
- }
- }
- };
- goog.editor.Field.prototype.attachIframe = function(iframe) {
- var field = this.getOriginalElement();
-
- iframe.className = field.className;
- iframe.id = field.id;
- goog.dom.replaceNode(iframe, field);
- };
- goog.editor.Field.prototype.getFieldFormatInfo = function(extraStyles) {
- var originalElement = this.getOriginalElement();
- var isStandardsMode = goog.editor.node.isStandardsMode(originalElement);
- return new goog.editor.icontent.FieldFormatInfo(
- this.id, isStandardsMode, false, false, extraStyles);
- };
- goog.editor.Field.prototype.writeIframeContent = function(
- iframe, innerHtml, extraStyles) {
- var formatInfo = this.getFieldFormatInfo(extraStyles);
- if (this.shouldLoadAsynchronously()) {
- var doc = goog.dom.getFrameContentDocument(iframe);
- goog.editor.icontent.writeHttpsInitialIframe(formatInfo, doc, innerHtml);
- } else {
- var styleInfo = new goog.editor.icontent.FieldStyleInfo(
- this.getElement(), this.cssStyles);
- goog.editor.icontent.writeNormalInitialIframe(
- formatInfo, innerHtml, styleInfo, iframe);
- }
- };
- goog.editor.Field.prototype.iframeFieldLoadHandler = function(
- iframe, innerHtml, styles) {
- this.clearFieldLoadListener_();
- iframe.allowTransparency = 'true';
- this.writeIframeContent(iframe, innerHtml, styles);
- var doc = goog.dom.getFrameContentDocument(iframe);
-
-
- var body = doc.body;
- this.setupFieldObject(body);
- if (!goog.editor.BrowserFeature.HAS_CONTENT_EDITABLE && this.usesIframe()) {
- this.turnOnDesignModeGecko();
- }
- this.handleFieldLoad();
- };
- goog.editor.Field.prototype.clearFieldLoadListener_ = function() {
- if (this.fieldLoadListenerKey_) {
- goog.events.unlistenByKey(this.fieldLoadListenerKey_);
- this.fieldLoadListenerKey_ = null;
- }
- };
- goog.editor.Field.prototype.getIframeAttributes = function() {
- var iframeStyle = 'padding:0;' + this.getOriginalElement().style.cssText;
- if (!goog.string.endsWith(iframeStyle, ';')) {
- iframeStyle += ';';
- }
- iframeStyle += 'background-color:white;';
-
-
-
-
- if (goog.userAgent.IE) {
- iframeStyle += 'overflow:visible;';
- }
- return {'frameBorder': 0, 'style': iframeStyle};
- };
|