form_builder.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>H+ 后台主题UI框架 - Bootstrap3 表单构建器</title>
  7. <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
  8. <meta name="description" content="H+是一个完全响应式,基于Bootstrap3最新版本开发的扁平化主题,她采用了主流的左右两栏式布局,使用了Html5+CSS3等现代技术">
  9. <link rel="shortcut icon" href="favicon.ico"> <link href="css/bootstrap.min.css?v=3.3.7" rel="stylesheet">
  10. <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
  11. <link href="css/animate.css" rel="stylesheet">
  12. <link href="css/plugins/summernote/summernote.css" rel="stylesheet">
  13. <link href="css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
  14. <link href="css/style.css?v=4.1.0" rel="stylesheet">
  15. <style>
  16. .droppable-active {
  17. background-color: #ffe !important;
  18. }
  19. .tools a {
  20. cursor: pointer;
  21. font-size: 80%;
  22. }
  23. .form-body .col-md-6,
  24. .form-body .col-md-12 {
  25. min-height: 400px;
  26. }
  27. .draggable {
  28. cursor: move;
  29. }
  30. </style>
  31. </head>
  32. <body class="gray-bg">
  33. <div class="wrapper wrapper-content">
  34. <div class="row">
  35. <div class="col-sm-5">
  36. <div class="ibox float-e-margins">
  37. <div class="ibox-title">
  38. <h5>元素</h5>
  39. <div class="ibox-tools">
  40. <a class="collapse-link">
  41. <i class="fa fa-chevron-up"></i>
  42. </a>
  43. <a class="dropdown-toggle" data-toggle="dropdown" href="form_editors.html#">
  44. <i class="fa fa-wrench"></i>
  45. </a>
  46. <ul class="dropdown-menu dropdown-user">
  47. <li><a href="form_editors.html#">选项1</a>
  48. </li>
  49. <li><a href="form_editors.html#">选项2</a>
  50. </li>
  51. </ul>
  52. <a class="close-link">
  53. <i class="fa fa-times"></i>
  54. </a>
  55. </div>
  56. </div>
  57. <div class="ibox-content">
  58. <div class="alert alert-info">
  59. 拖拽左侧的表单元素到右侧区域,即可生成相应的HTML代码,表单代码,轻松搞定!
  60. </div>
  61. <form role="form" class="form-horizontal m-t">
  62. <div class="form-group draggable">
  63. <label class="col-sm-3 control-label">文本框:</label>
  64. <div class="col-sm-9">
  65. <input type="text" name="" class="form-control" placeholder="请输入文本">
  66. <span class="help-block m-b-none">说明文字</span>
  67. </div>
  68. </div>
  69. <div class="form-group draggable">
  70. <label class="col-sm-3 control-label">密码框:</label>
  71. <div class="col-sm-9">
  72. <input type="password" class="form-control" name="password" placeholder="请输入密码">
  73. </div>
  74. </div>
  75. <div class="form-group draggable">
  76. <label class="col-sm-3 control-label">下拉列表:</label>
  77. <div class="col-sm-9">
  78. <select class="form-control" name="">
  79. <option>选项 1</option>
  80. <option>选项 2</option>
  81. <option>选项 3</option>
  82. <option>选项 4</option>
  83. </select>
  84. </div>
  85. </div>
  86. <div class="form-group draggable">
  87. <label class="col-sm-3 control-label">文件域:</label>
  88. <div class="col-sm-9">
  89. <input type="file" name="" class="form-control">
  90. </div>
  91. </div>
  92. <div class="form-group draggable">
  93. <label class="col-sm-3 control-label">纯文本:</label>
  94. <div class="col-sm-9">
  95. <p class="form-control-static">这里是纯文字信息</p>
  96. </div>
  97. </div>
  98. <div class="form-group draggable">
  99. <label class="col-sm-3 control-label">单选框:
  100. </label>
  101. <div class="col-sm-9">
  102. <label class="radio-inline">
  103. <input type="radio" checked="" value="option1" id="optionsRadios1" name="optionsRadios">选项1</label>
  104. <label class="radio-inline">
  105. <input type="radio" value="option2" id="optionsRadios2" name="optionsRadios">选项2</label>
  106. </div>
  107. </div>
  108. <div class="form-group draggable">
  109. <label class="col-sm-3 control-label">复选框:</label>
  110. <div class="col-sm-9">
  111. <label class="checkbox-inline">
  112. <input type="checkbox" value="option1" id="inlineCheckbox1">选项1</label>
  113. <label class="checkbox-inline">
  114. <input type="checkbox" value="option2" id="inlineCheckbox2">选项2</label>
  115. <label class="checkbox-inline">
  116. <input type="checkbox" value="option3" id="inlineCheckbox3">选项3</label>
  117. </div>
  118. </div>
  119. <div class="hr-line-dashed"></div>
  120. <div class="form-group draggable">
  121. <div class="col-sm-12 col-sm-offset-3">
  122. <button class="btn btn-primary" type="submit">保存内容</button>
  123. <button class="btn btn-white" type="submit">取消</button>
  124. </div>
  125. </div>
  126. </form>
  127. <div class="clearfix"></div>
  128. </div>
  129. </div>
  130. </div>
  131. <div class="col-sm-7">
  132. <div class="ibox float-e-margins">
  133. <div class="ibox-title">
  134. <h5>拖拽左侧表单元素到此区域</h5>
  135. <div class="ibox-tools">
  136. 请选择显示的列数:
  137. <select id="n-columns">
  138. <option value="1">显示1列</option>
  139. <option value="2">显示2列</option>
  140. </select>
  141. </div>
  142. </div>
  143. <div class="ibox-content">
  144. <div class="row form-body form-horizontal m-t">
  145. <div class="col-md-12 droppable sortable">
  146. </div>
  147. <div class="col-md-6 droppable sortable" style="display: none;">
  148. </div>
  149. <div class="col-md-6 droppable sortable" style="display: none;">
  150. </div>
  151. </div>
  152. <button type="submit" class="btn btn-warning" data-clipboard-text="testing" id="copy-to-clipboard">复制代码</button>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. <!-- 全局js -->
  159. <script src="js/jquery.min.js?v=2.1.4"></script>
  160. <script src="js/bootstrap.min.js?v=3.3.7"></script>
  161. <!-- 自定义js -->
  162. <script src="js/content.js?v=1.0.0"></script>
  163. <!-- jQuery UI -->
  164. <script src="js/jquery-ui-1.10.4.min.js"></script>
  165. <!-- From Builder -->
  166. <script src="js/plugins/beautifyhtml/beautifyhtml.js"></script>
  167. <script>
  168. $(document).ready(function () {
  169. setup_draggable();
  170. $("#n-columns").on("change", function () {
  171. var v = $(this).val();
  172. if (v === "1") {
  173. var $col = $('.form-body .col-md-12').toggle(true);
  174. $('.form-body .col-md-6 .draggable').each(function (i, el) {
  175. $(this).remove().appendTo($col);
  176. })
  177. $('.form-body .col-md-6').toggle(false);
  178. } else {
  179. var $col = $('.form-body .col-md-6').toggle(true);
  180. $(".form-body .col-md-12 .draggable").each(function (i, el) {
  181. $(this).remove().appendTo(i % 2 ? $col[1] : $col[0]);
  182. });
  183. $('.form-body .col-md-12').toggle(false);
  184. }
  185. });
  186. $("#copy-to-clipboard").on("click", function () {
  187. var $copy = $(".form-body").clone().appendTo(document.body);
  188. $copy.find(".tools, :hidden").remove();
  189. $.each(["draggable", "droppable", "sortable", "dropped",
  190. "ui-sortable", "ui-draggable", "ui-droppable", "form-body"], function (i, c) {
  191. $copy.find("." + c).removeClass(c).removeAttr("style");
  192. })
  193. var html = html_beautify($copy.html());
  194. $copy.remove();
  195. $modal = get_modal(html).modal("show");
  196. $modal.find(".btn").remove();
  197. $modal.find(".modal-title").html("复制HTML代码");
  198. $modal.find(":input:first").select().focus();
  199. return false;
  200. })
  201. });
  202. var setup_draggable = function () {
  203. $(".draggable").draggable({
  204. appendTo: "body",
  205. helper: "clone"
  206. });
  207. $(".droppable").droppable({
  208. accept: ".draggable",
  209. helper: "clone",
  210. hoverClass: "droppable-active",
  211. drop: function (event, ui) {
  212. $(".empty-form").remove();
  213. var $orig = $(ui.draggable)
  214. if (!$(ui.draggable).hasClass("dropped")) {
  215. var $el = $orig
  216. .clone()
  217. .addClass("dropped")
  218. .css({
  219. "position": "static",
  220. "left": null,
  221. "right": null
  222. })
  223. .appendTo(this);
  224. // update id
  225. var id = $orig.find(":input").attr("id");
  226. if (id) {
  227. id = id.split("-").slice(0, -1).join("-") + "-" + (parseInt(id.split("-").slice(-1)[0]) + 1)
  228. $orig.find(":input").attr("id", id);
  229. $orig.find("label").attr("for", id);
  230. }
  231. // tools
  232. $('<p class="tools col-sm-12 col-sm-offset-3">\
  233. <a class="edit-link">编辑HTML<a> | \
  234. <a class="remove-link">移除</a></p>').appendTo($el);
  235. } else {
  236. if ($(this)[0] != $orig.parent()[0]) {
  237. var $el = $orig
  238. .clone()
  239. .css({
  240. "position": "static",
  241. "left": null,
  242. "right": null
  243. })
  244. .appendTo(this);
  245. $orig.remove();
  246. }
  247. }
  248. }
  249. }).sortable();
  250. }
  251. var get_modal = function (content) {
  252. var modal = $('<div class="modal" style="overflow: auto;" tabindex="-1">\
  253. <div class="modal-dialog">\
  254. <div class="modal-content">\
  255. <div class="modal-header">\
  256. <a type="button" class="close"\
  257. data-dismiss="modal" aria-hidden="true">&times;</a>\
  258. <h4 class="modal-title">编辑HTML</h4>\
  259. </div>\
  260. <div class="modal-body ui-front">\
  261. <textarea class="form-control" \
  262. style="min-height: 200px; margin-bottom: 10px;\
  263. font-family: Monaco, Fixed">' + content + '</textarea>\
  264. <button class="btn btn-success">更新HTML</button>\
  265. </div>\
  266. </div>\
  267. </div>\
  268. </div>').appendTo(document.body);
  269. return modal;
  270. };
  271. $(document).on("click", ".edit-link", function (ev) {
  272. var $el = $(this).parent().parent();
  273. var $el_copy = $el.clone();
  274. var $edit_btn = $el_copy.find(".edit-link").parent().remove();
  275. var $modal = get_modal(html_beautify($el_copy.html())).modal("show");
  276. $modal.find(":input:first").focus();
  277. $modal.find(".btn-success").click(function (ev2) {
  278. var html = $modal.find("textarea").val();
  279. if (!html) {
  280. $el.remove();
  281. } else {
  282. $el.html(html);
  283. $edit_btn.appendTo($el);
  284. }
  285. $modal.modal("hide");
  286. return false;
  287. })
  288. });
  289. $(document).on("click", ".remove-link", function (ev) {
  290. $(this).parent().parent().remove();
  291. });
  292. </script>
  293. <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
  294. <!--统计代码,可删除-->
  295. </body>
  296. </html>