style.js.orig 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  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. return $ax.style.getElementImageOverride(id, 'mouseDown') || obj.style && obj.style.stateStyles && obj.style.stateStyles.mouseDown;
  114. };
  115. $ax.style.SetWidgetMouseDown = function(id, value) {
  116. if($ax.style.IsWidgetDisabled(id)) return;
  117. if(!_widgetHasState(id, MOUSE_DOWN)) return;
  118. // ApplyImageAndTextJson(id, value ? 'mouseDown' : !$.isEmptyObject(GetStyleForState(id, null, 'mouseOver')) ? 'mouseOver' : 'normal');
  119. var state = _generateMouseState(id, value ? MOUSE_DOWN : MOUSE_OVER, $ax.style.IsWidgetSelected(id));
  120. _applyImageAndTextJson(id, state);
  121. _updateElementIdImageStyle(id, state);
  122. };
  123. var _generateMouseState = function(id, mouseState, selected) {
  124. if(selected) {
  125. var viewChain = $ax.adaptive.getAdaptiveIdChain($ax.adaptive.currentViewId);
  126. viewChain[viewChain.length] = '';
  127. var obj = $obj(id);
  128. var any = function(dict) {
  129. for(var key in dict) return true;
  130. return false;
  131. };
  132. for(var i = 0; i < viewChain.length; i++) {
  133. var viewId = viewChain[i];
  134. // Need to check seperately for images.
  135. if((obj.adaptiveStyles && obj.adaptiveStyles[viewId] && any(obj.adaptiveStyles[viewId])) || obj.images['selected~' + viewId]) return SELECTED;
  136. }
  137. var selectedStyle = obj.style && obj.style.stateStyles && obj.style.stateStyles.selected;
  138. if(selectedStyle && any(selectedStyle)) return SELECTED;
  139. }
  140. // Not using selected
  141. return mouseState;
  142. };
  143. $ax.style.SetWidgetSelected = function(id, value, alwaysApply) {
  144. if($ax.style.IsWidgetDisabled(id)) return;
  145. if(value) {
  146. var group = $('#' + id).attr('selectiongroup');
  147. if(group) {
  148. $("[selectiongroup='" + group + "']").each(function() {
  149. var otherId = this.id;
  150. if(otherId == id) return;
  151. $ax.style.SetWidgetSelected(otherId, false);
  152. });
  153. }
  154. }
  155. var obj = $obj(id);
  156. if(obj) {
  157. if(obj.type == 'dynamicPanel') {
  158. var children = $axure('#' + id).getChildren()[0].children;
  159. for(var i = 0; i < children.length; i++) {
  160. var childId = children[i];
  161. // Special case for trees
  162. var childObj = $jobj(childId);
  163. if(childObj.hasClass('treeroot')) {
  164. var treenodes = childObj.find('.treenode');
  165. for(var j = 0; j < treenodes.length; j++) {
  166. $axure('#' + treenodes[j].id).selected(value);
  167. }
  168. } else $axure('#' + childId).selected(value);
  169. }
  170. } else {
  171. while(obj.isContained && !_widgetHasState(id, 'selected')) obj = obj.parent;
  172. var itemId = $ax.repeater.getItemIdFromElementId(id);
  173. var path = $ax.getPathFromScriptId($ax.repeater.getScriptIdFromElementId(id));
  174. path[path.length - 1] = obj.id;
  175. id = $ax.getElementIdFromPath(path, { itemNum: itemId });
  176. if(alwaysApply || _widgetHasState(id, SELECTED)) {
  177. var state = _generateSelectedState(id, value);
  178. _applyImageAndTextJson(id, state);
  179. _updateElementIdImageStyle(id, state);
  180. }
  181. }
  182. }
  183. // ApplyImageAndTextJson(id, value ? 'selected' : 'normal');
  184. _selectedWidgets[id] = value;
  185. };
  186. var _generateSelectedState = function(id, selected) {
  187. var mouseState = $ax.event.mouseDownObjectId == id ? MOUSE_DOWN : $ax.event.mouseOverIds.indexOf(id) != -1 ? MOUSE_OVER : NORMAL;
  188. return _generateMouseState(id, mouseState, selected);
  189. };
  190. $ax.style.IsWidgetSelected = function(id) {
  191. return Boolean(_selectedWidgets[id]);
  192. };
  193. $ax.style.SetWidgetEnabled = function(id, value) {
  194. _disabledWidgets[id] = !value;
  195. $('#' + id).find('a').css('cursor', value ? 'pointer' : 'default');
  196. if(!_widgetHasState(id, DISABLED)) return;
  197. if(!value) {
  198. _applyImageAndTextJson(id, DISABLED);
  199. _updateElementIdImageStyle(id, DISABLED);
  200. } else $ax.style.SetWidgetSelected(id, $ax.style.IsWidgetSelected(id), true);
  201. };
  202. $ax.style.SetWidgetPlaceholder = function(id, value, text, password) {
  203. var inputId = $ax.repeater.applySuffixToElementId(id, '_input');
  204. // Right now this is the only style on the widget. If other styles (ex. Rollover), are allowed
  205. // on TextBox/TextArea, or Placeholder is applied to more widgets, this may need to do more.
  206. var obj = $jobj(inputId);
  207. if(!value) {
  208. obj.attr('style', '');
  209. if(password) document.getElementById(inputId).type = 'password';
  210. } else {
  211. var style = _computeAllOverrides(id, undefined, HINT, $ax.adaptive.currentViewId);
  212. var styleProperties = _getCssStyleProperties(style);
  213. //moved this out of GetCssStyleProperties for now because it was breaking un/rollovers with gradient fills
  214. if(style.fill) styleProperties.runProps.backgroundColor = _getColorFromFill(style.fill);
  215. _applyCssProps($('#' + inputId)[0], styleProperties);
  216. if(password) document.getElementById(inputId).type = 'text';
  217. }
  218. obj.val(text);
  219. };
  220. var _isWidgetDisabled = $ax.style.IsWidgetDisabled = function(id) {
  221. return Boolean(_disabledWidgets[id]);
  222. };
  223. var _elementIdsToImageOverrides = {};
  224. $ax.style.mapElementIdToImageOverrides = function(elementId, override) {
  225. _elementIdsToImageOverrides[elementId] = override;
  226. };
  227. $ax.style.deleteElementIdToImageOverride = function(elementId) {
  228. delete _elementIdsToImageOverrides[elementId];
  229. };
  230. $ax.style.getElementImageOverride = function(elementId, state) {
  231. var url = _elementIdsToImageOverrides[elementId] && _elementIdsToImageOverrides[elementId][state];
  232. return url;
  233. };
  234. $ax.style.elementHasAnyImageOverride = function(elementId) {
  235. return Boolean(_elementIdsToImageOverrides[elementId]);
  236. };
  237. var NORMAL = 'normal';
  238. var MOUSE_OVER = 'mouseOver';
  239. var MOUSE_DOWN = 'mouseDown';
  240. var SELECTED = 'selected';
  241. var DISABLED = 'disabled';
  242. var HINT = 'hint';
  243. var _generateState = _style.generateState = function(id) {
  244. return _style.IsWidgetDisabled(id) ? DISABLED : _generateSelectedState(id, _style.IsWidgetSelected(id));
  245. };
  246. var _progressState = _style.progessState = function(state) {
  247. if(state == NORMAL) return false;
  248. if(state == MOUSE_DOWN) return MOUSE_OVER;
  249. return NORMAL;
  250. };
  251. var _unprogressState = function(state, goal) {
  252. state = state || NORMAL;
  253. if(state == goal) return undefined;
  254. if(state == NORMAL && goal == MOUSE_DOWN) return MOUSE_OVER;
  255. return goal;
  256. };
  257. var _updateElementIdImageStyle = _style.updateElementIdImageStyle = function(elementId, state) {
  258. if(!_style.elementHasAnyImageOverride(elementId)) return;
  259. if(!state) state = _generateState(elementId);
  260. var obj = $obj(elementId);
  261. var style = obj.style;
  262. var stateStyle = state == NORMAL ? style : style && style.stateStyles && style.stateStyles[state];
  263. if(!stateStyle && !_style.getElementImageOverride(elementId, state)) {
  264. state = _progressState(state);
  265. if(state) _updateElementIdImageStyle(elementId, state);
  266. return;
  267. }
  268. var computedStyle = _style.computeAllOverrides(elementId, undefined, state, $ax.adaptive.currentViewId);
  269. var defaultStyle = $ax.document.stylesheet.defaultStyles[obj.type];
  270. var query = $jobj($ax.repeater.applySuffixToElementId(elementId, '_img'));
  271. var borderId = $ax.repeater.applySuffixToElementId(elementId, '_border');
  272. var borderQuery = $jobj(borderId);
  273. if(!borderQuery.length) {
  274. borderQuery = $('<div></div>');
  275. borderQuery.attr('id', borderId);
  276. query.after(borderQuery);
  277. }
  278. borderQuery.attr('style', '');
  279. borderQuery.css('position', 'absolute');
  280. query.attr('style', '');
  281. var borderWidth = computedStyle.borderWidth || style.borderWidth || defaultStyle.borderWidth;
  282. if(borderWidth) {
  283. borderQuery.css('border-style', 'solid');
  284. borderQuery.css('border-width', borderWidth + 'px');
  285. borderQuery.css('width', style.size.width - borderWidth * 2);
  286. borderQuery.css('height', style.size.height - borderWidth * 2);
  287. }
  288. var linePattern = computedStyle.linePattern || style.linePattern || defaultStyle.linePattern;
  289. if(linePattern) borderQuery.css('border-style', linePattern);
  290. var borderFill = computedStyle.borderFill || style.borderFill || defaultStyle.borderFill;
  291. if(borderFill) {
  292. var color = borderFill.fillType == 'solid' ? borderFill.color :
  293. borderFill.fillType == 'linearGradient' ? borderFill.colors[0].color : 0;
  294. var alpha = Math.floor(color / 256 / 256 / 256);
  295. color -= alpha * 256 * 256 * 256;
  296. alpha = alpha / 255;
  297. var red = Math.floor(color / 256 / 256);
  298. color -= red * 256 * 256;
  299. var green = Math.floor(color / 256);
  300. var blue = color - green * 256;
  301. borderQuery.css('border-color', _rgbaToFunc(red, green, blue, alpha));
  302. }
  303. var cornerRadiusTopLeft = computedStyle.cornerRadiusTopLeft || style.cornerRadiusTopLeft || defaultStyle.cornerRadiusTopLeft;
  304. if(cornerRadiusTopLeft) {
  305. query.css('border-radius', cornerRadiusTopLeft + 'px');
  306. borderQuery.css('border-radius', cornerRadiusTopLeft + 'px');
  307. }
  308. var outerShadow = computedStyle.outerShadow || style.outerShadow || defaultStyle.outerShadow;
  309. if(outerShadow && outerShadow.on) {
  310. var arg = '';
  311. arg += outerShadow.offsetX + 'px' + ' ' + outerShadow.offsetY + 'px' + ' ';
  312. var rgba = outerShadow.color;
  313. arg += outerShadow.blurRadius + 'px' + ' 0px ' + _rgbaToFunc(rgba.r, rgba.g, rgba.b, rgba.a);
  314. query.css('-moz-box-shadow', arg);
  315. query.css('-wibkit-box-shadow', arg);
  316. query.css('box-shadow', arg);
  317. query.css('width', style.size.width);
  318. query.css('height', style.size.height);
  319. query.css('left', '0px');
  320. query.css('top', '0px');
  321. }
  322. };
  323. var _rgbaToFunc = function(red, green, blue, alpha) {
  324. return 'rgba(' + red + ',' + green + ',' + blue + ',' + alpha + ')';
  325. };
  326. //function $ax.style.GetTextIdFromShape(id) {
  327. // return $.grep(
  328. // $('#' + id).children().map(function (i, obj) { return obj.id; }), // all the child ids
  329. // function (item) { return item.indexOf(id) < 0; })[0]; // that are not similar to the parent
  330. //}
  331. <<<<<<< local
  332. =======
  333. var _getButtonShapeId = function(id) {
  334. var obj = $obj(id);
  335. return obj.type == 'treeNodeObject' ? $ax.getElementIdFromPath([obj.buttonShapeId], { relativeTo: id }) : id;
  336. };
  337. >>>>>>> other
  338. var _getButtonShape = function(id) {
  339. var obj = $obj(id);
  340. // some treeNodeObjects don't have button shapes
  341. return $jobj(obj.type == 'treeNodeObject' && obj.buttonShapeId ? $ax.getElementIdFromPath([obj.buttonShapeId], { relativeTo: id }) : id);
  342. };
  343. var _getTextIdFromShape = $ax.style.GetTextIdFromShape = function(id) {
  344. return _getButtonShape(id).find('.text').attr('id');
  345. };
  346. $ax.style.GetTextIdFromLink = function(id) {
  347. return $jobj(id).parentsUntil('.text').parent().attr('id');
  348. };
  349. var _getShapeIdFromText = $ax.style.GetShapeIdFromText = function(id) {
  350. if(!id) return undefined; // this is to prevent an infinite loop.
  351. //return $jobj(id).parent().attr('id');
  352. var current = $jobj(id).parent();
  353. while(!current.is("body")) {
  354. var id = current.attr('id');
  355. if(id && id != 'base') return id;
  356. current = current.parent();
  357. }
  358. return undefined;
  359. };
  360. $ax.style.GetImageIdFromShape = function(id) {
  361. var image = _getButtonShape(id).find('img[id$=img]');
  362. if(!image.length) image = $jobj(id).find('img[id$=image_sketch]');
  363. return image.attr('id');
  364. };
  365. var _applyImageAndTextJson = function(id, event) {
  366. var textId = $ax.style.GetTextIdFromShape(id);
  367. _resetTextJson(id, textId);
  368. // This should never be the case
  369. //if(event != '') {
  370. var imgQuery = $jobj($ax.style.GetImageIdFromShape(id));
  371. var e = imgQuery.data('events');
  372. if(e && e[event]) imgQuery.trigger(event);
  373. var imageUrl = $ax.adaptive.getImageForStateAndView(id, event);
  374. if(imageUrl) _applyImage(id, imageUrl, event);
  375. var style = _computeAllOverrides(id, undefined, event, $ax.adaptive.currentViewId);
  376. if(!$.isEmptyObject(style)) {
  377. _applyTextStyle(textId, style);
  378. }
  379. };
  380. /* -------------------
  381. here's the algorithm in a nutshell:
  382. [DOWN] -- refers to navigation down the view inheritance heirarchy (default to most specific)
  383. [UP] -- navigate up the heirarchy
  384. ComputeAllOverrides (object):
  385. All view styles [DOWN]
  386. If hyperlink
  387. - DO ComputeStateStyle for parent object
  388. - if (MouseOver || MouseDown)
  389. - linkMouseOver Style
  390. - if (MouseDown)
  391. - linkMouseDown style
  392. - ComputeStateStyleForViewChain (parent, STATE)
  393. if (MouseDown) DO ComputeStateStyleForViewChain for object, mouseOver
  394. DO ComputeStateStyleForViewChain for object, style
  395. ComputeStateStyleForViewChain (object, STATE)
  396. FIRST STATE state style [UP] the chain OR default object STATE style
  397. ------------------- */
  398. var FONT_PROPS = {
  399. 'typeface': true,
  400. 'fontName': true,
  401. 'fontWeight': true,
  402. 'fontStyle': true,
  403. 'fontStretch': true,
  404. 'fontSize': true,
  405. 'underline': true,
  406. 'foreGroundFill': true,
  407. 'horizontalAlignment': true
  408. };
  409. var _computeAllOverrides = $ax.style.computeAllOverrides = function(id, parentId, state, currentViewId) {
  410. var computedStyle = {};
  411. var diagramObject = $ax.getObjectFromElementId(id);
  412. var viewIdChain = $ax.adaptive.getAdaptiveIdChain(currentViewId);
  413. var excludeFont = _shapesWithSetRichText[id];
  414. for(var i = 0; i < viewIdChain.length; i++) {
  415. var viewId = viewIdChain[i];
  416. var style = diagramObject.adaptiveStyles[viewId];
  417. if(style) {
  418. // we want to exclude the normal font style for shapes where the rich text has been set with an interaction
  419. // so we copy the style so we don't modify the original, then delete all the font props.
  420. if(excludeFont) {
  421. style = $ax.deepCopy(style);
  422. for(var prop in FONT_PROPS) delete style[prop];
  423. }
  424. if(style) {
  425. var customStyle = style.baseStyle && $ax.document.stylesheet.stylesById[style.baseStyle];
  426. //make sure not to extend the customStyle this can mutate it for future use
  427. $.extend(computedStyle, customStyle);
  428. }
  429. $.extend(computedStyle, style);
  430. }
  431. }
  432. var isHyperlink = Boolean(parentId);
  433. <<<<<<< local
  434. var currState = state;
  435. while(state) {
  436. =======
  437. var currState = NORMAL;
  438. while(currState) {
  439. >>>>>>> other
  440. if(isHyperlink && (currState == MOUSE_DOWN || currState == MOUSE_OVER)) {
  441. var key = currState == MOUSE_OVER ? 'hyperlinkMouseOver' : 'hyperlinkMouseDown';
  442. $.extend(computedStyle, $ax.document.stylesheet.defaultStyles[key]);
  443. }
  444. $.extend(computedStyle, _computeStateStyleForViewChain(diagramObject, currState, viewIdChain, true));
  445. <<<<<<< local
  446. state = _progessState(state);
  447. =======
  448. currState = _unprogressState(currState, state);
  449. >>>>>>> other
  450. }
  451. return _removeUnsupportedProperties(computedStyle, diagramObject.type);
  452. };
  453. var _computeStateStyleForViewChain = function(diagramObject, state, viewIdChain, excludeNormal) {
  454. var styleObject = diagramObject;
  455. while(styleObject.isContained) styleObject = styleObject.parent;
  456. var adaptiveStyles = styleObject.adaptiveStyles;
  457. for(var i = viewIdChain.length - 1; i >= 0; i--) {
  458. var viewId = viewIdChain[i];
  459. var viewStyle = adaptiveStyles[viewId];
  460. var stateStyle = viewStyle && _getFullStateStyle(viewStyle, state, excludeNormal);
  461. if(stateStyle) return $.extend({}, stateStyle);
  462. }
  463. // 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
  464. var stateStyleFromDefault = _getFullStateStyle(styleObject.style, state, true);
  465. return $.extend({}, stateStyleFromDefault);
  466. };
  467. // returns the full effective style for an object in a state state and view
  468. var _computeFullStyle = function(id, state, currentViewId) {
  469. var obj = $obj(id);
  470. var overrides = _computeAllOverrides(id, undefined, state, currentViewId);
  471. // todo: account for image box
  472. var objStyle = obj.style;
  473. var customStyle = objStyle.baseStyle && $ax.document.stylesheet.stylesById[objStyle.baseStyle];
  474. var returnVal = $.extend({}, $ax.document.stylesheet.defaultStyles[obj.styleType], customStyle, objStyle, overrides);
  475. return _removeUnsupportedProperties(returnVal, obj.type);
  476. };
  477. var _removeUnsupportedProperties = function(style, objectType) {
  478. // for now all we need to do is remove padding from checkboxes and radio buttons
  479. if(objectType == 'radioButton' || objectType == 'checkbox') {
  480. style.paddingTop = 0;
  481. style.paddingLeft = 0;
  482. style.paddingRight = 0;
  483. style.paddingBottom = 0;
  484. }
  485. return style;
  486. };
  487. var _getFullStateStyle = function(style, state, excludeNormal) {
  488. //'normal' is needed because now DiagramObjects get their image from the Style and unapplying a rollover needs the image
  489. var stateStyle = state == 'normal' && !excludeNormal ? style : style && style.stateStyles && style.stateStyles[state];
  490. if(stateStyle) {
  491. var customStyle = stateStyle.baseStyle && $ax.document.stylesheet.stylesById[stateStyle.baseStyle];
  492. //make sure not to extend the customStyle this can mutate it for future use
  493. return $.extend({}, customStyle, stateStyle);
  494. }
  495. return undefined;
  496. };
  497. // commented this out for now... we actually will probably need it for ie
  498. var _applyOpacityFromStyle = $ax.style.applyOpacityFromStyle = function(id, style) {
  499. return;
  500. var opacity = style.opacity || '';
  501. $jobj(id).children().css('opacity', opacity);
  502. };
  503. var _initialize = function() {
  504. $ax.style.initializeObjectTextAlignment($ax('*'));
  505. };
  506. $ax.style.initialize = _initialize;
  507. var _initTextAlignment = function(elementId) {
  508. var textId = _getTextIdFromShape(elementId);
  509. _storeIdToAlignProps(textId);
  510. // now handle vertical alignment
  511. if(_getObjVisible(textId)) {
  512. _setTextAlignment(textId, _idToAlignProps[textId], false);
  513. }
  514. };
  515. $ax.style.initializeObjectTextAlignment = function(query) {
  516. query.filter(function(diagramObject) {
  517. return diagramObject.type == 'buttonShape' || diagramObject.type == 'flowShape' || diagramObject.type == 'imageBox';
  518. }).each(function(diagramObject, elementId) {
  519. if($jobj(elementId).length == 0) return;
  520. _initTextAlignment(elementId);
  521. });
  522. };
  523. var _storeIdToAlignProps = function(textId) {
  524. var shapeId = _getShapeIdFromText(textId);
  525. var state = _generateState(shapeId);
  526. var style = _computeFullStyle(shapeId, state, $ax.adaptive.currentViewId);
  527. var vAlign = style.verticalAlignment || 'middle';
  528. var paddingTop = style.paddingTop || 0;
  529. var paddingBottom = style.paddingBottom || 0;
  530. _idToAlignProps[textId] = { vAlign: vAlign, paddingTop: paddingTop, paddingBottom: paddingBottom };
  531. };
  532. var ALL_STATES = ['mouseOver', 'mouseDown', 'selected', 'disabled'];
  533. var _applyImage = $ax.style.applyImage = function(id, imgUrl, state) {
  534. var imgQuery = $jobj($ax.style.GetImageIdFromShape(id));
  535. var idQuery = $jobj(id);
  536. var _updateClass = function() {
  537. for(var i = 0; i < ALL_STATES.length; i++) {
  538. idQuery.removeClass(ALL_STATES[i]);
  539. imgQuery.removeClass(ALL_STATES[i]);
  540. }
  541. if(state != 'normal') {
  542. idQuery.addClass(state);
  543. imgQuery.addClass(state);
  544. }
  545. };
  546. if(imgQuery.attr('src') != imgUrl) {
  547. imgQuery[0].onload = function() {
  548. _updateClass();
  549. // IE 8 can't set onload to undefined
  550. if($.browser.msie && $.browser.version <= 8) imgQuery[0].onload = function () {};
  551. else imgQuery[0].onload = undefined;
  552. };
  553. } else {
  554. _updateClass();
  555. }
  556. imgQuery.attr('src', imgUrl);
  557. if(imgQuery.parents('a.basiclink').length > 0) imgQuery.css('border', 'none');
  558. if(imgUrl.indexOf(".png") > -1) $ax.utils.fixPng(imgQuery[0]);
  559. };
  560. var _resetTextJson = function(id, textid) {
  561. // reset the opacity
  562. $jobj(id).children().css('opacity', '');
  563. var cacheObject = _originalTextCache[textid];
  564. if(cacheObject) {
  565. _transformTextWithVerticalAlignment(textid, function() {
  566. var styleCache = cacheObject.styleCache;
  567. var textQuery = $('#' + textid);
  568. textQuery.find('*').each(function(index, element) {
  569. element.style.cssText = styleCache[element.id];
  570. });
  571. });
  572. }
  573. };
  574. // Preserves the alingment for the element textid after executing transformFn
  575. var _getRtfElementHeight = function(rtfElement) {
  576. if(rtfElement.innerHTML == '') rtfElement.innerHTML = '&nbsp;';
  577. // To handle render text as image
  578. var images = $(rtfElement).children('img');
  579. if(images.length) return images.height();
  580. return rtfElement.offsetHeight;
  581. };
  582. // why microsoft decided to default to round to even is beyond me...
  583. var _roundToEven = function(number) {
  584. var numString = number.toString();
  585. var parts = numString.split('.');
  586. if(parts.length == 1) return number;
  587. if(parts[1].length == 1 && parts[1] == '5') {
  588. var wholePart = Number(parts[0]);
  589. return wholePart % 2 == 0 ? wholePart : wholePart + 1;
  590. } else return Math.round(number);
  591. };
  592. var _transformTextWithVerticalAlignment = $ax.style.transformTextWithVerticalAlignment = function(textId, transformFn) {
  593. if(!_originalTextCache[textId]) {
  594. $ax.style.CacheOriginalText(textId);
  595. }
  596. var rtfElement = window.document.getElementById(textId);
  597. if(!rtfElement) return;
  598. transformFn();
  599. _storeIdToAlignProps(textId);
  600. $ax.style.updateTextAlignmentForVisibility(textId);
  601. };
  602. // this is for vertical alignments set on hidden objects
  603. var _idToAlignProps = {};
  604. $ax.style.updateTextAlignmentForVisibility = function(textId) {
  605. var alignProps = _idToAlignProps[textId];
  606. if(!alignProps || !_getObjVisible(textId)) return;
  607. _setTextAlignment(textId, alignProps);
  608. };
  609. var _getObjVisible = _style.getObjVisible = function(id) {
  610. return $('#' + id + ':visible').length != 0;
  611. };
  612. var _setTextAlignment = function(textId, alignProps, updateProps) {
  613. if(updateProps) {
  614. _storeIdToAlignProps(textId);
  615. }
  616. if(!alignProps) return;
  617. var vAlign = alignProps.vAlign;
  618. var paddingTop = Number(alignProps.paddingTop);
  619. var paddingBottom = Number(alignProps.paddingBottom);
  620. var textObj = $jobj(textId);
  621. var textHeight = _getRtfElementHeight(textObj[0]);
  622. var textObjParent = textObj.parent();
  623. var containerHeight = textObjParent.height();
  624. var newTop = 0;
  625. if(vAlign == "middle") {
  626. newTop = _roundToEven((containerHeight - textHeight + paddingTop - paddingBottom) / 2);
  627. } else if(vAlign == "bottom") {
  628. newTop = _roundToEven(containerHeight - textHeight - paddingBottom);
  629. } else { // else top align
  630. newTop = _roundToEven(paddingTop);
  631. }
  632. var oldTop = $jobj(textId).css('top').replace('px', '');
  633. if(oldTop != newTop) {
  634. textObj.css('top', newTop + 'px');
  635. _updateTransformOrigin(textId);
  636. }
  637. };
  638. var _updateTransformOrigin = function(textId) {
  639. var textObj = $jobj(textId);
  640. var transformOrigin = textObj.css('-webkit-transform-origin') ||
  641. textObj.css('-moz-transform-origin') ||
  642. textObj.css('-ms-transform-origin') ||
  643. textObj.css('transform-origin');
  644. if(transformOrigin) {
  645. var textObjParent = textObj.parent();
  646. var newX = (textObjParent.width() / 2 - textObj.css('left').replace('px', ''));
  647. var newY = (textObjParent.height() / 2 - textObj.css('top').replace('px', ''));
  648. var newOrigin = newX + 'px ' + newY + 'px';
  649. textObj.css('-webkit-transform-origin', newOrigin);
  650. textObj.css('-moz-transform-origin', newOrigin);
  651. textObj.css('-ms-transform-origin', newOrigin);
  652. textObj.css('transform-origin', newOrigin);
  653. }
  654. };
  655. $ax.style.clearAdaptiveStyles = function() {
  656. for(var shapeId in _adaptiveStyledWidgets) {
  657. var elementIds = [shapeId];
  658. var repeaterId = $ax.getParentRepeaterFromScriptId(shapeId);
  659. if(repeaterId) {
  660. var itemIds = $ax.getItemIdsForRepeater(repeaterId);
  661. elementIds = [];
  662. for(var i = 0; i < itemIds; i++) elementIds.push($ax.repeater.createElementId(shapeId, itemIds[i]));
  663. }
  664. for(var index = 0; index < elementIds.length; index++) {
  665. var elementId = elementIds[index];
  666. var textId = $ax.style.GetTextIdFromShape(elementId);
  667. _resetTextJson(elementId, textId);
  668. _applyImageAndTextJson(elementId, $ax.style.generateState(elementId));
  669. }
  670. }
  671. _adaptiveStyledWidgets = {};
  672. };
  673. $ax.style.setAdaptiveStyle = function(shapeId, style) {
  674. _adaptiveStyledWidgets[$ax.repeater.getScriptIdFromElementId(shapeId)] = style;
  675. var textId = $ax.style.GetTextIdFromShape(shapeId);
  676. <<<<<<< local
  677. _applyTextStyle(textId, style);
  678. =======
  679. if(textId) _applyTextStyle(textId, style);
  680. >>>>>>> other
  681. // removing this for now
  682. // if(style.location) {
  683. // $jobj(shapeId).css('top', style.location.x + "px")
  684. // .css('left', style.location.y + "px");
  685. // }
  686. };
  687. //-------------------------------------------------------------------------
  688. // _applyTextStyle
  689. //
  690. // Applies a rollover style to a text element.
  691. // id : the id of the text object to set.
  692. // styleProperties : an object mapping style properties to values. eg:
  693. // { 'fontWeight' : 'bold',
  694. // 'fontStyle' : 'italic' }
  695. //-------------------------------------------------------------------------
  696. var _applyTextStyle = function(id, style) {
  697. _transformTextWithVerticalAlignment(id, function() {
  698. var styleProperties = _getCssStyleProperties(style);
  699. $('#' + id).find('*').each(function(index, element) {
  700. _applyCssProps(element, styleProperties);
  701. });
  702. });
  703. };
  704. var _applyCssProps = function(element, styleProperties) {
  705. var nodeName = element.nodeName.toLowerCase();
  706. if(nodeName == 'p') {
  707. var parProps = styleProperties.parProps;
  708. for(var prop in parProps) element.style[prop] = parProps[prop];
  709. } else if(nodeName != 'a') {
  710. var runProps = styleProperties.runProps;
  711. for(prop in runProps) element.style[prop] = runProps[prop];
  712. }
  713. };
  714. var _getCssShadow = function(shadow) {
  715. return !shadow.on ? "none"
  716. : shadow.offsetX + "px " + shadow.offsetY + "px " + shadow.blurRadius + "px " + _getCssColor(shadow.color);
  717. };
  718. var _getCssStyleProperties = function(style) {
  719. var toApply = {};
  720. toApply.runProps = {};
  721. toApply.parProps = {};
  722. if(style.fontName) toApply.runProps.fontFamily = style.fontName;
  723. // we need to set font size on both runs and pars because otherwise it well mess up the measure and thereby vertical alignment
  724. if(style.fontSize) toApply.runProps.fontSize = toApply.parProps.fontSize = style.fontSize;
  725. if(style.fontWeight !== undefined) toApply.runProps.fontWeight = style.fontWeight;
  726. if(style.fontStyle !== undefined) toApply.runProps.fontStyle = style.fontStyle;
  727. if(style.underline !== undefined) toApply.runProps.textDecoration = style.underline ? 'underline' : 'none';
  728. if(style.foreGroundFill) {
  729. toApply.runProps.color = _getColorFromFill(style.foreGroundFill);
  730. if(style.foreGroundFill.opacity) toApply.runProps.opacity = style.foreGroundFill.opacity;
  731. }
  732. if(style.horizontalAlignment) toApply.parProps.textAlign = style.horizontalAlignment;
  733. if(style.lineSpacing) toApply.parProps.lineHeight = style.lineSpacing;
  734. if(style.textShadow) toApply.parProps.textShadow = _getCssShadow(style.textShadow);
  735. return toApply;
  736. };
  737. var _getColorFromFill = function(fill) {
  738. var fillString = '00000' + fill.color.toString(16);
  739. return '#' + fillString.substring(fillString.length - 6);
  740. };
  741. var _getCssColor = function(rgbaObj) {
  742. return "rgba(" + rgbaObj.r + ", " + rgbaObj.g + ", " + rgbaObj.b + ", " + rgbaObj.a + ")";
  743. };
  744. // //--------------------------------------------------------------------------
  745. // // ApplyStyleRecursive
  746. // //
  747. // // Applies a style recursively to all span and div tags including elementNode
  748. // // and all of its children.
  749. // //
  750. // // element : the element to apply the style to
  751. // // styleName : the name of the style property to set (eg. 'font-weight')
  752. // // styleValue : the value of the style to set (eg. 'bold')
  753. // //--------------------------------------------------------------------------
  754. // function ApplyStyleRecursive(element, styleName, styleValue) {
  755. // var nodeName = element.nodeName.toLowerCase();
  756. // if (nodeName == 'div' || nodeName == 'span' || nodeName == 'p') {
  757. // element.style[styleName] = styleValue;
  758. // }
  759. // for (var i = 0; i < element.childNodes.length; i++) {
  760. // ApplyStyleRecursive(element.childNodes[i], styleName, styleValue);
  761. // }
  762. // }
  763. // //---------------------------------------------------------------------------
  764. // // ApplyTextProperty
  765. // //
  766. // // Applies a text property to rtfElement.
  767. // //
  768. // // rtfElement : the the root text element of the rtf object (this is the
  769. // // element named <id>_rtf
  770. // // prop : the style property to set.
  771. // // value : the style value to set.
  772. // //---------------------------------------------------------------------------
  773. // function ApplyTextProperty(rtfElement, prop, value) {
  774. // /*
  775. // var oldHtml = rtfElement.innerHTML;
  776. // if (prop == 'fontWeight') {
  777. // rtfElement.innerHTML = oldHtml.replace(/< *b *\/?>/gi, "");
  778. // } else if (prop == 'fontStyle') {
  779. // rtfElement.innerHTML = oldHtml.replace(/< *i *\/?>/gi, "");
  780. // } else if (prop == 'textDecoration') {
  781. // rtfElement.innerHTML = oldHtml.replace(/< *u *\/?>/gi, "");
  782. // }
  783. // */
  784. // for (var i = 0; i < rtfElement.childNodes.length; i++) {
  785. // ApplyStyleRecursive(rtfElement.childNodes[i], prop, value);
  786. // }
  787. // }
  788. //}
  789. //---------------------------------------------------------------------------
  790. // GetAndCacheOriginalText
  791. //
  792. // Gets the html for the pre-rollover state and returns the Html representing
  793. // the Rich text.
  794. //---------------------------------------------------------------------------
  795. var CACHE_COUNTER = 0;
  796. $ax.style.CacheOriginalText = function(textId, hasRichTextBeenSet) {
  797. var rtfQuery = $('#' + textId);
  798. if(rtfQuery.length > 0) {
  799. var styleCache = {};
  800. rtfQuery.find('*').each(function(index, element) {
  801. var elementId = element.id;
  802. if(!elementId) element.id = elementId = 'cache' + CACHE_COUNTER++;
  803. styleCache[elementId] = element.style.cssText;
  804. });
  805. _originalTextCache[textId] = {
  806. styleCache: styleCache
  807. };
  808. if(hasRichTextBeenSet) {
  809. var shapeId = _getShapeIdFromText(textId);
  810. _shapesWithSetRichText[shapeId] = true;
  811. }
  812. }
  813. };
  814. $ax.style.ClearCacheForRepeater = function(repeaterId) {
  815. for(var elementId in _originalTextCache) {
  816. var scriptId = $ax.repeater.getScriptIdFromElementId(elementId);
  817. if($ax.getParentRepeaterFromScriptId(scriptId) == repeaterId) delete _originalTextCache[elementId];
  818. }
  819. };
  820. $ax.style.prefetch = function() {
  821. var scriptIds = $ax.getAllScriptIds();
  822. var image = new Image();
  823. for(var i = 0; i < scriptIds.length; i++) {
  824. var obj = $obj(scriptIds[i]);
  825. if(obj.type != 'imageBox') continue;
  826. var images = obj.images;
  827. for(var key in images) image.src = images[key];
  828. }
  829. };
  830. });