<commit_before>// Copyright (c) 2016, <NAME> (http://haralampi.com). All rights reserved.
// Use of this source code is governed by MIT license that can be found in the LICENSE file.
part of wedit;

class Page {

	String _host, _site, _path;

	String _title;
	String get title => _title;
	set title(String t) => _title = t;

	Map<String, Map> _mappedElementsData;
	Map<String, Map> _mappedRepeatsData;
	Map<String, Map> _mappedImagesData;

	Map<String, Element> _elements;
	Map<String, Image> _images;
	Map<String, Repeat> _repeats;

	bool _ctrlPressed = false;
	bool get ctrlPressed => _ctrlPressed;

	Message _message;

	Page.fromMap(Map map) {
		_host = map[PAGE_HOST];
		_site = map[PAGE_SITE];
		_path = map[PAGE_PATH];

		_title = map[PAGE_TITLE];

		_elements = new Map<String, Element>();
		_images = new Map<String, Image>();
		_repeats = new Map<String, Repeat>();

		_mappedElementsData = new Map<String, Map>();
		map[PAGE_ELEMENTS].forEach((e) => _mappedElementsData[e[ELEMENT_KEY]] = e);

		_mappedRepeatsData = new Map<String, Map>();
		map[PAGE_REPEATS].forEach((r) => _mappedRepeatsData[r[REPEAT_KEY]] = r);

		_mappedImagesData = new Map<String, Map>();
		map[PAGE_IMAGES].forEach((r) => _mappedImagesData[r[IMAGE_KEY]] = r);

		_syncElements();
		_bindEvents();

		html.window.dispatchEvent(new html.Event("varReady"));

		_message = new Message();
		//_pageMenu = new PageMenu(this);
	}

	Map toMap() {
		Map map = new Map();

		map[PAGE_HOST] = _host;
		map[PAGE_SITE] = _site;
		map[PAGE_PATH] = _path;

		map[PAGE_TITLE] = _title;

		List eList = new List();
		_elements.values.forEach((e) => eList.add(e.toMap()));
		map[PAGE_ELEMENTS] = eList;

		List rList = new List();
		_repeats.values.forEach((r) => rList.add(r.toMap()));
		map[PAGE_REPEATS] = rList;

    List iList = new List();
		_images.values.forEach((i) => iList.add(i.toMap()));
		map[PAGE_IMAGES] = iList;

		return map;
	}

	void registerElement(html.Element domElement) {
		var key = domElement.dataset["var"];

		if (key == null || key.isEmpty) return;

    if(Image.SUPPORTED_IMAGE_TAGS.contains(domElement.tagName.toLowerCase())) {

      Map cmsData = _mappedImagesData[key];

      Image image = new Image.fromMap(
        this, key, domElement, cmsData);

      _images[key] = image;

      image.render();
      return;
    }


      print("register element:" + domElement.tagName);

		Map cmsData = _mappedElementsData[key];

		Element element = new Element.fromMap(
			this, key, domElement, cmsData);

		_elements[key] = element;

		element.render();
	}

	void unregisterElement(html.Element domElement) {
		var key = domElement.dataset["var"];

    if(Image.SUPPORTED_IMAGE_TAGS.contains(domElement.tagName.toLowerCase())) {
      var image = _images[key];
      image.prepareDomForHtmlSave();
      _images.remove(key);
      return;
    }

    var element = _elements[key];
    element.prepareDomForHtmlSave();
		_elements.remove(key);
	}

	void _syncElements() {
		html.document.title = _title;

		List<html.Element> repeatedDomElements = new List<html.Element>();

		html.ElementList<html.Element> domElements = html
			.querySelectorAll("[data-var],[data-var-repeat]");

		for (int i = 0; i < domElements.length; i++) {
			html.Element domElement = domElements[i];

			String key = domElement.dataset["var-repeat"];

			if (key != null && !key.isEmpty) {
				Map cmsData = _mappedRepeatsData[key];

				Repeat repeat = new Repeat.fromMap(
					this, key, domElement, cmsData);
				_repeats[key] = repeat;

				List<html.Element> repeatedElements = repeat.render();

				for (int ri = 0; ri < repeatedElements.length; ri++) {
					_processDomElement(repeatedElements[ri]);
				}

				continue;
			}

			_processDomElement(domElement);

		}
	}

	void _processDomElement(html.Element domElement) {
		String key = domElement.dataset["var"];

		if (key == null || key.isEmpty) return;

		String elementTag = domElement.tagName.toLowerCase();

		if(Image.SUPPORTED_IMAGE_TAGS.contains(elementTag)) {

      Map cmsData = _mappedImagesData[key];

			Image image = new Image.fromMap(
				this, key, domElement, cmsData
			);
			_images[key] = image;

			image.render();
			return;
		}

		Map cmsData = _mappedElementsData[key];

		Element element = new Element.fromMap(
			this, key, domElement, cmsData);
		_elements[key] = element;

		element.render();
	}

	void _bindEvents() {
		html.window.onKeyDown.listen(_windowKeyDown);
		html.window.onKeyUp.listen(_windowKeyUp);
	}

