产品原型
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1381 lines
58 KiB

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