Takes care of page tree insertion important for a fresh page
352065
private function SaveNew()
    {
        $treeBuilder = new TreeBuilder(new PageTreeProvider($this->site));
        $treeBuilder->Insert($this->page, $this->parent, $this->previous);
    }
802748
function insertContent(pageNum) {
        var $pageOverlay = $pages.eq(pageNum - 1).find('.crocodoc-page-autoscale');
        var $content = $(util.template(config.template, {
            pageNum: pageNum
        }));

        // listen for click events on the buttons
        $content.find('.add-page-btn').on('click', function (event) {
            addPage(pageNum);
            event.stopPropagation();
        });
        $content.find('.remove-page-btn').on('click', function (event) {
            removePage(pageNum);
            event.stopPropagation();
        });

        $pageOverlay.append($content);
    }
203216
private void selectPage(long offset) {
    if (currentBuffer == null || currentBuffer.seekSuccessful(offset)) {
      currentBuffer = null;
      int i = 0;

      // Look if the given offset is already stored in a page
      while (i < pages.size() && currentBuffer == null) {
        if (pages.get(i).seekSuccessful(offset))
          currentBuffer = pages.get(i);
        i++;
      }

      if (currentBuffer == null) {
        // If the offset is not contained in any of the loaded pages, create a new one

        // FIFO
        if (pages.size() >= MaxPages)
          pages.remove(0);
        pages.add(new InputBuffer(input));

        currentBuffer = pages.get(pages.size() - 1);
      }
    }
  }
283361
public function eventAfterInsert()
    {
        $this->updateNavItemTimesamp();
        $this->reindex($this->nav_item_page_id, $this->placeholder_var, $this->prev_id);
        Log::add(1, ['tableName' => 'cms_nav_item_page_block_item', 'action' => 'insert', 'row' => $this->id, 'pageTitle' => $this->droppedPageTitle, 'blockName' => $this->block->getNameForLog()], 'cms_nav_item_page_block_item', $this->id);
    }
802211
function pageInfoFromParent() {
        var msgBody = getData()
        log('PageInfoFromParent called from parent: ' + msgBody)
        onPageInfo(JSON.parse(msgBody))
        log(' --')
      }
738548
function () {
                var items = this.items;
                var itemsLength = items.length;
                var pageSize = this.pageSize;
                if (pageSize <= 0) {
                    pageSize = -1;
                }
                var pages = [], pageLength = 0;
                var pageIndex = 0;
                var nbElementsInPage = 0;
                var firstElement = -1;
                for (var i = 0; i < itemsLength; i++) {
                    var elt = items[i];
                    if (elt.filteredIn) {
                        if (nbElementsInPage === 0) {
                            firstElement = i;
                        }
                        nbElementsInPage++;
                        elt.pageIndex = pageIndex;
                        if (nbElementsInPage == pageSize) {
                            pages[pageLength++] = {
                                pageIndex : pageIndex,
                                pageNumber : pageIndex + 1,
                                firstItemIndex : firstElement,
                                lastItemIndex : i,
                                firstItemNumber : pageIndex * pageSize + 1,
                                lastItemNumber : (pageIndex + 1) * pageSize
                            };
                            pageIndex++;
                            nbElementsInPage = 0;
                        }
                    } else {
                        elt.pageIndex = -1;
                    }
                }
                this._currentState.pageSize = pageSize;
                this.pageMode = (pageSize > 0);
                this.filteredInCount = pageIndex * pageSize + nbElementsInPage; // true even when pageMode == false (as
                // pageIndex == 0)
                if (nbElementsInPage > 0) {
                    pages[pageLength++] = {
                        pageIndex : pageIndex,
                        pageNumber : pageIndex + 1,
                        firstItemIndex : firstElement,
                        lastItemIndex : itemsLength - 1,
                        firstItemNumber : pageIndex * pageSize + 1,
                        lastItemNumber : this.filteredInCount
                    };
                }
                if (pageLength === 0) {
                    // there always must be at least one page
                    pages = this.EMPTY_PAGES;
                }
                this.pages = pages;
            }
