scripts.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <script src="__STATIC__/js/admin.js?v={$_static_version}"></script>
  2. <script src="__TMPL__/public/assets/js/jquery-ui.min.js?v={$_static_version}"></script>
  3. <script type="text/javascript">
  4. //编辑器路径定义
  5. var editorURL = GV.WEB_ROOT;
  6. </script>
  7. <script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
  8. <script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
  9. <script>
  10. $(function () {
  11. $('.rich_text_content').each(function (i,item){
  12. var editor = new baidu.editor.ui.Editor();
  13. editor.render(item);
  14. try {
  15. editor.sync();
  16. } catch (err) {
  17. }
  18. });
  19. });
  20. $('.widgets-group').sortable({
  21. connectWith: '.widgets-group',
  22. items: "> li.widgets-group-item",
  23. cursor: "move",
  24. opacity: 0.8,
  25. forcePlaceholderSize: true,
  26. scrollSensitivity: 100,
  27. scrollSpeed: 50,
  28. tolerance: 'pointer',
  29. stop: function (event, ui) {
  30. console.log(ui.item.parent().html())
  31. //$('.widgets-group').sortable('cancel')
  32. var widgetIds = {};
  33. $('.widgets-group').each(function () {
  34. var blockName = $(this).data('block_name');
  35. var fileId = 'file' + $(this).data('file_id');
  36. $(this).find('li.widgets-group-item').each(function () {
  37. if (!widgetIds.hasOwnProperty(fileId)) {
  38. widgetIds[fileId] = {};
  39. }
  40. if (!widgetIds[fileId].hasOwnProperty(blockName)) {
  41. widgetIds[fileId][blockName] = [];
  42. }
  43. widgetIds[fileId][blockName].push({
  44. file_id: $(this).data('file_id'),
  45. widget_id: $(this).data('id')
  46. });
  47. });
  48. });
  49. $.ajax({
  50. url: "{:url('Theme/widgetsSort')}",
  51. type: 'POST',
  52. dataType: 'json',
  53. data: widgetIds,
  54. success: function (data) {
  55. parent.simulator.location.reload(true);
  56. }
  57. })
  58. console.log(widgetIds);
  59. },
  60. over: function (event, ui) {
  61. // ui.placeholder.addClass('ui-sortable-placeholder-disabled');
  62. }
  63. })
  64. // $( "li", '.widgets-group' ).draggable({
  65. // // cancel: "a.ui-icon", // clicking an icon won't initiate dragging
  66. // revert: "invalid", // when not dropped, the item will revert back to its initial position
  67. // containment: "document",
  68. // cursor: "move"
  69. // });
  70. // $( '.widgets-group').droppable({
  71. // accept: ".widgets-group > li",
  72. // tolerance: 'pointer',
  73. // classes: {
  74. // "ui-droppable-active": "ui-state-active",
  75. // "ui-droppable-hover": "ui-state-hover"
  76. // },
  77. // drop: function( event, ui ) {
  78. // ui.draggable.appendTo($(this));
  79. // }
  80. // });
  81. Wind.use('colorpicker', function () {
  82. $('.js-color').each(function () {
  83. var $this = $(this);
  84. $this.ColorPicker({
  85. livePreview: true,
  86. onChange: function (hsb, hex, rgb) {
  87. $this.val('#' + hex);
  88. },
  89. onBeforeShow: function () {
  90. $(this).ColorPickerSetColor(this.value);
  91. }
  92. });
  93. });
  94. });
  95. function doSelectData(obj) {
  96. var $obj = $(obj);
  97. var $realInput = $obj.next();
  98. var selectedObjectsId = $realInput.val();
  99. var dataSource = $obj.data('source');
  100. var title = $obj.data('title');
  101. parent.openIframeLayer("{:url('Theme/dataSource')}?ids=" + selectedObjectsId + '&data_source=' + dataSource, title, {
  102. area: GV.IS_MOBILE ? ['100%', '100%'] : ['95%', '90%'],
  103. offset: GV.IS_MOBILE ? ['0px', '0px'] : 'auto',
  104. btn: ['确定', '取消'],
  105. yes: function (index, layero) {
  106. var iframeWin = parent.window[layero.find('iframe')[0]['name']];
  107. var selectedObjects = iframeWin.confirm();
  108. if (selectedObjects.selectedObjectsId.length == 0) {
  109. layer.msg('您没有选择任何数据!');
  110. return;
  111. }
  112. $realInput.val(selectedObjects.selectedObjectsId.join(','));
  113. $obj.val(selectedObjects.selectedObjectsName.join(','));
  114. parent.layer.close(index); //如果设定了yes回调,需进行手工关闭
  115. }
  116. });
  117. }
  118. function doEditArrayData(obj) {
  119. var $obj = $(obj);
  120. var mVar = $obj.data('var');
  121. var title = $obj.data('title');
  122. var widget = $obj.data('widget');
  123. widget = widget ? '&widget=' + widget : '';
  124. var fileId = $obj.data('file_id');
  125. if (!fileId) {
  126. fileId = '{$file_id}';
  127. }
  128. var blockName = "{$block_name|default=''}";
  129. blockName = blockName ? '&block_name=' + blockName : '';
  130. var widgetId = "{$widget_id|default=''}";
  131. widgetId = widgetId ? '&widget_id=' + widgetId : '';
  132. parent.openIframeLayer(
  133. "{:url('Theme/fileArrayData')}?tab={$tab|default=''}&file_id=" + fileId + "&" + 'var=' + mVar + widget + blockName + widgetId,
  134. title,
  135. {
  136. area: GV.IS_MOBILE ? ['100%', '100%'] : ['95%', '90%'],
  137. offset: GV.IS_MOBILE ? ['0px', '0px'] : 'auto',
  138. btn: ['确定', '取消'],
  139. yes: function (index, layero) {
  140. var iframeWin = parent.window[layero.find('iframe')[0]['name']];
  141. var result = iframeWin.confirm();
  142. if (result) {
  143. parent.layer.close(index); //如果设定了yes回调,需进行手工关闭
  144. }
  145. },
  146. end: function () {
  147. window.location.reload();
  148. }
  149. }
  150. );
  151. }
  152. function doWidgetSetting(obj) {
  153. var $obj = $(obj);
  154. var $widgetsBlock = $obj.parents('.widgets-group');
  155. var $parent = $obj.parent();
  156. var blockName = $widgetsBlock.data('block_name');
  157. var widgetId = $parent.data('id');
  158. var fileId = $widgetsBlock.data('file_id');
  159. var title = $parent.data('title');
  160. parent.openIframeLayer(
  161. "{:url('Theme/widgetSetting')}?file_id=" + fileId + "&widget_id=" + widgetId + '&block_name=' + blockName,
  162. title,
  163. {
  164. area: GV.IS_MOBILE ? ['100%', '100%'] : ['600px', '100%'],
  165. offset: GV.IS_MOBILE ? ['0px', '0px'] : 'auto',
  166. btn: ['保存', '取消'],
  167. yes: function (index, layero) {
  168. var iframeWin = parent.window[layero.find('iframe')[0]['name']];
  169. var result = iframeWin.confirm();
  170. if (result) {
  171. parent.layer.close(index); //如果设定了yes回调,需进行手工关闭
  172. }
  173. },
  174. end: function () {
  175. parent.simulator.location.reload(true);
  176. }
  177. }
  178. );
  179. }
  180. function doSelectLocation(obj) {
  181. var $obj = $(obj);
  182. var title = $obj.data('title');
  183. var $realInput = $obj.next();
  184. var location = $realInput.val();
  185. parent.openIframeLayer(
  186. "{:url('dialog/map')}?location=" + location,
  187. title,
  188. {
  189. area: GV.IS_MOBILE ? ['100%', '100%'] : ['95%', '90%'],
  190. offset: GV.IS_MOBILE ? ['0px', '0px'] : 'auto',
  191. btn: ['确定', '取消'],
  192. yes: function (index, layero) {
  193. var iframeWin = parent.window[layero.find('iframe')[0]['name']];
  194. var location = iframeWin.confirm();
  195. $realInput.val(location.lng + ',' + location.lat);
  196. $obj.val(location.address);
  197. parent.layer.close(index); //如果设定了yes回调,需进行手工关闭
  198. }
  199. }
  200. );
  201. }
  202. /**
  203. * 单个图片上传
  204. * @param dialog_title 上传对话框标题
  205. * @param input_selector 图片容器
  206. * @param extra_params 额外参数,object
  207. * @param app 应用名,CMF的应用名
  208. */
  209. function doUploadOneImage(dialog_title, input_selector, extra_params, app) {
  210. parent.openUploadDialog(dialog_title, function (dialog, files) {
  211. $(input_selector).val(files[0].filepath);
  212. $(input_selector + '-preview').attr('src', files[0].preview_url);
  213. $(input_selector + '-name').val(files[0].name);
  214. $(input_selector + '-name-text').text(files[0].name);
  215. }, extra_params, 0, 'image', app);
  216. }
  217. /**
  218. * 单个文件上传
  219. * @param dialog_title 上传对话框标题
  220. * @param input_selector 图片容器
  221. * @param filetype 文件类型,image,video,audio,file
  222. * @param extra_params 额外参数,object
  223. * @param app 应用名,CMF的应用名
  224. */
  225. function doUploadOne(dialog_title, input_selector, filetype, extra_params, app) {
  226. filetype = filetype ? filetype : 'file';
  227. parent.openUploadDialog(dialog_title, function (dialog, files) {
  228. $(input_selector).val(files[0].filepath);
  229. $(input_selector + '-preview').attr('href', files[0].preview_url);
  230. $(input_selector + '-name').val(files[0].name);
  231. $(input_selector + '-name-text').text(files[0].name);
  232. }, extra_params, 0, filetype, app);
  233. }
  234. function confirm() {
  235. $('#submit-btn').click();
  236. }
  237. function removeImage(wigetVarName) {
  238. //需要定位input和image
  239. //清空Input
  240. $('#js-' + wigetVarName + '-input').val('');
  241. //修改Image为原图。
  242. var defaultImage = $('#js-' + wigetVarName + '-button-remove').attr('defaultImage');
  243. $('#js-' + wigetVarName + '-input-preview').attr('src', defaultImage);
  244. //移除自身
  245. $('#js-' + wigetVarName + '-button-remove').remove();
  246. }
  247. </script>