style.js 60 KB

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