828720
function ConfigureWebPageElements(n) {
        RED.nodes.createNode(this, n);

        this.usecount = 0;

        this.name = n.name;
        this.expression = n.expression;
        this.selector = n.selector;
        this.page = n.page;
        this.markers = n.markers;
        this.framePath = n.framePath;

        let node = this;
        // node.log(n);
        this.register = function() {
            node.usecount += 1;
        };

        this.deregister = function() {
            node.usecount -= 1;
            if (node.usecount == 0) {
            }
        };
    }
726887
def insertLink(page, lnk, mark = True):
    
    CheckParent(page)
    annot = getLinkText(page, lnk)
    if annot == "":
        raise ValueError("link kind not supported")

    page._addAnnot_FromString([annot])
    return
85229
function prependTo(newNode, parentNode, siblingNode) {
  parentNode.insertBefore(newNode, siblingNode || parentNode.firstChild);
}
55397
function nextPage () {
    if (!ctrl.canPageForward()) { return; }

    var newOffset = MdTabsPaginationService.increasePageOffset(getElements(), ctrl.offsetLeft);

    ctrl.offsetLeft = fixOffset(newOffset);
  }
1060783
private void handleRequest(
		ChainWriter out,
		WebSiteRequest req,
		HttpServletResponse resp,
		List<? extends TreePageData> tree,
		int scrollToX,
		int scrollToY,
		boolean[] opened
	) throws IOException, SQLException {
		WebPageLayout layout=getWebPageLayout(req);
		layout.startContent(out, req, resp, 1, getPreferredContentWidth(req));
		layout.printContentTitle(out, req, resp, this, 1);
		layout.printContentHorizontalDivider(out, req, resp, 1, false);
		layout.startContentLine(out, req, resp, 1, null, null);
		try {
			// Get the tree data
			int treeLen = tree.size();

			// Break apart each line
			String[][] paths = getLines(tree);

			if (opened == null) {
				// Default to opened for first item
				opened = new boolean[treeLen];
				if (treeLen > 0) opened[0] = true;
			}

			// Write the javascript that controls the form
			out.print("<script type='text/javascript'>\n"
					+ "  // <![CDATA[\n"
					+ "  function openNode(index) {\n"
					+ "    eval('document.forms[\"tree_form\"].opened_'+index+'.value=\"true\";');\n"
					+ "    document.forms[\"tree_form\"].scroll_to_x.value=getPageXOffset(window);\n"
					+ "    document.forms[\"tree_form\"].scroll_to_y.value=getPageYOffset(window);\n"
					+ "    document.forms[\"tree_form\"].submit();\n"
					+ "  }\n"
					+ "\n"
					+ "  function closeNode(index) {\n"
					+ "    eval('document.forms[\"tree_form\"].opened_'+index+'.value=\"false\";');\n"
					+ "    document.forms[\"tree_form\"].scroll_to_x.value=getPageXOffset(window);\n"
					+ "    document.forms[\"tree_form\"].scroll_to_y.value=getPageYOffset(window);\n"
					+ "    document.forms[\"tree_form\"].submit();\n"
					+ "  }\n"
					+ "  // ]]>\n"
					+ "</script>\n");

			// Write the form containing the current settings
			out.print("<form action='' id='tree_form' method='post'><div>\n");
			req.printFormFields(out, 1);
			out.print("  <input type='hidden' name='scroll_to_x' value='").print(scrollToX).print("' />\n"
					+ "  <input type='hidden' name='scroll_to_y' value='").print(scrollToY).print("' />\n");
			for(int c=0; c<treeLen; c++) {
				out.print("  <input type='hidden' name='opened_").print(c).print("' value='").print(opened[c]).print("' />\n");
			}

			// Display the tree in a table with links for opening/closing the different parts
			out.print("  <table cellspacing='0' cellpadding='0'>\n");

			String[] last = AoArrays.EMPTY_STRING_ARRAY;
			for (int c = 0; c < treeLen; c++) {
				String[] path = paths[c];
				int pathLen = path.length;

				// Every parent must be open for this to be visible
				boolean visible = true;
				Loop2 :
					for (int d = 0; d < (pathLen - 1); d++) {
						// Find the first row that has all the path up to current step
						for (int e = 0; e < c; e++) {
							String[] parentpath = paths[e];
							if (parentpath.length > d) {
								boolean isParent = true;
								for (int f = 0; f <= d; f++) {
									if (!parentpath[f].equals(path[f])) {
										isParent = false;
										break;
									}
								}
								if (isParent) {
									if (!opened[e]) {
										visible = false;
										break Loop2;
									}
									break;
								}
							}
						}
					}
					if (visible) {
						out.print("    <tr>\n"
								+ "      <td style='white-space:nowrap; border:0px;'><table cellspacing='0' cellpadding='0'><tr><td style='white-space:nowrap; border:0px;'>");

						int max = Math.min(pathLen - 1, last.length);
						int pos = 0;

						// Skip the part of the path that is already displayed by the parent
						for (; pos < max; pos++) {
							if (last[pos].equals(path[pos])) {
								boolean hasMore = false;
								for (int d = c + 1; d < treeLen; d++) {
									int end = pos;
									for (int e = 0; e < end; e++) {
										if (paths[d][e].equals(path[e])) {
											if (e == (end - 1) && !paths[d][end].equals(path[end])) {
												hasMore = true;
												break;
											}
										} else break;
									}
								}
								out.print("<img src='").encodeXmlAttribute(resp.encodeURL(req.getContextPath()+req.getURL(this, "image_num="+(hasMore?1:0)))).print("' style='border:0px; display:inline; vertical-align:bottom;' width='"+IMAGE_WIDTH+"' height='"+IMAGE_HEIGHT+"' alt='' />");
							} else break;
						}

						// Display the remaining part of the path
						for(; pos < pathLen; pos++) {
							if(path[pos].length()>0) {
								// Determine has sub items
								boolean hasSub = false;
								if (c < (treeLen - 1)) {
									String[] next_path = paths[c + 1];
									if (next_path.length >= pathLen) {
										hasSub = true;
										for (int e = 0; e < pathLen; e++) {
											String tempPath=path[e];
											if(tempPath.length()>0 && !tempPath.equals(next_path[e])) {
												hasSub = false;
												break;
											}
										}
									}
								}

								// Determine if the line continues farther down
								boolean hasMore = false;
								for (int d = c; d < treeLen; d++) {
									int end = pos;
									for (int e = 0; e < end; e++) {
										if (paths[d][e].equals(path[e])) {
											if (e == (end - 1) && !paths[d][end].equals(path[end])) {
												hasMore = true;
												break;
											}
										} else break;
									}
								}

								if(hasSub) {
									out
										.print("<a href='javascript:")
										.print(opened[c] ? "closeNode(" : "openNode(")
										.print(c)
										.print(");'><img alt='").print(opened[c] ? "Close" : "Open")
										.print("' src='")
										.encodeXmlAttribute(
											resp.encodeURL(
												req.getContextPath()+req.getURL(
													this,
													"image_num="+(
														opened[c]
														? (hasMore ? 4 : (c > 0 ? 5 : 9))
														: (hasMore ? 6 : (c > 0 ? 7 : 8))
													)
												)
											)
										).print("' style='vertical-align:bottom; border:0px; display:inline;' width='"+IMAGE_WIDTH+"' height='"+IMAGE_HEIGHT+"' /></a>");
								} else {
									out
										.print("<img src='")
										.encodeXmlAttribute(
											resp.encodeURL(
												req.getContextPath()+req.getURL(
													this,
													"image_num="+(hasMore ? 2 : 3)
												)
											)
										).print("' style='vertical-align:bottom; border:0px; display:inline;' width='"+IMAGE_WIDTH+"' height='"+IMAGE_HEIGHT+"' alt='' />");
								}
								out.print("<img src='").encodeXmlAttribute(resp.encodeURL(req.getContextPath()+req.getURL(this, "image_num=0"))).print("' style='vertical-align:bottom; border:0px; display:inline;' width='4' height='"+IMAGE_HEIGHT+"' alt='' /></td><td style='white-space:nowrap'>");
							}

							boolean useCodeFont=useCodeFont(req);
							if (useCodeFont) out.print("<code>");
							String href;
							if(
								(
									(pathLen>=2 && pos==(pathLen-2) && path[pathLen-1].length()==0)
									|| (pos==(pathLen-1) && path[pathLen-1].length()>0)
								) && (href = tree.get(c).getUrl()) != null
							) {
								out.print("<a class='aoLightLink' href='").encodeXmlAttribute(resp.encodeURL(href)).print("'>").print(path[pos]).print("</a>");
							} else if(path[pos].length()>0) out.print(path[pos]);
							if(useCodeFont) out.print("</code>");
						}

						out.print("</td></tr></table></td>\n"
								+ "      <td style='white-space:nowrap; width:20px'><img src='").encodeXmlAttribute(resp.encodeURL(req.getContextPath()+req.getURL(this, "image_num=0"))).print("' style='vertical-align:bottom; border:0px; display:inline;' width='20' height='1' alt='' /></td>\n"
								+ "      <td style='white-space:nowrap'>");
						String description=tree.get(c).getDescription();
						if(description!=null) out.print(description);
						out.print("</td>\n"
								+ "    </tr>\n");
						last = path;
					}
			}

			out.print("  </table>\n"
					+ "</div></form>\n");
		} finally {
			layout.endContentLine(out, req, resp, 1, false);
			layout.endContent(this, out, req, resp, 1);
		}
	}
