style.js 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. $axure.internal(function($ax) {
  2. var _style = {};
  3. $ax.style = _style;
  4. var _disabledWidgets = {};
  5. var _selectedWidgets = {};
  6. // A table to cache the outerHTML of the _rtf elements before the rollover state is applied.
  7. var _originalTextCache = {};
  8. // A table to exclude the normal style from adaptive overrides
  9. var _shapesWithSetRichText = {};
  10. // just a listing of shape ids
  11. var _adaptiveStyledWidgets = {};
  12. var _setLinkStyle = function(id, styleName) {
  13. var textId = $ax.style.GetTextIdFromLink(id);
  14. var style = _computeAllOverrides(id, textId, styleName, $ax.adaptive.currentViewId);
  15. if(!_originalTextCache[textId]) {
  16. $ax.style.CacheOriginalText(textId);
  17. }
  18. if($.isEmptyObject(style)) return;
  19. var parentObjectCache = _originalTextCache[textId].styleCache;
  20. _transformTextWithVerticalAlignment(textId, function() {
  21. var cssProps = _getCssStyleProperties(style);
  22. $('#' + id).find('*').andSelf().each(function(index, element) {
  23. element.setAttribute('style', parentObjectCache[element.id]);
  24. _applyCssProps(element, cssProps);
  25. });
  26. });
  27. };
  28. var _resetLinkStyle = function(id) {
  29. var textId = $ax.style.GetTextIdFromLink(id);
  30. var parentObjectCache = _originalTextCache[textId].styleCache;
  31. _transformTextWithVerticalAlignment(textId, function() {
  32. $('#' + id).find('*').andSelf().each(function(index, element) {
  33. element.style.cssText = parentObjectCache[element.id];
  34. });
  35. });
  36. if($ax.event.mouseDownObjectId) {
  37. $ax.style.SetWidgetMouseDown($ax.event.mouseDownObjectId, true);
  38. } else if($ax.event.mouseOverObjectId) {
  39. $ax.style.SetWidgetHover($ax.event.mouseOverObjectId, true);
  40. }
  41. };
  42. $ax.style.SetLinkHover = function(id) {
  43. _setLinkStyle(id, MOUSE_OVER);
  44. };
  45. $ax.style.SetLinkNotHover = function(id) {
  46. _resetLinkStyle(id);
  47. };
  48. $ax.style.SetLinkMouseDown = function(id) {
  49. _setLinkStyle(id, MOUSE_DOWN);
  50. };
  51. $ax.style.SetLinkNotMouseDown = function(id) {
  52. _resetLinkStyle(id);
  53. var style = _computeAllOverrides(id, $ax.event.mouseOverObjectId, MOUSE_OVER, $ax.adaptive.currentViewId);
  54. if(!$.isEmptyObject(style)) $ax.style.SetLinkHover(id);
  55. //we dont do anything here because the widget not mouse down has taken over here
  56. };
  57. var _widgetHasState = function(id, state) {
  58. if($ax.style.getElementImageOverride(id, state)) return true;
  59. var diagramObject = $ax.getObjectFromElementId(id);
  60. var adaptiveIdChain = $ax.adaptive.getAdaptiveIdChain($ax.adaptive.currentViewId);
  61. for(var i = 0; i < adaptiveIdChain.length; i++) {
  62. var viewId = adaptiveIdChain[i];
  63. var adaptiveStyle = diagramObject.adaptiveStyles[viewId];
  64. if(adaptiveStyle && adaptiveStyle.stateStyles && adaptiveStyle.stateStyles[state]) return true;
  65. }
  66. if(diagramObject.style.stateStyles) return diagramObject.style.stateStyles[state];
  67. return false;
  68. };
  69. // Returns what overrides the hover, or false if nothing.
  70. var _hoverOverride = function(id) {
  71. if($ax.style.IsWidgetDisabled(id)) return DISABLED;
  72. if($ax.style.IsWidgetSelected(id)) return SELECTED;
  73. var obj = $ax.getObjectFromElementId(id);
  74. if(!obj.isContained) return false;
  75. var path = $ax.getPathFromScriptId($ax.repeater.getScriptIdFromElementId(id));
  76. path[path.length - 1] = obj.parent.id;
  77. var itemId = $ax.repeater.getItemIdFromElementId(id);
  78. return _hoverOverride($ax.getElementIdFromPath(path, { itemNum: itemId }));
  79. };
  80. $ax.style.SetWidgetHover = function(id, value) {
  81. var override = _hoverOverride(id);
  82. if(override == DISABLED) return;
  83. if(!_widgetHasState(id, MOUSE_OVER)) return;
  84. var valToSet = value || _isRolloverOverride(id);
  85. var state = _generateMouseState(id, valToSet ? MOUSE_OVER : NORMAL, override == SELECTED);
  86. _applyImageAndTextJson(id, state);
  87. _updateElementIdImageStyle(id, state);
  88. };
  89. var _rolloverOverrides = [];
  90. var _isRolloverOverride = function(id) {
  91. return _rolloverOverrides.indexOf(id) != -1;
  92. };
  93. $ax.style.AddRolloverOverride = function(id) {
  94. if(_isRolloverOverride(id)) return;
  95. _rolloverOverrides[_rolloverOverrides.length] = id;
  96. if($ax.event.mouseOverIds.indexOf(id) == -1) $ax.style.SetWidgetHover(id, true);
  97. };
  98. $ax.style.RemoveRolloverOverride = function(id) {
  99. var index = _rolloverOverrides.indexOf(id);
  100. if(index == -1) return;
  101. $ax.splice(_rolloverOverrides, index, 1);
  102. if($ax.event.mouseOverIds.indexOf(id) == -1) $ax.style.SetWidgetHover(id, false);
  103. };
  104. // function GetWidgetCurrentState(id) {
  105. // if($ax.style.IsWidgetDisabled(id)) return "disabled";
  106. // if($ax.style.IsWidgetSelected(id)) return "selected";
  107. // if($ax.event.mouseOverObjectId == id) return "mouseOver";
  108. // if($ax.event.mouseDownObjectId == id) return "mouseDown";
  109. // return "normal";
  110. // }
  111. $ax.style.ObjHasMouseDown = function(id) {
  112. var obj = $obj(id);
  113. if($ax.style.getElementImageOverride(id, 'mouseDown') || obj.style && obj.style.stateStyles && obj.style.stateStyles.mouseDown) return true;
  114. var chain = $ax.adaptive.getAdaptiveIdChain($ax.adaptive.currentViewId);
  115. for(var i = 0; i < chain.length; i++) {
  116. var style = obj.adaptiveStyles[chain[i]];
  117. if(style && style.stateStyles && style.stateStyles.mouseDown) return true;
  118. }
  119. return false;
  120. };
  121. $ax.style.SetWidgetMouseDown = function(id, value) {
  122. if($ax.style.IsWidgetDisabled(id)) return;
  123. if(!_widgetHasState(id, MOUSE_DOWN)) return;
  124. // ApplyImageAndTextJson(id, value ? 'mouseDown' : !$.isEmptyObject(GetStyleForState(id, null, 'mouseOver')) ? 'mouseOver' : 'normal');
  125. var state = _generateMouseState(id, value ? MOUSE_DOWN : MOUSE_OVER, $ax.style.IsWidgetSelected(id));
  126. _applyImageAndTextJson(id, state);
  127. _updateElementIdImageStyle(id, state);
  128. };
  129. var _generateMouseState = function(id, mouseState, selected) {
  130. if (selected) {
  131. if (_style.getElementImageOverride(id, SELECTED)) return SELECTED;
  132. var viewChain = $ax.adaptive.getAdaptiveIdChain($ax.adaptive.currentViewId);
  133. viewChain[viewChain.length] = '';
  134. var obj = $obj(id);
  135. if(obj.type == "dynamicPanel") return SELECTED;
  136. var any = function(dict) {
  137. for(var key in dict) return true;
  138. return false;
  139. };
  140. for(var i = 0; i < viewChain.length; i++) {
  141. var viewId = viewChain[i];
  142. // Need to check seperately for images.
  143. if(obj.adaptiveStyles && obj.adaptiveStyles[viewId] && any(obj.adaptiveStyles[viewId])
  144. || obj.images && obj.images['selected~' + viewId]) return SELECTED;
  145. }
  146. var selectedStyle = obj.style && obj.style.stateStyles && obj.style.stateStyles.selected;
  147. if(selectedStyle && any(selectedStyle)) return SELECTED;
  148. }
  149. // Not using selected
  150. return mouseState;
  151. };
  152. $ax.style.SetWidgetSelected = function(id, value, alwaysApply) {
  153. if(_isWidgetDisabled(id)) return;
  154. //NOTE: not firing select events if state didn't change
  155. var raiseSelectedEvents = $ax.style.IsWidgetSelected(id) != value;
  156. if(value) {
  157. var group = $('#' + id).attr('selectiongroup');
  158. if(group) {
  159. $("[selectiongroup='" + group + "']").each(function() {
  160. var otherId = this.id;
  161. if(otherId == id) return;
  162. if ($ax.visibility.isScriptIdLimbo($ax.repeater.getScriptIdFromElementId(otherId))) return;
  163. $ax.style.SetWidgetSelected(otherId, false);
  164. });
  165. }
  166. }
  167. var obj = $obj(id);
  168. if(obj) {
  169. var actionId = id;
  170. if ($ax.public.fn.IsDynamicPanel(obj.type) || $ax.public.fn.IsLayer(obj.type)) {
  171. var children = $axure('#' + id).getChildren()[0].children;
  172. for(var i = 0; i < children.length; i++) {
  173. var childId = children[i];
  174. // Special case for trees
  175. var childObj = $jobj(childId);
  176. if(childObj.hasClass('treeroot')) {
  177. var treenodes = childObj.find('.treenode');
  178. for(var j = 0; j < treenodes.length; j++) {
  179. $axure('#' + treenodes[j].id).selected(value);
  180. }
  181. } else $axure('#' + childId).selected(value);
  182. }
  183. } else {
  184. var widgetHasSelectedState = _widgetHasState(id, SELECTED);
  185. while(obj.isContained && !widgetHasSelectedState) obj = obj.parent;
  186. var itemId = $ax.repeater.getItemIdFromElementId(id);
  187. var path = $ax.getPathFromScriptId($ax.repeater.getScriptIdFromElementId(id));
  188. path[path.length - 1] = obj.id;
  189. actionId = $ax.getElementIdFromPath(path, { itemNum: itemId });
  190. if(alwaysApply || widgetHasSelectedState) {
  191. var state = _generateSelectedState(actionId, value);
  192. _applyImageAndTextJson(actionId, state);
  193. _updateElementIdImageStyle(actionId, state);
  194. }
  195. //added actionId and this hacky logic because we set style state on child, but interaction on parent
  196. //then the id saved in _selectedWidgets would be depended on widgetHasSelectedState... more see case 1818143
  197. while(obj.isContained && !$ax.getObjectFromElementId(id).interactionMap) obj = obj.parent;
  198. path = $ax.getPathFromScriptId($ax.repeater.getScriptIdFromElementId(id));
  199. path[path.length - 1] = obj.id;
  200. actionId = $ax.getElementIdFromPath(path, { itemNum: itemId });
  201. }
  202. }
  203. // ApplyImageAndTextJson(id, value ? 'selected' : 'normal');
  204. _selectedWidgets[id] = value;
  205. if(raiseSelectedEvents) $ax.event.raiseSelectedEvents(actionId, value);
  206. };
  207. var _generateSelectedState = function(id, selected) {
  208. var mouseState = $ax.event.mouseDownObjectId == id ? MOUSE_DOWN : $ax.event.mouseOverIds.indexOf(id) != -1 ? MOUSE_OVER : NORMAL;
  209. return _generateMouseState(id, mouseState, selected);
  210. };
  211. $ax.style.IsWidgetSelected = function(id) {
  212. return Boolean(_selectedWidgets[id]) || $('#'+id).hasClass('selected');
  213. };
  214. $ax.style.SetWidgetEnabled = function(id, value) {
  215. _disabledWidgets[id] = !value;
  216. $('#' + id).find('a').css('cursor', value ? 'pointer' : 'default');
  217. if(!_widgetHasState(id, DISABLED)) return;
  218. if(!value) {
  219. _applyImageAndTextJson(id, DISABLED);
  220. _updateElementIdImageStyle(id, DISABLED);
  221. } else $ax.style.SetWidgetSelected(id, $ax.style.IsWidgetSelected(id), true);
  222. };
  223. $ax.style.SetWidgetPlaceholder = function(id, value, text, password) {
  224. var inputId = $ax.repeater.applySuffixToElementId(id, '_input');
  225. // Right now this is the only style on the widget. If other styles (ex. Rollover), are allowed
  226. // on TextBox/TextArea, or Placeholder is applied to more widgets, this may need to do more.
  227. var obj = $jobj(inputId);
  228. var height = document.getElementById(inputId).style['height'];
  229. var width = document.getElementById(inputId).style['width'];
  230. obj.attr('style', '');
  231. //removing all styles, but now we can change the size, so we should add them back
  232. //this is more like a quick hack
  233. if (height) obj.css('height', height);
  234. if (width) obj.css('width', width);
  235. if(!value) {
  236. try { //ie8 and below error
  237. if(password) document.getElementById(inputId).type = 'password';
  238. } catch(e) { }
  239. } else {
  240. var element = $('#' + inputId)[0];
  241. var style = _computeAllOverrides(id, undefined, HINT, $ax.adaptive.currentViewId);
  242. var styleProperties = _getCssStyleProperties(style);
  243. //moved this out of GetCssStyleProperties for now because it was breaking un/rollovers with gradient fills
  244. if(style.fill) styleProperties.allProps.backgroundColor = _getColorFromFill(style.fill);
  245. _applyCssProps(element, styleProperties, true);
  246. try { //ie8 and below error
  247. if(password) document.getElementById(inputId).type = 'text';
  248. } catch(e) { }
  249. }
  250. obj.val(text);
  251. };
  252. var _isWidgetDisabled = $ax.style.IsWidgetDisabled = function(id) {
  253. return Boolean(_disabledWidgets[id]);
  254. };
  255. var _elementIdsToImageOverrides = {};
  256. $ax.style.mapElementIdToImageOverrides = function (elementId, override) {
  257. for(var key in override) _addImageOverride(elementId, key, override[key]);
  258. };
  259. var _addImageOverride = function (elementId, state, val) {
  260. if (!_elementIdsToImageOverrides[elementId]) _elementIdsToImageOverrides[elementId] = {};
  261. _elementIdsToImageOverrides[elementId][state] = val;
  262. }
  263. $ax.style.deleteElementIdToImageOverride = function(elementId) {
  264. delete _elementIdsToImageOverrides[elementId];
  265. };
  266. $ax.style.getElementImageOverride = function(elementId, state) {
  267. var url = _elementIdsToImageOverrides[elementId] && _elementIdsToImageOverrides[elementId][state];
  268. return url;
  269. };
  270. $ax.style.elementHasAnyImageOverride = function(elementId) {
  271. return Boolean(_elementIdsToImageOverrides[elementId]);
  272. };
  273. var NORMAL = 'normal';
  274. var MOUSE_OVER = 'mouseOver';
  275. var MOUSE_DOWN = 'mouseDown';
  276. var SELECTED = 'selected';
  277. var DISABLED = 'disabled';
  278. var HINT = 'hint';
  279. var _generateState = _style.generateState = function(id) {
  280. return $ax.placeholderManager.isActive(id) ? HINT : _style.IsWidgetDisabled(id) ? DISABLED : _generateSelectedState(id, _style.IsWidgetSelected(id));
  281. };
  282. var _progressState = _style.progessState = function(state) {
  283. if(state == NORMAL) return false;
  284. if(state == MOUSE_DOWN) return MOUSE_OVER;
  285. return NORMAL;
  286. };
  287. var _unprogressState = function(state, goal) {
  288. state = state || NORMAL;
  289. if(state == goal) return undefined;
  290. if(state == NORMAL && goal == MOUSE_DOWN) return MOUSE_OVER;
  291. return goal;
  292. };
  293. var _updateElementIdImageStyle = _style.updateElementIdImageStyle = function(elementId, state) {
  294. if(!_style.elementHasAnyImageOverride(elementId)) return;
  295. if(!state) state = _generateState(elementId);
  296. var style = _computeFullStyle(elementId, state, $ax.adaptive.currentViewId);
  297. var query = $jobj($ax.repeater.applySuffixToElementId(elementId, '_img'));
  298. style.size.width = query.width();
  299. style.size.height = query.height();
  300. var borderId = $ax.repeater.applySuffixToElementId(elementId, '_border');
  301. var borderQuery = $jobj(borderId);
  302. if(!borderQuery.length) {
  303. borderQuery = $('<div></div>');
  304. borderQuery.attr('id', borderId);
  305. query.after(borderQuery);
  306. }
  307. borderQuery.attr('style', '');
  308. borderQuery.css('position', 'absolute');
  309. query.attr('style', '');
  310. var borderWidth = Number(style.borderWidth);
  311. var hasBorderWidth = borderWidth > 0;
  312. if(hasBorderWidth) {
  313. borderQuery.css('border-style', 'solid');
  314. borderQuery.css('border-width', borderWidth + 'px');
  315. borderQuery.css('width', style.size.width - borderWidth * 2);
  316. borderQuery.css('height', style.size.height - borderWidth * 2);
  317. }
  318. var linePattern = style.linePattern;
  319. if(hasBorderWidth && linePattern) borderQuery.css('border-style', linePattern);
  320. var borderFill = style.borderFill;
  321. if(hasBorderWidth && borderFill) {
  322. var color = borderFill.fillType == 'solid' ? borderFill.color :
  323. borderFill.fillType == 'linearGradient' ? borderFill.colors[0].color : 0;
  324. var alpha = Math.floor(color / 256 / 256 / 256);
  325. color -= alpha * 256 * 256 * 256;
  326. alpha = alpha / 255;
  327. var red = Math.floor(color / 256 / 256);
  328. color -= red * 256 * 256;
  329. var green = Math.floor(color / 256);
  330. var blue = color - green * 256;
  331. borderQuery.css('border-color', _rgbaToFunc(red, green, blue, alpha));
  332. }
  333. var cornerRadiusTopLeft = style.cornerRadius;
  334. if(cornerRadiusTopLeft) {
  335. query.css('border-radius', cornerRadiusTopLeft + 'px');
  336. borderQuery.css('border-radius', cornerRadiusTopLeft + 'px');
  337. }
  338. var outerShadow = style.outerShadow;
  339. if(outerShadow && outerShadow.on) {
  340. var arg = '';
  341. arg += outerShadow.offsetX + 'px' + ' ' + outerShadow.offsetY + 'px' + ' ';
  342. var rgba = outerShadow.color;
  343. arg += outerShadow.blurRadius + 'px' + ' 0px ' + _rgbaToFunc(rgba.r, rgba.g, rgba.b, rgba.a);
  344. query.css('-moz-box-shadow', arg);
  345. query.css('-wibkit-box-shadow', arg);
  346. query.css('box-shadow', arg);
  347. query.css('left', '0px');
  348. query.css('top', '0px');
  349. }
  350. query.css({ width: style.size.width, height: style.size.height });
  351. };
  352. var _rgbaToFunc = function(red, green, blue, alpha) {
  353. return 'rgba(' + red + ',' + green + ',' + blue + ',' + alpha + ')';
  354. };
  355. //function $ax.style.GetTextIdFromShape(id) {
  356. // return $.grep(
  357. // $('#' + id).children().map(function (i, obj) { return obj.id; }), // all the child ids
  358. // function (item) { return item.indexOf(id) < 0; })[0]; // that are not similar to the parent
  359. //}
  360. var _getButtonShapeId = function(id) {
  361. var obj = $obj(id);
  362. return $ax.public.fn.IsTreeNodeObject(obj.type) ? $ax.getElementIdFromPath([obj.buttonShapeId], { relativeTo: id }) : id;
  363. };
  364. var _getButtonShape = function(id) {
  365. var obj = $obj(id);
  366. // some treeNodeObjects don't have button shapes
  367. return $jobj($ax.public.fn.IsTreeNodeObject(obj.type) && obj.buttonShapeId ? $ax.getElementIdFromPath([obj.buttonShapeId], { relativeTo: id }) : id);
  368. };
  369. var _getTextIdFromShape = $ax.style.GetTextIdFromShape = function(id) {
  370. return _getButtonShape(id).find('.text').attr('id');
  371. };
  372. $ax.style.GetTextIdFromLink = function(id) {
  373. return $jobj(id).parentsUntil('.text').parent().attr('id');
  374. };
  375. var _getShapeIdFromText = $ax.style.GetShapeIdFromText = function(id) {
  376. if(!id) return undefined; // this is to prevent an infinite loop.
  377. //return $jobj(id).parent().attr('id');
  378. var current = $jobj(id).parent();
  379. while(!current.is("body")) {
  380. var currentId = current.attr('id');
  381. if(currentId && currentId != 'base') return $ax.visibility.getWidgetFromContainer(currentId);
  382. current = current.parent();
  383. }
  384. return undefined;
  385. };
  386. $ax.style.GetImageIdFromShape = function(id) {
  387. var image = _getButtonShape(id).find('img[id$=img]');
  388. if(!image.length) image = $jobj(id).find('img[id$=image_sketch]');
  389. return image.attr('id');
  390. };
  391. var _applyImageAndTextJson = function(id, event) {
  392. var textId = $ax.style.GetTextIdFromShape(id);
  393. _resetTextJson(id, textId);
  394. // This should never be the case
  395. //if(event != '') {
  396. var imgQuery = $jobj($ax.style.GetImageIdFromShape(id));
  397. var e = imgQuery.data('events');
  398. if(e && e[event]) imgQuery.trigger(event);
  399. var imageUrl = $ax.adaptive.getImageForStateAndView(id, event);
  400. if(imageUrl) _applyImage(id, imageUrl, event);
  401. var style = _computeAllOverrides(id, undefined, event, $ax.adaptive.currentViewId);
  402. if(!$.isEmptyObject(style)) {
  403. _applyTextStyle(textId, style);
  404. }
  405. _updateStateClasses(id, event);
  406. _updateStateClasses($ax.repeater.applySuffixToElementId(id, '_div'), event);
  407. };
  408. var _updateStateClasses = function(id, event) {
  409. var jobj = $jobj(id);
  410. //if(jobj[0] && jobj[0].hasAttribute('widgetwidth')) {
  411. // for (var x = 0; x < jobj[0].children.length; x++) {
  412. // var childId = jobj[0].children[x].id;
  413. // if (childId.indexOf('p') < 0) continue;
  414. // _updateStateClasses(childId, event) ;
  415. // }
  416. //} else {
  417. for (var i = 0; i < ALL_STATES.length; i++) jobj.removeClass(ALL_STATES[i]);
  418. if (event == 'mouseDown') jobj.addClass('mouseOver');
  419. jobj.addClass(event);
  420. //}
  421. }
  422. /* -------------------
  423. here's the algorithm in a nutshell:
  424. [DOWN] -- refers to navigation down the view inheritance heirarchy (default to most specific)
  425. [UP] -- navigate up the heirarchy
  426. ComputeAllOverrides (object):
  427. All view styles [DOWN]
  428. If hyperlink
  429. - DO ComputeStateStyle for parent object
  430. - if (MouseOver || MouseDown)
  431. - linkMouseOver Style
  432. - if (MouseDown)
  433. - linkMouseDown style
  434. - ComputeStateStyleForViewChain (parent, STATE)
  435. if (MouseDown) DO ComputeStateStyleForViewChain for object, mouseOver
  436. DO ComputeStateStyleForViewChain for object, style
  437. ComputeStateStyleForViewChain (object, STATE)
  438. FIRST STATE state style [UP] the chain OR default object STATE style
  439. ------------------- */
  440. var FONT_PROPS = {
  441. 'typeface': true,
  442. 'fontName': true,
  443. 'fontWeight': true,
  444. 'fontStyle': true,
  445. 'fontStretch': true,
  446. 'fontSize': true,
  447. 'underline': true,
  448. 'foreGroundFill': true,
  449. 'horizontalAlignment': true
  450. };
  451. var _computeAllOverrides = $ax.style.computeAllOverrides = function(id, parentId, state, currentViewId) {
  452. var computedStyle = {};
  453. if(parentId) computedStyle = _computeAllOverrides(parentId, null, state, currentViewId);
  454. var diagramObject = $ax.getObjectFromElementId(id);
  455. var viewIdChain = $ax.adaptive.getAdaptiveIdChain(currentViewId);
  456. var excludeFont = _shapesWithSetRichText[id];
  457. for(var i = 0; i < viewIdChain.length; i++) {
  458. var viewId = viewIdChain[i];
  459. var style = diagramObject.adaptiveStyles[viewId];
  460. if(style) {
  461. // we want to exclude the normal font style for shapes where the rich text has been set with an interaction
  462. // so we copy the style so we don't modify the original, then delete all the font props.
  463. if(excludeFont) {
  464. style = $ax.deepCopy(style);
  465. for(var prop in FONT_PROPS) delete style[prop];
  466. }
  467. if(style) {
  468. var customStyle = style.baseStyle && $ax.document.stylesheet.stylesById[style.baseStyle];
  469. //make sure not to extend the customStyle this can mutate it for future use
  470. $.extend(computedStyle, customStyle);
  471. }
  472. $.extend(computedStyle, style);
  473. }
  474. }
  475. var currState = NORMAL;
  476. while(currState) {
  477. $.extend(computedStyle, _computeStateStyleForViewChain(diagramObject, currState, viewIdChain, true));
  478. currState = _unprogressState(currState, state);
  479. }
  480. return _removeUnsupportedProperties(computedStyle, diagramObject.type);
  481. };
  482. var _computeStateStyleForViewChain = function(diagramObject, state, viewIdChain, excludeNormal) {
  483. var styleObject = diagramObject;
  484. while(styleObject.isContained) styleObject = styleObject.parent;
  485. var adaptiveStyles = styleObject.adaptiveStyles;
  486. for(var i = viewIdChain.length - 1; i >= 0; i--) {
  487. var viewId = viewIdChain[i];
  488. var viewStyle = adaptiveStyles[viewId];
  489. var stateStyle = viewStyle && _getFullStateStyle(viewStyle, state, excludeNormal);
  490. if(stateStyle) return $.extend({}, stateStyle);
  491. }
  492. // we dont want to actually include the object style because those are not overrides, hence the true for "excludeNormal" and not passing the val through
  493. var stateStyleFromDefault = _getFullStateStyle(styleObject.style, state, true);
  494. return $.extend({}, stateStyleFromDefault);
  495. };
  496. // returns the full effective style for an object in a state state and view
  497. var _computeFullStyle = function(id, state, currentViewId) {
  498. var obj = $obj(id);
  499. var overrides = _computeAllOverrides(id, undefined, state, currentViewId);
  500. // todo: account for image box
  501. var objStyle = obj.style;
  502. var customStyle = objStyle.baseStyle && $ax.document.stylesheet.stylesById[objStyle.baseStyle];
  503. var returnVal = $.extend({}, $ax.document.stylesheet.defaultStyle, customStyle, objStyle, overrides);
  504. return _removeUnsupportedProperties(returnVal, obj.type);
  505. };
  506. var _removeUnsupportedProperties = function(style, objectType) {
  507. // for now all we need to do is remove padding from checkboxes and radio buttons
  508. if ($ax.public.fn.IsRadioButton(objectType) || $ax.public.fn.IsCheckBox(objectType)) {
  509. style.paddingTop = 0;
  510. style.paddingLeft = 0;
  511. style.paddingRight = 0;
  512. style.paddingBottom = 0;
  513. }
  514. return style;
  515. };
  516. var _getFullStateStyle = function(style, state, excludeNormal) {
  517. //'normal' is needed because now DiagramObjects get their image from the Style and unapplying a rollover needs the image
  518. var stateStyle = state == 'normal' && !excludeNormal ? style : style && style.stateStyles && style.stateStyles[state];
  519. if(stateStyle) {
  520. var customStyle = stateStyle.baseStyle && $ax.document.stylesheet.stylesById[stateStyle.baseStyle];
  521. //make sure not to extend the customStyle this can mutate it for future use
  522. return $.extend({}, customStyle, stateStyle);
  523. }
  524. return undefined;
  525. };
  526. // commented this out for now... we actually will probably need it for ie
  527. var _applyOpacityFromStyle = $ax.style.applyOpacityFromStyle = function(id, style) {
  528. return;
  529. var opacity = style.opacity || '';
  530. $jobj(id).children().css('opacity', opacity);
  531. };
  532. var _initialize = function() {
  533. //being handled at on window.load
  534. //$ax.style.initializeObjectTextAlignment($ax('*'));
  535. };
  536. $ax.style.initialize = _initialize;
  537. var _initTextAlignment = function(elementId) {
  538. var textId = _getTextIdFromShape(elementId);
  539. _storeIdToAlignProps(textId);
  540. // now handle vertical alignment
  541. if(_getObjVisible(textId)) {
  542. _setTextAlignment(textId, _idToAlignProps[textId], false);
  543. }
  544. };
  545. $ax.style.initializeObjectTextAlignment = function(query) {
  546. query.filter(function(diagramObject) {
  547. return $ax.public.fn.IsVector(diagramObject.type) || $ax.public.fn.IsImageBox(diagramObject.type);
  548. }).each(function(diagramObject, elementId) {
  549. if($jobj(elementId).length == 0) return;
  550. _initTextAlignment(elementId);
  551. });
  552. };
  553. var _storeIdToAlignProps = function(textId) {
  554. var shapeId = _getShapeIdFromText(textId);
  555. var shapeObj = $obj(shapeId);
  556. var state = _generateState(shapeId);
  557. var style = _computeFullStyle(shapeId, state, $ax.adaptive.currentViewId);
  558. var vAlign = style.verticalAlignment || 'middle';
  559. var paddingLeft = Number(style.paddingLeft || 0);
  560. paddingLeft += shapeObj && shapeObj.extraLeft || 0;
  561. var paddingTop = style.paddingTop || 0;
  562. var paddingRight = style.paddingRight || 0;
  563. var paddingBottom = style.paddingBottom || 0;
  564. _idToAlignProps[textId] = { vAlign: vAlign, paddingLeft: paddingLeft, paddingTop: paddingTop, paddingRight: paddingRight, paddingBottom: paddingBottom };
  565. };
  566. var ALL_STATES = ['mouseOver', 'mouseDown', 'selected', 'disabled'];
  567. var _applyImage = $ax.style.applyImage = function (id, imgUrl, state) {
  568. var object = $obj(id);
  569. if (object.generateCompound) {
  570. for (var i = 0; i < object.compoundChildren.length; i++) {
  571. var componentId = object.compoundChildren[i];
  572. var childId = $ax.public.fn.getComponentId(id, componentId);
  573. var childImgQuery = $jobj(childId + '_img');
  574. var childQuery = $jobj(childId);
  575. childImgQuery.attr('src', imgUrl[componentId]);
  576. for (var j = 0; j < ALL_STATES.length; j++) {
  577. childImgQuery.removeClass(ALL_STATES[j]);
  578. childQuery.removeClass(ALL_STATES[j]);
  579. }
  580. if (state != 'normal') {
  581. childImgQuery.addClass(state);
  582. childQuery.addClass(state);
  583. }
  584. }
  585. } else {
  586. var imgQuery = $jobj($ax.style.GetImageIdFromShape(id));
  587. var idQuery = $jobj(id);
  588. //it is hard to tell if setting the image or the class first causing less flashing when adding shadows.
  589. imgQuery.attr('src', imgUrl);
  590. for (var i = 0; i < ALL_STATES.length; i++) {
  591. idQuery.removeClass(ALL_STATES[i]);
  592. imgQuery.removeClass(ALL_STATES[i]);
  593. }
  594. if (state != 'normal') {
  595. idQuery.addClass(state);
  596. imgQuery.addClass(state);
  597. }
  598. if (imgQuery.parents('a.basiclink').length > 0) imgQuery.css('border', 'none');
  599. if (imgUrl.indexOf(".png") > -1) $ax.utils.fixPng(imgQuery[0]);
  600. }
  601. };
  602. $ax.public.fn.getComponentId = function (id, componentId) {
  603. var idParts = id.split('-');
  604. idParts[0] = idParts[0] + componentId;
  605. return idParts.join('-');
  606. }
  607. var _resetTextJson = function(id, textid) {
  608. // reset the opacity
  609. $jobj(id).children().css('opacity', '');
  610. var cacheObject = _originalTextCache[textid];
  611. if(cacheObject) {
  612. _transformTextWithVerticalAlignment(textid, function() {
  613. var styleCache = cacheObject.styleCache;
  614. var textQuery = $('#' + textid);
  615. textQuery.find('*').each(function(index, element) {
  616. element.style.cssText = styleCache[element.id];
  617. });
  618. });
  619. }
  620. };
  621. // Preserves the alingment for the element textid after executing transformFn
  622. var _getRtfElementHeight = function(rtfElement) {
  623. if(rtfElement.innerHTML == '') rtfElement.innerHTML = '&nbsp;';
  624. // To handle render text as image
  625. var images = $(rtfElement).children('img');
  626. if(images.length) return images.height();
  627. return rtfElement.offsetHeight;
  628. };
  629. // why microsoft decided to default to round to even is beyond me...
  630. var _roundToEven = function(number) {
  631. var numString = number.toString();
  632. var parts = numString.split('.');
  633. if(parts.length == 1) return number;
  634. if(parts[1].length == 1 && parts[1] == '5') {
  635. var wholePart = Number(parts[0]);
  636. return wholePart % 2 == 0 ? wholePart : wholePart + 1;
  637. } else return Math.round(number);
  638. };
  639. var _transformTextWithVerticalAlignment = $ax.style.transformTextWithVerticalAlignment = function(textId, transformFn) {
  640. if(!_originalTextCache[textId]) {
  641. $ax.style.CacheOriginalText(textId);
  642. }
  643. var rtfElement = window.document.getElementById(textId);
  644. if(!rtfElement) return;
  645. transformFn();
  646. _storeIdToAlignProps(textId);
  647. $ax.style.updateTextAlignmentForVisibility(textId);
  648. };
  649. // this is for vertical alignments set on hidden objects
  650. var _idToAlignProps = {};
  651. _style.checkAlignmentQueue = function (id) {
  652. var index = queuedTextToAlign.indexOf(id);
  653. if (index != -1) {
  654. $ax.splice(queuedTextToAlign, index, 1);
  655. _style.updateTextAlignmentForVisibility(id);
  656. }
  657. }
  658. var queuedTextToAlign = [];
  659. $ax.style.updateTextAlignmentForVisibility = function (textId) {
  660. var textObj = $jobj(textId);
  661. // must check if parent id exists. Doesn't exist for text objs in check boxes, and potentially elsewhere.
  662. var parentId = textObj.parent().attr('id');
  663. if (parentId && $ax.visibility.isContainer(parentId)) {
  664. if (queuedTextToAlign.indexOf(textId) == -1) queuedTextToAlign.push(textId);
  665. return;
  666. }
  667. var alignProps = _idToAlignProps[textId];
  668. if(!alignProps || !_getObjVisible(textId)) return;
  669. _setTextAlignment(textId, alignProps);
  670. };
  671. var _getObjVisible = _style.getObjVisible = function(id) {
  672. var element = document.getElementById(id);
  673. return element && (element.offsetWidth || element.offsetHeight);
  674. };
  675. var _setTextAlignment = function (textId, alignProps, updateProps) {
  676. if(updateProps) {
  677. _storeIdToAlignProps(textId);
  678. }
  679. if(!alignProps) return;
  680. var vAlign = alignProps.vAlign;
  681. var paddingTop = Number(alignProps.paddingTop);
  682. var paddingBottom = Number(alignProps.paddingBottom);
  683. var paddingLeft = Number(alignProps.paddingLeft);
  684. var paddingRight = Number(alignProps.paddingRight);
  685. var topParam = 0.0;
  686. var bottomParam = 1.0;
  687. var leftParam = 0.0;
  688. var rightParam = 1.0;
  689. var textObj = $jobj(textId);
  690. var textHeight = _getRtfElementHeight(textObj[0]);
  691. var textObjParent = textObj.offsetParent();
  692. var parentId = textObjParent.attr('id');
  693. var isConnector = false;
  694. if(parentId) {
  695. parentId = $ax.visibility.getWidgetFromContainer(textObjParent.attr('id'));
  696. textObjParent = $jobj(parentId);
  697. var parentObj = $obj(parentId);
  698. if (parentObj['bottomTextPadding']) bottomParam = parentObj['bottomTextPadding'];
  699. if (parentObj['topTextPadding']) topParam = parentObj['topTextPadding'];
  700. if (parentObj['leftTextPadding']) leftParam = parentObj['leftTextPadding'];
  701. if (parentObj['rightTextPadding']) rightParam = parentObj['rightTextPadding'];
  702. // for now all this smart shapes weird shit is mutually exclusive from compound vectors.
  703. isConnector = parentObj.type == $ax.constants.CONNECTOR_TYPE;
  704. }
  705. if (isConnector) return;
  706. var axTextObjectParent = $ax('#' + textObjParent.attr('id'));
  707. var oldWidth = $ax.getNumFromPx(textObj.css('width'));
  708. var oldLeft = $ax.getNumFromPx(textObj.css('left'));
  709. var oldTop = $ax.getNumFromPx(textObj.css('top'));
  710. var newTop = 0;
  711. var newLeft = 0.0;
  712. var width = axTextObjectParent.width();
  713. var height = axTextObjectParent.height();
  714. // If text rotated need to handle getting the correct width for text based on bounding rect of rotated parent.
  715. var boundingRotation = -$ax.move.getRotationDegree(textId);
  716. var boundingParent = $axure.fn.getBoundingSizeForRotate(width, height, boundingRotation);
  717. var extraLeftPadding = (width - boundingParent.width) / 2;
  718. width = boundingParent.width;
  719. var relativeTop = 0.0;
  720. relativeTop = height * topParam;
  721. var containerHeight = height * bottomParam - relativeTop;
  722. if (vAlign == "middle") newTop = _roundToEven(relativeTop + (containerHeight - textHeight + paddingTop - paddingBottom) / 2);
  723. else if (vAlign == "bottom") newTop = _roundToEven(relativeTop + containerHeight - textHeight - paddingBottom);
  724. else newTop = _roundToEven(paddingTop + relativeTop);
  725. newLeft = paddingLeft + extraLeftPadding + width * leftParam;
  726. var newWidth = width * (rightParam - leftParam) - paddingLeft - paddingRight;
  727. var vertChange = oldTop != newTop;
  728. if (vertChange) textObj.css('top', newTop + 'px');
  729. var horizChange = newWidth != oldWidth || newLeft != oldLeft;
  730. if (horizChange) {
  731. textObj.css('left', newLeft);
  732. textObj.width(newWidth);
  733. }
  734. if ((vertChange || horizChange)) _updateTransformOrigin(textId);
  735. };
  736. var _updateTransformOrigin = function(textId) {
  737. var textObj = $jobj(textId);
  738. var transformOrigin = textObj.css('-webkit-transform-origin') ||
  739. textObj.css('-moz-transform-origin') ||
  740. textObj.css('-ms-transform-origin') ||
  741. textObj.css('transform-origin');
  742. if(transformOrigin) {
  743. var textObjParent = $ax('#' + textObj.parent().attr('id'));
  744. var newX = (textObjParent.width() / 2 - textObj.css('left').replace('px', ''));
  745. var newY = (textObjParent.height() / 2 - textObj.css('top').replace('px', ''));
  746. var newOrigin = newX + 'px ' + newY + 'px';
  747. textObj.css('-webkit-transform-origin', newOrigin);
  748. textObj.css('-moz-transform-origin', newOrigin);
  749. textObj.css('-ms-transform-origin', newOrigin);
  750. textObj.css('transform-origin', newOrigin);
  751. }
  752. };
  753. $ax.style.reselectElements = function() {
  754. for(var id in _selectedWidgets) {
  755. // Only looking for the selected widgets that don't have their class set
  756. if(!_selectedWidgets[id] || $jobj(id).hasClass('selected')) continue;
  757. $jobj(id).addClass('selected');
  758. _applyImageAndTextJson(id, $ax.style.generateState(id));
  759. }
  760. for(id in _disabledWidgets) {
  761. // Only looking for the disabled widgets that don't have their class yet
  762. if (!_disabledWidgets[id] || $jobj(id).hasClass('disabled')) continue;
  763. $jobj(id).addClass('disabled');
  764. _applyImageAndTextJson(id, $ax.style.generateState(id));
  765. }
  766. }
  767. $ax.style.clearAdaptiveStyles = function() {
  768. for(var shapeId in _adaptiveStyledWidgets) {
  769. var elementIds = [shapeId];
  770. var repeaterId = $ax.getParentRepeaterFromScriptId(shapeId);
  771. if(repeaterId) {
  772. var itemIds = $ax.getItemIdsForRepeater(repeaterId);
  773. elementIds = [];
  774. for(var i = 0; i < itemIds; i++) elementIds.push($ax.repeater.createElementId(shapeId, itemIds[i]));
  775. }
  776. for(var index = 0; index < elementIds.length; index++) {
  777. var elementId = _getButtonShapeId(elementIds[index]);
  778. if(elementId) {
  779. var textId = $ax.style.GetTextIdFromShape(elementId);
  780. _resetTextJson(elementId, textId);
  781. _applyImageAndTextJson(elementId, $ax.style.generateState(elementId));
  782. }
  783. }
  784. }
  785. _adaptiveStyledWidgets = {};
  786. };
  787. $ax.style.setAdaptiveStyle = function(shapeId, style) {
  788. _adaptiveStyledWidgets[$ax.repeater.getScriptIdFromElementId(shapeId)] = style;
  789. var textId = $ax.style.GetTextIdFromShape(shapeId);
  790. if(textId) _applyTextStyle(textId, style);
  791. $ax.placeholderManager.refreshPlaceholder(shapeId);
  792. // removing this for now
  793. // if(style.location) {
  794. // $jobj(shapeId).css('top', style.location.x + "px")
  795. // .css('left', style.location.y + "px");
  796. // }
  797. };
  798. //-------------------------------------------------------------------------
  799. // _applyTextStyle
  800. //
  801. // Applies a rollover style to a text element.
  802. // id : the id of the text object to set.
  803. // styleProperties : an object mapping style properties to values. eg:
  804. // { 'fontWeight' : 'bold',
  805. // 'fontStyle' : 'italic' }
  806. //-------------------------------------------------------------------------
  807. var _applyTextStyle = function(id, style) {
  808. _transformTextWithVerticalAlignment(id, function() {
  809. var styleProperties = _getCssStyleProperties(style);
  810. $('#' + id).find('*').each(function(index, element) {
  811. _applyCssProps(element, styleProperties);
  812. });
  813. });
  814. };
  815. var _applyCssProps = function(element, styleProperties, applyAllStyle) {
  816. if(applyAllStyle) {
  817. var allProps = styleProperties.allProps;
  818. for(var prop in allProps) element.style[prop] = allProps[prop];
  819. } else {
  820. var nodeName = element.nodeName.toLowerCase();
  821. if(nodeName == 'p') {
  822. var parProps = styleProperties.parProps;
  823. for(prop in parProps) element.style[prop] = parProps[prop];
  824. } else if(nodeName != 'a') {
  825. var runProps = styleProperties.runProps;
  826. for(prop in runProps) element.style[prop] = runProps[prop];
  827. }
  828. }
  829. };
  830. var _getCssShadow = function(shadow) {
  831. return !shadow.on ? "none"
  832. : shadow.offsetX + "px " + shadow.offsetY + "px " + shadow.blurRadius + "px " + _getCssColor(shadow.color);
  833. };
  834. var _getCssStyleProperties = function(style) {
  835. var toApply = {};
  836. toApply.runProps = {};
  837. toApply.parProps = {};
  838. toApply.allProps = {};
  839. if(style.fontName) toApply.allProps.fontFamily = toApply.runProps.fontFamily = style.fontName;
  840. // we need to set font size on both runs and pars because otherwise it well mess up the measure and thereby vertical alignment
  841. if(style.fontSize) toApply.allProps.fontSize = toApply.runProps.fontSize = toApply.parProps.fontSize = style.fontSize;
  842. if(style.fontWeight !== undefined) toApply.allProps.fontWeight = toApply.runProps.fontWeight = style.fontWeight;
  843. if(style.fontStyle !== undefined) toApply.allProps.fontStyle = toApply.runProps.fontStyle = style.fontStyle;
  844. if(style.underline !== undefined) toApply.allProps.textDecoration = toApply.runProps.textDecoration = style.underline ? 'underline' : 'none';
  845. if(style.foreGroundFill) {
  846. toApply.allProps.color = toApply.runProps.color = _getColorFromFill(style.foreGroundFill);
  847. //if(style.foreGroundFill.opacity) toApply.allProps.opacity = toApply.runProps.opacity = style.foreGroundFill.opacity;
  848. }
  849. if(style.horizontalAlignment) toApply.allProps.textAlign = toApply.parProps.textAlign = toApply.runProps.textAlign = style.horizontalAlignment;
  850. if(style.lineSpacing) toApply.allProps.lineHeight = toApply.parProps.lineHeight = style.lineSpacing;
  851. if(style.textShadow) toApply.allProps.textShadow = toApply.parProps.textShadow = _getCssShadow(style.textShadow);
  852. return toApply;
  853. };
  854. var _getColorFromFill = function(fill) {
  855. //var fillString = '00000' + fill.color.toString(16);
  856. //return '#' + fillString.substring(fillString.length - 6);
  857. var val = fill.color;
  858. var color = {};
  859. color.b = val % 256;
  860. val = Math.floor(val / 256);
  861. color.g = val % 256;
  862. val = Math.floor(val / 256);
  863. color.r = val % 256;
  864. color.a = typeof (fill.opacity) == 'number' ? fill.opacity : 1;
  865. return _getCssColor(color);
  866. };
  867. var _getCssColor = function(rgbaObj) {
  868. return "rgba(" + rgbaObj.r + ", " + rgbaObj.g + ", " + rgbaObj.b + ", " + rgbaObj.a + ")";
  869. };
  870. // //--------------------------------------------------------------------------
  871. // // ApplyStyleRecursive
  872. // //
  873. // // Applies a style recursively to all span and div tags including elementNode
  874. // // and all of its children.
  875. // //
  876. // // element : the element to apply the style to
  877. // // styleName : the name of the style property to set (eg. 'font-weight')
  878. // // styleValue : the value of the style to set (eg. 'bold')
  879. // //--------------------------------------------------------------------------
  880. // function ApplyStyleRecursive(element, styleName, styleValue) {
  881. // var nodeName = element.nodeName.toLowerCase();
  882. // if (nodeName == 'div' || nodeName == 'span' || nodeName == 'p') {
  883. // element.style[styleName] = styleValue;
  884. // }
  885. // for (var i = 0; i < element.childNodes.length; i++) {
  886. // ApplyStyleRecursive(element.childNodes[i], styleName, styleValue);
  887. // }
  888. // }
  889. // //---------------------------------------------------------------------------
  890. // // ApplyTextProperty
  891. // //
  892. // // Applies a text property to rtfElement.
  893. // //
  894. // // rtfElement : the the root text element of the rtf object (this is the
  895. // // element named <id>_rtf
  896. // // prop : the style property to set.
  897. // // value : the style value to set.
  898. // //---------------------------------------------------------------------------
  899. // function ApplyTextProperty(rtfElement, prop, value) {
  900. // /*
  901. // var oldHtml = rtfElement.innerHTML;
  902. // if (prop == 'fontWeight') {
  903. // rtfElement.innerHTML = oldHtml.replace(/< *b *\/?>/gi, "");
  904. // } else if (prop == 'fontStyle') {
  905. // rtfElement.innerHTML = oldHtml.replace(/< *i *\/?>/gi, "");
  906. // } else if (prop == 'textDecoration') {
  907. // rtfElement.innerHTML = oldHtml.replace(/< *u *\/?>/gi, "");
  908. // }
  909. // */
  910. // for (var i = 0; i < rtfElement.childNodes.length; i++) {
  911. // ApplyStyleRecursive(rtfElement.childNodes[i], prop, value);
  912. // }
  913. // }
  914. //}
  915. //---------------------------------------------------------------------------
  916. // GetAndCacheOriginalText
  917. //
  918. // Gets the html for the pre-rollover state and returns the Html representing
  919. // the Rich text.
  920. //---------------------------------------------------------------------------
  921. var CACHE_COUNTER = 0;
  922. $ax.style.CacheOriginalText = function(textId, hasRichTextBeenSet) {
  923. var rtfQuery = $('#' + textId);
  924. if(rtfQuery.length > 0) {
  925. var styleCache = {};
  926. rtfQuery.find('*').each(function(index, element) {
  927. var elementId = element.id;
  928. if(!elementId) element.id = elementId = 'cache' + CACHE_COUNTER++;
  929. styleCache[elementId] = element.style.cssText;
  930. });
  931. _originalTextCache[textId] = {
  932. styleCache: styleCache
  933. };
  934. if(hasRichTextBeenSet) {
  935. var shapeId = _getShapeIdFromText(textId);
  936. _shapesWithSetRichText[shapeId] = true;
  937. }
  938. }
  939. };
  940. $ax.style.ClearCacheForRepeater = function(repeaterId) {
  941. for(var elementId in _originalTextCache) {
  942. var scriptId = $ax.repeater.getScriptIdFromElementId(elementId);
  943. if($ax.getParentRepeaterFromScriptId(scriptId) == repeaterId) delete _originalTextCache[elementId];
  944. }
  945. };
  946. $ax.style.prefetch = function() {
  947. var scriptIds = $ax.getAllScriptIds();
  948. var image = new Image();
  949. for(var i = 0; i < scriptIds.length; i++) {
  950. var obj = $obj(scriptIds[i]);
  951. if (!$ax.public.fn.IsImageBox(obj.type)) continue;
  952. var images = obj.images;
  953. for (var key in images) image.src = images[key];
  954. var imageOverrides = obj.imageOverrides;
  955. for(var elementId in imageOverrides) {
  956. var override = imageOverrides[elementId];
  957. for (var state in override) {
  958. _addImageOverride(elementId, state, override[state]);
  959. image.src = override[state];
  960. }
  961. }
  962. }
  963. };
  964. });