learun-component.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. var $selectBoxCurrent = null;
  2. angular.module('starter.component', [])
  3. .factory('$lrComponent', ['$rootScope', '$lrfnGuid', '$lrDoBroadcastToparent', function ($rootScope, $lrfnGuid, $lrDoBroadcastToparent) {
  4. return{
  5. lrHeader: function ($div, sortable, componentData) {
  6. var isNewed = $div.find('.lr-component-heading').length;
  7. if (isNewed == 0) {
  8. var _hSize = { "H1": "36px", "H2": "30px", "H3": "24px", "H4": "18px", "H5": "14px" };
  9. var _setAttrLr = function (data) {
  10. switch (data.attrName) {
  11. case "text":
  12. $selectBoxCurrent.text(data.object.text);
  13. break;
  14. case "size":
  15. $selectBoxCurrent.css("font-size", _hSize[data.object.attr.size]);
  16. break;
  17. case "weightSize":
  18. $selectBoxCurrent.css("font-weight", data.object.attr.weight.size);
  19. break;
  20. case "isItalic":
  21. var _style = data.object.attr.weight.isItalic == "true" ? 'italic' : 'normal';
  22. $selectBoxCurrent.css("font-style", _style);
  23. break;
  24. case "color":
  25. $selectBoxCurrent.css("color", data.object.attr.color);
  26. break;
  27. case "align":
  28. $selectBoxCurrent.css("text-align", data.object.attr.align);
  29. break;
  30. }
  31. };
  32. var component = {
  33. id: $lrfnGuid(),
  34. size: "H1",
  35. weight: {
  36. size: 500,
  37. isItalic: 'false'
  38. },
  39. color: "#000000",
  40. align: "left",
  41. text: "标题",
  42. value: "lrHeader",
  43. img: "fa fa-header",
  44. type: "component"
  45. };
  46. if (componentData != undefined) {
  47. component = componentData;
  48. }
  49. $div.html('<h1 class="lr-component-heading lr-f ">' + component.text + '</h1>');
  50. $obj = $div.find('.lr-component-heading');
  51. $obj.attr('data-value', component.id);
  52. var $selectBox = $('.ic-select-box');
  53. $rootScope.$on('componentScroll', function (event, data) {
  54. if ($selectBoxCurrent != null) {
  55. $selectBox.offset($selectBoxCurrent.offset());
  56. }
  57. });
  58. $obj.on('click', function () {
  59. $selectBox.show();
  60. var obj = {
  61. value: component.value,
  62. id: $(this).attr('data-value')
  63. };
  64. $selectBox.attr('data-value', obj.id)
  65. .width($(this).width())
  66. .height($(this).height())
  67. .offset($(this).offset());
  68. $('.ic-selected').removeClass("ic-selected");
  69. $(this).addClass("ic-selected");
  70. $selectBoxCurrent = $(this);
  71. $selectBoxCurrent.setAttrLr = _setAttrLr;
  72. $lrDoBroadcastToparent(appBroadcastCode.doComponentPhone, { "cmd": "selectComponent", "id": obj.id });
  73. });
  74. window.onresize = function () {
  75. if ($selectBoxCurrent != null) {
  76. $selectBox.width($selectBoxCurrent.width());
  77. }
  78. };
  79. if (sortable) {
  80. setTimeout(function () {
  81. $obj.trigger('click');
  82. }, 50);
  83. $lrDoBroadcastToparent(appBroadcastCode.addComponent, component);
  84. }
  85. }
  86. else {
  87. $div.find('.lr-component-heading').trigger('click');
  88. }
  89. },
  90. lrParagraph: function ($div, sortable, componentData) {
  91. var isNewed = $div.find('.lr-component-one').length;
  92. if (isNewed == 0) {
  93. var _setAttrLr = function (data) {
  94. switch (data.attrName) {
  95. case "content":
  96. $selectBoxCurrent.text(data.object.attr.content);
  97. break;
  98. case "size":
  99. $selectBoxCurrent.css("font-size", data.object.attr.size);
  100. break;
  101. case "color":
  102. $selectBoxCurrent.css("color", data.object.attr.color);
  103. case "align":
  104. $selectBoxCurrent.css("text-align", data.object.attr.align);
  105. break;
  106. }
  107. };
  108. var component = {
  109. id: $lrfnGuid(),
  110. size: "14px",
  111. color: "#000000",
  112. align: "left",
  113. text:"段落",
  114. content: "请填写内容",
  115. value: "lrParagraph",
  116. type: "component",
  117. img: "fa fa-align-left"
  118. };
  119. if (componentData != undefined) {
  120. component = componentData;
  121. }
  122. $div.html('<p class="lr-component-one lr-f ">' + component.content + '</p>');
  123. $obj = $div.find('.lr-component-one');
  124. $obj.attr('data-value', component.id);
  125. var $selectBox = $('.ic-select-box');
  126. $rootScope.$on('componentScroll', function (event, data) {
  127. if ($selectBoxCurrent != null) {
  128. $selectBox.offset($selectBoxCurrent.offset());
  129. }
  130. });
  131. $obj.on('click', function () {
  132. $selectBox.show();
  133. var obj = {
  134. value: component.value,
  135. id: $(this).attr('data-value')
  136. };
  137. $selectBox.attr('data-value', obj.id)
  138. .width($(this).width())
  139. .height($(this).height())
  140. .offset($(this).offset());
  141. $('.ic-selected').removeClass("ic-selected");
  142. $(this).addClass("ic-selected");
  143. $selectBoxCurrent = $(this);
  144. $selectBoxCurrent.setAttrLr = _setAttrLr;
  145. $lrDoBroadcastToparent(appBroadcastCode.doComponentPhone, { "cmd": "selectComponent", "id": obj.id });
  146. });
  147. window.onresize = function () {
  148. if ($selectBoxCurrent != null) {
  149. $selectBox.width($selectBoxCurrent.width());
  150. }
  151. };
  152. if (sortable) {
  153. setTimeout(function () {
  154. $obj.trigger('click');
  155. }, 50);
  156. $lrDoBroadcastToparent(appBroadcastCode.addComponent, component);
  157. }
  158. }
  159. else {
  160. $div.find('.lr-component-one').trigger('click');
  161. }
  162. },
  163. lrBtn: function ($div, sortable, componentData) {
  164. var isNewed = $div.find('.button').length;
  165. if (isNewed == 0) {
  166. var _setAttrLr = function (data) {
  167. switch (data.attrName) {
  168. case "text":
  169. $selectBoxCurrent.text(data.object.text);
  170. break;
  171. case "size":
  172. $selectBoxCurrent.css("font-size", data.object.attr.size);
  173. break;
  174. case "weightSize":
  175. $selectBoxCurrent.css("font-weight", data.object.attr.weight.size);
  176. break;
  177. case "isItalic":
  178. var _style = data.object.attr.weight.isItalic == "true" ? 'italic' : 'normal';
  179. $selectBoxCurrent.css("font-style", _style);
  180. break;
  181. case "color":
  182. $selectBoxCurrent.css("color", data.object.attr.color);
  183. break;
  184. case "align":
  185. $selectBoxCurrent.css("text-align", data.object.attr.align);
  186. break;
  187. case "btnType":
  188. $selectBoxCurrent.removeClass('button-default');
  189. $selectBoxCurrent.removeClass('button-clear');
  190. $selectBoxCurrent.removeClass('button-outline');
  191. $selectBoxCurrent.addClass('button-' + data.object.attr.btnType);
  192. break;
  193. case "btnTheme":
  194. var _class = $selectBoxCurrent.attr("data-btnTheme");
  195. $selectBoxCurrent.removeClass('button-' + _class);
  196. $selectBoxCurrent.attr("data-btnTheme", data.object.attr.btnTheme);
  197. $selectBoxCurrent.addClass('button-' + data.object.attr.btnTheme);
  198. break;
  199. case "btnSize":
  200. $selectBoxCurrent.removeClass('button-standard');
  201. $selectBoxCurrent.removeClass('button-large');
  202. $selectBoxCurrent.removeClass('button-small');
  203. $selectBoxCurrent.addClass('button-' + data.object.attr.btnSize);
  204. $selectBoxCurrent.trigger('click');
  205. break;
  206. }
  207. };
  208. var component = {
  209. id: $lrfnGuid(),
  210. link: "NotLinked",
  211. text: "按钮",
  212. size: "16px",
  213. weight: {
  214. size: 500,
  215. isItalic: 'false'
  216. },
  217. color: "#ffffff",
  218. align: "center",
  219. btnType: "default",
  220. btnTheme: "positive",
  221. btnSize:"standard",
  222. value: "lrBtn",
  223. type: "component",
  224. img: "fa fa-square"
  225. };
  226. if (componentData != undefined) {
  227. component = componentData;
  228. }
  229. $div.html('<a class=" button button-block button-positive " data-btnTheme= "button-positive">' + component.text + '</a>');
  230. $obj = $div.find('.button');
  231. $obj.attr('data-value', component.id);
  232. var $selectBox = $('.ic-select-box');
  233. $rootScope.$on('componentScroll', function (event, data) {
  234. if ($selectBoxCurrent != null) {
  235. $selectBox.offset($selectBoxCurrent.offset());
  236. }
  237. });
  238. $obj.on('click', function () {
  239. $selectBox.show();
  240. var obj = {
  241. value: component.value,
  242. id: $(this).attr('data-value')
  243. };
  244. var _width = $(this)[0].offsetWidth;
  245. var _height = $(this)[0].offsetHeight-1;
  246. $selectBox.attr('data-value', obj.id)
  247. .width(_width-2)
  248. .height(_height)
  249. .offset($(this).offset());
  250. $('.ic-selected').removeClass("ic-selected");
  251. $(this).addClass("ic-selected");
  252. $selectBoxCurrent = $(this);
  253. $selectBoxCurrent.setAttrLr = _setAttrLr;
  254. $lrDoBroadcastToparent(appBroadcastCode.doComponentPhone, { "cmd": "selectComponent", "id": obj.id });
  255. });
  256. window.onresize = function () {
  257. if ($selectBoxCurrent != null) {
  258. var _width = $selectBoxCurrent[0].offsetWidth;
  259. $selectBox.width(_width-2);
  260. }
  261. };
  262. if (sortable) {
  263. setTimeout(function () {
  264. $obj.trigger('click');
  265. }, 50);
  266. $lrDoBroadcastToparent(appBroadcastCode.addComponent, component);
  267. }
  268. }
  269. else {
  270. $div.find('.button').trigger('click');
  271. }
  272. },
  273. lrInput: function ($div, sortable, componentData) {
  274. var isNewed = $div.find('.item-input').length;
  275. if (isNewed == 0) {
  276. var _setAttrLr = function (data) {
  277. switch (data.attrName) {
  278. case "placeholder":
  279. $selectBoxCurrent.html(data.object.attr.placeholder);
  280. break;
  281. }
  282. };
  283. var component = {
  284. id: $lrfnGuid(),
  285. text: "输入框",
  286. placeholder: "输入框",
  287. inputType: "text",
  288. name: "",
  289. value: "lrInput",
  290. type: "component",
  291. img: "fa fa-italic"
  292. };
  293. if (componentData != undefined) {
  294. component = componentData;
  295. }
  296. $div.html('<div class="item item-input" style="padding:10px;color: #B8B8B8;" >输入框</div>');
  297. $obj = $div.find('.item-input');
  298. $obj.attr('data-value', component.id);
  299. var $selectBox = $('.ic-select-box');
  300. $rootScope.$on('componentScroll', function (event, data) {
  301. if ($selectBoxCurrent != null) {
  302. $selectBox.offset($selectBoxCurrent.offset());
  303. }
  304. });
  305. $obj.on('click', function () {
  306. $selectBox.show();
  307. var obj = {
  308. value: component.value,
  309. id: $(this).attr('data-value')
  310. };
  311. var _width = $(this)[0].offsetWidth;
  312. var _height = $(this)[0].offsetHeight - 1;
  313. $selectBox.attr('data-value', obj.id)
  314. .width(_width - 2)
  315. .height(_height)
  316. .offset($(this).offset());
  317. $('.ic-selected').removeClass("ic-selected");
  318. $(this).addClass("ic-selected");
  319. $selectBoxCurrent = $(this);
  320. $selectBoxCurrent.setAttrLr = _setAttrLr;
  321. $lrDoBroadcastToparent(appBroadcastCode.doComponentPhone, { "cmd": "selectComponent", "id": obj.id });
  322. });
  323. window.onresize = function () {
  324. if ($selectBoxCurrent != null) {
  325. var _width = $selectBoxCurrent[0].offsetWidth;
  326. $selectBox.width(_width - 2);
  327. }
  328. };
  329. if (sortable) {
  330. setTimeout(function () {
  331. $obj.trigger('click');
  332. }, 50);
  333. $lrDoBroadcastToparent(appBroadcastCode.addComponent, component);
  334. }
  335. }
  336. else {
  337. $div.find('.item-input').trigger('click');
  338. }
  339. },
  340. lrList3: function ($div, sortable, componentData) {
  341. var isNewed = $div.find('.lr-list-type3').length;
  342. if (isNewed == 0) {
  343. var _setAttrLr = function (data) {
  344. switch (data.attrName) {
  345. case "name":
  346. $selectBoxCurrent.find('span').html(data.object.attr.name);
  347. break;
  348. case "icon":
  349. var _$i = $selectBoxCurrent.find('i');
  350. var _class = _$i.attr("data-icon");
  351. _$i.removeClass(_class);
  352. _$i.attr("data-icon", data.object.attr.icon);
  353. _$i.addClass(data.object.attr.icon);
  354. break;
  355. case "color":
  356. var _$i = $selectBoxCurrent.find('i');
  357. var _class = _$i.attr("data-color");
  358. _$i.removeClass(_class+"-bg");
  359. _$i.attr("data-color", data.object.attr.color);
  360. _$i.addClass(data.object.attr.color + "-bg");
  361. break;
  362. }
  363. };
  364. var component = {
  365. id: $lrfnGuid(),
  366. text: "列表类型一",
  367. name: "列表类型一",
  368. icon: "ion-ios-barcode-outline",
  369. color: "royal",
  370. link: "NotLinked",
  371. value: "lrList3",
  372. type: "component",
  373. img: "fa fa-th-list"
  374. };
  375. if (componentData != undefined) {
  376. component = componentData;
  377. }
  378. var _chtml = '<div class="lr-list-type3"><div class="item item-icon-left" >';
  379. _chtml += '<i class="icon ion-ios-barcode-outline royal-bg" data-icon="ion-ios-barcode-outline" data-color="royal"></i>';
  380. _chtml += '<span class="ng-binding">' + component.name + '</span></div></div>';
  381. $div.html(_chtml);
  382. $obj = $div.find('.lr-list-type3');
  383. $obj.attr('data-value', component.id);
  384. var $selectBox = $('.ic-select-box');
  385. $rootScope.$on('componentScroll', function (event, data) {
  386. if ($selectBoxCurrent != null) {
  387. $selectBox.offset($selectBoxCurrent.offset());
  388. }
  389. });
  390. $obj.on('click', function () {
  391. $selectBox.show();
  392. var obj = {
  393. value: component.value,
  394. id: $(this).attr('data-value')
  395. };
  396. var _width = $(this)[0].offsetWidth;
  397. var _height = $(this)[0].offsetHeight - 2;
  398. $selectBox.attr('data-value', obj.id)
  399. .width(_width - 2)
  400. .height(_height)
  401. .offset($(this).offset());
  402. $('.ic-selected').removeClass("ic-selected");
  403. $(this).addClass("ic-selected");
  404. $selectBoxCurrent = $(this);
  405. $selectBoxCurrent.setAttrLr = _setAttrLr;
  406. $lrDoBroadcastToparent(appBroadcastCode.doComponentPhone, { "cmd": "selectComponent", "id": obj.id });
  407. });
  408. window.onresize = function () {
  409. if ($selectBoxCurrent != null) {
  410. var _width = $selectBoxCurrent[0].offsetWidth;
  411. $selectBox.width(_width - 2);
  412. }
  413. };
  414. if (sortable) {
  415. setTimeout(function () {
  416. $obj.trigger('click');
  417. }, 50);
  418. $lrDoBroadcastToparent(appBroadcastCode.addComponent, component);
  419. }
  420. }
  421. else {
  422. $div.find('.lr-list-type3').trigger('click');
  423. }
  424. },
  425. lrList4: function ($div, sortable, componentData) {
  426. var isNewed = $div.find('.lr-iconitem').length;
  427. if (isNewed == 0) {
  428. var _setAttrLr = function (data) {
  429. switch (data.attrName) {
  430. case "name":
  431. $selectBoxCurrent.find('span').html(data.object.attr.name);
  432. break;
  433. case "icon":
  434. var _$i = $selectBoxCurrent.find('i:first-child');
  435. var _class = _$i.attr("data-icon");
  436. _$i.removeClass(_class);
  437. _$i.attr("data-icon", data.object.attr.icon);
  438. _$i.addClass(data.object.attr.icon);
  439. break;
  440. case "color":
  441. var _$i = $selectBoxCurrent.find('i:first-child');
  442. var _class = _$i.attr("data-color");
  443. _$i.removeClass("bgcolor_" + _class);
  444. _$i.attr("data-color", data.object.attr.color);
  445. _$i.addClass("bgcolor_" + data.object.attr.color);
  446. break;
  447. }
  448. };
  449. var component = {
  450. id: $lrfnGuid(),
  451. text: "列表类型一",
  452. name: "列表类型二",
  453. icon: "ion-ios-paper-outline",
  454. color: "b",
  455. link: "NotLinked",
  456. value: "lrList4",
  457. type: "component",
  458. img: "fa fa-list-ul"
  459. };
  460. if (componentData != undefined) {
  461. component = componentData;
  462. }
  463. var _chtml = ' <ion-item class="item-icon-right lr-iconitem item" >';
  464. _chtml += '<i class="icon ion-ios-paper-outline bgcolor_b" data-icon="ion-ios-paper-outline" data-color="bgcolor_b"></i>';
  465. _chtml += '<span class="ng-binding">' + component.name + '</span>';
  466. _chtml += '<i class="icon ion-chevron-right icon-accessory "></i>';
  467. _chtml += '</ion-item>';
  468. $div.html(_chtml);
  469. $obj = $div.find('.lr-iconitem');
  470. $obj.attr('data-value', component.id);
  471. var $selectBox = $('.ic-select-box');
  472. $rootScope.$on('componentScroll', function (event, data) {
  473. if ($selectBoxCurrent != null) {
  474. $selectBox.offset($selectBoxCurrent.offset());
  475. }
  476. });
  477. $obj.on('click', function () {
  478. $selectBox.show();
  479. var obj = {
  480. value: component.value,
  481. id: $(this).attr('data-value')
  482. };
  483. var _width = $(this)[0].offsetWidth;
  484. var _height = $(this)[0].offsetHeight - 2;
  485. $selectBox.attr('data-value', obj.id)
  486. .width(_width - 2)
  487. .height(_height)
  488. .offset($(this).offset());
  489. $('.ic-selected').removeClass("ic-selected");
  490. $(this).addClass("ic-selected");
  491. $selectBoxCurrent = $(this);
  492. $selectBoxCurrent.setAttrLr = _setAttrLr;
  493. $lrDoBroadcastToparent(appBroadcastCode.doComponentPhone, { "cmd": "selectComponent", "id": obj.id });
  494. });
  495. window.onresize = function () {
  496. if ($selectBoxCurrent != null) {
  497. var _width = $selectBoxCurrent[0].offsetWidth;
  498. $selectBox.width(_width - 2);
  499. }
  500. };
  501. if (sortable) {
  502. setTimeout(function () {
  503. $obj.trigger('click');
  504. }, 50);
  505. $lrDoBroadcastToparent(appBroadcastCode.addComponent, component);
  506. }
  507. }
  508. else {
  509. $div.find('.lr-iconitem').trigger('click');
  510. }
  511. }
  512. };
  513. }])
  514. ;