591098
def node_insert_before(self, node, new_node):
        """"""

        assert(not self.node_is_on_list(new_node))
        assert(node is not new_node)

        prev = self.node_prev(node)
        assert(prev is not None)
        self.node_set_prev(node, new_node)
        self.node_set_next(new_node, node)

        self.node_set_prev(new_node, prev)
        self.node_set_next(prev, new_node)
578028
private Entry insertHereWithSplit(Entry toInsert, Node insertNode,
			long timestamp) {
		//Handle root split
   	    if (insertNode.getEntries()[0].getParentEntry()==null){
   	    	root.makeOlder(timestamp, negLambda);
   	    	Entry irrelevantEntry = insertNode.getIrrelevantEntry(this.weightThreshold);
   	        int numFreeEntries = insertNode.numFreeEntries();
   	        if (irrelevantEntry != null) {
   		        irrelevantEntry.overwriteOldEntry(toInsert);
   	        }
   	        else if (numFreeEntries>0){
   	        	insertNode.addEntry(toInsert, timestamp);
   	        }
   	        else{
	            this.numRootSplits++;
	            this.height += this.height < this.maxHeight ? 1 : 0;
	            Entry oldRootEntry = new Entry(this.numberDimensions,
	                    root, timestamp, null, null);
	            Node newRoot = new Node(this.numberDimensions,
	                    this.height);
	            Entry newRootEntry = split(toInsert, root, oldRootEntry, timestamp);
	            newRoot.addEntry(oldRootEntry, timestamp);
	            newRoot.addEntry(newRootEntry, timestamp);
	            this.root = newRoot;
	            for (Entry c : oldRootEntry.getChild().getEntries())
	            	c.setParentEntry(root.getEntries()[0]);
	            for (Entry c : newRootEntry.getChild().getEntries())
	            	c.setParentEntry(root.getEntries()[1]);
   	        }
            return null;
   	    }
   	    insertNode.makeOlder(timestamp, negLambda);
    	Entry irrelevantEntry = insertNode.getIrrelevantEntry(this.weightThreshold);
        int numFreeEntries = insertNode.numFreeEntries();
        if (irrelevantEntry != null) {
	        irrelevantEntry.overwriteOldEntry(toInsert);
        }
        else if (numFreeEntries>0){
        	insertNode.addEntry(toInsert, timestamp);
        }
        else {
	            // We have to split.
	        	Entry parentEntry = insertNode.getEntries()[0].getParentEntry();
	        	Entry residualEntry = split(toInsert, insertNode, parentEntry, timestamp);
	        	if (alsoUpdate!=null){
	        		alsoUpdate = residualEntry;
	        	}
	        	Node nodeForResidualEntry = insertNode.getEntries()[0].getParentEntry().getNode();
	        	//recursive call
	        	return insertHereWithSplit(residualEntry, nodeForResidualEntry, timestamp);
	    }
        
        //no Split
        return null;
	}
