⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sectionstack.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 4 页
字号:
                    // isOpen = section.autoShow || section.showHeader == false;                    section.autoShow || section.showHeader == false;            if (section.hidden == null) section.hidden = false;            // normalize items to Arrays            if (section.items == null) section.items = [];            else if (!isc.isA.Array(section.items)) section.items = [section.items];            // create a header for each section, which will also serve as the section itself.            // NOTE: if showHeader is false, we still create a header object to represent the            // section and track it's position in the members array, but it will never be            // show()n, hence never drawn            var headerClass = isc.ClassFactory.getClass(this.sectionHeaderClass),                sectionHeader = headerClass.createRaw();            sectionHeader.autoDraw = false;            sectionHeader._generated = true;            sectionHeader.expanded = expanded;            sectionHeader.isSectionHeader = true;            // Suppress double clicks on section headers            sectionHeader.noDoubleClicks = true;                        // if you specify hidden:true and expanded: true, then expanded wins            sectionHeader.visibility = (section.hidden || section.showHeader == false) ?                 isc.Canvas.HIDDEN : isc.Canvas.INHERIT;            // a section header drag is an internal resize, never an external drop (until we            // implement tear-offs)            sectionHeader.dragScrollType = "parentsOnly";            sectionHeader.dragScrollDirection =                 this.vertical ? isc.Canvas.VERTICAL : isc.Canvas.HORIZONTAL;            sectionHeader.layout = this;            if (this.vertical) sectionHeader.height = this.headerHeight;            else sectionHeader.width = this.headerHeight;            // if the user has specified an ID, pass that through under a renamed property _ID            // so as not to incur a global, then restore the ID on the object they passed in so            // as not to modify the user-passed object (they may reference the ID property on            // their object later or even reuse the constructor)                        if (section.ID != null) {                section._ID = section.ID;                delete section.ID;            }            isc.addProperties(sectionHeader, section);            if (section._ID != null) {                section.ID = section._ID;                delete section._ID;            }            sectionHeader.completeCreation();            section = sectionHeader;            this.sections.addAt(section, position+i);            this.addMember(section, this._getSectionPosition(section));            // expand any non-collapsed sections.  This will add the section's items as members             if (expanded && !section.hidden) {                this.expandSection(section);                // remember last section to be expanded                this._lastExpandedSection = section;            // If it's not expanded - ensure any drawn section items are cleared since they may            // have been drawn outside the sectionStack's scope            } else {                for (var ii = 0; ii < section.items.length; ii++) {                    var item = section.items[ii];                    if (item.parentElement && item.parentElement != this) item.deparent();                    // note: item may not have yet been created                    if (isc.isA.Canvas(item) && item.isDrawn()) item.clear();                }            }            // apply resizeability flag to items            if (section.items) {                if (!this.canResizeSections) section.items.setProperty("resizeable", false);                else if (section.resizeable != null) {                    // allow both an explicit true and explicit false value.                    // - false allows fixed-sized sections                    // - true forces inherent height members to be resizeable                    section.items.setProperty("resizeable", section.resizeable);                }            }        }                // if we were asked to make sure one section gets shown, show the first section if none        // were marked expanded:true        if (expandOne && this._lastExpandedSection == null) {            var firstSectionConfig = sections.first();            // NOTE: avoid forcing open the first section if it's config marked it explicitly            // not expanded            if (!(firstSectionConfig.expanded == false)) {                var firstSection = this.sections.first();                this.expandSection(firstSection);                this._lastExpandedSection = firstSection;            }        }    },    //> @method sectionStack.addSection()    //    // Add a section to the SectionStack.    //    // @param sections  (SectionStackSection Properties | List of SectionStackSection Properties) Initialization block    //                  for the section or a list of initialization blocks to add.    // @param [position]    (number) index for the new section(s) (if not specified, the section    //                      will be added at the end of the SectionStack).    //    // @visibility external    // @example sectionsAddAndRemove    //<    addSection : function (sections, position) {        this.addSections(sections, position);    },    //> @method sectionStack.removeSection()    //    // Remove a section or set of sections from the SectionStack.  The removed sections' header    // and items (if any) are automatically destroyed.    //    // @param sections  (position|sectionId|list of sectionIDs) Section(s) to remove.  For this    //                  parameter, you can pass the position of the section in the    //                  SectionStack, the ID of the section, or a List of sectionIDs    //    // @visibility external    // @example sectionsAddAndRemove    //<    removeSection : function (section) {        section = this.getSectionHeader(section);        this.removeMembers(section.items);        this.sections.remove(section);        section.destroy();    },        //> @method sectionStack.getSections()    //    // Returns a list of all sectionIDs in the order in which they appear in the SectionStack.    //    // @return (List) list of all sectionIDs in the order in which they appear in the SectionStack.    // @visibility external    //<    getSections : function () {        return this.sections.getProperty("_ID");    },    //> @method sectionStack.reorderSection()    //    // Reorder the sections by shifting the specified section to a new position    //    // @param section  (position|sectionId) Section to move.  You can pass the position     //                      of the section in the SectionStack or the ID of the section.        // @param position   (number) new position index for the section.    //    // @deprecated As of SmartClient version 5.5, use +link{sectionStack.moveSection}.    //    // @visibility external    //<    reorderSection : function (section, newPosition) {        this.moveSection(section, newPosition);    },    //> @method sectionStack.moveSection()    //    // Moves the specified section(s) to a new position in the SectionStack order.  If you pass    // in multiple sections, then each section will be moved to <code>newPosition</code> in the    // order specified by the <code>sections</code> argument.    //    // @param sections  (position|sectionId|list of sectionIDs) Section(s) to move.  For this    //                  parameter, you can pass the position of the section in the    //                  SectionStack, the ID of the section, or a List of sectionIDs    //    // @param position    (number) new position index for the section(s).    //    // @visibility external    //<    moveSection : function (sections, newPosition) {        if (!isc.isAn.Array(sections)) sections = [sections];                for (var i = 0; i < sections.length; i++) {            var section = this.getSectionHeader(sections[i]);            if (section == null || newPosition == null) continue;                    // determine the current position of the section            var position = this.sections.indexOf(section);                    // determine the current and new positions for the members            var start = this.members.indexOf(section),                end = start+1;            // If the section is open, its items will be visible members            // Otherwise when it is opened, they wall automatically be added as members /             // repositioned by the 'showSection' call            if (this.sectionIsExpanded(section) && section.items)                 end += section.items.length;                                var newMemberPosition = this.members.indexOf(this.sections[newPosition]);                    // actually update the arrays            this.sections.slide(position, newPosition);            // this will also cause a reflow            this.reorderMembers(start, end, newMemberPosition);        }    },    //> @method sectionStack.showSection()    //     // Shows a section or sections.  This includes the section header and its items.  If the    // section is collapsed, only the header is shown.  If the section is expanded, the section    // header and all items are shown.    //    // @param sections (position|sectionId|list of sectionIDs)    //                      Section(s) to show.  For this parameter, you can pass the position     //                      of the section in the SectionStack, the ID of the section, or a    //                      List of sectionIDs    // @param [callback] callback to fire when the sections have been expanded.        //    // @see sectionStack.expandSection    // @see sectionStack.scrollSectionIntoView    // @visibility external    // @example sectionsShowAndHide    //<    showSection : function (sections, callback) {        this._showSection(sections, true, false, callback);    },    //> @method sectionStack.expandSection()    //     // Expands a section or sections.  This action shows all the items assigned to the section.    // If the section is currently hidden, it is shown first and then expanded.  Calling this    // method is equivalent to the user clicking on the SectionHeader of a collapsed section.    //    // @param sections (position|sectionId|list of sectionIDs)    //                      Section(s) to expand.  For this parameter, you can pass the position     //                      of the section in the SectionStack, the ID of the section, or a    //                      List of sectionIDs    // @param [callback] callback to fire when the section has been expanded.     //    // @see sectionStack.showSection    // @see sectionStack.scrollSectionIntoView    // @visibility external    // @example sectionsExpandCollapse    //<    expandSection : function (sections, callback) {        this._showSection(sections, false, true, callback);      },    _showSection : function (sections, showSection, expandSection, callback) {        if (!isc.isAn.Array(sections)) sections = [sections];        var itemsToShow = [];        for (var i = 0; i < sections.length; i++) {            var section = this.getSectionHeader(sections[i]);                    // bad section specification            if (section == null) {                this.logWarn("no such section: " + this.echo(sections[i]));                continue;            }            // header - if we're just expanding, but the section is hidden, show it.            if (((showSection && section.showHeader) || expandSection) && section.hidden) {                itemsToShow.add(section);                section.hidden = false;            }            if (expandSection || section.expanded) {                // Backcompat: setOpen is deprecated, but we still want to call it if                // there's a backcompat definition. Otoh it's possible that we just have                // setExpanded, so try that first and then call setOpen                if (section.setExpanded && !section.setOpen) section.setExpanded(true);                else if (section.setOpen) section.setOpen(true);                    // NOTE: a section with no items doesn't make much sense, but it occurs in tools                if (section.items) {                     // handle string names, uninstantiated objects, etc                    this.createCanvii(section.items);                    // ensure the section's members are added, after the section header                    var sectionPosition = this._getSectionPosition(section) + 1;                    // NOTE: don't animate on add because we do the animation on showMembers                    // instead                    this.addMembers(section.items, sectionPosition, true);                    itemsToShow.addList(section.items);                }            }        }        var theStack = this;        this.showMembers(itemsToShow,                          function () { theStack._completeShowOrExpandSection(sections, callback); }                         );    },        // fired as a callback to showMembers() from showSection() and expandSection()    _completeShowOrExpandSection : function (sections, callback) {        // sections is always an array here because this is an internal method and sections is        // normalized by the caller        if (sections.length == 0) return;        // this method jsut scrolls things into view, but if we haven't been drawn yet, then        // there's no need to do anything.        if (this.isDrawn()) {                // scroll the first passed section into view            var section = this.getSectionHeader(sections[0]);                // bring the section that was just shown into the viewport            if (this.vscrollOn && this.scrollSectionIntoView) {                var firstMember = (section.showHeader ? section : section.items.first()),                    lastMember = section.items.last();                        // NOTE: visible height wouldn't be correct until component is drawn                this.delayCall("scrollIntoView",                                 [firstMember.getLeft(), firstMember.getTop(),                                 firstMember.getVisibleWidth(), lastMember.getVisibleHeight(),                                 "left", "top"], 0);            }        }                if (callback != null) this.fireCallback(callback);    },        //> @method sectionStack.hideSection()    //     // Hides a section or sections.  This includes the section header and its items.  The space    // vacated by this action is reassigned to the nearest visible section item above this    // section.  If there are no visible section items above this section, the space is    // reassigned to the nearest visible section item below this section.    //    // @param sections (position|sectionId|list of sectionIDs)    //                      Section(s) to hide.  For this parameter, you can pass the position     //                      of the section in the SectionStack, the ID of the section, or a

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -