vue_jqxscrollview.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <div v-bind:id="id">
  3. <slot></slot>
  4. </div>
  5. </template>
  6. <script>
  7. import '../jqwidgets/jqxcore.js';
  8. import '../jqwidgets/jqxbuttons.js';
  9. import '../jqwidgets/jqxscrollview.js';
  10. export default {
  11. props: {
  12. animationDuration: Number,
  13. bounceEnabled: Boolean,
  14. buttonsOffset: Array,
  15. currentPage: Number,
  16. disabled: Boolean,
  17. height: [Number, String],
  18. moveThreshold: Number,
  19. showButtons: Boolean,
  20. slideShow: Boolean,
  21. slideDuration: Number,
  22. theme: String,
  23. width: [Number, String],
  24. autoCreate: {
  25. default: true,
  26. type: Boolean
  27. }
  28. },
  29. created: function () {
  30. this.id = 'jqxScrollView' + JQXLite.generateID();
  31. this.componentSelector = '#' + this.id;
  32. },
  33. mounted: function () {
  34. if (this.autoCreate) this.__createComponent__();
  35. },
  36. methods: {
  37. createComponent: function (options) {
  38. if (!this.autoCreate) this.__createComponent__(options)
  39. else console.warn('Component is already created! If you want to use createComponent, please set "autoCreate" property to "false".');
  40. },
  41. setOptions: function (options) {
  42. JQXLite(this.componentSelector).jqxScrollView(options);
  43. },
  44. getOptions: function () {
  45. const usedProps = Object.keys(this.__manageProps__());
  46. const resultToReturn = {};
  47. for (let i = 0; i < usedProps.length; i++) {
  48. resultToReturn[usedProps[i]] = JQXLite(this.componentSelector).jqxScrollView(usedProps[i]);
  49. }
  50. return resultToReturn;
  51. },
  52. back: function() {
  53. JQXLite(this.componentSelector).jqxScrollView('back');
  54. },
  55. changePage: function(index) {
  56. JQXLite(this.componentSelector).jqxScrollView('changePage', index);
  57. },
  58. forward: function() {
  59. JQXLite(this.componentSelector).jqxScrollView('forward');
  60. },
  61. refresh: function() {
  62. JQXLite(this.componentSelector).jqxScrollView('refresh');
  63. },
  64. _animationDuration: function(arg) {
  65. if (arg !== undefined) {
  66. JQXLite(this.componentSelector).jqxScrollView('animationDuration', arg)
  67. } else {
  68. return JQXLite(this.componentSelector).jqxScrollView('animationDuration');
  69. }
  70. },
  71. _bounceEnabled: function(arg) {
  72. if (arg !== undefined) {
  73. JQXLite(this.componentSelector).jqxScrollView('bounceEnabled', arg)
  74. } else {
  75. return JQXLite(this.componentSelector).jqxScrollView('bounceEnabled');
  76. }
  77. },
  78. _buttonsOffset: function(arg) {
  79. if (arg !== undefined) {
  80. JQXLite(this.componentSelector).jqxScrollView('buttonsOffset', arg)
  81. } else {
  82. return JQXLite(this.componentSelector).jqxScrollView('buttonsOffset');
  83. }
  84. },
  85. _currentPage: function(arg) {
  86. if (arg !== undefined) {
  87. JQXLite(this.componentSelector).jqxScrollView('currentPage', arg)
  88. } else {
  89. return JQXLite(this.componentSelector).jqxScrollView('currentPage');
  90. }
  91. },
  92. _disabled: function(arg) {
  93. if (arg !== undefined) {
  94. JQXLite(this.componentSelector).jqxScrollView('disabled', arg)
  95. } else {
  96. return JQXLite(this.componentSelector).jqxScrollView('disabled');
  97. }
  98. },
  99. _height: function(arg) {
  100. if (arg !== undefined) {
  101. JQXLite(this.componentSelector).jqxScrollView('height', arg)
  102. } else {
  103. return JQXLite(this.componentSelector).jqxScrollView('height');
  104. }
  105. },
  106. _moveThreshold: function(arg) {
  107. if (arg !== undefined) {
  108. JQXLite(this.componentSelector).jqxScrollView('moveThreshold', arg)
  109. } else {
  110. return JQXLite(this.componentSelector).jqxScrollView('moveThreshold');
  111. }
  112. },
  113. _showButtons: function(arg) {
  114. if (arg !== undefined) {
  115. JQXLite(this.componentSelector).jqxScrollView('showButtons', arg)
  116. } else {
  117. return JQXLite(this.componentSelector).jqxScrollView('showButtons');
  118. }
  119. },
  120. _slideShow: function(arg) {
  121. if (arg !== undefined) {
  122. JQXLite(this.componentSelector).jqxScrollView('slideShow', arg)
  123. } else {
  124. return JQXLite(this.componentSelector).jqxScrollView('slideShow');
  125. }
  126. },
  127. _slideDuration: function(arg) {
  128. if (arg !== undefined) {
  129. JQXLite(this.componentSelector).jqxScrollView('slideDuration', arg)
  130. } else {
  131. return JQXLite(this.componentSelector).jqxScrollView('slideDuration');
  132. }
  133. },
  134. _theme: function(arg) {
  135. if (arg !== undefined) {
  136. JQXLite(this.componentSelector).jqxScrollView('theme', arg)
  137. } else {
  138. return JQXLite(this.componentSelector).jqxScrollView('theme');
  139. }
  140. },
  141. _width: function(arg) {
  142. if (arg !== undefined) {
  143. JQXLite(this.componentSelector).jqxScrollView('width', arg)
  144. } else {
  145. return JQXLite(this.componentSelector).jqxScrollView('width');
  146. }
  147. },
  148. __createComponent__: function (options) {
  149. let widgetOptions;
  150. options ? widgetOptions = options : widgetOptions = this.__manageProps__();
  151. JQXLite(this.componentSelector).jqxScrollView(widgetOptions);
  152. this.__extendProps__();
  153. this.__wireEvents__();
  154. },
  155. __manageProps__: function () {
  156. const widgetProps = ['animationDuration','bounceEnabled','buttonsOffset','currentPage','disabled','height','moveThreshold','showButtons','slideShow','slideDuration','theme','width'];
  157. const componentProps = this.$options.propsData;
  158. let options = {};
  159. for (let prop in componentProps) {
  160. if (widgetProps.indexOf(prop) !== -1) {
  161. options[prop] = componentProps[prop];
  162. }
  163. }
  164. return options;
  165. },
  166. __extendProps__: function () {
  167. const that = this;
  168. Object.defineProperty(that, 'animationDuration', {
  169. get: function() {
  170. return that._animationDuration();
  171. },
  172. set: function(newValue) {
  173. that._animationDuration(newValue);
  174. },
  175. enumerable: true,
  176. configurable: true
  177. });
  178. Object.defineProperty(that, 'bounceEnabled', {
  179. get: function() {
  180. return that._bounceEnabled();
  181. },
  182. set: function(newValue) {
  183. that._bounceEnabled(newValue);
  184. },
  185. enumerable: true,
  186. configurable: true
  187. });
  188. Object.defineProperty(that, 'buttonsOffset', {
  189. get: function() {
  190. return that._buttonsOffset();
  191. },
  192. set: function(newValue) {
  193. that._buttonsOffset(newValue);
  194. },
  195. enumerable: true,
  196. configurable: true
  197. });
  198. Object.defineProperty(that, 'currentPage', {
  199. get: function() {
  200. return that._currentPage();
  201. },
  202. set: function(newValue) {
  203. that._currentPage(newValue);
  204. },
  205. enumerable: true,
  206. configurable: true
  207. });
  208. Object.defineProperty(that, 'disabled', {
  209. get: function() {
  210. return that._disabled();
  211. },
  212. set: function(newValue) {
  213. that._disabled(newValue);
  214. },
  215. enumerable: true,
  216. configurable: true
  217. });
  218. Object.defineProperty(that, 'height', {
  219. get: function() {
  220. return that._height();
  221. },
  222. set: function(newValue) {
  223. that._height(newValue);
  224. },
  225. enumerable: true,
  226. configurable: true
  227. });
  228. Object.defineProperty(that, 'moveThreshold', {
  229. get: function() {
  230. return that._moveThreshold();
  231. },
  232. set: function(newValue) {
  233. that._moveThreshold(newValue);
  234. },
  235. enumerable: true,
  236. configurable: true
  237. });
  238. Object.defineProperty(that, 'showButtons', {
  239. get: function() {
  240. return that._showButtons();
  241. },
  242. set: function(newValue) {
  243. that._showButtons(newValue);
  244. },
  245. enumerable: true,
  246. configurable: true
  247. });
  248. Object.defineProperty(that, 'slideShow', {
  249. get: function() {
  250. return that._slideShow();
  251. },
  252. set: function(newValue) {
  253. that._slideShow(newValue);
  254. },
  255. enumerable: true,
  256. configurable: true
  257. });
  258. Object.defineProperty(that, 'slideDuration', {
  259. get: function() {
  260. return that._slideDuration();
  261. },
  262. set: function(newValue) {
  263. that._slideDuration(newValue);
  264. },
  265. enumerable: true,
  266. configurable: true
  267. });
  268. Object.defineProperty(that, 'theme', {
  269. get: function() {
  270. return that._theme();
  271. },
  272. set: function(newValue) {
  273. that._theme(newValue);
  274. },
  275. enumerable: true,
  276. configurable: true
  277. });
  278. Object.defineProperty(that, 'width', {
  279. get: function() {
  280. return that._width();
  281. },
  282. set: function(newValue) {
  283. that._width(newValue);
  284. },
  285. enumerable: true,
  286. configurable: true
  287. });
  288. },
  289. __wireEvents__: function () {
  290. const that = this;
  291. JQXLite(this.componentSelector).on('pageChanged', function (event) { that.$emit('pageChanged', event); });
  292. }
  293. }
  294. }
  295. </script>