65677
function(node) {
        this.logger.log("insertAfter: " + node);
        var p = node.parent;
        if (p) {

            if (this.tree) {
                this.tree.popNode(this);
            }

            var refIndex = node.isChildOf(p);
            this.logger.log(refIndex);

            if (!node.nextSibling) {
                this.nextSibling = null;
                return this.appendTo(p);
            }

            p.children.splice(refIndex + 1, 0, this);

            node.nextSibling.previousSibling = this;
            this.previousSibling = node;
            this.nextSibling = node.nextSibling;
            node.nextSibling = this;

            this.applyParent(p);
        }

        return this;
    }
529946
function mergePageWithBasePage( page, basePage ) {
      const extendingAreas = page.definition.areas;
      const mergedPageAreas = deepClone( basePage.definition.areas );
      if( has( basePage.definition, 'layout' ) ) {
         if( has( page.definition, 'layout' ) ) {
            throw formatError( page, `Page overwrites layout set by base page "${basePage.name}"` );
         }
         page.definition.layout = basePage.definition.layout;
      }

      Object.keys( extendingAreas ).forEach( areaName => {
         const itemList = extendingAreas[ areaName ];
         if( !( areaName in mergedPageAreas ) ) {
            mergedPageAreas[ areaName ] = itemList;
            return;
         }

         mergeItemLists( mergedPageAreas[ areaName ], itemList, page );
      } );

      page.definition.areas = mergedPageAreas;
   }
