/*
Checks if page changed and we need a new start of page block
15999
public function checkForDetailPageStart() // PDF

    {
        //if ( $this->inOverflow )
        //return;

        if ($this->page_detail_started) {
            return;
        }

        $this->draw_mode = "CALCULATE";
        $this->newReportPageLineByStyle("RMB1", $this->mid_page_reportbody_styles, false);
        $this->newReportPageLineByStyle("HMP1", $this->top_page_page_styles, true);
        $this->draw_mode = "DRAW";
        $this->newReportPageLineByStyle("RMB1", $this->mid_page_reportbody_styles, false);
        $this->newReportPageLineByStyle("HMP1", $this->top_page_page_styles, true);
        $this->page_detail_started = true;
    }
802563
function blockNavigation($scope, mainBlockUI, blockUIConfig) {

  if (blockUIConfig.blockBrowserNavigation) {

    function registerLocationChange() {

      $scope.$on('$locationChangeStart', function (event) {

        //        console.log('$locationChangeStart', mainBlockUI.$_blockLocationChange + ' ' + mainBlockUI.state().blockCount);

        if (mainBlockUI.$_blockLocationChange && mainBlockUI.state().blockCount > 0) {
          event.preventDefault();
        }
      });

      $scope.$on('$locationChangeSuccess', function () {
        mainBlockUI.$_blockLocationChange = blockUIConfig.blockBrowserNavigation;

        //        console.log('$locationChangeSuccess', mainBlockUI.$_blockLocationChange + ' ' + mainBlockUI.state().blockCount);
      });
    }

    if (moduleLoaded('ngRoute')) {

      // After the initial content has been loaded we'll spy on any location
      // changes and discard them when needed.

      var fn = $scope.$on('$viewContentLoaded', function () {

        // Unhook the view loaded and hook a function that will prevent
        // location changes while the block is active.

        fn();
        registerLocationChange();

      });

    } else {
      registerLocationChange();
    }

  }
}
1134206
function( page ) {

            if ( this.nextButton ) {
                if(!this.tileSources || this.tileSources.length - 1 === page) {
                    //Disable next button
                    if ( !this.navPrevNextWrap ) {
                        this.nextButton.disable();
                    }
                } else {
                    this.nextButton.enable();
                }
            }
            if ( this.previousButton ) {
                if ( page > 0 ) {
                    //Enable previous button
                    this.previousButton.enable();
                } else {
                    if ( !this.navPrevNextWrap ) {
                        this.previousButton.disable();
                    }
                }
            }
      }
1333852
function checkSelectionChange()
	{
		try
		{
			// In IE, the "selectionchange" event may still get thrown when
			// releasing the WYSIWYG mode, so we need to check it first.
			var sel = this.getSelection();
			if ( !sel || !sel.document.getWindow().$ )
				return;

			var firstElement = sel.getStartElement();
			var currentPath = new CKEDITOR.dom.elementPath( firstElement );

			if ( !currentPath.compare( this._.selectionPreviousPath ) )
			{
				this._.selectionPreviousPath = currentPath;
				this.fire( 'selectionChange', { selection : sel, path : currentPath, element : firstElement } );
			}
		}
		catch (e)
		{}
	}
719028
function (pageIndex, callback, noPageCheck) {

            if (this.$loadingPage) {
                if (callback) {
                    callback();
                }
                return;
            }
            var self = this;

            function cb(err) {
                if (callback) {
                    callback(err);
                }
                self.$loadingPage = false;
            }

            if (this.hasPage(pageIndex)) {
                this.$loadingPage = true;

                var i;
                pageIndex = pageIndex || 0;
                noPageCheck = _.isUndefined(noPageCheck) ? true : noPageCheck;

                if (!this.$.baseList || (!noPageCheck && pageIndex === this.$.page)) {
                    // nothing to do
                    cb();
                    return;
                }

                var list = this.$.list;
                var baseList = this.$.baseList;

                list.clear();

                // add items
                var startIndex = this.$.pageSize * pageIndex;
                if (baseList.$items.length > startIndex) {
                    for (i = 0; i < this.$.pageSize; i++) {
                        list.add(baseList.at(startIndex + i));
                    }
                }


                if (baseList instanceof Collection) {
                    // determinate pages to load based on the page size
                    var collectionPageSize = this.$.baseList.$.pageSize;

                    var collectionStartPage = this._itemIndexToPageIndex(this._pageIndexToItemIndex(pageIndex), collectionPageSize);
                    var collectionEndPage = this._itemIndexToPageIndex(this._pageIndexToItemIndex(pageIndex + 1) - 1, collectionPageSize);

                    var pageIndices = {};
                    for (i = collectionStartPage; i <= collectionEndPage; i++) {
                        pageIndices[i] = i;
                    }


                    flow()
                        .seq("execId", function () {
                            return ++self.$execId;
                        })
                        .parEach(pageIndices, function (pageIndex, cb) {
                            baseList.fetchPage(pageIndex, null, cb);
                        })
                        .exec(function (err, results) {

                            if (!err && results.execId == self.$execId) {
                                var items = [];
                                for (i = collectionStartPage; i <= collectionEndPage; i++) {
                                    items = items.concat(results[i].$items);
                                }

                                self._calculatePageCount();


                                var viewStartIndex = self._pageIndexToItemIndex(pageIndex, self.$.pageSize);
                                viewStartIndex -= collectionStartPage * collectionPageSize;
                                if (viewStartIndex < items.length) {
                                    // remove overlapping at start and end
                                    items = items.slice(viewStartIndex, viewStartIndex + self.$.pageSize);

                                    // and reset list
                                    self.$.list.reset(items);
                                }
                            }
                            self.set('page', pageIndex);
                            cb(err);
                        });

                } else {
                    self._calculatePageCount();
                    self.set('page', pageIndex);
                    cb();
                }
            } else {
                this._calculatePageCount();
                cb();
            }

        }
393259
function checkOpenBlocks(blocks, html) {
	var issues = [];
	var lines = html.split('\n');
	blocks.forEach(function(block) {
		var issue = checkOpenBlock(block, lines);
		if (issue) issues.push(issue);
	});
	return issues;
}
653677
function(changeIndex) {
			var count = 0;
			var blockIndex = 0;
			
			if (0 <= changeIndex) {
				// iterate through blocks looking for the one that contains 
				// the change with the specified changeIndex
				while (blockIndex < this._root.children.length) {
					var numChangesInCurrentBlock = this._root.children[blockIndex].children.length;
					if (((count + numChangesInCurrentBlock) - 1) < changeIndex) {
						count += numChangesInCurrentBlock; //keep going
					} else {
						// found block, go to change in block
						var changeIndexInBlock = changeIndex - count;
						return this.gotoBlock(blockIndex, changeIndexInBlock);
					}
					blockIndex++;
				}
			}
		}
1267820
def on(page_class, browser = @browser)
      page = page_class.new(browser)
      yield page if block_given?
      page
    end
219555
def previous_page(self):
        
        if self.is_first_page():
            return False

        self.page -= 1
        self.items = self.fetch_items()
        return True
414111
function pollInterstitialPage() {
            if (keepPolling && Inspector.connected()) {
                Inspector.Runtime.evaluate("window.isBracketsLiveDevelopmentInterstitialPageLoaded", function (response) {
                    var result = response.result;

                    if (result.type === "boolean" && result.value) {
                        window.clearTimeout(timer);
                        deferred.resolve();
                    } else {
                        window.setTimeout(pollInterstitialPage, 100);
                    }
                });
            } else {
                deferred.reject();
            }
        }
685800
function detectChangesInternal(hostView, hostNode, component) {
    var oldView = enterView(hostView, hostNode);
    var hostTView = hostView[TVIEW];
    var template = hostTView.template;
    var viewQuery = hostTView.viewQuery;
    try {
        namespaceHTML();
        createViewQuery(viewQuery, hostView[FLAGS], component);
        template(getRenderFlags(hostView), component);
        refreshView();
        updateViewQuery(viewQuery, component);
    }
    finally {
        leaveView(oldView);
    }
}
659903
function() {
            if (this.started) {
                logging.warn("routing history already started");
                return false;
            }

            var self = this;
            var $window = $(window);
            var rootUrl = document.location.protocol+'//'+(document.location.hostname||document.location.host);

            logging.log("start routing history");
            $window.bind('hashchange', _.bind(this._handleCurrentState, this));

            var ret = this._handleCurrentState();
            this.started = true;

            return ret;
        }
36896
function(event) {
        var changed = false;
        if(this.features) {
            if(this.num === null) {
                this.num = -1;
            }
            var start = (this.num + 1) * this.length;
            changed = this.page(start, event);
        }
        return changed;
    }
679971
def check(self, action, page=None, lang=None, method=None):
        """"""
        if self.user.is_superuser:
            return True

        if action == 'change':
            return self.has_change_permission(page, lang, method)

        if action == 'delete':
            if not self.delete_page():
                return False
            return True
        if action == 'add':
            if not self.add_page():
                return False
            return True
        if action == 'freeze':
            perm = self.user.has_perm('pages.can_freeze')
            if perm:
                return True
            return False
        if action == 'publish':
            perm = self.user.has_perm('pages.can_publish')
            if perm:
                return True
            return False

        return False
604443
private void processModifiedPage(PageModificationContext context) {
        PageWrapper page = context.getPageWrapper();
        boolean emptyPage = page.getPage().getCount() == 0;
        ByteArraySegment pageKey = page.getPageKey();
        if (emptyPage && page.getParent() != null) {
            // This page is empty. Remove it from the PageCollection (so we don't write it back to our data source)
            // and remember its Page Key so we can delete its pointer from its parent page.
            context.getPageCollection().remove(page);
            context.setDeletedPageKey(pageKey);
        } else {
            // This page needs to be kept around.
            if (emptyPage && page.getPage().getConfig().isIndexPage()) {
                // We have an empty Index Root Page. We must convert this to a Leaf Page before moving on.
                page.setPage(createEmptyLeafPage());
            }

            // Assign a new offset to the page and record its new Page Pointer.
            context.pageCollection.complete(page);
            page.setMinOffset(calculateMinOffset(page));
            context.updatePagePointer(new PagePointer(pageKey, page.getOffset(), page.getPage().getLength(), page.getMinOffset()));
        }
    }
126207
function toolbarChanged() {
	var updatedUrl, value,
		field = this,
		params = {};

	// Detect if field is a select menu or a checkbox
	if ( "selectedIndex" in field ) {
		value = field.options[ field.selectedIndex ].value || undefined;
	} else {
		value = field.checked ? ( field.defaultValue || true ) : undefined;
	}

	params[ field.name ] = value;
	updatedUrl = setUrl( params );

	if ( "hidepassed" === field.name && "replaceState" in window.history ) {
		config[ field.name ] = value || false;
		if ( value ) {
			addClass( id( "qunit-tests" ), "hidepass" );
		} else {
			removeClass( id( "qunit-tests" ), "hidepass" );
		}

		// It is not necessary to refresh the whole page
		window.history.replaceState( null, "", updatedUrl );
	} else {
		window.location = updatedUrl;
	}
}
152444
boolean compareAndSetLeaf(Page oldPage, Page page)
  {
    if (oldPage == page) {
      return true;
    }
    
    int pid = (int) page.getId();
    
    updateTailPid(pid);
    
    if (oldPage instanceof PageLeafImpl && page instanceof PageLeafImpl) {
      PageLeafImpl oldLeaf = (PageLeafImpl) oldPage;
      PageLeafImpl newLeaf = (PageLeafImpl) page;
      
      if (BlockTree.compareKey(oldLeaf.getMaxKey(), newLeaf.getMaxKey(), 0) < 0) {
        System.err.println(" DERP: " + oldPage + " " + page);
        Thread.dumpStack();
        /*
        throw new IllegalStateException("DERP: old=" + oldPage + " " + page
                                        + " old-dirt:" + oldPage.isDirty());
                                        */
      }
    }
    
    boolean result = _pages.compareAndSet(pid, oldPage, page);
    
    return result;
  }