|
420 | 420 | }
|
421 | 421 |
|
422 | 422 | // It opens edit mode by default (for now);
|
423 |
| - self._eeState.edit = true; |
| 423 | + if (!self.is('edit') && !self.is('preview')) { |
| 424 | + self._eeState.edit = true; |
| 425 | + } |
424 | 426 |
|
425 | 427 | callback = callback || function () {};
|
426 | 428 |
|
|
547 | 549 | _elementStates = {}
|
548 | 550 | self._goFullscreen = function (el) {
|
549 | 551 |
|
550 |
| - if (self._eeState.fullscreen) { |
| 552 | + if (self.is('fullscreen')) { |
551 | 553 | self._exitFullscreen(el);
|
552 | 554 | return;
|
553 | 555 | }
|
|
556 | 558 | el.webkitRequestFullScreen();
|
557 | 559 | }
|
558 | 560 |
|
559 |
| - _isInEdit = self._eeState.edit; |
| 561 | + _isInEdit = self.is('edit'); |
560 | 562 |
|
561 | 563 | // Set the state of EE in fullscreen
|
562 | 564 | // We set edit and preview to true also because they're visible
|
|
674 | 676 | window.clearTimeout(keypressTimer);
|
675 | 677 | }
|
676 | 678 | keypressTimer = window.setTimeout(function () {
|
677 |
| - if (self._eeState.fullscreen) { |
| 679 | + if (self.is('fullscreen')) { |
678 | 680 | self.preview();
|
679 | 681 | }
|
680 | 682 | }, 250);
|
|
743 | 745 | if (e.keyCode == 17) { isCtrl = true } // check for ctrl/cmnd press, in order to catch ctrl/cmnd + s
|
744 | 746 |
|
745 | 747 | // Check for alt+p and make sure were not in fullscreen - default shortcut to switch to preview
|
746 |
| - if (isMod === true && e.keyCode == self.settings.shortcut.preview && !self._eeState.fullscreen) { |
| 748 | + if (isMod === true && e.keyCode == self.settings.shortcut.preview && !self.is('fullscreen')) { |
747 | 749 | e.preventDefault();
|
748 |
| - if (self._eeState.edit) { |
| 750 | + if (self.is('edit')) { |
749 | 751 | self.preview();
|
750 | 752 | }
|
751 | 753 | else {
|
|
765 | 767 | }
|
766 | 768 |
|
767 | 769 | // When a user presses "esc", revert everything!
|
768 |
| - if (e.keyCode == 27 && self._eeState.fullscreen) { |
| 770 | + if (e.keyCode == 27 && self.is('fullscreen')) { |
769 | 771 | self._exitFullscreen(fsElement);
|
770 | 772 | }
|
771 | 773 |
|
|
820 | 822 | window.addEventListener('resize', function () {
|
821 | 823 | // If NOT webkit, and in fullscreen, we need to account for browser resizing
|
822 | 824 | // we don't care about webkit because you can't resize in webkit's fullscreen
|
823 |
| - if (!self.iframe.webkitRequestFullScreen && self._eeState.fullscreen) { |
| 825 | + if (!self.iframe.webkitRequestFullScreen && self.is('fullscreen')) { |
824 | 826 | _applyStyles(self.iframeElement, {
|
825 | 827 | 'width': window.outerWidth + 'px'
|
826 | 828 | , 'height': window.innerHeight + 'px'
|
|
841 | 843 | });
|
842 | 844 | }
|
843 | 845 | // Makes the editor support fluid width when not in fullscreen mode
|
844 |
| - else if (!self._eeState.fullscreen) { |
| 846 | + else if (!self.is('fullscreen')) { |
845 | 847 | resetWidth(elementsToResize);
|
846 | 848 | }
|
847 | 849 | });
|
848 | 850 |
|
849 |
| - self.iframe.close(); |
| 851 | + // Set states before flipping edit and preview modes |
850 | 852 | self._eeState.loaded = true;
|
851 | 853 | self._eeState.unloaded = false;
|
| 854 | + |
| 855 | + if (self.is('preview')) { |
| 856 | + self.preview(); |
| 857 | + } |
| 858 | + else { |
| 859 | + self.edit(); |
| 860 | + } |
| 861 | + |
| 862 | + self.iframe.close(); |
852 | 863 | // The callback and call are the same thing, but different ways to access them
|
853 | 864 | callback.call(this);
|
854 | 865 | this.emit('load');
|
|
862 | 873 | EpicEditor.prototype.unload = function (callback) {
|
863 | 874 |
|
864 | 875 | // Make sure the editor isn't already unloaded.
|
865 |
| - if (this._eeState.unloaded) { |
| 876 | + if (this.is('unloaded')) { |
866 | 877 | throw new Error('Editor isn\'t loaded');
|
867 | 878 | }
|
868 | 879 |
|
|
907 | 918 | self.previewer.innerHTML = self.exportFile(null, 'html');
|
908 | 919 |
|
909 | 920 | // Hide the editor and display the previewer
|
910 |
| - if (!self._eeState.fullscreen) { |
| 921 | + if (!self.is('fullscreen')) { |
911 | 922 | self.editorIframe.style.display = 'none';
|
912 | 923 | self.previewerIframe.style.display = 'block';
|
913 | 924 | self._eeState.preview = true;
|
|
924 | 935 | * @returns {object} EpicEditor will be returned
|
925 | 936 | */
|
926 | 937 | EpicEditor.prototype.enterFullscreen = function () {
|
927 |
| - if (this._eeState.fullscreen) { return this; } |
| 938 | + if (this.is('fullscreen')) { return this; } |
928 | 939 | this._goFullscreen(this.iframeElement);
|
929 | 940 | return this;
|
930 | 941 | }
|
|
934 | 945 | * @returns {object} EpicEditor will be returned
|
935 | 946 | */
|
936 | 947 | EpicEditor.prototype.exitFullscreen = function () {
|
937 |
| - if (!this._eeState.fullscreen) { return this; } |
| 948 | + if (!this.is('fullscreen')) { return this; } |
938 | 949 | this._exitFullscreen(this.iframeElement);
|
939 | 950 | return this;
|
940 | 951 | }
|
|
973 | 984 |
|
974 | 985 | // Check that the given string is a possible option and verify the editor isn't unloaded
|
975 | 986 | // without this, you'd be given a reference to an object that no longer exists in the DOM
|
976 |
| - if (!available[name] || this._eeState.unloaded) { |
| 987 | + if (!available[name] || this.is('unloaded')) { |
977 | 988 | return null;
|
978 | 989 | }
|
979 | 990 | else {
|
980 | 991 | return available[name];
|
981 | 992 | }
|
982 | 993 | }
|
983 | 994 |
|
| 995 | + /** |
| 996 | + * Returns a boolean of each "state" of the editor. For example "editor.is('loaded')" // returns true/false |
| 997 | + * @param {String} what the state you want to check for |
| 998 | + * @returns {Boolean} |
| 999 | + */ |
984 | 1000 | EpicEditor.prototype.is = function (what) {
|
985 | 1001 | var self = this;
|
986 | 1002 | switch (what) {
|
|
1137 | 1153 |
|
1138 | 1154 | self.save();
|
1139 | 1155 |
|
1140 |
| - if (self._eeState.fullscreen) { |
| 1156 | + if (self.is('fullscreen')) { |
1141 | 1157 | self.preview();
|
1142 | 1158 | }
|
1143 | 1159 |
|
|
0 commit comments