sync-options.client.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. (function (angular) {
  2. const SECTION_NAME = "sync-options";
  3. angular
  4. .module("BrowserSync")
  5. .controller("SyncOptionsController", [
  6. "Socket",
  7. "options",
  8. "pagesConfig",
  9. SyncOptionsController
  10. ]);
  11. /**
  12. * @param Socket
  13. * @param options
  14. * @param pagesConfig
  15. * @constructor
  16. */
  17. function SyncOptionsController(Socket, options, pagesConfig) {
  18. var ctrl = this;
  19. ctrl.options = options.bs;
  20. ctrl.section = pagesConfig[SECTION_NAME];
  21. ctrl.setMany = function (value) {
  22. Socket.uiEvent({
  23. namespace: SECTION_NAME,
  24. event: "setMany",
  25. data: {
  26. value: value
  27. }
  28. });
  29. ctrl.syncItems = ctrl.syncItems.map(function (item) {
  30. item.value = value;
  31. return item;
  32. });
  33. };
  34. /**
  35. * Toggle Options
  36. * @param item
  37. */
  38. ctrl.toggleSyncItem = function (item) {
  39. Socket.uiEvent({
  40. namespace: SECTION_NAME,
  41. event: "set",
  42. data: {
  43. path: item.path,
  44. value: item.value
  45. }
  46. });
  47. };
  48. ctrl.syncItems = [];
  49. var taglines = {
  50. clicks: "Mirror clicks across devices",
  51. scroll: "Mirror scroll position across devices",
  52. "ghostMode.submit": "Form Submissions will be synced",
  53. "ghostMode.inputs": "Text inputs (including text-areas) will be synced",
  54. "ghostMode.toggles": "Radio + Checkboxes changes will be synced",
  55. codeSync: "Reload or Inject files they change"
  56. };
  57. // If watching files, add the code-sync toggle
  58. ctrl.syncItems.push(addItem("codeSync", ["codeSync"], ctrl.options.codeSync, taglines["codeSync"]));
  59. Object.keys(ctrl.options.ghostMode).forEach(function (item) {
  60. if (item !== "forms" && item !== "location") {
  61. ctrl.syncItems.push(addItem(item, ["ghostMode", item], ctrl.options.ghostMode[item], taglines[item]));
  62. }
  63. });
  64. Object.keys(ctrl.options.ghostMode.forms).forEach(function (item) {
  65. ctrl.syncItems.push(addItem("Forms: " + item, ["ghostMode", "forms", item], ctrl.options.ghostMode["forms"][item], taglines["ghostMode." + item]));
  66. });
  67. function addItem (item, path, value, tagline) {
  68. return {
  69. value: value,
  70. name: item,
  71. path: path,
  72. title: ucfirst(item),
  73. tagline: tagline
  74. };
  75. }
  76. }
  77. function ucfirst (string) {
  78. return string.charAt(0).toUpperCase() + string.slice(1);
  79. }
  80. })(angular);