style.js 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  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. // todo: account for image box
  571. var objStyle = obj.style;
  572. var customStyle = objStyle.baseStyle && $ax.document.stylesheet.stylesById[objStyle.baseStyle];
  573. var returnVal = $.extend({}, $ax.document.stylesheet.defaultStyle, customStyle, objStyle, overrides);
  574. return _removeUnsupportedProperties(returnVal, obj);
  575. };
  576. var _removeUnsupportedProperties = function(style, object) {
  577. // for now all we need to do is remove padding from checkboxes and radio buttons
  578. if ($ax.public.fn.IsRadioButton(object.type) || $ax.public.fn.IsCheckBox(object.type)) {
  579. style.paddingTop = 0;
  580. style.paddingLeft = 0;
  581. style.paddingRight = 0;
  582. style.paddingBottom = 0;
  583. }
  584. if ($ax.public.fn.IsTextBox(object.type) || $ax.public.fn.IsTextArea(object.type) || $ax.public.fn.IsButton(object.type)
  585. || $ax.public.fn.IsListBox(object.type) || $ax.public.fn.IsComboBox(object.type)) {
  586. if (object.images && style.fill) delete style['fill'];
  587. }
  588. return style;
  589. };
  590. var _getFullStateStyle = function(style, state, excludeNormal) {
  591. //'normal' is needed because now DiagramObjects get their image from the Style and unapplying a rollover needs the image
  592. var stateStyle = state == 'normal' && !excludeNormal ? style : style && style.stateStyles && style.stateStyles[state];
  593. if(stateStyle) {
  594. var customStyle = stateStyle.baseStyle && $ax.document.stylesheet.stylesById[stateStyle.baseStyle];
  595. //make sure not to extend the customStyle this can mutate it for future use
  596. return $.extend({}, customStyle, stateStyle);
  597. }
  598. return undefined;
  599. };
  600. // commented this out for now... we actually will probably need it for ie
  601. var _applyOpacityFromStyle = $ax.style.applyOpacityFromStyle = function(id, style) {
  602. return;
  603. var opacity = style.opacity || '';
  604. $jobj(id).children().css('opacity', opacity);
  605. };
  606. var _initialize = function() {
  607. //$ax.style.initializeObjectTextAlignment($ax('*'));
  608. };
  609. $ax.style.initialize = _initialize;
  610. //var _initTextAlignment = function(elementId) {
  611. // var textId = $ax.GetTextPanelId(elementId);
  612. // if(textId) {
  613. // _storeIdToAlignProps(textId);
  614. // // now handle vertical alignment
  615. // if(_getObjVisible(textId)) {
  616. // //_setTextAlignment(textId, _idToAlignProps[textId], false);
  617. // _setTextAlignment(textId);
  618. // }
  619. // }
  620. //};
  621. //$ax.style.initializeObjectTextAlignment = function(query) {
  622. // query.filter(function(diagramObject) {
  623. // return $ax.public.fn.IsVector(diagramObject.type) || $ax.public.fn.IsImageBox(diagramObject.type);
  624. // }).each(function(diagramObject, elementId) {
  625. // if($jobj(elementId).length == 0) return;
  626. // _initTextAlignment(elementId);
  627. // });
  628. //};
  629. //$ax.style.initializeObjectTextAlignment = function (query) {
  630. // var textIds = [];
  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. // var textId = $ax.GetTextPanelId(elementId);
  636. // if(textId) {
  637. // _storeIdToAlignProps(textId);
  638. // textIds.push(textId);
  639. // }
  640. // });
  641. // $ax.style.setTextAlignment(textIds);
  642. //};
  643. //var _getPadding = $ax.style.getPadding = function (textId) {
  644. // var shapeId = $ax.GetShapeIdFromText(textId);
  645. // var shapeObj = $obj(shapeId);
  646. // var state = _generateState(shapeId);
  647. // var style = _computeFullStyle(shapeId, state, $ax.adaptive.currentViewId);
  648. // var vAlign = style.verticalAlignment || 'middle';
  649. // var paddingLeft = Number(style.paddingLeft) || 0;
  650. // paddingLeft += (Number(shapeObj && shapeObj.extraLeft) || 0);
  651. // var paddingTop = style.paddingTop || 0;
  652. // var paddingRight = style.paddingRight || 0;
  653. // var paddingBottom = style.paddingBottom || 0;
  654. // return { vAlign: vAlign, paddingLeft: paddingLeft, paddingTop: paddingTop, paddingRight: paddingRight, paddingBottom: paddingBottom };
  655. //}
  656. //var _storeIdToAlignProps = function(textId) {
  657. // _idToAlignProps[textId] = _getPadding(textId);
  658. //};
  659. var _applyImage = $ax.style.applyImage = function (id, imgUrl, state) {
  660. var object = $obj(id);
  661. if (object.generateCompound) {
  662. for (var i = 0; i < object.compoundChildren.length; i++) {
  663. var componentId = object.compoundChildren[i];
  664. var childId = $ax.public.fn.getComponentId(id, componentId);
  665. var childImgQuery = $jobj(childId + '_img');
  666. childImgQuery.attr('src', imgUrl[componentId]);
  667. _updateStateClasses(
  668. [
  669. childId + '_img',
  670. childId
  671. ], state, false
  672. );
  673. }
  674. } else {
  675. var imgQuery = $jobj($ax.GetImageIdFromShape(id));
  676. //it is hard to tell if setting the image or the class first causing less flashing when adding shadows.
  677. imgQuery.attr('src', imgUrl);
  678. _updateStateClasses(
  679. [
  680. id,
  681. $ax.GetImageIdFromShape(id)
  682. ], state, false
  683. );
  684. if (imgQuery.parents('a.basiclink').length > 0) imgQuery.css('border', 'none');
  685. }
  686. };
  687. $ax.public.fn.getComponentId = function (id, componentId) {
  688. var idParts = id.split('-');
  689. idParts[0] = idParts[0] + componentId;
  690. return idParts.join('-');
  691. }
  692. var _resetTextJson = function(id, textid) {
  693. // reset the opacity
  694. $jobj(id).children().css('opacity', '');
  695. var cacheObject = _originalTextCache[textid];
  696. if(cacheObject) {
  697. _transformTextWithVerticalAlignment(textid, function() {
  698. var styleCache = cacheObject.styleCache;
  699. var textQuery = $('#' + textid);
  700. textQuery.find('*').each(function(index, element) {
  701. element.style.cssText = styleCache[element.id];
  702. });
  703. });
  704. }
  705. };
  706. // Preserves the alingment for the element textid after executing transformFn
  707. //var _getRtfElementHeight = function(rtfElement) {
  708. // if(rtfElement.innerHTML == '') rtfElement.innerHTML = '&nbsp;';
  709. // // To handle render text as image
  710. // //var images = $(rtfElement).children('img');
  711. // //if(images.length) return images.height();
  712. // return rtfElement.offsetHeight;
  713. //};
  714. // why microsoft decided to default to round to even is beyond me...
  715. //var _roundToEven = function(number) {
  716. // var numString = number.toString();
  717. // var parts = numString.split('.');
  718. // if(parts.length == 1) return number;
  719. // if(parts[1].length == 1 && parts[1] == '5') {
  720. // var wholePart = Number(parts[0]);
  721. // return wholePart % 2 == 0 ? wholePart : wholePart + 1;
  722. // } else return Math.round(number);
  723. //};
  724. //var _suspendTextAlignment = 0;
  725. //var _suspendedTextIds = [];
  726. //$ax.style.startSuspendTextAlignment = function() {
  727. // _suspendTextAlignment++;
  728. //}
  729. //$ax.style.resumeSuspendTextAlignment = function () {
  730. // _suspendTextAlignment--;
  731. // if(_suspendTextAlignment == 0) $ax.style.setTextAlignment(_suspendedTextIds);
  732. //}
  733. var _transformTextWithVerticalAlignment = $ax.style.transformTextWithVerticalAlignment = function(textId, transformFn) {
  734. if(!_originalTextCache[textId]) {
  735. $ax.style.CacheOriginalText(textId);
  736. }
  737. var rtfElement = window.document.getElementById(textId);
  738. if(!rtfElement) return;
  739. transformFn();
  740. //_storeIdToAlignProps(textId);
  741. //if (_suspendTextAlignment) {
  742. // _suspendedTextIds.push(textId);
  743. // return;
  744. //}
  745. //$ax.style.setTextAlignment([textId]);
  746. };
  747. // this is for vertical alignments set on hidden objects
  748. //var _idToAlignProps = {};
  749. //$ax.style.updateTextAlignmentForVisibility = function (textId) {
  750. // var textObj = $jobj(textId);
  751. // // must check if parent id exists. Doesn't exist for text objs in check boxes, and potentially elsewhere.
  752. // var parentId = textObj.parent().attr('id');
  753. // if (parentId && $ax.visibility.isContainer(parentId)) return;
  754. // //var alignProps = _idToAlignProps[textId];
  755. // //if(!alignProps || !_getObjVisible(textId)) return;
  756. // //if (!alignProps) return;
  757. // //_setTextAlignment(textId, alignProps);
  758. // _setTextAlignment(textId);
  759. //};
  760. var _getObjVisible = _style.getObjVisible = function (id) {
  761. var element = document.getElementById(id);
  762. return element && (element.offsetWidth || element.offsetHeight);
  763. };
  764. //$ax.style.setTextAlignment = function (textIds) {
  765. // var getTextAlignDim = function(textId, alignProps) {
  766. // var dim = {};
  767. // var vAlign = alignProps.vAlign;
  768. // var paddingTop = Number(alignProps.paddingTop);
  769. // var paddingBottom = Number(alignProps.paddingBottom);
  770. // var paddingLeft = Number(alignProps.paddingLeft);
  771. // var paddingRight = Number(alignProps.paddingRight);
  772. // var topParam = 0.0;
  773. // var bottomParam = 1.0;
  774. // var leftParam = 0.0;
  775. // var rightParam = 1.0;
  776. // var textObj = $jobj(textId);
  777. // var textObjParent = textObj.offsetParent();
  778. // var parentId = textObjParent.attr('id');
  779. // if(!parentId) {
  780. // // 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)
  781. // textObjParent = textObjParent.parent();
  782. // parentId = textObjParent.attr('id');
  783. // }
  784. // parentId = $ax.visibility.getWidgetFromContainer(textObjParent.attr('id'));
  785. // textObjParent = $jobj(parentId);
  786. // var parentObj = $obj(parentId);
  787. // if(parentObj['bottomTextPadding']) bottomParam = parentObj['bottomTextPadding'];
  788. // if(parentObj['topTextPadding']) topParam = parentObj['topTextPadding'];
  789. // if(parentObj['leftTextPadding']) leftParam = parentObj['leftTextPadding'];
  790. // if(parentObj['rightTextPadding']) rightParam = parentObj['rightTextPadding'];
  791. // // smart shapes are mutually exclusive from compound vectors.
  792. // var isConnector = parentObj.type == $ax.constants.CONNECTOR_TYPE;
  793. // if(isConnector) return;
  794. // var axTextObjectParent = $ax('#' + textObjParent.attr('id'));
  795. // var jDims = textObj.css(['width','left','top']);
  796. // var oldWidth = $ax.getNumFromPx(jDims['width']);
  797. // var oldLeft = $ax.getNumFromPx(jDims['left']);
  798. // var oldTop = $ax.getNumFromPx(jDims['top']);
  799. // var newTop = 0;
  800. // var newLeft = 0.0;
  801. // var size = axTextObjectParent.size();
  802. // var width = size.width;
  803. // var height = size.height;
  804. // //var width = axTextObjectParent.width();
  805. // //var height = axTextObjectParent.height();
  806. // // If text rotated need to handle getting the correct width for text based on bounding rect of rotated parent.
  807. // var boundingRotation = -$ax.move.getRotationDegreeFromElement(textObj[0]);
  808. // var boundingParent = $axure.fn.getBoundingSizeForRotate(width, height, boundingRotation);
  809. // var extraLeftPadding = (width - boundingParent.width) / 2;
  810. // width = boundingParent.width;
  811. // var relativeTop = 0.0;
  812. // relativeTop = height * topParam;
  813. // var containerHeight = height * bottomParam - relativeTop;
  814. // newLeft = paddingLeft + extraLeftPadding + width * leftParam;
  815. // var newWidth = width * (rightParam - leftParam) - paddingLeft - paddingRight;
  816. // var horizChange = newWidth != oldWidth || newLeft != oldLeft;
  817. // if(horizChange) {
  818. // dim.left = newLeft;
  819. // dim.width = newWidth;
  820. // //textObj.css('left', newLeft);
  821. // //textObj.width(newWidth);
  822. // }
  823. // var textHeight = _getRtfElementHeight(textObj[0]);
  824. // if(vAlign == "middle")
  825. // newTop = _roundToEven(relativeTop + (containerHeight - textHeight + paddingTop - paddingBottom) / 2);
  826. // else if(vAlign == "bottom")
  827. // newTop = _roundToEven(relativeTop + containerHeight - textHeight - paddingBottom);
  828. // else newTop = _roundToEven(paddingTop + relativeTop);
  829. // var vertChange = oldTop != newTop;
  830. // if (vertChange) dim.top = newTop; //textObj.css('top', newTop + 'px');
  831. // return dim;
  832. // };
  833. // var applyTextAlignment = function(textId, dim) {
  834. // var textObj = $jobj(textId);
  835. // if(dim.left) {
  836. // textObj.css('left', dim.left);
  837. // textObj.width(dim.width);
  838. // }
  839. // if(dim.top) textObj.css('top', dim.top);
  840. // if((dim.top || dim.left)) _updateTransformOrigin(textId);
  841. // };
  842. // var idToDim = [];
  843. // for (var i = 0; i < textIds.length; i++) {
  844. // var textId = textIds[i];
  845. // var alignProps = _idToAlignProps[textId];
  846. // if (!alignProps || !_getObjVisible(textId)) continue;
  847. // idToDim.push({ id: textId, dim: getTextAlignDim(textId, alignProps) });
  848. // }
  849. // for (var i = 0; i < idToDim.length; i++) {
  850. // var info = idToDim[i];
  851. // applyTextAlignment(info.id, info.dim);
  852. // }
  853. //};
  854. //var _setTextAlignment = function(textId, alignProps, updateProps) {
  855. // if(updateProps) _storeIdToAlignProps(textId);
  856. // if(!alignProps) return;
  857. // var vAlign = alignProps.vAlign;
  858. // var paddingTop = Number(alignProps.paddingTop);
  859. // var paddingBottom = Number(alignProps.paddingBottom);
  860. // var paddingLeft = Number(alignProps.paddingLeft);
  861. // var paddingRight = Number(alignProps.paddingRight);
  862. // var topParam = 0.0;
  863. // var bottomParam = 1.0;
  864. // var leftParam = 0.0;
  865. // var rightParam = 1.0;
  866. // var textObj = $jobj(textId);
  867. // var textObjParent = textObj.offsetParent();
  868. // var parentId = textObjParent.attr('id');
  869. // var isConnector = false;
  870. // if(parentId) {
  871. // parentId = $ax.visibility.getWidgetFromContainer(textObjParent.attr('id'));
  872. // textObjParent = $jobj(parentId);
  873. // var parentObj = $obj(parentId);
  874. // if(parentObj['bottomTextPadding']) bottomParam = parentObj['bottomTextPadding'];
  875. // if(parentObj['topTextPadding']) topParam = parentObj['topTextPadding'];
  876. // if(parentObj['leftTextPadding']) leftParam = parentObj['leftTextPadding'];
  877. // if(parentObj['rightTextPadding']) rightParam = parentObj['rightTextPadding'];
  878. // // smart shapes are mutually exclusive from compound vectors.
  879. // isConnector = parentObj.type == $ax.constants.CONNECTOR_TYPE;
  880. // }
  881. // if(isConnector) return;
  882. // var axTextObjectParent = $ax('#' + textObjParent.attr('id'));
  883. // var oldWidth = $ax.getNumFromPx(textObj.css('width'));
  884. // var oldLeft = $ax.getNumFromPx(textObj.css('left'));
  885. // var oldTop = $ax.getNumFromPx(textObj.css('top'));
  886. // var newTop = 0;
  887. // var newLeft = 0.0;
  888. // var width = axTextObjectParent.width();
  889. // var height = axTextObjectParent.height();
  890. // // If text rotated need to handle getting the correct width for text based on bounding rect of rotated parent.
  891. // var boundingRotation = -$ax.move.getRotationDegreeFromElement(textObj[0]);
  892. // var boundingParent = $axure.fn.getBoundingSizeForRotate(width, height, boundingRotation);
  893. // var extraLeftPadding = (width - boundingParent.width) / 2;
  894. // width = boundingParent.width;
  895. // var relativeTop = 0.0;
  896. // relativeTop = height * topParam;
  897. // var containerHeight = height * bottomParam - relativeTop;
  898. // newLeft = paddingLeft + extraLeftPadding + width * leftParam;
  899. // var newWidth = width * (rightParam - leftParam) - paddingLeft - paddingRight;
  900. // var horizChange = newWidth != oldWidth || newLeft != oldLeft;
  901. // if(horizChange) {
  902. // textObj.css('left', newLeft);
  903. // textObj.width(newWidth);
  904. // }
  905. // var textHeight = _getRtfElementHeight(textObj[0]);
  906. // if(vAlign == "middle") newTop = _roundToEven(relativeTop + (containerHeight - textHeight + paddingTop - paddingBottom) / 2);
  907. // else if(vAlign == "bottom") newTop = _roundToEven(relativeTop + containerHeight - textHeight - paddingBottom);
  908. // else newTop = _roundToEven(paddingTop + relativeTop);
  909. // var vertChange = oldTop != newTop;
  910. // if(vertChange) textObj.css('top', newTop + 'px');
  911. // if((vertChange || horizChange)) _updateTransformOrigin(textId);
  912. //};
  913. //var _updateTransformOrigin = function (textId) {
  914. // var textObj = $jobj(textId);
  915. // var parentId = textObj.parent().attr('id');
  916. // if(!$obj(parentId).hasTransformOrigin) return;
  917. // //var transformOrigin = textObj.css('-webkit-transform-origin') ||
  918. // // textObj.css('-moz-transform-origin') ||
  919. // // textObj.css('-ms-transform-origin') ||
  920. // // textObj.css('transform-origin');
  921. // //if(transformOrigin) {
  922. // var textObjParent = $ax('#' + textObj.parent().attr('id'));
  923. // var newX = (textObjParent.width() / 2 - $ax.getNumFromPx(textObj.css('left')));
  924. // var newY = (textObjParent.height() / 2 - $ax.getNumFromPx(textObj.css('top')));
  925. // var newOrigin = newX + 'px ' + newY + 'px';
  926. // textObj.css('-webkit-transform-origin', newOrigin);
  927. // textObj.css('-moz-transform-origin', newOrigin);
  928. // textObj.css('-ms-transform-origin', newOrigin);
  929. // textObj.css('transform-origin', newOrigin);
  930. // //}
  931. //};
  932. $ax.style.reselectElements = function() {
  933. for(var id in _selectedWidgets) {
  934. // Only looking for the selected widgets that don't have their class set
  935. if(!_selectedWidgets[id] || $jobj(id).hasClass('selected')) continue;
  936. $jobj(id).addClass('selected');
  937. _applyImageAndTextJson(id, $ax.style.generateState(id));
  938. }
  939. for(id in _disabledWidgets) {
  940. // Only looking for the disabled widgets that don't have their class yet
  941. if (!_disabledWidgets[id] || $jobj(id).hasClass('disabled')) continue;
  942. $jobj(id).addClass('disabled');
  943. _applyImageAndTextJson(id, $ax.style.generateState(id));
  944. }
  945. }
  946. $ax.style.clearStateForRepeater = function(repeaterId) {
  947. var children = $ax.getChildElementIdsForRepeater(repeaterId);
  948. for(var i = 0; i < children.length; i++) {
  949. var id = children[i];
  950. delete _selectedWidgets[id];
  951. delete _disabledWidgets[id];
  952. }
  953. }
  954. _style.updateStateClass = function (repeaterId) {
  955. var subElementIds = $ax.getChildElementIdsForRepeater(repeaterId);
  956. for (var i = 0; i < subElementIds.length; i++) {
  957. _applyImageAndTextJson(subElementIds[i], $ax.style.generateState(subElementIds[i]));
  958. }
  959. }
  960. $ax.style.clearAdaptiveStyles = function() {
  961. for(var shapeId in _adaptiveStyledWidgets) {
  962. var repeaterId = $ax.getParentRepeaterFromScriptId(shapeId);
  963. if(repeaterId) continue;
  964. var elementId = $ax.GetButtonShapeId(shapeId);
  965. if(elementId) _applyImageAndTextJson(elementId, $ax.style.generateState(elementId));
  966. }
  967. _adaptiveStyledWidgets = {};
  968. };
  969. $ax.style.setAdaptiveStyle = function(shapeId, style) {
  970. _adaptiveStyledWidgets[$ax.repeater.getScriptIdFromElementId(shapeId)] = style;
  971. var textId = $ax.GetTextPanelId(shapeId);
  972. if(textId) _applyTextStyle(textId, style);
  973. $ax.placeholderManager.refreshPlaceholder(shapeId);
  974. // removing this for now
  975. // if(style.location) {
  976. // $jobj(shapeId).css('top', style.location.x + "px")
  977. // .css('left', style.location.y + "px");
  978. // }
  979. };
  980. //-------------------------------------------------------------------------
  981. // _applyTextStyle
  982. //
  983. // Applies a rollover style to a text element.
  984. // id : the id of the text object to set.
  985. // styleProperties : an object mapping style properties to values. eg:
  986. // { 'fontWeight' : 'bold',
  987. // 'fontStyle' : 'italic' }
  988. //-------------------------------------------------------------------------
  989. var _applyTextStyle = function(id, style) {
  990. _transformTextWithVerticalAlignment(id, function() {
  991. var styleProperties = _getCssStyleProperties(style);
  992. $('#' + id).find('*').each(function(index, element) {
  993. _applyCssProps(element, styleProperties);
  994. });
  995. });
  996. };
  997. var _applyCssProps = function(element, styleProperties, applyAllStyle) {
  998. if(applyAllStyle) {
  999. var allProps = styleProperties.allProps;
  1000. for(var prop in allProps) element.style[prop] = allProps[prop];
  1001. } else {
  1002. var nodeName = element.nodeName.toLowerCase();
  1003. if(nodeName == 'p') {
  1004. var parProps = styleProperties.parProps;
  1005. for(prop in parProps) element.style[prop] = parProps[prop];
  1006. } else if(nodeName != 'a') {
  1007. var runProps = styleProperties.runProps;
  1008. for(prop in runProps) element.style[prop] = runProps[prop];
  1009. }
  1010. }
  1011. };
  1012. var _getCssShadow = function(shadow) {
  1013. return !shadow.on ? "none"
  1014. : shadow.offsetX + "px " + shadow.offsetY + "px " + shadow.blurRadius + "px " + _getCssColor(shadow.color);
  1015. };
  1016. var _getCssStyleProperties = function(style) {
  1017. var toApply = {};
  1018. toApply.runProps = {};
  1019. toApply.parProps = {};
  1020. toApply.allProps = {};
  1021. if(style.fontName) toApply.allProps.fontFamily = toApply.runProps.fontFamily = style.fontName;
  1022. // we need to set font size on both runs and pars because otherwise it well mess up the measure and thereby vertical alignment
  1023. if(style.fontSize) toApply.allProps.fontSize = toApply.runProps.fontSize = toApply.parProps.fontSize = style.fontSize;
  1024. if(style.fontWeight !== undefined) toApply.allProps.fontWeight = toApply.runProps.fontWeight = style.fontWeight;
  1025. if(style.fontStyle !== undefined) toApply.allProps.fontStyle = toApply.runProps.fontStyle = style.fontStyle;
  1026. var textDecoration = [];
  1027. if(style.underline !== undefined) textDecoration[0] = style.underline ? 'underline ' : 'none';
  1028. if(style.strikethrough !== undefined) {
  1029. var index = textDecoration.length;
  1030. if(style.strikethrough) textDecoration[index] ='line-through';
  1031. else if(index == 0) textDecoration[0] = 'none';
  1032. }
  1033. if (textDecoration.length > 0) {
  1034. var decorationLineUp = "";
  1035. for (var l = 0; l < textDecoration.length; l++) {
  1036. decorationLineUp = decorationLineUp + textDecoration[l];
  1037. }
  1038. toApply.allProps.textDecoration = toApply.runProps.textDecoration = decorationLineUp;
  1039. }
  1040. if(style.foreGroundFill) {
  1041. toApply.allProps.color = toApply.runProps.color = _getColorFromFill(style.foreGroundFill);
  1042. //if(style.foreGroundFill.opacity) toApply.allProps.opacity = toApply.runProps.opacity = style.foreGroundFill.opacity;
  1043. }
  1044. if(style.horizontalAlignment) toApply.allProps.textAlign = toApply.parProps.textAlign = toApply.runProps.textAlign = style.horizontalAlignment;
  1045. if(style.lineSpacing) toApply.allProps.lineHeight = toApply.parProps.lineHeight = style.lineSpacing;
  1046. if(style.textShadow) toApply.allProps.textShadow = toApply.parProps.textShadow = _getCssShadow(style.textShadow);
  1047. if (style.letterCase) toApply.allProps.textTransform = toApply.parProps.textTransform = style.letterCase;
  1048. if (style.characterSpacing) toApply.allProps.letterSpacing = toApply.runProps.letterSpacing = style.characterSpacing;
  1049. return toApply;
  1050. };
  1051. var _getColorFromFill = function(fill) {
  1052. //var fillString = '00000' + fill.color.toString(16);
  1053. //return '#' + fillString.substring(fillString.length - 6);
  1054. var val = fill.color;
  1055. var color = {};
  1056. color.b = val % 256;
  1057. val = Math.floor(val / 256);
  1058. color.g = val % 256;
  1059. val = Math.floor(val / 256);
  1060. color.r = val % 256;
  1061. color.a = typeof (fill.opacity) == 'number' ? fill.opacity : 1;
  1062. return _getCssColor(color);
  1063. };
  1064. var _getCssColor = function(rgbaObj) {
  1065. return "rgba(" + rgbaObj.r + ", " + rgbaObj.g + ", " + rgbaObj.b + ", " + rgbaObj.a + ")";
  1066. };
  1067. // //--------------------------------------------------------------------------
  1068. // // ApplyStyleRecursive
  1069. // //
  1070. // // Applies a style recursively to all span and div tags including elementNode
  1071. // // and all of its children.
  1072. // //
  1073. // // element : the element to apply the style to
  1074. // // styleName : the name of the style property to set (eg. 'font-weight')
  1075. // // styleValue : the value of the style to set (eg. 'bold')
  1076. // //--------------------------------------------------------------------------
  1077. // function ApplyStyleRecursive(element, styleName, styleValue) {
  1078. // var nodeName = element.nodeName.toLowerCase();
  1079. // if (nodeName == 'div' || nodeName == 'span' || nodeName == 'p') {
  1080. // element.style[styleName] = styleValue;
  1081. // }
  1082. // for (var i = 0; i < element.childNodes.length; i++) {
  1083. // ApplyStyleRecursive(element.childNodes[i], styleName, styleValue);
  1084. // }
  1085. // }
  1086. // //---------------------------------------------------------------------------
  1087. // // ApplyTextProperty
  1088. // //
  1089. // // Applies a text property to rtfElement.
  1090. // //
  1091. // // rtfElement : the the root text element of the rtf object (this is the
  1092. // // element named <id>_rtf
  1093. // // prop : the style property to set.
  1094. // // value : the style value to set.
  1095. // //---------------------------------------------------------------------------
  1096. // function ApplyTextProperty(rtfElement, prop, value) {
  1097. // /*
  1098. // var oldHtml = rtfElement.innerHTML;
  1099. // if (prop == 'fontWeight') {
  1100. // rtfElement.innerHTML = oldHtml.replace(/< *b *\/?>/gi, "");
  1101. // } else if (prop == 'fontStyle') {
  1102. // rtfElement.innerHTML = oldHtml.replace(/< *i *\/?>/gi, "");
  1103. // } else if (prop == 'textDecoration') {
  1104. // rtfElement.innerHTML = oldHtml.replace(/< *u *\/?>/gi, "");
  1105. // }
  1106. // */
  1107. // for (var i = 0; i < rtfElement.childNodes.length; i++) {
  1108. // ApplyStyleRecursive(rtfElement.childNodes[i], prop, value);
  1109. // }
  1110. // }
  1111. //}
  1112. //---------------------------------------------------------------------------
  1113. // GetAndCacheOriginalText
  1114. //
  1115. // Gets the html for the pre-rollover state and returns the Html representing
  1116. // the Rich text.
  1117. //---------------------------------------------------------------------------
  1118. var CACHE_COUNTER = 0;
  1119. $ax.style.CacheOriginalText = function(textId, hasRichTextBeenSet) {
  1120. var rtfQuery = $('#' + textId);
  1121. if(rtfQuery.length > 0) {
  1122. var styleCache = {};
  1123. rtfQuery.find('*').each(function(index, element) {
  1124. var elementId = element.id;
  1125. if(!elementId) element.id = elementId = 'cache' + CACHE_COUNTER++;
  1126. styleCache[elementId] = element.style.cssText;
  1127. });
  1128. _originalTextCache[textId] = {
  1129. styleCache: styleCache
  1130. };
  1131. if(hasRichTextBeenSet) {
  1132. var shapeId = $ax.GetShapeIdFromText(textId);
  1133. _shapesWithSetRichText[shapeId] = true;
  1134. }
  1135. }
  1136. };
  1137. $ax.style.ClearCacheForRepeater = function(repeaterId) {
  1138. for(var elementId in _originalTextCache) {
  1139. var scriptId = $ax.repeater.getScriptIdFromElementId(elementId);
  1140. if($ax.getParentRepeaterFromScriptId(scriptId) == repeaterId) delete _originalTextCache[elementId];
  1141. }
  1142. };
  1143. $ax.style.prefetch = function() {
  1144. var scriptIds = $ax.getAllScriptIds();
  1145. var image = new Image();
  1146. for(var i = 0; i < scriptIds.length; i++) {
  1147. var obj = $obj(scriptIds[i]);
  1148. if (!$ax.public.fn.IsImageBox(obj.type)) continue;
  1149. var images = obj.images;
  1150. for (var key in images) image.src = images[key];
  1151. var imageOverrides = obj.imageOverrides;
  1152. for(var elementId in imageOverrides) {
  1153. var override = imageOverrides[elementId];
  1154. for (var state in override) {
  1155. _addImageOverride(elementId, state, override[state]);
  1156. image.src = override[state];
  1157. }
  1158. }
  1159. }
  1160. };
  1161. });