468538
public void moveBefore( Row item )
	{
		if( this == item )
			return;

		Element lastTrToMove = getLastLeafTR();
		Element firstChildRow = DOM.getNextSibling( m_tr );

		// remove from its current position
		Row parentItem = m_parent;
		if( parentItem == null )
			parentItem = this.treeTable.m_rootItem;
		parentItem.getChilds().remove( this );

		// insert at the selected position
		if( item == null )
		{
			// insert at the end of the current parent

			// DOM add
			Row lastLeaf = parentItem.getLastLeaf();
			Element trToInsertAfter = lastLeaf.m_tr;
			if( trToInsertAfter != null )
			{
				int after = DOM.getChildIndex( this.treeTable.m_body, trToInsertAfter );
				int before = after + 1;

				DOM.insertChild( this.treeTable.m_body, m_tr, before );
			}
			else
			{
				DOM.appendChild( this.treeTable.m_body, m_tr );
			}

			parentItem.getChilds().add( this );
		}
		else
		{
			Row newParentItem = item.m_parent;
			if( newParentItem == null )
				newParentItem = this.treeTable.m_rootItem;
			int itemPos = item.m_parent.getChilds().indexOf( item );
			newParentItem.getChilds().add( itemPos, this );
			DOM.insertBefore( this.treeTable.m_body, m_tr, item.m_tr );
		}

		// take care of the left padding
		Element firstTd = DOM.getChild( m_tr, 0 );
		firstTd.getStyle().setPaddingLeft( getLevel() * this.treeTable.treePadding, Unit.PX );

		// update child rows
		Element nextTR = DOM.getNextSibling( m_tr );
		if( firstChildRow != null && lastTrToMove != null && hasChilds() )
		{
			while( true )
			{
				Element next = DOM.getNextSibling( firstChildRow );
				DOM.insertBefore( this.treeTable.m_body, firstChildRow, nextTR );
				if( firstChildRow == lastTrToMove )
					break;
				firstChildRow = next;
			}
		}
	}
836200
function insertContent(pageNum) {
        var $page = $pages.eq(pageNum - 1).find('.crocodoc-page-inner');
        var $content = $(util.template(config.template, {
            pageInfo: config.pageInfos[pageNum - 1] || config.defaultInfo
        }));

        $page.append($content);
        // listen for click events on the buttons
        $page.find('.front').on('click', function (event) {
            showPageInfo(pageNum);
            event.stopPropagation();
        });
    }