	void _windowKeyDown(html.KeyboardEvent e) {

		if (e.ctrlKey && e.keyCode == html.KeyCode.S) {
			save();
		}
<commit_msg>fixing windows chrome save page bug<commit_after>// Copyright (c) 2016, <NAME> (http://haralampi.com). All rights reserved.
// Use of this source code is governed by MIT license that can be found in the LICENSE file.
part of wedit;

class Page {

	String _host, _site, _path;

	String _title;
	String get title => _title;
	set title(String t) => _title = t;

	Map<String, Map> _mappedElementsData;
	Map<String, Map> _mappedRepeatsData;
	Map<String, Map> _mappedImagesData;

	Map<String, Element> _elements;
	Map<String, Image> _images;
	Map<String, Repeat> _repeats;

	bool _ctrlPressed = false;
	bool get ctrlPressed => _ctrlPressed;

	Message _message;

	Page.fromMap(Map map) {
		_host = map[PAGE_HOST];
		_site = map[PAGE_SITE];
		_path = map[PAGE_PATH];

		_title = map[PAGE_TITLE];

		_elements = new Map<String, Element>();
		_images = new Map<String, Image>();
		_repeats = new Map<String, Repeat>();

		_mappedElementsData = new Map<String, Map>();
		map[PAGE_ELEMENTS].forEach((e) => _mappedElementsData[e[ELEMENT_KEY]] = e);

		_mappedRepeatsData = new Map<String, Map>();
		map[PAGE_REPEATS].forEach((r) => _mappedRepeatsData[r[REPEAT_KEY]] = r);

		_mappedImagesData = new Map<String, Map>();
		map[PAGE_IMAGES].forEach((r) => _mappedImagesData[r[IMAGE_KEY]] = r);

		_syncElements();
		_bindEvents();

		html.window.dispatchEvent(new html.Event("varReady"));

		_message = new Message();
		//_pageMenu = new PageMenu(this);
	}

	Map toMap() {
		Map map = new Map();

		map[PAGE_HOST] = _host;
		map[PAGE_SITE] = _site;
		map[PAGE_PATH] = _path;

		map[PAGE_TITLE] = _title;

		List eList = new List();
		_elements.values.forEach((e) => eList.add(e.toMap()));
		map[PAGE_ELEMENTS] = eList;

		List rList = new List();
		_repeats.values.forEach((r) => rList.add(r.toMap()));
		map[PAGE_REPEATS] = rList;

    List iList = new List();
		_images.values.forEach((i) => iList.add(i.toMap()));
		map[PAGE_IMAGES] = iList;

		return map;
	}

	void registerElement(html.Element domElement) {
		var key = domElement.dataset["var"];

		if (key == null || key.isEmpty) return;

    if(Image.SUPPORTED_IMAGE_TAGS.contains(domElement.tagName.toLowerCase())) {

      Map cmsData = _mappedImagesData[key];

      Image image = new Image.fromMap(
        this, key, domElement, cmsData);

      _images[key] = image;

      image.render();
      return;
    }


      print("register element:" + domElement.tagName);

		Map cmsData = _mappedElementsData[key];

		Element element = new Element.fromMap(
			this, key, domElement, cmsData);

		_elements[key] = element;

		element.render();
	}

	void unregisterElement(html.Element domElement) {
		var key = domElement.dataset["var"];

    if(Image.SUPPORTED_IMAGE_TAGS.contains(domElement.tagName.toLowerCase())) {
      var image = _images[key];
      image.prepareDomForHtmlSave();
      _images.remove(key);
      return;
    }

    var element = _elements[key];
    element.prepareDomForHtmlSave();
		_elements.remove(key);
	}

	void _syncElements() {
		html.document.title = _title;

		List<html.Element> repeatedDomElements = new List<html.Element>();

		html.ElementList<html.Element> domElements = html
			.querySelectorAll("[data-var],[data-var-repeat]");

		for (int i = 0; i < domElements.length; i++) {
			html.Element domElement = domElements[i];

			String key = domElement.dataset["var-repeat"];

			if (key != null && !key.isEmpty) {
				Map cmsData = _mappedRepeatsData[key];

				Repeat repeat = new Repeat.fromMap(
					this, key, domElement, cmsData);
				_repeats[key] = repeat;

				List<html.Element> repeatedElements = repeat.render();

				for (int ri = 0; ri < repeatedElements.length; ri++) {
					_processDomElement(repeatedElements[ri]);
				}

				continue;
			}

			_processDomElement(domElement);

		}
	}

	void _processDomElement(html.Element domElement) {
		String key = domElement.dataset["var"];

		if (key == null || key.isEmpty) return;

		String elementTag = domElement.tagName.toLowerCase();

		if(Image.SUPPORTED_IMAGE_TAGS.contains(elementTag)) {

      Map cmsData = _mappedImagesData[key];

			Image image = new Image.fromMap(
				this, key, domElement, cmsData
			);
			_images[key] = image;

			image.render();
			return;
		}

		Map cmsData = _mappedElementsData[key];

		Element element = new Element.fromMap(
			this, key, domElement, cmsData);
		_elements[key] = element;

		element.render();
	}

	void _bindEvents() {
		html.window.onKeyDown.listen(_windowKeyDown);
		html.window.onKeyUp.listen(_windowKeyUp);
	}

	void _windowKeyDown(html.KeyboardEvent e) {

		if (e.ctrlKey && e.keyCode == html.KeyCode.S) {
			save();
      // Stop the browser default behaivier
      e.stopPropagation();
      e.stopImmediatePropagation();
      e.preventDefault();
		}

{'fraction_non_alphanumeric': 0.14027584732171497, 'fraction_numerical': 0.0012830107986742223, 'mean_word_length': 3.8769551616266944, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '181403', 'n_tokens_mistral': 3553, 'n_tokens_neox': 3198, 'n_words': 693}